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  /// @brief Get the instance stride
434  /// (return false if it does not exist).
435  bool getInstanceAttribStride(int instance_group,
436  const UT_StringHolder &name,
437  exint& out_stride) const;
438 
439  /// Fetch the per-instance attribute version (to avoid refilling)
440  bool getInstanceAttribVersion(int instance_group,
441  const UT_StringHolder &name,
442  RE_CacheVersion& out_ver) const;
443  /// Set the per-instance attribute version (to avoid refilling)
444  void setInstanceAttribVersion(int instance_group,
445  const UT_StringHolder& name,
446  const RE_CacheVersion& ver);
447 
448  // ----------------------------------------------------------------------
449  // Connectivity
450 
451  /// Connect all points to form prims of `prim` type
452  void connectAllPrims(int connect_index,
453  RV_PrimType prim,
454  int patch_size = 0);
455  /// Connect a range of points to form prims of `prim` type
456  void connectSomePrims(int connect_index,
457  RV_PrimType prim,
458  int start,
459  int length,
460  unsigned int stride = 0,
461  int patch_size = 0);
462  /// Connect points form prims `prim` type from a list of `num_elements`
463  /// point indices. The index buffer must be populated after a
464  /// `populateBuffers()` call with `getIndexBuffer()->uploadData()`.
465  void connectIndexedPrims(int connect_index,
466  RV_PrimType prim,
467  int num_elements,
468  bool need_prim_info = false,
469  int patch_size = 0);
470  /// Connect a range of vertices to form prims of `prim` type
471  void connectSomeVerts(int connect_index,
472  RV_PrimType prim,
473  int start,
474  int length,
475  unsigned int stride = 0,
476  int patch_size = 0);
477 
478  void connectIndexedVerts(int connect_index,
479  RV_PrimType prim,
480  int num_elements,
481  bool need_prim_info = false,
482  int patch_size = 0);
483 
484  /// Set the primitive to GPU primitive ratio for acessing primitive
485  /// attributes. For example, if all polygons are quads, the divisor would be
486  /// 2 as the GPU creates 2 triangles for each quad.
487  void setConnectDivisor(int connect_index, int divisor,
488  int base_prim=0);
489  /// Generate a primitive info buffer for accessing primtive attribute data
490  /// if the polygon vertex counts vary (use getPrimVertexBuffer() after
491  // calling populateBuffers() to fill it).
492  void setConnectUsePrimInfo(int connect_index, int base_prim= 0);
493 
494  // Override the parameters used for the draw call in the connect group,
495  // without modifying the connect group
496  void setDrawModeOverride(int connect_index,
497  RV_PrimType prim_type,
498  exint vert_count);
499 
500  // disables any active draw mode overrides for the given connect group
501  void resetDrawModeOverride(int connect_index);
502 
503  /// Set a PrimInfo buffer to be shared across connect groups with same
504  /// primitive type. Attribute must already exist in geometry.
505  void setPrimitiveInfoAttrib(RV_TopologyClass prim_type,
506  const UT_StringHolder &name);
507  /// return the number of primitives that are rendered for a connect group
508  int getNumRenderPrims(int connect_index) const;
509 
510  /// return the type of primitives that are rendered for a connect group
511  RV_PrimType getRenderPrimType(int connect_index) const;
512 
513  /// return the number of vertices that are rendered for a connect group
514  int getLength(int connect_index) const;
515 
516  /// Fetch the index buffer to fill (after populateBuffers())
517  RV_Buffer *getIndexBuffer(int connect_index) const;
518  /// Fetch the primitive buffer to fill (after populateBuffers())
519  RV_Buffer *getPrimBuffer(int connect_index) const;
520  /// Fetch the primitive/vertex buffer to fill (after populateBuffers())
521  RV_Buffer *getPrimVertexBuffer(int connect_index) const;
522 
523  // True if the vertex shader is run at vertex frequency (False if at point)
524  bool isVertexFrequency(int connect_index) const;
525 
526  /// Return true if the connect group exists
527  bool hasConnectGroup(int connect_index) const;
528  /// Return true if the connect group isn't empty
529  bool hasNonEmptyConnectGroup(int connect_index) const;
530  /// Return the maximum connect group index
531  int getMaxConnectGroup() const;
532 
533  /// Remove a connect group
534  bool removeConnectedPrims(int connect_index);
535  /// Remove all connect groups.
536  void resetConnectedPrims(); // remove all
537 
538  // -------------------------------------------------------------
539  /// Populates all RV_Buffers declared above which haven't been populated yet.
540  bool populateBuffers(RV_Render *r);
541 
542  // --------------------------------------------------------------
543  // Drawing
544 
545  /// Setup Uniform buffers and Descriptor Set to be used by current shader
546  void prepareForDraw(RV_Render *r,
547  int connect_index,
548  const RV_OverrideList *overrides = nullptr);
549  /// Setup Uniform buffers and Descriptor Set to be used by current shader,
550  /// when drawing with instances
551  void prepareForDrawInstance( RV_Render* r,
552  int connect_index,
553  int instance_group,
554  const RV_OverrideList *overrides = nullptr);
555 
556  /// draw a single connection group
557  /// draw_offset and draw_size can specifiy a vertex range in the connect
558  void draw(
559  RV_Render *r,
560  int connect_index,
561  const RV_OverrideList *overrides = nullptr,
562  exint draw_offset = -1, exint draw_size = -1);
563 
564  /// draw a single connection group using with instancing, using the indices
565  /// in instance_group
566  /// draw_offset and draw_size can specifiy a vertex range in the connect
567  void drawInstanceGroup(
568  RV_Render *r,
569  int connect_index,
570  int instance_group,
571  const RV_OverrideList *overrides = nullptr,
572  exint draw_offset = -1, exint draw_size = -1);
573 
574  /// draw multiple connection groups (really just a loop over draw()).
575  void drawRange(
576  RV_Render *r,
577  int connect_index_start,
578  int num_connect_indexs,
579  const RV_OverrideList *overrides = nullptr);
580 
581  /// draw instanced over multiple connection groups.
582  void drawInstanceGroupRange(
583  RV_Render *r,
584  int connect_start,
585  int num_connect,
586  int instance_group,
587  const RV_OverrideList *overrides = nullptr);
588 
589  /// draw indirectly from a buffer
590  void drawIndirect(
591  RV_Render *r,
592  int connect_index,
593  RV_Buffer &indirect_buffer);
594 
595  /// dispatch a compute shader for a single connect group
596  void dispatch(RV_Render *r,
597  int connect_index,
598  int instance_group,
599  const RV_OverrideList *overrides = nullptr);
600 
601  /// dispatch compute shader for multiple connect groups
602  void dispatchRange(RV_Render *r,
603  int connect_index,
604  int num_connect,
605  int instance_group,
606  const RV_OverrideList *overrides = nullptr);
607 
608  static void initResources(RV_Instance* inst);
609  static void cleanupResources();
610 
611  // --------------------------------------------------------------
612  // Ray tracing
613  void updateAccelerationStructure(
614  RV_Render *r,
615  int tag,
616  int light_id,
617  int surface_connect_index,
618  const UT_Matrix4F &obj_mat);
619 
620  RV_VKAccelerationStructure* getAccelerationStructure();
621 
622  // manually force acceleration structure rebuild
623  void dirtyAccelerationStructure() { myIsAccelStructDirty = true; }
624 
625  // -------------------------------------------------------------------
626  // DEBUG
627 
628  /// @brief Debug output
629  /// Debug methd to print information about all attributes, connect groups,
630  /// and instance groups
631  void print() const;
632  // TODO: setDebugDraw() to print shader state during draw
633 
634 private:
635 
636  // ------------------------------------------------------------------
637  // CONNECTIVITY
638  rv_Connectivity* getConnect(int group_idx, bool do_create);
639 
640  // ------------------------------------------------------------------
641  // INSTANCE
642  static void getInstanceAttribName(UT_WorkBuffer &out_name,
643  const char *base_name,
644  int instance_group);
645 
646  int getTransformAttribCount(const rv_Attribute* attr) const;
647 
648  // ------------------------------------------------------------------
649  // ATTRIBUTES
650  const rv_Attribute* findAttribute(const UT_StringRef& name,
651  const RV_OverrideList *overrides,
652  int instance_group,
653  int* out_idx = nullptr) const;
654 
655  bool privCreateAttribute( const UT_StringHolder& name,
656  RV_GPUType data_format,
657  int vector_size,
658  bool normalize,
660  exint capacity = -1,
661  int inst_group = -1,
662  bool attr_owned = false,
663  bool allow_gpu_write = false);
664  bool privFreeAttrib(RV_Render* r, rv_Attribute &attr);
665 
666  // ------------------------------------------------------------------
667  // BUFFERS
668  RV_Buffer *allocateAttributeBuffer(
669  RV_Render *r,
670  rv_Attribute &attr,
671  UT_Array<RV_BufferPtr> *opt_old_buffers = nullptr);
672  bool allocateConnectBuffers(RV_Render* r, rv_Connectivity& c,
673  UT_Array<RV_BufferPtr>* opt_old_buffers);
674  bool allocateInstIndexBuffer(RV_Render* r, rv_InstanceGroup& g,
675  UT_Array<RV_BufferPtr>* opt_old_buffers);
676 
677  RV_BufferPtr allocOrReuseBuffer( RV_Render *r, rv_Attribute &attr,
678  exint length, VkBufferUsageFlags vk_usage,
679  UT_Array<RV_BufferPtr> *old_buffers);
680 
681  void resetAttribBuffers(RV_Render* r);
682  void resetConnectBuffers(RV_Render* r);
683  void resetCachedSets(RV_Render* r);
684 
685  bool privPrepareDraw(
686  RV_Render* r,
687  const rv_Connectivity *connect,
688  int instance_group_idx,
689  const RV_OverrideList* overrides
690  );
691 
692  void privDraw(
693  RV_Render *r,
694  const rv_Connectivity *connect,
695  int instance_group_idx,
696  const RV_OverrideList *overrides,
697  RV_Buffer* indirect_buf,
698  exint draw_offset = -1,
699  exint draw_length = -1
700  );
701 
702  void privDispatch(
703  RV_Render *r,
704  const rv_Connectivity *connect,
705  int instance_group_idx,
706  const RV_OverrideList *overrides,
707  RV_Buffer *indirect_buf
708  );
709 
710  void fillInstanceInfoBlock(RV_Render *r, int instance_group_idx, RV_ShaderBlock* block);
711  void fillGeometryInfoBlock(RV_Render *r, const rv_Connectivity* connect, RV_ShaderBlock* geo);
712 
713  // ------------------------------------------------------------------
714  // DATA
715  RV_Render* myR = nullptr;
716  UT_StringHolder myName;
717 
718  uint32_t myNumPoints = 0;
719  uint32_t myVertBufferSize = 0;
720  uint32_t myPrimBufferSize = 0;
721 
722  bool myAttributesValid = false;
723 
724  // TODO: Make sure nothing name-to-idx mapping is stable
725  // (i.e. attrib names can't be removed)
726  UT_StringMap<int> myAttributeTable;
727  UT_Array<int> myDefaultAttribTable;
728  UT_Array<int> myPrimInfoAttribTable;
729  UT_Array<rv_Attribute> myAttributeList;
730 
731  // own directly so helper structs can be passed around more easily
732  UT_Array<RV_BufferPtr> myOwnedAttribBuffers;
733  UT_Array<RV_BufferPtr> myOwnedConnectBuffers;
734  UT_Array<RV_BufferPtr> myOwnedFallbackBuffers;
735  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedGeoBuffers;
736  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedInstBuffers;
737 
738  // TODO: allocate buffers from single block of memory
739  //UT_UniquePtr<RV_VKMemory> myMemBlock;
740 
741  UT_Array<rv_Connectivity> myConnectivityGroups;
742 
743  UT_Array<rv_InstanceGroupPtr> myInstanceGroups;
744 
745  struct rv_DrawSetInfo
746  {
747  // track the override list used
748  RV_OverrideList myOverrideList;
749  int myConnectGroupIdx;
750  int myInstanceGroupIdx;
751 
752  bool myIsValid = false;
753 
754  UT_UniquePtr<RV_ShaderVariableSet> myDescriptorSet;
755  UT_UniquePtr<RV_ShaderBlock> myUniformBlock;
756 
757  // TODO: move into connect group
758  UT_UniquePtr<RV_ShaderBlock> myGeometryBlock;
759 
760  int myInstTransformUniformIdx = -1;
761  int myInstNestLevelUniformIdx = -1;
762 
763  // TODO: keep a list of the [attrib ID, binding ID] pairs
764  // and check if they are up-to-date per-frame
765  // TODO: requires RV_Geo and RV_ShaderVariableSet
766  // be setup to refer to attribs by consistent
767  // idx/binding num
768  // currently invalidating any time the interface
769  // may have changed
770  };
771 
772  // Set Used for drawing
773  // cached by (connect group, instance group, set id)
774  typedef UT_Map<std::tuple<int, int, int>, rv_DrawSetInfo> DrawSetCache;
775  DrawSetCache myDrawSet;
776 
777  // Get the set that is compatible with the passed in shader
778  // creating it if necessary
779  rv_DrawSetInfo* getDrawSet(
780  RV_Render* r,
782  const rv_Connectivity *connect,
783  int instance_group_idx,
784  const RV_OverrideList* overrides);
785 
786  // Prepare a set, making sure all attributes are attached and
787  // up-to-date
788  bool prepareDrawSet(
789  RV_Render* r,
790  rv_DrawSetInfo& set_info,
791  const rv_Connectivity *connect,
792  int instance_group_idx,
793  const RV_OverrideList* overrides
794  );
795 
796  bool bindInputAttribute(
797  RV_Render* r,
798  RV_VKPipelineInputInfo& pipe_input,
799  const rv_Connectivity *connect,
800  const rv_Attribute *attrib,
801  bool instance,
802  int location,
804  int vec_size);
805  //rv_DrawSetCache myDrawSets;
806 
807  // Zero-valued constant buffers to fill attribs we don't have values for
808  // TODO: use nullDescriptor bindings if VK_EXT_robustness2 is available
809  void populateFallbackAttribs(RV_Render* r);
810  void resetFallbackAttribs(RV_Render* r);
811  rv_Attribute* getFallbackVertAttrib(RV_GPUType type);
812  rv_Attribute* getFallbackTexBufAttrib(RV_UniformType type);
813  UT_UniquePtr<rv_Attribute> myDefaultVertexAttrib;
814  UT_UniquePtr<rv_Attribute> myDefaultIntVertexAttrib;
815  UT_UniquePtr<rv_Attribute> myDefaultUIntVertexAttrib;
816  UT_UniquePtr<rv_Attribute> myDefaultSamplerAttrib;
817  UT_UniquePtr<rv_Attribute> myDefaultIntSamplerAttrib;
818  UT_UniquePtr<rv_Attribute> myDefaultUIntSamplerAttrib;
819  UT_UniquePtr<rv_Attribute> myDefaultIndexSamplerAttrib;
820  UT_UniquePtr<rv_Attribute> myDefaultIndexVertexAttrib;
821 
822  // Ray tracing
823  RV_VKAccelerationStructurePtr myAccelerationStructure;
824 
825  UT_Matrix4F myLastObjTransform = UT_Matrix4F::getIdentityMatrix();
826  bool myIsAccelStructDirty = true;
827  bool myIsAccelStructInstDirty = true;
828 };
829 
830 #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:623
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