BsTimerQuery.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 bs { namespace ct
  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. * @param[in] cb Optional command buffer to queue the operation on. If not provided operation
  24. * is executed on the main command buffer. Otherwise it is executed when
  25. * RenderAPI::executeCommands() is called. Buffer must support graphics or compute operations.
  26. *
  27. * @note Place any commands you want to measure after this call. Call "end" when done.
  28. */
  29. virtual void begin(const SPtr<CommandBuffer>& cb = nullptr) = 0;
  30. /**
  31. * Stops the counter.
  32. *
  33. * @param[in] cb Command buffer that was provided to the last begin() operation (if any).
  34. */
  35. virtual void end(const SPtr<CommandBuffer>& cb = nullptr) = 0;
  36. /** Check if GPU has processed the query. */
  37. virtual bool isReady() const = 0;
  38. /**
  39. * Returns the time it took for the query to execute.
  40. *
  41. * @return The time milliseconds.
  42. *
  43. * @note Only valid after isReady() returns true.
  44. */
  45. virtual float getTimeMs() = 0;
  46. /** Triggered when GPU processes the query. As a parameter it provides query duration in milliseconds. */
  47. Event<void(float)> onTriggered;
  48. /**
  49. * Creates a new query, but does not schedule it on GPU.
  50. *
  51. * @param[in] deviceIdx Index of the GPU device to create the query on.
  52. */
  53. static SPtr<TimerQuery> create(UINT32 deviceIdx = 0);
  54. protected:
  55. friend class QueryManager;
  56. /** Returns true if the has still not been completed by the GPU. */
  57. bool isActive() const { return mActive; }
  58. void setActive(bool active) { mActive = active; }
  59. protected:
  60. bool mActive;
  61. };
  62. /** @} */
  63. }}