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