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 #include "RV_VKDescriptorSet.h"
36 #include "RV_ShaderProgram.h"
37 
38 class RV_Render;
39 class RV_ShaderBlock;
40 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  /// Set number of points in geometry for vertex shader inputs
179  bool setNumPoints(exint num_points);
180  /// Number of points in geometry for vertex shader inputs
181  exint getNumPoints() const;
182 
183  /// Set number of per-vertex elements, accessed in fragment shader/
184  /// Must match the number of primitives drawn.
185  void setVertexBufferSize(exint vert_buffer_elements);
186  /// Number of per-primitive elements, accessed in fragment shader
187  exint getVertexBufferSize() const;
188 
189  /// Set number of per-primitive elements, accessed in fragment shader/
190  /// Must match the number of primitives drawn.
191  void setPrimitiveBufferSize(exint prim_buffer_elements);
192  /// Number of per-primitive elements, accessed in fragment shader
193  exint getPrimitiveBufferSize() const;
194 
195  // ---------------------------------------------------------------
196  // Methods for configuring the structure of the geometry
197 
198  /// @brief Create an attribute definition
199  /// Create an attribute definition for a vertex shader input
200  /// Capacity - optional buffer capacity in elements, in case of resizes
201  bool createAttribute(const UT_StringHolder &name,
202  RV_GPUType data_format, int vector_size,
203  exint capacity = -1, bool normalized = true,
204  bool allow_gpu_write = false);
205 
206  /// Creates a single value for a vertex shader input.
207  bool createConstant(const UT_StringHolder &name,
208  RV_GPUType data_format, int vector_size,
209  bool normalized = true);
210 
211  /// Create a vertex buffer for fragment shader indexing via vertex ID
212  bool createVertexBuffer(const UT_StringHolder &name,
213  RV_GPUType data_format, int vector_size,
214  exint capacity = -1, bool normalized = true,
215  bool allow_gpu_write = false);
216 
217  /// Create a buffer view for fragment shader indexing via gl_PrimitiveID
218  bool createPrimitiveBuffer(const UT_StringHolder &name,
219  RV_GPUType data_format, int vector_size,
220  bool normalized = true);
221 
222  /// Create a random-access attribute for instancing and other random access
223  /// Uses a buffer view.
224  bool createBufferAttribute(const UT_StringHolder &name,
225  RV_GPUType data_format, int vector_size,
226  exint buffer_size, bool normalized = true);
227 
228  /// Create an attribute that is allocated immediately
229  /// separate from those allocated during 'populateBuffers'
230  RV_Buffer* createAllocatedAttribute(RV_Render* r,
231  const UT_StringHolder &name,
232  RV_GPUType data_format, int vector_size,
234  exint capacity = -1,
235  bool normalized = true);
236 
237  /// @brief Fetch a buffer for an attribute.
238  /// Return the RV buffer for attribute `name`. Will not exist until
239  /// `populateBuffers()` is called.
240  RV_Buffer* getAttribute(const UT_StringHolder &name) const;
241  /// Tag the attribute with version information.
242  void setAttributeVersion(const UT_StringHolder &name,
243  const RE_CacheVersion &ver);
244  /// Set the attribute type (point, primitive, constant, random).
245  void setAttributeUsage(const UT_StringHolder &name,
246  RV_AttributeType ver);
247 
248  /// Set a vertex shader input to a constant value.
249  void setAttributeConstValue(const UT_StringHolder &name,
250  fpreal64 val);
251 
252  /// Remove attribute and free its resource
253  bool freeAttribute(RV_Render* r, const UT_StringHolder &name);
254 
255  /// @brief Get an attribute's usage
256  /// Get the type of an attribute (point, prim, const, random, null). May be
257  /// null if the attribute was freed.
258  bool getAttributeType(const UT_StringHolder &name,
259  RV_AttributeType& out_type) const;
260  /// Get the format of an attribute (return false if it does not exist).
261  bool getAttributeFormat(const UT_StringHolder &name,
262  RV_GPUType& out_type,
263  int& out_vec_size) const;
264  /// @brief Get the length of an attribute
265  /// Get the length, in elements (not bytes) of an attribute
266  /// (return false if it does not exist).
267  bool getAttributeLength(const UT_StringHolder &name,
268  exint& out_len) const;
269  /// Get the version of an attribute (return false if it does not exist).
270  bool getAttributeVersion(const UT_StringHolder &name,
271  RE_CacheVersion& out_ver) const;
272 
273  /// @brief Get an attribute's usage
274  /// Get the version of an attribute (return false if it does not exist).
275  /// Will always return the usage it was defined with, even if freed.
276  bool getAttributeUsage(const UT_StringHolder &name,
277  RV_AttributeType& out_ver) const;
278 
279  /// Get the constant value for the vertex input 'name'
280  fpreal64 getAttributeConstValue(const UT_StringHolder &name) const;
281 
282  /// True if the attribute exists in the geometry.
283  bool hasAttribute(const UT_StringHolder &name,
284  int instance_group = -1) const;
285 
286  // Instancing support ----------------------------------------------
287 
288  // subsets of instances (for materials)
289 
290  /// Create a instance group for instanced drawing
291  bool createInstanceGroup(int group_index);
292  /// Remove an instance group
293  void removeInstanceGroup(int group_index);
294  /// Return true if the instance group exists
295  bool hasInstanceGroup(int group_index) const;
296  /// Return the maximum index of all instance groups.
297  int getMaxInstanceGroup() const;
298 
299  /// Set the numbers of instances drawn in a group
300  void setInstanceGroupCount(int instance_group, int count);
301  /// Fetch the numbers of instances drawn in a group
302  int getInstanceGroupCount(int instance_group) const;
303  /// Fetch the numbers of instanced transforms in a group, ignoring index lists
304  int getInstanceGroupTransformCount(int instance_group) const;
305 
306  /// Set the group to draw all transforms, ignoring existing index list
307  void setInstanceGroupForceFullDraw(int instance_group, bool enable);
308  /// Fetch whether group was set to force full draws
309  bool getInstanceGroupForceFullDraw(int instance_group) const;
310 
311  /// Select a subset of instance indices for an instance group (eg, culling)
312  void setInstanceGroupIndexList(int group_index,
313  const UT_IntArray &indices,
314  int max_capacity = -1);
315  /// Draw one instance with a specific index
316  void setInstanceGroupConstIndex(int instance_group,
317  int instance_to_draw);
318  /// Draw all instances
319  void setInstanceGroupDrawEverything(int instance_group);
320  /// Draw none of the instances
321  void setInstanceGroupDrawNothing(int instance_group);
322 
323  // Transforms for instances
324 
325  /// Single transform for all instances (or additional transform if
326  /// remove_instanced_xform is false)
327  void setConstInstanceGroupTransform(int instance_group,
328  const UT_Matrix4F &xform,
329  bool remove_instanced_xform);
330 
331  /// set instance group to use the same const transform as another
332  void copyConstInstanceGroupTransform(int instance_group, int src_group);
333 
334  /// @brief Create an per-instance attribute
335  /// Reserve an buffer for per-instance data (call populateBuffers() to
336  /// create the RV_Buffer for it).
337  bool setInstanceGroupAttrib(int instance_group,
338  const UT_StringHolder &name,
339  RV_GPUType data_type,
340  int vector_size,
341  int instance_step,
342  int num_instances,
343  exint capacity = -1,
344  bool normalized = true);
345 
346  /// Create per-instance attribute that can be shared by multiple RV_Geometrys
347  bool createSharedInstanceGroupAttrib(int instance_group,
348  const UT_StringHolder &name,
349  RV_GPUType data_type,
350  int vector_size,
351  int instance_step,
352  int num_instances,
353  exint capacity = -1,
354  bool normalized = true);
355 
356  /// Assign a buffer for the per-instance shared attribute
357  bool assignSharedInstanceGroupAttrib(int instance_group,
358  const UT_StringHolder &name,
360 
361  /// Remove per-instance attribute and free its resource
362  bool freeInstanceGroupAttrib(int instance_group,
363  const UT_StringHolder &name);
364 
365  /// Helper to allocate a shared per-instance buffer
366  static RV_VKBufferPtr allocateSharedInstanceBuffer(
367  RV_Render* r,
368  RV_GPUType data_type,
369  int vector_size,
370  exint length,
371  bool normalized = true,
372  const char* name = nullptr);
373 
374  static RV_VKBufferPtr allocateSharedCPUMappedInstanceBuffer(
375  RV_Render* r,
376  RV_GPUType data_type,
377  int vector_size,
378  exint length,
379  bool normalized = true,
380  bool cpu_mapped = true,
381  const char* name = nullptr);
382 
383  /// Fetch the buffer backing an per-instance attribute, usually to fill it
384  RV_Buffer * getInstanceGroupAttrib(int instance_group,
385  const UT_StringHolder &name) const;
386  /// @brief Get the length of an attribute
387  /// Get the length, in elements (not bytes) of an attribute
388  /// (return false if it does not exist).
389  bool getInstanceAttribLength(int instance_group,
390  const UT_StringHolder &name,
391  exint& out_len) const;
392 
393  /// Fetch the per-instance attribute version (to avoid refilling)
394  bool getInstanceAttribVersion(int instance_group,
395  const UT_StringHolder &name,
396  RE_CacheVersion& out_ver) const;
397  /// Set the per-instance attribute version (to avoid refilling)
398  void setInstanceAttribVersion(int instance_group,
399  const UT_StringHolder& name,
400  const RE_CacheVersion& ver);
401 
402  // ----------------------------------------------------------------------
403  // Connectivity
404 
405  /// Connect all points to form prims of `prim` type
406  void connectAllPrims(int connect_index,
407  RV_PrimType prim,
408  int patch_size = 0);
409  /// Connect a range of points to form prims of `prim` type
410  void connectSomePrims(int connect_index,
411  RV_PrimType prim,
412  int start,
413  int length,
414  unsigned int stride = 0,
415  int patch_size = 0);
416  /// Connect points form prims `prim` type from a list of `num_elements`
417  /// point indices. The index buffer must be populated after a
418  /// `populateBuffers()` call with `getIndexBuffer()->uploadData()`.
419  void connectIndexedPrims(int connect_index,
420  RV_PrimType prim,
421  int num_elements,
422  bool need_prim_info = false,
423  int patch_size = 0);
424  /// Connect a range of vertices to form prims of `prim` type
425  void connectSomeVerts(int connect_index,
426  RV_PrimType prim,
427  int start,
428  int length,
429  unsigned int stride = 0,
430  int patch_size = 0);
431 
432  void connectIndexedVerts(int connect_index,
433  RV_PrimType prim,
434  int num_elements,
435  bool need_prim_info = false,
436  int patch_size = 0);
437 
438  /// Set the primitive to GPU primitive ratio for acessing primitive
439  /// attributes. For example, if all polygons are quads, the divisor would be
440  /// 2 as the GPU creates 2 triangles for each quad.
441  void setConnectDivisor(int connect_index, int divisor,
442  int base_prim=0);
443  /// Generate a primitive info buffer for accessing primtive attribute data
444  /// if the polygon vertex counts vary (use getPrimVertexBuffer() after
445  // calling populateBuffers() to fill it).
446  void setConnectUsePrimInfo(int connect_index, int base_prim= 0);
447 
448  /// Set a PrimInfo buffer to be shared across connect groups with same
449  /// primitive type. Attribute must already exist in geometry.
450  void setPrimitiveInfoAttrib(RV_TopologyClass prim_type,
451  const UT_StringHolder &name);
452  /// return the number of primitives that are rendered for a connect group
453  int getNumRenderPrims(int connect_index) const;
454 
455  /// return the type of primitives that are rendered for a connect group
456  RV_PrimType getRenderPrimType(int connect_index) const;
457 
458  /// Fetch the index buffer to fill (after populateBuffers())
459  RV_Buffer *getIndexBuffer(int connect_index) const;
460  /// Fetch the primitive buffer to fill (after populateBuffers())
461  RV_Buffer *getPrimBuffer(int connect_index) const;
462  /// Fetch the primitive/vertex buffer to fill (after populateBuffers())
463  RV_Buffer *getPrimVertexBuffer(int connect_index) const;
464 
465  /// Return true if the connect group exists
466  bool hasConnectGroup(int connect_index) const;
467  /// Return true if the connect group isn't empty
468  bool hasNonEmptyConnectGroup(int connect_index) const;
469  /// Return the maximum connect group index
470  int getMaxConnectGroup() const;
471 
472  /// Remove a connect group
473  bool removeConnectedPrims(int connect_index);
474  /// Remove all connect groups.
475  void resetConnectedPrims(); // remove all
476 
477  // -------------------------------------------------------------
478  /// Populates all RV_Buffers declared above which haven't been populated yet.
479  bool populateBuffers(RV_Render *r);
480 
481  // --------------------------------------------------------------
482  // Drawing
483 
484  /// Setup Uniform buffers and Descriptor Set to be used by current shader
485  void prepareForDraw(RV_Render *r,
486  int connect_index,
487  const RV_OverrideList *overrides = nullptr);
488  /// Setup Uniform buffers and Descriptor Set to be used by current shader,
489  /// when drawing with instances
490  void prepareForDrawInstance( RV_Render* r,
491  int connect_index,
492  int instance_group,
493  const RV_OverrideList *overrides = nullptr);
494 
495  /// draw a single connection group
496  void draw(
497  RV_Render *r,
498  int connect_index,
499  const RV_OverrideList *overrides = nullptr,
500  bool force_point_prims = false);
501 
502  /// draw a single connection group
503  /// draw_offset and draw_size can specifiy a vertex range in the connect
504  void draw(
505  RV_Render *r,
506  int connect_index,
507  const RV_OverrideList *overrides,
508  exint draw_offset, exint draw_size);
509 
510  /// draw a single connection group using with instancing, using the indices
511  /// in instance_group
512  void drawInstanceGroup(
513  RV_Render *r,
514  int connect_index,
515  int instance_group,
516  const RV_OverrideList *overrides = nullptr,
517  bool force_point_prims = false);
518 
519  /// draw a single connection group using with instancing, using the indices
520  /// in instance_group
521  /// draw_offset and draw_size can specifiy a vertex range in the connect
522  void drawInstanceGroup(
523  RV_Render *r,
524  int connect_index,
525  int instance_group,
526  const RV_OverrideList *overrides,
527  exint draw_offset, exint draw_size);
528 
529  /// draw multiple connection groups (really just a loop over draw()).
530  void drawRange(
531  RV_Render *r,
532  int connect_index_start,
533  int num_connect_indexs,
534  const RV_OverrideList *overrides = nullptr,
535  bool force_point_prims = false);
536 
537  /// draw instanced over multiple connection groups.
538  void drawInstanceGroupRange(
539  RV_Render *r,
540  int connect_start,
541  int num_connect,
542  int instance_group,
543  const RV_OverrideList *overrides = nullptr,
544  bool force_point_prims = false);
545 
546  /// draw indirectly from a buffer
547  void drawIndirect(
548  RV_Render *r,
549  int connect_index,
550  RV_Buffer &indirect_buffer);
551 
552  /// dispatch a compute shader for a single connect group
553  void dispatch(RV_Render *r,
554  int connect_index,
555  int instance_group,
556  const RV_OverrideList *overrides = nullptr);
557 
558  /// dispatch compute shader for multiple connect groups
559  void dispatchRange(RV_Render *r,
560  int connect_index,
561  int num_connect,
562  int instance_group,
563  const RV_OverrideList *overrides = nullptr);
564 
565  static void initResources(RV_Instance* inst);
566  static void cleanupResources();
567 
568  // -------------------------------------------------------------------
569  // DEBUG
570 
571  /// @brief Debug output
572  /// Debug methd to print information about all attributes, connect groups,
573  /// and instance groups
574  void print() const;
575  // TODO: setDebugDraw() to print shader state during draw
576 
577 private:
578 
579  // ------------------------------------------------------------------
580  // CONNECTIVITY
581  rv_Connectivity* getConnect(int group_idx, bool do_create);
582 
583  // ------------------------------------------------------------------
584  // INSTANCE
585  static void getInstanceAttribName(UT_WorkBuffer &out_name,
586  const char *base_name,
587  int instance_group);
588 
589  // ------------------------------------------------------------------
590  // ATTRIBUTES
591  const rv_Attribute* findAttribute(const UT_StringRef& name,
592  const RV_OverrideList *overrides,
593  int instance_group,
594  int* out_idx = nullptr) const;
595 
596  bool privCreateAttribute( const UT_StringHolder& name,
597  RV_GPUType data_format,
598  int vector_size,
599  bool normalize,
600  RV_AttributeType usage,
601  exint capacity = -1,
602  int inst_group = -1,
603  bool attr_owned = false,
604  bool allow_gpu_write = false);
605  bool privFreeAttrib(RV_Render* r, rv_Attribute &attr);
606 
607  // ------------------------------------------------------------------
608  // BUFFERS
609  RV_Buffer *allocateAttributeBuffer(
610  RV_Render *r,
611  rv_Attribute &attr,
612  UT_Array<RV_BufferPtr> *opt_old_buffers = nullptr);
613  bool allocateConnectBuffers(RV_Render* r, rv_Connectivity& c,
614  UT_Array<RV_BufferPtr>* opt_old_buffers);
615  bool allocateInstIndexBuffer(RV_Render* r, rv_InstanceGroup& g,
616  UT_Array<RV_BufferPtr>* opt_old_buffers);
617 
618  RV_BufferPtr allocOrReuseBuffer( RV_Render *r, rv_Attribute &attr,
619  exint length, VkBufferUsageFlags vk_usage,
620  UT_Array<RV_BufferPtr> *old_buffers);
621 
622  void resetAttribBuffers(RV_Render* r);
623  void resetConnectBuffers(RV_Render* r);
624  void resetCachedSets(RV_Render* r);
625 
626  bool privPrepareDraw(
627  RV_Render* r,
628  const rv_Connectivity *connect,
629  int instance_group_idx,
630  const RV_OverrideList* overrides
631  );
632 
633  void privDraw(
634  RV_Render *r,
635  const rv_Connectivity *connect,
636  int instance_group_idx,
637  const RV_OverrideList *overrides,
638  RV_Buffer* indirect_buf,
639  bool force_point_prims
640  );
641 
642  void privDraw(
643  RV_Render *r,
644  const rv_Connectivity *connect,
645  int instance_group_idx,
646  const RV_OverrideList *overrides,
647  RV_Buffer* indirect_buf,
648  bool force_point_prims,
649  exint draw_offset,
650  exint draw_length
651  );
652 
653  void privDispatch(
654  RV_Render *r,
655  const rv_Connectivity *connect,
656  int instance_group_idx,
657  const RV_OverrideList *overrides,
658  RV_Buffer *indirect_buf
659  );
660 
661  void fillInstanceInfoBlock(RV_Render *r, int instance_group_idx, RV_ShaderBlock* block);
662  void fillGeometryInfoBlock(RV_Render *r, const rv_Connectivity* connect, RV_ShaderBlock* geo);
663 
664  // ------------------------------------------------------------------
665  // DATA
666  RV_Render* myR = nullptr;
667 
668  uint32_t myNumPoints = 0;
669  uint32_t myVertBufferSize = 0;
670  uint32_t myPrimBufferSize = 0;
671 
672  bool myAttributesValid = false;
673 
674  // TODO: Make sure nothing name-to-idx mapping is stable
675  // (i.e. attrib names can't be removed)
676  UT_StringMap<int> myAttributeTable;
677  UT_Array<int> myDefaultAttribTable;
678  UT_Array<int> myPrimInfoAttribTable;
679  UT_Array<rv_Attribute> myAttributeList;
680 
681  // own directly so helper structs can be passed around more easily
682  UT_Array<RV_BufferPtr> myOwnedAttribBuffers;
683  UT_Array<RV_BufferPtr> myOwnedConnectBuffers;
684  UT_Array<RV_BufferPtr> myOwnedFallbackBuffers;
685  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedGeoBuffers;
686  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedInstBuffers;
687 
688  // TODO: allocate buffers from single block of memory
689  //UT_UniquePtr<RV_VKMemory> myMemBlock;
690 
691  UT_Array<rv_Connectivity> myConnectivityGroups;
692 
693  UT_Array<rv_InstanceGroupPtr> myInstanceGroups;
694 
695  struct rv_DrawSetInfo
696  {
697  // track the override list used
698  RV_OverrideList myOverrideList;
699  int myConnectGroupIdx;
700  int myInstanceGroupIdx;
701 
702  bool myIsValid = false;
703 
704  UT_UniquePtr<RV_ShaderVariableSet> myDescriptorSet;
705  UT_UniquePtr<RV_ShaderBlock> myUniformBlock;
706 
707  // TODO: move into connect group
708  UT_UniquePtr<RV_ShaderBlock> myGeometryBlock;
709 
710  int myInstTransformUniformIdx = -1;
711  int myInstNestLevelUniformIdx = -1;
712 
713  // TODO: keep a list of the [attrib ID, binding ID] pairs
714  // and check if they are up-to-date per-frame
715  // TODO: requires RV_Geo and RV_ShaderVariableSet
716  // be setup to refer to attribs by consistent
717  // idx/binding num
718  // currently invalidating any time the interface
719  // may have changed
720  };
721 
722  // Set Used for drawing
723  // cached by (connect group, instance group, set id)
724  typedef UT_Map<std::tuple<int, int, int>, rv_DrawSetInfo> DrawSetCache;
725  DrawSetCache myDrawSet;
726 
727  // Get the set that is compatible with the passed in shader
728  // creating it if necessary
729  rv_DrawSetInfo* getDrawSet(
730  RV_Render* r,
732  const rv_Connectivity *connect,
733  int instance_group_idx,
734  const RV_OverrideList* overrides);
735 
736  // Prepare a set, making sure all attributes are attached and
737  // up-to-date
738  bool prepareDrawSet(
739  RV_Render* r,
740  rv_DrawSetInfo& set_info,
741  const rv_Connectivity *connect,
742  int instance_group_idx,
743  const RV_OverrideList* overrides
744  );
745 
746  bool bindInputAttribute(
747  RV_Render* r,
748  RV_VKPipelineInputInfo& pipe_input,
749  const rv_Connectivity *connect,
750  const rv_Attribute *attrib,
751  bool instance,
752  int location,
754  int vec_size);
755  //rv_DrawSetCache myDrawSets;
756 
757  // Zero-valued constant buffers to fill attribs we don't have values for
758  // TODO: use nullDescriptor bindings if VK_EXT_robustness2 is available
759  void populateFallbackAttribs(RV_Render* r);
760  void resetFallbackAttribs(RV_Render* r);
761  rv_Attribute* getFallbackVertAttrib(RV_GPUType type);
762  rv_Attribute* getFallbackTexBufAttrib(RV_UniformType type);
763  UT_UniquePtr<rv_Attribute> myDefaultVertexAttrib;
764  UT_UniquePtr<rv_Attribute> myDefaultIntVertexAttrib;
765  UT_UniquePtr<rv_Attribute> myDefaultUIntVertexAttrib;
766  UT_UniquePtr<rv_Attribute> myDefaultSamplerAttrib;
767  UT_UniquePtr<rv_Attribute> myDefaultIntSamplerAttrib;
768  UT_UniquePtr<rv_Attribute> myDefaultUIntSamplerAttrib;
769  UT_UniquePtr<rv_Attribute> myDefaultIndexSamplerAttrib;
770  UT_UniquePtr<rv_Attribute> myDefaultIndexVertexAttrib;
771 };
772 
773 #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:107
VkPrimitiveTopology RVgetVkPrimType(RV_PrimType t)
Definition: RV_Geometry.h:59
UT_UniquePtr< RV_VKBuffer > RV_VKBufferPtr
Definition: RV_TypePtrs.h:55
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
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
Definition: core.h:760
GLboolean reset
Definition: glad.h:5138
RV_AttributeType
Definition: RV_Type.h:96
RV_UniformType
Definition: RV_Type.h:284
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:38
GLdouble t
Definition: glad.h:2397
UT_GPUType RVconvertToUTGPUType(RV_GPUType t)
Definition: RV_Geometry.h:81
RV_PrimType
Definition: RV_Type.h:367
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:394
RV_GPUType
Definition: RV_Type.h:37
GLuint GLfloat * val
Definition: glcorearb.h:1608
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)
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
type
Definition: core.h:1059
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
GLint GLsizei count
Definition: glcorearb.h:405
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept