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  /// Disables all attributes that are marked as stashable, and clears
270  /// attributes that were previously stashed. Attributes can be marked
271  /// as stashable and kept active by calling `unstashAttribute()` after
272  /// calling `stashAttributes()`
273  /// Should only be called by `GR_GeoRenderVK::fillGeoAttribs()`
274  void stashAttributes();
275 
276  /// Marks an attribute as active and stashable
277  bool unstashAttribute(const UT_StringHolder &name);
278  bool unstashInstanceAttrib(int group_index,
279  const UT_StringHolder &name);
280  /// Remove attribute and free its resource
281  bool freeAttribute(RV_Render* r, const UT_StringHolder &name);
282 
283  /// @brief Get an attribute's usage
284  /// Get the type of an attribute (point, prim, const, random, null). May be
285  /// null if the attribute was freed.
287  RV_AttributeType& out_type) const;
288 
289  /// Get the format of an attribute (return false if it does not exist).
290  bool getAttributeFormat(const UT_StringHolder &name,
291  RV_GPUType& out_type,
292  int& out_vec_size) const;
293 
294  /// @brief Get the length of an attribute
295  /// Get the length, in elements (not bytes) of an attribute
296  /// (return false if it does not exist).
297  bool getAttributeLength(const UT_StringHolder &name,
298  exint& out_len) const;
299  /// Get the version of an attribute (return false if it does not exist).
300  bool getAttributeVersion(const UT_StringHolder &name,
301  RE_CacheVersion& out_ver) const;
302 
303  /// @brief Get an attribute's usage
304  /// Get the version of an attribute (return false if it does not exist).
305  /// Will always return the usage it was defined with, even if freed.
306  bool getAttributeUsage(const UT_StringHolder &name,
307  RV_AttributeType& out_ver) const;
308 
309  /// Get the display format of an attribute (return false if it does not exist).
310  /// May be different from the actual Vulkan Buffer's data format, if an
311  /// implicit reformatting occured on the data before upload
312  bool getAttributeDisplayFormat(const UT_StringHolder &name,
313  RV_GPUType& out_type,
314  int& out_vec_size) const;
315 
316  /// Get the constant value for the vertex input 'name', after set as scalar
317  fpreal64 getAttributeConstValue(const UT_StringHolder &name) const;
318 
319  /// Get the constant value for the vertex input 'name', after set as vector
320  const UT_Vector4F&getAttributeConstVecValue(const UT_StringHolder &name) const;
321 
322  /// True if the attribute exists in the geometry.
323  bool hasAttribute(const UT_StringHolder &name,
324  int instance_group = -1) const;
325 
326  // Instancing support ----------------------------------------------
327 
328  // subsets of instances (for materials)
329 
330  /// Create a instance group for instanced drawing
331  bool createInstanceGroup(int group_index);
332  /// Remove an instance group
333  void removeInstanceGroup(int group_index);
334  /// Return true if the instance group exists
335  bool hasInstanceGroup(int group_index) const;
336  /// Return the maximum index of all instance groups.
337  int getMaxInstanceGroup() const;
338 
339  /// Set the numbers of instances drawn in a group
340  void setInstanceGroupCount(int instance_group, int count);
341  /// Fetch the numbers of instances drawn in a group
342  int getInstanceGroupCount(int instance_group) const;
343  /// Fetch the numbers of instanced transforms in a group, ignoring index lists
344  int getInstanceGroupTransformCount(int instance_group) const;
345 
346  /// Set the group to draw all transforms, ignoring existing index list
347  void setInstanceGroupForceFullDraw(int instance_group, bool enable);
348  /// Fetch whether group was set to force full draws
349  bool getInstanceGroupForceFullDraw(int instance_group) const;
350 
351  /// Select a subset of instance indices for an instance group (eg, culling)
352  void setInstanceGroupIndexList(int group_index,
353  const UT_IntArray &indices,
354  int max_capacity = -1);
355  /// Draw one instance with a specific index
356  void setInstanceGroupConstIndex(int instance_group,
357  int instance_to_draw);
358  /// Draw all instances
359  void setInstanceGroupDrawEverything(int instance_group);
360  /// Draw none of the instances
361  void setInstanceGroupDrawNothing(int instance_group);
362 
363  // Transforms for instances
364 
365  /// Single transform for all instances (or additional transform if
366  /// remove_instanced_xform is false)
367  void setConstInstanceGroupTransform(int instance_group,
368  const UT_Matrix4F &xform,
369  bool remove_instanced_xform);
370 
371  /// set instance group to use the same const transform as another
372  void copyConstInstanceGroupTransform(int instance_group, int src_group);
373 
374  /// @brief Create an per-instance attribute
375  /// Reserve an buffer for per-instance data (call populateBuffers() to
376  /// create the RV_Buffer for it).
377  bool setInstanceGroupAttrib(int instance_group,
378  const UT_StringHolder &name,
379  RV_GPUType data_type,
380  int vector_size,
381  int instance_step,
382  int num_instances,
383  exint capacity = -1,
384  bool normalized = true);
385 
386  /// Create per-instance attribute that can be shared by multiple RV_Geometrys
387  bool createSharedInstanceGroupAttrib(int instance_group,
388  const UT_StringHolder &name,
389  RV_GPUType data_type,
390  int vector_size,
391  int instance_step,
392  int num_instances,
393  exint capacity = -1,
394  bool normalized = true);
395 
396  /// Assign a buffer for the per-instance shared attribute
397  bool assignSharedInstanceGroupAttrib(int instance_group,
398  const UT_StringHolder &name,
400 
401  /// Remove per-instance attribute and free its resource
402  bool freeInstanceGroupAttrib(int instance_group,
403  const UT_StringHolder &name);
404 
405  /// Helper to allocate a shared per-instance buffer
406  static RV_VKBufferPtr allocateSharedInstanceBuffer(
407  RV_Render* r,
408  RV_GPUType data_type,
409  int vector_size,
410  exint length,
411  bool normalized = true,
412  const char* name = nullptr);
413 
414  static RV_VKBufferPtr allocateSharedCPUMappedInstanceBuffer(
415  RV_Render* r,
416  RV_GPUType data_type,
417  int vector_size,
418  exint length,
419  bool normalized = true,
420  bool cpu_mapped = true,
421  const char* name = nullptr);
422 
423  /// Fetch the buffer backing an per-instance attribute, usually to fill it
424  RV_Buffer * getInstanceGroupAttrib(int instance_group,
425  const UT_StringHolder &name) const;
426  /// @brief Get the length of an attribute
427  /// Get the length, in elements (not bytes) of an attribute
428  /// (return false if it does not exist).
429  bool getInstanceAttribLength(int instance_group,
430  const UT_StringHolder &name,
431  exint& out_len) const;
432 
433  /// Fetch the per-instance attribute version (to avoid refilling)
434  bool getInstanceAttribVersion(int instance_group,
435  const UT_StringHolder &name,
436  RE_CacheVersion& out_ver) const;
437  /// Set the per-instance attribute version (to avoid refilling)
438  void setInstanceAttribVersion(int instance_group,
439  const UT_StringHolder& name,
440  const RE_CacheVersion& ver);
441 
442  // ----------------------------------------------------------------------
443  // Connectivity
444 
445  /// Connect all points to form prims of `prim` type
446  void connectAllPrims(int connect_index,
447  RV_PrimType prim,
448  int patch_size = 0);
449  /// Connect a range of points to form prims of `prim` type
450  void connectSomePrims(int connect_index,
451  RV_PrimType prim,
452  int start,
453  int length,
454  unsigned int stride = 0,
455  int patch_size = 0);
456  /// Connect points form prims `prim` type from a list of `num_elements`
457  /// point indices. The index buffer must be populated after a
458  /// `populateBuffers()` call with `getIndexBuffer()->uploadData()`.
459  void connectIndexedPrims(int connect_index,
460  RV_PrimType prim,
461  int num_elements,
462  bool need_prim_info = false,
463  int patch_size = 0);
464  /// Connect a range of vertices to form prims of `prim` type
465  void connectSomeVerts(int connect_index,
466  RV_PrimType prim,
467  int start,
468  int length,
469  unsigned int stride = 0,
470  int patch_size = 0);
471 
472  void connectIndexedVerts(int connect_index,
473  RV_PrimType prim,
474  int num_elements,
475  bool need_prim_info = false,
476  int patch_size = 0);
477 
478  /// Set the primitive to GPU primitive ratio for acessing primitive
479  /// attributes. For example, if all polygons are quads, the divisor would be
480  /// 2 as the GPU creates 2 triangles for each quad.
481  void setConnectDivisor(int connect_index, int divisor,
482  int base_prim=0);
483  /// Generate a primitive info buffer for accessing primtive attribute data
484  /// if the polygon vertex counts vary (use getPrimVertexBuffer() after
485  // calling populateBuffers() to fill it).
486  void setConnectUsePrimInfo(int connect_index, int base_prim= 0);
487 
488  /// Set a PrimInfo buffer to be shared across connect groups with same
489  /// primitive type. Attribute must already exist in geometry.
490  void setPrimitiveInfoAttrib(RV_TopologyClass prim_type,
491  const UT_StringHolder &name);
492  /// return the number of primitives that are rendered for a connect group
493  int getNumRenderPrims(int connect_index) const;
494 
495  /// return the type of primitives that are rendered for a connect group
496  RV_PrimType getRenderPrimType(int connect_index) const;
497 
498  /// Fetch the index buffer to fill (after populateBuffers())
499  RV_Buffer *getIndexBuffer(int connect_index) const;
500  /// Fetch the primitive buffer to fill (after populateBuffers())
501  RV_Buffer *getPrimBuffer(int connect_index) const;
502  /// Fetch the primitive/vertex buffer to fill (after populateBuffers())
503  RV_Buffer *getPrimVertexBuffer(int connect_index) const;
504 
505  // True if the vertex shader is run at vertex frequency (False if at point)
506  bool isVertexFrequency(int connect_index) const;
507 
508  /// Return true if the connect group exists
509  bool hasConnectGroup(int connect_index) const;
510  /// Return true if the connect group isn't empty
511  bool hasNonEmptyConnectGroup(int connect_index) const;
512  /// Return the maximum connect group index
513  int getMaxConnectGroup() const;
514 
515  /// Remove a connect group
516  bool removeConnectedPrims(int connect_index);
517  /// Remove all connect groups.
518  void resetConnectedPrims(); // remove all
519 
520  // -------------------------------------------------------------
521  /// Populates all RV_Buffers declared above which haven't been populated yet.
522  bool populateBuffers(RV_Render *r);
523 
524  // --------------------------------------------------------------
525  // Drawing
526 
527  /// Setup Uniform buffers and Descriptor Set to be used by current shader
528  void prepareForDraw(RV_Render *r,
529  int connect_index,
530  const RV_OverrideList *overrides = nullptr);
531  /// Setup Uniform buffers and Descriptor Set to be used by current shader,
532  /// when drawing with instances
533  void prepareForDrawInstance( RV_Render* r,
534  int connect_index,
535  int instance_group,
536  const RV_OverrideList *overrides = nullptr);
537 
538  /// draw a single connection group
539  /// draw_offset and draw_size can specifiy a vertex range in the connect
540  void draw(
541  RV_Render *r,
542  int connect_index,
543  const RV_OverrideList *overrides = nullptr,
544  exint draw_offset = -1, exint draw_size = -1);
545 
546  /// draw a single connection group using with instancing, using the indices
547  /// in instance_group
548  /// draw_offset and draw_size can specifiy a vertex range in the connect
549  void drawInstanceGroup(
550  RV_Render *r,
551  int connect_index,
552  int instance_group,
553  const RV_OverrideList *overrides = nullptr,
554  exint draw_offset = -1, exint draw_size = -1);
555 
556  /// draw multiple connection groups (really just a loop over draw()).
557  void drawRange(
558  RV_Render *r,
559  int connect_index_start,
560  int num_connect_indexs,
561  const RV_OverrideList *overrides = nullptr);
562 
563  /// draw instanced over multiple connection groups.
564  void drawInstanceGroupRange(
565  RV_Render *r,
566  int connect_start,
567  int num_connect,
568  int instance_group,
569  const RV_OverrideList *overrides = nullptr);
570 
571  /// draw indirectly from a buffer
572  void drawIndirect(
573  RV_Render *r,
574  int connect_index,
575  RV_Buffer &indirect_buffer);
576 
577  /// dispatch a compute shader for a single connect group
578  void dispatch(RV_Render *r,
579  int connect_index,
580  int instance_group,
581  const RV_OverrideList *overrides = nullptr);
582 
583  /// dispatch compute shader for multiple connect groups
584  void dispatchRange(RV_Render *r,
585  int connect_index,
586  int num_connect,
587  int instance_group,
588  const RV_OverrideList *overrides = nullptr);
589 
590  static void initResources(RV_Instance* inst);
591  static void cleanupResources();
592 
593  // --------------------------------------------------------------
594  // Ray tracing
595  void updateAccelerationStructure(
596  RV_Render *r,
597  int tag,
598  int light_id,
599  int surface_connect_index,
600  const UT_Matrix4F &obj_mat);
601 
602  RV_VKAccelerationStructure* getAccelerationStructure();
603 
604  // manually force acceleration structure rebuild
605  void dirtyAccelerationStructure() { myIsAccelStructDirty = true; }
606 
607  // -------------------------------------------------------------------
608  // DEBUG
609 
610  /// @brief Debug output
611  /// Debug methd to print information about all attributes, connect groups,
612  /// and instance groups
613  void print() const;
614  // TODO: setDebugDraw() to print shader state during draw
615 
616 private:
617 
618  // ------------------------------------------------------------------
619  // CONNECTIVITY
620  rv_Connectivity* getConnect(int group_idx, bool do_create);
621 
622  // ------------------------------------------------------------------
623  // INSTANCE
624  static void getInstanceAttribName(UT_WorkBuffer &out_name,
625  const char *base_name,
626  int instance_group);
627 
628  int getTransformAttribCount(const rv_Attribute* attr) const;
629 
630  // ------------------------------------------------------------------
631  // ATTRIBUTES
632  const rv_Attribute* findAttribute(const UT_StringRef& name,
633  const RV_OverrideList *overrides,
634  int instance_group,
635  int* out_idx = nullptr) const;
636 
637  bool privCreateAttribute( const UT_StringHolder& name,
638  RV_GPUType data_format,
639  int vector_size,
640  bool normalize,
642  exint capacity = -1,
643  int inst_group = -1,
644  bool attr_owned = false,
645  bool allow_gpu_write = false);
646  bool privFreeAttrib(RV_Render* r, rv_Attribute &attr);
647 
648  // ------------------------------------------------------------------
649  // BUFFERS
650  RV_Buffer *allocateAttributeBuffer(
651  RV_Render *r,
652  rv_Attribute &attr,
653  UT_Array<RV_BufferPtr> *opt_old_buffers = nullptr);
654  bool allocateConnectBuffers(RV_Render* r, rv_Connectivity& c,
655  UT_Array<RV_BufferPtr>* opt_old_buffers);
656  bool allocateInstIndexBuffer(RV_Render* r, rv_InstanceGroup& g,
657  UT_Array<RV_BufferPtr>* opt_old_buffers);
658 
659  RV_BufferPtr allocOrReuseBuffer( RV_Render *r, rv_Attribute &attr,
660  exint length, VkBufferUsageFlags vk_usage,
661  UT_Array<RV_BufferPtr> *old_buffers);
662 
663  void resetAttribBuffers(RV_Render* r);
664  void resetConnectBuffers(RV_Render* r);
665  void resetCachedSets(RV_Render* r);
666 
667  bool privPrepareDraw(
668  RV_Render* r,
669  const rv_Connectivity *connect,
670  int instance_group_idx,
671  const RV_OverrideList* overrides
672  );
673 
674  void privDraw(
675  RV_Render *r,
676  const rv_Connectivity *connect,
677  int instance_group_idx,
678  const RV_OverrideList *overrides,
679  RV_Buffer* indirect_buf,
680  exint draw_offset = -1,
681  exint draw_length = -1
682  );
683 
684  void privDispatch(
685  RV_Render *r,
686  const rv_Connectivity *connect,
687  int instance_group_idx,
688  const RV_OverrideList *overrides,
689  RV_Buffer *indirect_buf
690  );
691 
692  void fillInstanceInfoBlock(RV_Render *r, int instance_group_idx, RV_ShaderBlock* block);
693  void fillGeometryInfoBlock(RV_Render *r, const rv_Connectivity* connect, RV_ShaderBlock* geo);
694 
695  // ------------------------------------------------------------------
696  // DATA
697  RV_Render* myR = nullptr;
698  UT_StringHolder myName;
699 
700  uint32_t myNumPoints = 0;
701  uint32_t myVertBufferSize = 0;
702  uint32_t myPrimBufferSize = 0;
703 
704  bool myAttributesValid = false;
705 
706  // TODO: Make sure nothing name-to-idx mapping is stable
707  // (i.e. attrib names can't be removed)
708  UT_StringMap<int> myAttributeTable;
709  UT_Array<int> myDefaultAttribTable;
710  UT_Array<int> myPrimInfoAttribTable;
711  UT_Array<rv_Attribute> myAttributeList;
712 
713  // own directly so helper structs can be passed around more easily
714  UT_Array<RV_BufferPtr> myOwnedAttribBuffers;
715  UT_Array<RV_BufferPtr> myOwnedConnectBuffers;
716  UT_Array<RV_BufferPtr> myOwnedFallbackBuffers;
717  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedGeoBuffers;
718  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedInstBuffers;
719 
720  // TODO: allocate buffers from single block of memory
721  //UT_UniquePtr<RV_VKMemory> myMemBlock;
722 
723  UT_Array<rv_Connectivity> myConnectivityGroups;
724 
725  UT_Array<rv_InstanceGroupPtr> myInstanceGroups;
726 
727  struct rv_DrawSetInfo
728  {
729  // track the override list used
730  RV_OverrideList myOverrideList;
731  int myConnectGroupIdx;
732  int myInstanceGroupIdx;
733 
734  bool myIsValid = false;
735 
736  UT_UniquePtr<RV_ShaderVariableSet> myDescriptorSet;
737  UT_UniquePtr<RV_ShaderBlock> myUniformBlock;
738 
739  // TODO: move into connect group
740  UT_UniquePtr<RV_ShaderBlock> myGeometryBlock;
741 
742  int myInstTransformUniformIdx = -1;
743  int myInstNestLevelUniformIdx = -1;
744 
745  // TODO: keep a list of the [attrib ID, binding ID] pairs
746  // and check if they are up-to-date per-frame
747  // TODO: requires RV_Geo and RV_ShaderVariableSet
748  // be setup to refer to attribs by consistent
749  // idx/binding num
750  // currently invalidating any time the interface
751  // may have changed
752  };
753 
754  // Set Used for drawing
755  // cached by (connect group, instance group, set id)
756  typedef UT_Map<std::tuple<int, int, int>, rv_DrawSetInfo> DrawSetCache;
757  DrawSetCache myDrawSet;
758 
759  // Get the set that is compatible with the passed in shader
760  // creating it if necessary
761  rv_DrawSetInfo* getDrawSet(
762  RV_Render* r,
764  const rv_Connectivity *connect,
765  int instance_group_idx,
766  const RV_OverrideList* overrides);
767 
768  // Prepare a set, making sure all attributes are attached and
769  // up-to-date
770  bool prepareDrawSet(
771  RV_Render* r,
772  rv_DrawSetInfo& set_info,
773  const rv_Connectivity *connect,
774  int instance_group_idx,
775  const RV_OverrideList* overrides
776  );
777 
778  bool bindInputAttribute(
779  RV_Render* r,
780  RV_VKPipelineInputInfo& pipe_input,
781  const rv_Connectivity *connect,
782  const rv_Attribute *attrib,
783  bool instance,
784  int location,
786  int vec_size);
787  //rv_DrawSetCache myDrawSets;
788 
789  // Zero-valued constant buffers to fill attribs we don't have values for
790  // TODO: use nullDescriptor bindings if VK_EXT_robustness2 is available
791  void populateFallbackAttribs(RV_Render* r);
792  void resetFallbackAttribs(RV_Render* r);
793  rv_Attribute* getFallbackVertAttrib(RV_GPUType type);
794  rv_Attribute* getFallbackTexBufAttrib(RV_UniformType type);
795  UT_UniquePtr<rv_Attribute> myDefaultVertexAttrib;
796  UT_UniquePtr<rv_Attribute> myDefaultIntVertexAttrib;
797  UT_UniquePtr<rv_Attribute> myDefaultUIntVertexAttrib;
798  UT_UniquePtr<rv_Attribute> myDefaultSamplerAttrib;
799  UT_UniquePtr<rv_Attribute> myDefaultIntSamplerAttrib;
800  UT_UniquePtr<rv_Attribute> myDefaultUIntSamplerAttrib;
801  UT_UniquePtr<rv_Attribute> myDefaultIndexSamplerAttrib;
802  UT_UniquePtr<rv_Attribute> myDefaultIndexVertexAttrib;
803 
804  // Ray tracing
805  RV_VKAccelerationStructurePtr myAccelerationStructure;
806 
807  UT_Matrix4F myLastObjTransform = UT_Matrix4F::getIdentityMatrix();
808  bool myIsAccelStructDirty = true;
809  bool myIsAccelStructInstDirty = true;
810 };
811 
812 #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:605
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