BsTimerQuery.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Represents a GPU query that measures execution time of GPU operations. The query will measure
  7. * any GPU operations that take place between its "begin" and "end" calls.
  8. *
  9. * @note Core thread only.
  10. */
  11. class BS_CORE_EXPORT TimerQuery
  12. {
  13. public:
  14. virtual ~TimerQuery() {}
  15. /**
  16. * @brief Starts the counter.
  17. *
  18. * @note Place any commands you want to measure after this call. Call "end" when done.
  19. */
  20. virtual void begin() = 0;
  21. /**
  22. * @brief Stops the counter.
  23. */
  24. virtual void end() = 0;
  25. /**
  26. * @brief Check if GPU has processed the query.
  27. */
  28. virtual bool isReady() const = 0;
  29. /**
  30. * @brief Returns the time it took for the query to execute.
  31. *
  32. * @return The time milliseconds.
  33. *
  34. * @note Only valid after "isReady" returns true.
  35. */
  36. virtual float getTimeMs() = 0;
  37. /**
  38. * @brief Triggered when GPU processes the query. As a parameter
  39. * it provides query duration in milliseconds.
  40. */
  41. Event<void(float)> onTriggered;
  42. /**
  43. * @brief Creates a new query, but does not schedule it on GPU.
  44. */
  45. static TimerQueryPtr create();
  46. protected:
  47. friend class QueryManager;
  48. /**
  49. * @brief Returns true if the has still not been completed by the GPU.
  50. */
  51. bool isActive() const { return mActive; }
  52. void setActive(bool active) { mActive = active; }
  53. protected:
  54. bool mActive;
  55. };
  56. }