HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_VKQuery.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_VKQuery.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * Class to handle Vulkan Queries
10  */
11 
12 #ifndef RV_VKQuery_h
13 #define RV_VKQuery_h
14 
15 #include "RV_API.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_Array.h>
19 #include <UT/UT_Span.h>
20 #include <UT/UT_UniquePtr.h>
21 
22 #include <VE/VE_VK.h>
23 
24 #include "RV_VKCommandBuffer.h"
25 
26 class RV_Instance;
27 class RV_Render;
28 class RV_VKBuffer;
29 
31 {
32 public:
33  enum QueryType
34  {
39  };
40 
42  RV_Instance* inst,
43  int count,
45  bool gpu_exclusive);
46 
47  QueryType getType() const { return myType; }
48  bool isGPUExclusive() const { return myIsGPUOnly; }
49  int getSize() const { return myQueryFlags.size(); }
50 
51  // Recording Actions ---------
52  bool begin(RV_VKCommandBuffer* cb, int idx = 0);
53  void end(RV_VKCommandBuffer* cb, int idx = 0);
54  void reset(RV_VKCommandBuffer* cb, int idx = 0);
55  void softReset(int idx = 0);
56 
57  // timestamp only valid for timestamp queries
60  int idx = 0);
61 
62  // acceleratrion structure compact size queries
65  const VkAccelerationStructureKHR* accel_struct,
66  int idx = 0);
67 
68  // Results ---------
69  bool isResultAvailable(RV_Instance* inst, int idx = 0);
70 
71  int32 getResult(RV_Instance* inst, int idx = 0);
72  int64 getLongResult(RV_Instance* inst, int idx = 0);
73 
74  // When called with RV_Render it can flush the CB if needed
75  int32 getResult(RV_Render* r, int idx = 0);
76  int64 getLongResult(RV_Render* inst, int idx = 0);
77 
78  // Write the results and the result status into the buffer `buf`
79  void writeResult(
82  bool wait,
83  int idx = 0);
87  bool wait,
88  int idx = 0);
89 
90  // Lifecycle Queries ---------
91 
92  // IsReset means the Query is completely blank:
93  // it is not active and it will not be modified by the GPU
94  bool isReset(int idx = 0)
95  {
96  auto& flags = myQueryFlags(idx);
97  return !flags.myIsActiveRecording && !flags.myIsFinishedRecording
98  && !flags.myIsSubmitted && !flags.myIsAvailable;
99  }
100 
101  bool isDoneRecording(int idx = 0)
102  {
103  auto& flags = myQueryFlags(idx);
104  return !flags.myIsActiveRecording && flags.myIsFinishedRecording;
105  }
106 
107  bool isSubmitted(int idx = 0)
108  {
109  auto& flags = myQueryFlags(idx);
110  return flags.myIsFinishedRecording && flags.myIsSubmitted;
111  }
112 
113  bool isWaiting(int idx = 0)
114  {
115  auto& flags = myQueryFlags(idx);
116  return flags.myIsFinishedRecording && !flags.myIsAvailable;
117  }
118 
119  ~RV_VKQuery();
120 
121 private:
122  struct PassKey {};
123 public:
124  RV_VKQuery(
125  RV_Instance* inst,
126  int count,
127  VkQueryPool pool,
128  QueryType type,
129  bool gpu_exclusive,
130  const PassKey&);
131 
132 protected:
133  void markSubmitted(int idx);
134 
135  friend class RV_FinishQueryTask;
136 
137 private:
138  bool privGetCPUResult(
139  RV_Instance* inst,
140  int idx,
142  const UT_Span<uint8>& out_data);
143 
144  bool privWait(RV_Instance* inst, int idx);
145  bool privWait(RV_Render r, int idx); // version with RV_Render can flush
146 
147  RV_Instance* myInst;
148  VkQueryPool myVkQuery;
149 
150  // Create Info
151  QueryType myType;
152  int myCount;
153  bool myIsGPUOnly;
154 
155  // TODO: move lifecycle flags to RV_Query or make array
156  // stages: (RECORDING)UNAVAILABLE // after reset
157  // (RECORDING)ACTIVE // after begin
158  // (RECORDING)AVAILABLE // after end
159  // -> Waiting for submission (not available on CPU until submission + wait)
160  // (EXECUTING)ACTIVE // after begin
161  // (EXECUTING)AVAILABLE // after end
162  // (EXECUTING)UNAVAILABLE // after reset
163  // NOTE: GPU-only queries will only care about the RECORDING
164  // stages -- sync can be done of the GPU-timeline
165 
166  // Lifecycle flags
167  // TODO: atomic ? they're local to CB: should only be used on one thread
168  struct QueryFlags
169  {
170  bool myIsResetRecorded = false;
171  bool myIsActiveRecording = false;
172  bool myIsFinishedRecording = false;
173 
174  // flags only used for CPU-access tracking
175  bool myIsSubmitted = false;
176  bool myIsAvailable = false;
177  };
178  UT_Array<QueryFlags> myQueryFlags;
179 };
180 
181 #if 0
182 class RV_TimeStampQuery
183 {
184 public:
185  enum RV_OcclusionResult
186  {
187  BOOLEAN,
188  NUM_SAMPLES
189  };
190  RV_TimerQuery();
191  init(RV_Render* r);
192 
193  void timestamp(RV_VKCommandBuffer* cb);
194  int64 getTimestampNS();
195 
196  void writeResult(RV_VKCommandBuffer* cb, RV_VKBuffer* buf);
197 private:
198  RV_VKQuery myQuery;
199  bool myIsBoolean;
200 }
201 
202 class RV_TimerQuery
203 {
204 public:
205  RV_TimerQuery();
206  init(RV_Render* r);
207 
208  void init(RV_Render* inst);
209  bool begin(RV_VKCommandBuffer *cb);
210  void end(RV_VKCommandBuffer* cb);
211 
212  int64 getTimeNS();
213 
214  void writeResult(RV_VKCommandBuffer* cb, RV_VKBuffer* buf);
215 private:
216  RV_VKQuery myQuery;
217  bool myIsBoolean;
218 }
219 
220 #endif
221 
223 {
224 public:
227 
229  {
231  }
232 
234  : myQuery(query)
235  , myQueryIdx(idx)
236  {}
237 };
238 
240  RV_VKQuery* query,
241  int idx);
242 
243 #endif
GLenum query
Definition: glad.h:2772
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
int64 writeLongResult(RV_VKCommandBuffer *cb, RV_VKBuffer *buf, bool wait, int idx=0)
GLbitfield flags
Definition: glcorearb.h:1596
void end(RV_VKCommandBuffer *cb, int idx=0)
int int32
Definition: SYS_Types.h:39
bool isSubmitted(int idx=0)
Definition: RV_VKQuery.h:107
void writeTimestamp(RV_VKCommandBuffer *cb, VkPipelineStageFlagBits stage=VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, int idx=0)
int32 getResult(RV_Instance *inst, int idx=0)
bool isGPUExclusive() const
Definition: RV_VKQuery.h:48
exint size() const
Definition: UT_Array.h:653
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void writeResult(RV_VKCommandBuffer *cb, RV_VKBuffer *buf, bool wait, int idx=0)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
int64 getLongResult(RV_Instance *inst, int idx=0)
RV_VKQuery * myQuery
Definition: RV_VKQuery.h:225
GLuint GLuint end
Definition: glcorearb.h:475
void reset(RV_VKCommandBuffer *cb, int idx=0)
bool isReset(int idx=0)
Definition: RV_VKQuery.h:94
RV_VKCommandBuffer::Callback RVmakeFinishQueryTask(RV_VKQuery *query, int idx)
void softReset(int idx=0)
long long int64
Definition: SYS_Types.h:116
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:44
void operator()(RV_Instance *)
Definition: RV_VKQuery.h:228
QueryType getType() const
Definition: RV_VKQuery.h:47
*tasks wait()
bool isWaiting(int idx=0)
Definition: RV_VKQuery.h:113
VkPipelineStageFlagBits
Definition: vulkan_core.h:2365
RV_FinishQueryTask(RV_VKQuery *query, int idx)
Definition: RV_VKQuery.h:233
int getSize() const
Definition: RV_VKQuery.h:49
static UT_UniquePtr< RV_VKQuery > createQuery(RV_Instance *inst, int count, QueryType type, bool gpu_exclusive)
RV_VKQuery(RV_Instance *inst, int count, VkQueryPool pool, QueryType type, bool gpu_exclusive, const PassKey &)
GLboolean r
Definition: glcorearb.h:1222
bool begin(RV_VKCommandBuffer *cb, int idx=0)
void writeAccelStructCompactSize(RV_VKCommandBuffer *cb, const VkAccelerationStructureKHR *accel_struct, int idx=0)
A vulkan buffer object.
Definition: RV_VKBuffer.h:81
VkFlags VkQueryResultFlags
Definition: vulkan_core.h:2461
void markSubmitted(int idx)
UT_Function< void(RV_Instance *)> Callback
GLint GLsizei count
Definition: glcorearb.h:405
bool isResultAvailable(RV_Instance *inst, int idx=0)
bool isDoneRecording(int idx=0)
Definition: RV_VKQuery.h:101
**Note that the tasks the is the thread number *for the pool
Definition: thread.h:646
RV_OcclusionResult
Definition: RV_Query.h:24
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:566