BsTimerQuery.h 1.8 KB

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