HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_Geometry.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_Geometry.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * High level class for wrapping geometry for drawing
10  */
11 
12 #ifndef RV_Geometry_h
13 #define RV_Geometry_h
14 
15 #include "RV_API.h"
16 
17 #include <RE/RE_CachedObject.h>
18 #include <SYS/SYS_Types.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Assert.h>
21 #include <UT/UT_ComputeGPU.h>
22 #include <UT/UT_Matrix4.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringMap.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <UT/UT_ValArray.h>
27 #include <UT/UT_VectorTypes.h>
28 #include <UT/UT_WorkBuffer.h>
29 
30 #include <VE/VE_VK.h>
31 
32 #include "RV_Type.h"
33 #include "RV_TypePtrs.h"
34 #include "RV_VKBuffer.h"
35 
36 class RV_Render;
37 class RV_ShaderBlock;
38 class RV_ShaderProgram;
44 
45 typedef RV_VKBuffer RV_Buffer;
46 
48 {
50 };
51 
53 {
57 };
58 
60 {
61  switch (t)
62  {
74  default : break;
75  }
76 
77  UT_ASSERT_MSG(false, "RVgetVkPrimType Invalid RV_PrimType");
79 }
80 
82 {
83  switch (t)
84  {
85  case RV_GPU_UINT1: return UT_GPU_UINT1;
86  case RV_GPU_UINT4: return UT_GPU_UINT4;
87  case RV_GPU_UINT8: return UT_GPU_UINT8;
88  case RV_GPU_UINT16: return UT_GPU_UINT16;
89  case RV_GPU_UINT32: return UT_GPU_UINT32;
90 
91  case RV_GPU_INT8: return UT_GPU_INT8;
92  case RV_GPU_INT16: return UT_GPU_INT16;
93  case RV_GPU_INT32: return UT_GPU_INT32;
94 
95  case RV_GPU_FLOAT16: return UT_GPU_FLOAT16;
96  case RV_GPU_FLOAT24: return UT_GPU_FLOAT24;
97  case RV_GPU_FLOAT32: return UT_GPU_FLOAT32;
98  case RV_GPU_FLOAT64: return UT_GPU_FLOAT64;
99 
100  case RV_GPU_MATRIX2: return UT_GPU_MATRIX2;
101  case RV_GPU_MATRIX3: return UT_GPU_MATRIX3;
102  case RV_GPU_MATRIX4: return UT_GPU_MATRIX4;
103  default : break;
104  }
105 
106  UT_ASSERT(!"Unknown RV_GPUType.");
107  return UT_GPU_UINT8;
108 }
109 
111 {
112  switch (t)
113  {
114  case UT_GPU_UINT1: return RV_GPU_UINT1;
115  case UT_GPU_UINT4: return RV_GPU_UINT4;
116  case UT_GPU_UINT8: return RV_GPU_UINT8;
117  case UT_GPU_UINT16: return RV_GPU_UINT16;
118  case UT_GPU_UINT32: return RV_GPU_UINT32;
119 
120  case UT_GPU_INT8: return RV_GPU_INT8;
121  case UT_GPU_INT16: return RV_GPU_INT16;
122  case UT_GPU_INT32: return RV_GPU_INT32;
123 
124  case UT_GPU_FLOAT16: return RV_GPU_FLOAT16;
125  case UT_GPU_FLOAT24: return RV_GPU_FLOAT24;
126  case UT_GPU_FLOAT32: return RV_GPU_FLOAT32;
127  case UT_GPU_FLOAT64: return RV_GPU_FLOAT64;
128 
129  case UT_GPU_MATRIX2: return RV_GPU_MATRIX2;
130  case UT_GPU_MATRIX3: return RV_GPU_MATRIX3;
131  case UT_GPU_MATRIX4: return RV_GPU_MATRIX4;
132  default : break;
133  }
134 
135  UT_ASSERT(!"Unknown UT_GPUType.");
136  return RV_GPU_UNKNOWN;
137 }
138 
139 struct rv_DrawSetInfo;
140 struct rv_DrawInputInfo;
141 struct rv_Attribute;
142 struct rv_Connectivity;
143 struct rv_InstanceGroup;
144 
145 // TODO: use cache for multiple Drawing-Sets
146 //typedef UT_Map<RV_VKDescriptorSetInfo, rv_DrawSetInfo> rv_DrawSetCache;
147 
150 
151 /// @brief Object that represents drawable geometry.
152 /// This object holds vertex, instancing and index buffers for drawing.
153 /// The normal workflow is to:
154 /// - Set the number of points in the geometry with `setNumPoints()`
155 /// - Create all needed attribute definitions (P, N, uv, etc).
156 /// - Create all needed index buffer definitions or connect groups
157 /// - Call populateBuffers()
158 /// - Fetch each attribute with getAttribute() and fill it with
159 /// `RV_Buffer::uploadData()`
160 /// - Fetch each index buffer with getIndexBuffer() and fill it with
161 /// `RV_Buffer::uploadData()`
162 /// - Draw connect groups with any of the draw...() methods.
163 /// Draws must be done inside a begin/endRendering() block; all others must be
164 /// done outside.
166 {
167 public:
168  RV_Geometry();
169  ~RV_Geometry();
170 
171  // Setup and cleanup
172 
173  /// clear & free resources
174  void reset();
175  /// remove from VRAM; move to back in RAM (not implemented yet)
176  void unload();
177 
178  /// Memory use of all buffers for this geometry (in bytes) including RT
179  /// acceleration structures.
180  exint gpuMemoryUsage() const;
181 
182  /// Set name used for debugging
183  void setName(const UT_StringHolder &name) { myName = name; }
184  /// Get name used for debugging
185  const UT_StringHolder &getName() const { return myName; }
186 
187  /// Set number of points in geometry for vertex shader inputs
188  bool setNumPoints(exint num_points);
189  /// Number of points in geometry for vertex shader inputs
190  exint getNumPoints() const;
191 
192  /// Set number of per-vertex elements, accessed in fragment shader/
193  /// Must match the number of primitives drawn.
194  void setVertexBufferSize(exint vert_buffer_elements);
195  /// Number of per-primitive elements, accessed in fragment shader
196  exint getVertexBufferSize() const;
197 
198  /// Set number of per-primitive elements, accessed in fragment shader/
199  /// Must match the number of primitives drawn.
200  void setPrimitiveBufferSize(exint prim_buffer_elements);
201  /// Number of per-primitive elements, accessed in fragment shader
202  exint getPrimitiveBufferSize() const;
203 
204  // ---------------------------------------------------------------
205  // Methods for configuring the structure of the geometry
206 
207  /// @brief Create an attribute definition
208  /// Create an attribute definition for a vertex shader input
209  /// Capacity - optional buffer capacity in elements, in case of resizes
210  bool createAttribute(const UT_StringHolder &name,
211  RV_GPUType data_format, int vector_size,
212  exint capacity = -1, bool normalized = true,
213  bool allow_gpu_write = false);
214 
215  /// Creates a single value for a vertex shader input.
216  bool createConstant(const UT_StringHolder &name,
217  RV_GPUType data_format, int vector_size,
218  bool normalized = true);
219 
220  /// Create a vertex buffer for fragment shader indexing via vertex ID
221  bool createVertexBuffer(const UT_StringHolder &name,
222  RV_GPUType data_format, int vector_size,
223  exint capacity = -1, bool normalized = true,
224  bool allow_gpu_write = false);
225 
226  /// Create a buffer view for fragment shader indexing via gl_PrimitiveID
227  bool createPrimitiveBuffer(const UT_StringHolder &name,
228  RV_GPUType data_format, int vector_size,
229  bool normalized = true);
230 
231  /// Create a random-access attribute for instancing and other random access
232  /// Uses a buffer view.
233  bool createBufferAttribute(const UT_StringHolder &name,
234  RV_GPUType data_format, int vector_size,
235  exint buffer_size, bool normalized = true);
236 
237  /// Create an attribute that is allocated immediately
238  /// separate from those allocated during 'populateBuffers'
239  RV_Buffer* createAllocatedAttribute(RV_Render* r,
240  const UT_StringHolder &name,
241  RV_GPUType data_format, int vector_size,
243  exint capacity = -1,
244  bool normalized = true);
245 
246  /// @brief Fetch a buffer for an attribute.
247  /// Return the RV buffer for attribute `name`. Will not exist until
248  /// `populateBuffers()` is called.
249  RV_Buffer* getAttribute(const UT_StringHolder &name) const;
250  /// Tag the attribute with version information.
251  void setAttributeVersion(const UT_StringHolder &name,
252  const RE_CacheVersion &ver);
253  /// Set the attribute type (point, primitive, constant, random).
254  void setAttributeUsage(const UT_StringHolder &name,
255  RV_AttributeType ver);
256 
257  /// Set the attribute's original format, used for display
258  void setAttributeDisplayFormat(const UT_StringHolder &name,
259  RV_GPUType out_type,
260  int out_vec_size) const;
261 
262  /// Record a vertex shader input's constant scalar value.
263  void setAttributeConstValue(const UT_StringHolder &name,
264  fpreal64 val);
265  /// Record a vertex shader input's constant vector value.
266  void setAttributeConstVecValue(const UT_StringHolder &name,
267  const UT_Vector4F &val);
268 
269  /// Remove attribute and free its resource
270  bool freeAttribute(RV_Render* r, const UT_StringHolder &name);
271 
272  /// @brief Get an attribute's usage
273  /// Get the type of an attribute (point, prim, const, random, null). May be
274  /// null if the attribute was freed.
276  RV_AttributeType& out_type) const;
277 
278  /// Get the format of an attribute (return false if it does not exist).
279  bool getAttributeFormat(const UT_StringHolder &name,
280  RV_GPUType& out_type,
281  int& out_vec_size) const;
282 
283  /// @brief Get the length of an attribute
284  /// Get the length, in elements (not bytes) of an attribute
285  /// (return false if it does not exist).
286  bool getAttributeLength(const UT_StringHolder &name,
287  exint& out_len) const;
288  /// Get the version of an attribute (return false if it does not exist).
289  bool getAttributeVersion(const UT_StringHolder &name,
290  RE_CacheVersion& out_ver) const;
291 
292  /// @brief Get an attribute's usage
293  /// Get the version of an attribute (return false if it does not exist).
294  /// Will always return the usage it was defined with, even if freed.
295  bool getAttributeUsage(const UT_StringHolder &name,
296  RV_AttributeType& out_ver) const;
297 
298  /// Get the display format of an attribute (return false if it does not exist).
299  /// May be different from the actual Vulkan Buffer's data format, if an
300  /// implicit reformatting occured on the data before upload
301  bool getAttributeDisplayFormat(const UT_StringHolder &name,
302  RV_GPUType& out_type,
303  int& out_vec_size) const;
304 
305  /// Get the constant value for the vertex input 'name', after set as scalar
306  fpreal64 getAttributeConstValue(const UT_StringHolder &name) const;
307 
308  /// Get the constant value for the vertex input 'name', after set as vector
309  const UT_Vector4F&getAttributeConstVecValue(const UT_StringHolder &name) const;
310 
311  /// True if the attribute exists in the geometry.
312  bool hasAttribute(const UT_StringHolder &name,
313  int instance_group = -1) const;
314 
315  // Instancing support ----------------------------------------------
316 
317  // subsets of instances (for materials)
318 
319  /// Create a instance group for instanced drawing
320  bool createInstanceGroup(int group_index);
321  /// Remove an instance group
322  void removeInstanceGroup(int group_index);
323  /// Return true if the instance group exists
324  bool hasInstanceGroup(int group_index) const;
325  /// Return the maximum index of all instance groups.
326  int getMaxInstanceGroup() const;
327 
328  /// Set the numbers of instances drawn in a group
329  void setInstanceGroupCount(int instance_group, int count);
330  /// Fetch the numbers of instances drawn in a group
331  int getInstanceGroupCount(int instance_group) const;
332  /// Fetch the numbers of instanced transforms in a group, ignoring index lists
333  int getInstanceGroupTransformCount(int instance_group) const;
334 
335  /// Set the group to draw all transforms, ignoring existing index list
336  void setInstanceGroupForceFullDraw(int instance_group, bool enable);
337  /// Fetch whether group was set to force full draws
338  bool getInstanceGroupForceFullDraw(int instance_group) const;
339 
340  /// Select a subset of instance indices for an instance group (eg, culling)
341  void setInstanceGroupIndexList(int group_index,
342  const UT_IntArray &indices,
343  int max_capacity = -1);
344  /// Draw one instance with a specific index
345  void setInstanceGroupConstIndex(int instance_group,
346  int instance_to_draw);
347  /// Draw all instances
348  void setInstanceGroupDrawEverything(int instance_group);
349  /// Draw none of the instances
350  void setInstanceGroupDrawNothing(int instance_group);
351 
352  // Transforms for instances
353 
354  /// Single transform for all instances (or additional transform if
355  /// remove_instanced_xform is false)
356  void setConstInstanceGroupTransform(int instance_group,
357  const UT_Matrix4F &xform,
358  bool remove_instanced_xform);
359 
360  /// set instance group to use the same const transform as another
361  void copyConstInstanceGroupTransform(int instance_group, int src_group);
362 
363  /// @brief Create an per-instance attribute
364  /// Reserve an buffer for per-instance data (call populateBuffers() to
365  /// create the RV_Buffer for it).
366  bool setInstanceGroupAttrib(int instance_group,
367  const UT_StringHolder &name,
368  RV_GPUType data_type,
369  int vector_size,
370  int instance_step,
371  int num_instances,
372  exint capacity = -1,
373  bool normalized = true);
374 
375  /// Create per-instance attribute that can be shared by multiple RV_Geometrys
376  bool createSharedInstanceGroupAttrib(int instance_group,
377  const UT_StringHolder &name,
378  RV_GPUType data_type,
379  int vector_size,
380  int instance_step,
381  int num_instances,
382  exint capacity = -1,
383  bool normalized = true);
384 
385  /// Assign a buffer for the per-instance shared attribute
386  bool assignSharedInstanceGroupAttrib(int instance_group,
387  const UT_StringHolder &name,
389 
390  /// Remove per-instance attribute and free its resource
391  bool freeInstanceGroupAttrib(int instance_group,
392  const UT_StringHolder &name);
393 
394  /// Helper to allocate a shared per-instance buffer
395  static RV_VKBufferPtr allocateSharedInstanceBuffer(
396  RV_Render* r,
397  RV_GPUType data_type,
398  int vector_size,
399  exint length,
400  bool normalized = true,
401  const char* name = nullptr);
402 
403  static RV_VKBufferPtr allocateSharedCPUMappedInstanceBuffer(
404  RV_Render* r,
405  RV_GPUType data_type,
406  int vector_size,
407  exint length,
408  bool normalized = true,
409  bool cpu_mapped = true,
410  const char* name = nullptr);
411 
412  /// Fetch the buffer backing an per-instance attribute, usually to fill it
413  RV_Buffer * getInstanceGroupAttrib(int instance_group,
414  const UT_StringHolder &name) const;
415  /// @brief Get the length of an attribute
416  /// Get the length, in elements (not bytes) of an attribute
417  /// (return false if it does not exist).
418  bool getInstanceAttribLength(int instance_group,
419  const UT_StringHolder &name,
420  exint& out_len) const;
421 
422  /// Fetch the per-instance attribute version (to avoid refilling)
423  bool getInstanceAttribVersion(int instance_group,
424  const UT_StringHolder &name,
425  RE_CacheVersion& out_ver) const;
426  /// Set the per-instance attribute version (to avoid refilling)
427  void setInstanceAttribVersion(int instance_group,
428  const UT_StringHolder& name,
429  const RE_CacheVersion& ver);
430 
431  // ----------------------------------------------------------------------
432  // Connectivity
433 
434  /// Connect all points to form prims of `prim` type
435  void connectAllPrims(int connect_index,
436  RV_PrimType prim,
437  int patch_size = 0);
438  /// Connect a range of points to form prims of `prim` type
439  void connectSomePrims(int connect_index,
440  RV_PrimType prim,
441  int start,
442  int length,
443  unsigned int stride = 0,
444  int patch_size = 0);
445  /// Connect points form prims `prim` type from a list of `num_elements`
446  /// point indices. The index buffer must be populated after a
447  /// `populateBuffers()` call with `getIndexBuffer()->uploadData()`.
448  void connectIndexedPrims(int connect_index,
449  RV_PrimType prim,
450  int num_elements,
451  bool need_prim_info = false,
452  int patch_size = 0);
453  /// Connect a range of vertices to form prims of `prim` type
454  void connectSomeVerts(int connect_index,
455  RV_PrimType prim,
456  int start,
457  int length,
458  unsigned int stride = 0,
459  int patch_size = 0);
460 
461  void connectIndexedVerts(int connect_index,
462  RV_PrimType prim,
463  int num_elements,
464  bool need_prim_info = false,
465  int patch_size = 0);
466 
467  /// Set the primitive to GPU primitive ratio for acessing primitive
468  /// attributes. For example, if all polygons are quads, the divisor would be
469  /// 2 as the GPU creates 2 triangles for each quad.
470  void setConnectDivisor(int connect_index, int divisor,
471  int base_prim=0);
472  /// Generate a primitive info buffer for accessing primtive attribute data
473  /// if the polygon vertex counts vary (use getPrimVertexBuffer() after
474  // calling populateBuffers() to fill it).
475  void setConnectUsePrimInfo(int connect_index, int base_prim= 0);
476 
477  /// Set a PrimInfo buffer to be shared across connect groups with same
478  /// primitive type. Attribute must already exist in geometry.
479  void setPrimitiveInfoAttrib(RV_TopologyClass prim_type,
480  const UT_StringHolder &name);
481  /// return the number of primitives that are rendered for a connect group
482  int getNumRenderPrims(int connect_index) const;
483 
484  /// return the type of primitives that are rendered for a connect group
485  RV_PrimType getRenderPrimType(int connect_index) const;
486 
487  /// Fetch the index buffer to fill (after populateBuffers())
488  RV_Buffer *getIndexBuffer(int connect_index) const;
489  /// Fetch the primitive buffer to fill (after populateBuffers())
490  RV_Buffer *getPrimBuffer(int connect_index) const;
491  /// Fetch the primitive/vertex buffer to fill (after populateBuffers())
492  RV_Buffer *getPrimVertexBuffer(int connect_index) const;
493 
494  // True if the vertex shader is run at vertex frequency (False if at point)
495  bool isVertexFrequency(int connect_index) const;
496 
497  /// Return true if the connect group exists
498  bool hasConnectGroup(int connect_index) const;
499  /// Return true if the connect group isn't empty
500  bool hasNonEmptyConnectGroup(int connect_index) const;
501  /// Return the maximum connect group index
502  int getMaxConnectGroup() const;
503 
504  /// Remove a connect group
505  bool removeConnectedPrims(int connect_index);
506  /// Remove all connect groups.
507  void resetConnectedPrims(); // remove all
508 
509  // -------------------------------------------------------------
510  /// Populates all RV_Buffers declared above which haven't been populated yet.
511  bool populateBuffers(RV_Render *r);
512 
513  // --------------------------------------------------------------
514  // Drawing
515 
516  /// Setup Uniform buffers and Descriptor Set to be used by current shader
517  void prepareForDraw(RV_Render *r,
518  int connect_index,
519  const RV_OverrideList *overrides = nullptr);
520  /// Setup Uniform buffers and Descriptor Set to be used by current shader,
521  /// when drawing with instances
522  void prepareForDrawInstance( RV_Render* r,
523  int connect_index,
524  int instance_group,
525  const RV_OverrideList *overrides = nullptr);
526 
527  /// draw a single connection group
528  /// draw_offset and draw_size can specifiy a vertex range in the connect
529  void draw(
530  RV_Render *r,
531  int connect_index,
532  const RV_OverrideList *overrides = nullptr,
533  exint draw_offset = -1, exint draw_size = -1);
534 
535  /// draw a single connection group using with instancing, using the indices
536  /// in instance_group
537  /// draw_offset and draw_size can specifiy a vertex range in the connect
538  void drawInstanceGroup(
539  RV_Render *r,
540  int connect_index,
541  int instance_group,
542  const RV_OverrideList *overrides = nullptr,
543  exint draw_offset = -1, exint draw_size = -1);
544 
545  /// draw multiple connection groups (really just a loop over draw()).
546  void drawRange(
547  RV_Render *r,
548  int connect_index_start,
549  int num_connect_indexs,
550  const RV_OverrideList *overrides = nullptr);
551 
552  /// draw instanced over multiple connection groups.
553  void drawInstanceGroupRange(
554  RV_Render *r,
555  int connect_start,
556  int num_connect,
557  int instance_group,
558  const RV_OverrideList *overrides = nullptr);
559 
560  /// draw indirectly from a buffer
561  void drawIndirect(
562  RV_Render *r,
563  int connect_index,
564  RV_Buffer &indirect_buffer);
565 
566  /// dispatch a compute shader for a single connect group
567  void dispatch(RV_Render *r,
568  int connect_index,
569  int instance_group,
570  const RV_OverrideList *overrides = nullptr);
571 
572  /// dispatch compute shader for multiple connect groups
573  void dispatchRange(RV_Render *r,
574  int connect_index,
575  int num_connect,
576  int instance_group,
577  const RV_OverrideList *overrides = nullptr);
578 
579  static void initResources(RV_Instance* inst);
580  static void cleanupResources();
581 
582  // --------------------------------------------------------------
583  // Ray tracing
584  void updateAccelerationStructure(
585  RV_Render *r,
586  int tag,
587  int light_id,
588  int surface_connect_index,
589  const UT_Matrix4F &obj_mat);
590 
591  RV_VKAccelerationStructure* getAccelerationStructure();
592 
593  // manually force acceleration structure rebuild
594  void dirtyAccelerationStructure() { myIsAccelStructDirty = true; }
595 
596  // -------------------------------------------------------------------
597  // DEBUG
598 
599  /// @brief Debug output
600  /// Debug methd to print information about all attributes, connect groups,
601  /// and instance groups
602  void print() const;
603  // TODO: setDebugDraw() to print shader state during draw
604 
605 private:
606 
607  // ------------------------------------------------------------------
608  // CONNECTIVITY
609  rv_Connectivity* getConnect(int group_idx, bool do_create);
610 
611  // ------------------------------------------------------------------
612  // INSTANCE
613  static void getInstanceAttribName(UT_WorkBuffer &out_name,
614  const char *base_name,
615  int instance_group);
616 
617  int getTransformAttribCount(const rv_Attribute* attr) const;
618 
619  // ------------------------------------------------------------------
620  // ATTRIBUTES
621  const rv_Attribute* findAttribute(const UT_StringRef& name,
622  const RV_OverrideList *overrides,
623  int instance_group,
624  int* out_idx = nullptr) const;
625 
626  bool privCreateAttribute( const UT_StringHolder& name,
627  RV_GPUType data_format,
628  int vector_size,
629  bool normalize,
631  exint capacity = -1,
632  int inst_group = -1,
633  bool attr_owned = false,
634  bool allow_gpu_write = false);
635  bool privFreeAttrib(RV_Render* r, rv_Attribute &attr);
636 
637  // ------------------------------------------------------------------
638  // BUFFERS
639  RV_Buffer *allocateAttributeBuffer(
640  RV_Render *r,
641  rv_Attribute &attr,
642  UT_Array<RV_BufferPtr> *opt_old_buffers = nullptr);
643  bool allocateConnectBuffers(RV_Render* r, rv_Connectivity& c,
644  UT_Array<RV_BufferPtr>* opt_old_buffers);
645  bool allocateInstIndexBuffer(RV_Render* r, rv_InstanceGroup& g,
646  UT_Array<RV_BufferPtr>* opt_old_buffers);
647 
648  RV_BufferPtr allocOrReuseBuffer( RV_Render *r, rv_Attribute &attr,
649  exint length, VkBufferUsageFlags vk_usage,
650  UT_Array<RV_BufferPtr> *old_buffers);
651 
652  void resetAttribBuffers(RV_Render* r);
653  void resetConnectBuffers(RV_Render* r);
654  void resetCachedSets(RV_Render* r);
655 
656  bool privPrepareDraw(
657  RV_Render* r,
658  const rv_Connectivity *connect,
659  int instance_group_idx,
660  const RV_OverrideList* overrides
661  );
662 
663  void privDraw(
664  RV_Render *r,
665  const rv_Connectivity *connect,
666  int instance_group_idx,
667  const RV_OverrideList *overrides,
668  RV_Buffer* indirect_buf,
669  exint draw_offset = -1,
670  exint draw_length = -1
671  );
672 
673  void privDispatch(
674  RV_Render *r,
675  const rv_Connectivity *connect,
676  int instance_group_idx,
677  const RV_OverrideList *overrides,
678  RV_Buffer *indirect_buf
679  );
680 
681  void fillInstanceInfoBlock(RV_Render *r, int instance_group_idx, RV_ShaderBlock* block);
682  void fillGeometryInfoBlock(RV_Render *r, const rv_Connectivity* connect, RV_ShaderBlock* geo);
683 
684  // ------------------------------------------------------------------
685  // DATA
686  RV_Render* myR = nullptr;
687  UT_StringHolder myName;
688 
689  uint32_t myNumPoints = 0;
690  uint32_t myVertBufferSize = 0;
691  uint32_t myPrimBufferSize = 0;
692 
693  bool myAttributesValid = false;
694 
695  // TODO: Make sure nothing name-to-idx mapping is stable
696  // (i.e. attrib names can't be removed)
697  UT_StringMap<int> myAttributeTable;
698  UT_Array<int> myDefaultAttribTable;
699  UT_Array<int> myPrimInfoAttribTable;
700  UT_Array<rv_Attribute> myAttributeList;
701 
702  // own directly so helper structs can be passed around more easily
703  UT_Array<RV_BufferPtr> myOwnedAttribBuffers;
704  UT_Array<RV_BufferPtr> myOwnedConnectBuffers;
705  UT_Array<RV_BufferPtr> myOwnedFallbackBuffers;
706  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedGeoBuffers;
707  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedInstBuffers;
708 
709  // TODO: allocate buffers from single block of memory
710  //UT_UniquePtr<RV_VKMemory> myMemBlock;
711 
712  UT_Array<rv_Connectivity> myConnectivityGroups;
713 
714  UT_Array<rv_InstanceGroupPtr> myInstanceGroups;
715 
716  struct rv_DrawSetInfo
717  {
718  // track the override list used
719  RV_OverrideList myOverrideList;
720  int myConnectGroupIdx;
721  int myInstanceGroupIdx;
722 
723  bool myIsValid = false;
724 
725  UT_UniquePtr<RV_ShaderVariableSet> myDescriptorSet;
726  UT_UniquePtr<RV_ShaderBlock> myUniformBlock;
727 
728  // TODO: move into connect group
729  UT_UniquePtr<RV_ShaderBlock> myGeometryBlock;
730 
731  int myInstTransformUniformIdx = -1;
732  int myInstNestLevelUniformIdx = -1;
733 
734  // TODO: keep a list of the [attrib ID, binding ID] pairs
735  // and check if they are up-to-date per-frame
736  // TODO: requires RV_Geo and RV_ShaderVariableSet
737  // be setup to refer to attribs by consistent
738  // idx/binding num
739  // currently invalidating any time the interface
740  // may have changed
741  };
742 
743  // Set Used for drawing
744  // cached by (connect group, instance group, set id)
745  typedef UT_Map<std::tuple<int, int, int>, rv_DrawSetInfo> DrawSetCache;
746  DrawSetCache myDrawSet;
747 
748  // Get the set that is compatible with the passed in shader
749  // creating it if necessary
750  rv_DrawSetInfo* getDrawSet(
751  RV_Render* r,
753  const rv_Connectivity *connect,
754  int instance_group_idx,
755  const RV_OverrideList* overrides);
756 
757  // Prepare a set, making sure all attributes are attached and
758  // up-to-date
759  bool prepareDrawSet(
760  RV_Render* r,
761  rv_DrawSetInfo& set_info,
762  const rv_Connectivity *connect,
763  int instance_group_idx,
764  const RV_OverrideList* overrides
765  );
766 
767  bool bindInputAttribute(
768  RV_Render* r,
769  RV_VKPipelineInputInfo& pipe_input,
770  const rv_Connectivity *connect,
771  const rv_Attribute *attrib,
772  bool instance,
773  int location,
775  int vec_size);
776  //rv_DrawSetCache myDrawSets;
777 
778  // Zero-valued constant buffers to fill attribs we don't have values for
779  // TODO: use nullDescriptor bindings if VK_EXT_robustness2 is available
780  void populateFallbackAttribs(RV_Render* r);
781  void resetFallbackAttribs(RV_Render* r);
782  rv_Attribute* getFallbackVertAttrib(RV_GPUType type);
783  rv_Attribute* getFallbackTexBufAttrib(RV_UniformType type);
784  UT_UniquePtr<rv_Attribute> myDefaultVertexAttrib;
785  UT_UniquePtr<rv_Attribute> myDefaultIntVertexAttrib;
786  UT_UniquePtr<rv_Attribute> myDefaultUIntVertexAttrib;
787  UT_UniquePtr<rv_Attribute> myDefaultSamplerAttrib;
788  UT_UniquePtr<rv_Attribute> myDefaultIntSamplerAttrib;
789  UT_UniquePtr<rv_Attribute> myDefaultUIntSamplerAttrib;
790  UT_UniquePtr<rv_Attribute> myDefaultIndexSamplerAttrib;
791  UT_UniquePtr<rv_Attribute> myDefaultIndexVertexAttrib;
792 
793  // Ray tracing
794  RV_VKAccelerationStructurePtr myAccelerationStructure;
795 
796  UT_Matrix4F myLastObjTransform = UT_Matrix4F::getIdentityMatrix();
797  bool myIsAccelStructDirty = true;
798  bool myIsAccelStructInstDirty = true;
799 };
800 
801 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
RV_ConnectionType
Definition: RV_Geometry.h:52
VkPrimitiveTopology
Definition: vulkan_core.h:1957
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
VkFlags VkBufferUsageFlags
Definition: vulkan_core.h:2515
Unsorted map container.
Definition: UT_Map.h:109
VkPrimitiveTopology RVgetVkPrimType(RV_PrimType t)
Definition: RV_Geometry.h:59
UT_UniquePtr< RV_VKBuffer > RV_VKBufferPtr
Definition: RV_TypePtrs.h:63
GLuint start
Definition: glcorearb.h:475
GLboolean GLboolean g
Definition: glcorearb.h:1222
int64 exint
Definition: SYS_Types.h:125
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
RV_GPUType RVconvertFromGPUType(UT_GPUType t)
Definition: RV_Geometry.h:110
GLuint buffer
Definition: glcorearb.h:660
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
double fpreal64
Definition: SYS_Types.h:201
#define UT_ASSERT_MSG(ZZ,...)
Definition: UT_Assert.h:159
UT_GPUType
Definition: UT_ComputeGPU.h:42
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GLboolean reset
Definition: glad.h:5138
UT_UniquePtr< RV_VKAccelerationStructure > RV_VKAccelerationStructurePtr
Definition: RV_TypePtrs.h:84
RV_AttributeType
Definition: RV_Type.h:99
static const UT_Matrix4T< fpreal32 > & getIdentityMatrix()
RV_UniformType
Definition: RV_Type.h:332
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define RV_API
Definition: RV_API.h:10
GLint location
Definition: glcorearb.h:805
RV_GenericAttribID
Definition: RV_Geometry.h:47
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint GLenum GLboolean normalized
Definition: glcorearb.h:872
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:44
GLdouble t
Definition: glad.h:2397
UT_GPUType RVconvertToUTGPUType(RV_GPUType t)
Definition: RV_Geometry.h:81
RV_PrimType
Definition: RV_Type.h:424
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:664
UT_UniquePtr< rv_InstanceGroup > rv_InstanceGroupPtr
Definition: RV_Geometry.h:143
RV_TopologyClass
Definition: RV_Type.h:451
RV_GPUType
Definition: RV_Type.h:40
void dirtyAccelerationStructure()
Definition: RV_Geometry.h:594
GLuint GLfloat * val
Definition: glcorearb.h:1608
FMT_CONSTEXPR basic_fp< F > normalize(basic_fp< F > value)
Definition: format.h:1701
GR_API RE_GPUType getAttributeType(RE_Render *r, const char *attrib_name, int &vsize, const GT_DataArrayHandle &pa, const GR_DisplayOption &opts, RE_ArrayType array_type)
const UT_StringHolder & getName() const
Get name used for debugging.
Definition: RV_Geometry.h:185
Simple class for a mutli-integer cache tag.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
RV_VKBuffer RV_Buffer
Definition: RV_Geometry.h:43
GLboolean r
Definition: glcorearb.h:1222
UT_UniquePtr< RV_Buffer > RV_BufferPtr
Definition: RV_Geometry.h:149
A vulkan buffer object.
Definition: RV_VKBuffer.h:81
GLuint divisor
Definition: glcorearb.h:1670
void setName(const UT_StringHolder &name)
Set name used for debugging.
Definition: RV_Geometry.h:183
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2903
GLint GLsizei count
Definition: glcorearb.h:405