BsQueryManager.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #include "BsEventQuery.h"
  6. #include "BsModule.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup RenderAPI-Internal
  10. * @{
  11. */
  12. /**
  13. * Handles creation and destruction of GPU queries.
  14. *
  15. * @note Core thread only.
  16. */
  17. class BS_CORE_EXPORT QueryManager : public Module<QueryManager>
  18. {
  19. public:
  20. QueryManager();
  21. ~QueryManager();
  22. /**
  23. * Creates a new event query that allows you to get notified when GPU starts executing the query.
  24. *
  25. * @param[in] deviceIdx Index of the GPU device to create the query on.
  26. */
  27. virtual SPtr<EventQuery> createEventQuery(UINT32 deviceIdx = 0) const = 0;
  28. /**
  29. * Creates a new timer query that allows you to get notified of how much time has passed between query start and end.
  30. *
  31. * @param[in] deviceIdx Index of the GPU device to create the query on.
  32. */
  33. virtual SPtr<TimerQuery> createTimerQuery(UINT32 deviceIdx = 0) const = 0;
  34. /**
  35. * Creates a new occlusion query that allows you to know how many fragments were rendered between query start and
  36. * end.
  37. *
  38. * @param[in] binary If query is binary it will not give you an exact count of fragments rendered, but will
  39. * instead just return 0 (no fragments were rendered) or 1 (one or more fragments were
  40. * rendered). Binary queries can return sooner as they potentially do not need to wait
  41. * until all of the geometry is rendered.
  42. * @param[in] deviceIdx Index of the GPU device to create the query on.
  43. */
  44. virtual SPtr<OcclusionQuery> createOcclusionQuery(bool binary, UINT32 deviceIdx = 0) const = 0;
  45. /** Triggers completed queries. Should be called every frame. */
  46. void _update();
  47. protected:
  48. friend class EventQuery;
  49. friend class TimerQuery;
  50. friend class OcclusionQuery;
  51. /**
  52. * Deletes an Event query. Always use this method and don't delete them manually. Actual deletion will be delayed
  53. * until next update.
  54. */
  55. static void deleteEventQuery(EventQuery* query);
  56. /**
  57. * Deletes a Timer query. Always use this method and don't delete them manually. Actual deletion will be delayed
  58. * until next update.
  59. */
  60. static void deleteTimerQuery(TimerQuery* query);
  61. /**
  62. * Deletes an Occlusion query. Always use this method and don't delete them manually. Actual deletion will be
  63. * delayed until next update.
  64. */
  65. static void deleteOcclusionQuery(OcclusionQuery* query);
  66. /** Deletes any queued queries. */
  67. void processDeletedQueue();
  68. protected:
  69. mutable Vector<EventQuery*> mEventQueries;
  70. mutable Vector<TimerQuery*> mTimerQueries;
  71. mutable Vector<OcclusionQuery*> mOcclusionQueries;
  72. mutable Vector<EventQuery*> mDeletedEventQueries;
  73. mutable Vector<TimerQuery*> mDeletedTimerQueries;
  74. mutable Vector<OcclusionQuery*> mDeletedOcclusionQueries;
  75. };
  76. /** @} */
  77. }}