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