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
7namespace bs { namespace ct
8{
9 /** @addtogroup RenderAPI-Internal
10 * @{
11 */
12
13 /**
14 * Represents a GPU query that gets triggered when GPU starts processing the query.
15 *
16 * @note
17 * Normally GPU will have many commands in its command buffer. When begin() is called it is placed in that command
18 * buffer. Once the buffer empties and GPU reaches the EventQuery command, the query callback is triggered.
19 * @note
20 * Core thread only.
21 */
22 class BS_CORE_EXPORT EventQuery
23 {
24 public:
25 EventQuery() = default;
26 virtual ~EventQuery() = default;
27
28 /**
29 * Starts the query.
30 *
31 * @param[in] cb Optional command buffer to queue the operation on. If not provided operation
32 * is executed on the main command buffer. Otherwise it is executed when
33 * RenderAPI::executeCommands() is called. Buffer must support graphics or compute operations.
34 *
35 * @note
36 * Once the query is started you may poll isReady() method to check when query has finished, or you may hook up
37 * an #onTriggered callback and be notified that way.
38 */
39 virtual void begin(const SPtr<CommandBuffer>& cb = nullptr) = 0;
40
41 /** Check if GPU has processed the query. */
42 virtual bool isReady() const = 0;
43
44 /** Triggered when GPU starts processing the query. */
45 Event<void()> onTriggered;
46
47 /**
48 * Creates a new query, but does not schedule it on GPU.
49 *
50 * @param[in] deviceIdx Index of the GPU device to create the query on.
51 */
52 static SPtr<EventQuery> create(UINT32 deviceIdx = 0);
53
54 protected:
55 friend class QueryManager;
56
57 /** Returns true if the has still not been completed by the GPU. */
58 bool isActive() const { return mActive; }
59 void setActive(bool active) { mActive = active; }
60
61 protected:
62 bool mActive = false;
63 };
64
65 /** @} */
66}}