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  /// @brief Create an per-instance attribute
332  /// Reserve an buffer for per-instance data (call populateBuffers() to
333  /// create the RV_Buffer for it).
334  bool setInstanceGroupAttrib(int instance_group,
335  const UT_StringHolder &name,
336  RV_GPUType data_type,
337  int vector_size,
338  int instance_step,
339  int num_instances,
340  exint capacity = -1,
341  bool normalized = true);
342 
343  /// Create per-instance attribute that can be shared by multiple RV_Geometrys
344  bool createSharedInstanceGroupAttrib(int instance_group,
345  const UT_StringHolder &name,
346  RV_GPUType data_type,
347  int vector_size,
348  int instance_step,
349  int num_instances,
350  exint capacity = -1,
351  bool normalized = true);
352 
353  /// Assign a buffer for the per-instance shared attribute
354  bool assignSharedInstanceGroupAttrib(int instance_group,
355  const UT_StringHolder &name,
357 
358  /// Remove per-instance attribute and free its resource
359  bool freeInstanceGroupAttrib(int instance_group,
360  const UT_StringHolder &name);
361 
362  /// Helper to allocate a shared per-instance buffer
363  static RV_VKBufferPtr allocateSharedInstanceBuffer(
364  RV_Render* r,
365  RV_GPUType data_type,
366  int vector_size,
367  exint length,
368  bool normalized = true,
369  const char* name = nullptr);
370 
371  static RV_VKBufferPtr allocateSharedCPUMappedInstanceBuffer(
372  RV_Render* r,
373  RV_GPUType data_type,
374  int vector_size,
375  exint length,
376  bool normalized = true,
377  bool cpu_mapped = true,
378  const char* name = nullptr);
379 
380  /// Fetch the buffer backing an per-instance attribute, usually to fill it
381  RV_Buffer * getInstanceGroupAttrib(int instance_group,
382  const UT_StringHolder &name) const;
383  /// @brief Get the length of an attribute
384  /// Get the length, in elements (not bytes) of an attribute
385  /// (return false if it does not exist).
386  bool getInstanceAttribLength(int instance_group,
387  const UT_StringHolder &name,
388  exint& out_len) const;
389 
390  /// Fetch the per-instance attribute version (to avoid refilling)
391  bool getInstanceAttribVersion(int instance_group,
392  const UT_StringHolder &name,
393  RE_CacheVersion& out_ver) const;
394  /// Set the per-instance attribute version (to avoid refilling)
395  void setInstanceAttribVersion(int instance_group,
396  const UT_StringHolder& name,
397  const RE_CacheVersion& ver);
398 
399  // ----------------------------------------------------------------------
400  // Connectivity
401 
402  /// Connect all points to form prims of `prim` type
403  void connectAllPrims(int connect_index,
404  RV_PrimType prim,
405  int patch_size = 0);
406  /// Connect a range of points to form prims of `prim` type
407  void connectSomePrims(int connect_index,
408  RV_PrimType prim,
409  int start,
410  int length,
411  unsigned int stride = 0,
412  int patch_size = 0);
413  /// Connect points form prims `prim` type from a list of `num_elements`
414  /// point indices. The index buffer must be populated after a
415  /// `populateBuffers()` call with `getIndexBuffer()->uploadData()`.
416  void connectIndexedPrims(int connect_index,
417  RV_PrimType prim,
418  int num_elements,
419  bool need_prim_info = false,
420  int patch_size = 0);
421  /// Connect a range of vertices to form prims of `prim` type
422  void connectSomeVerts(int connect_index,
423  RV_PrimType prim,
424  int start,
425  int length,
426  unsigned int stride = 0,
427  int patch_size = 0);
428 
429  void connectIndexedVerts(int connect_index,
430  RV_PrimType prim,
431  int num_elements,
432  bool need_prim_info = false,
433  int patch_size = 0);
434 
435  /// Set the primitive to GPU primitive ratio for acessing primitive
436  /// attributes. For example, if all polygons are quads, the divisor would be
437  /// 2 as the GPU creates 2 triangles for each quad.
438  void setConnectDivisor(int connect_index, int divisor,
439  int base_prim=0);
440  /// Generate a primitive info buffer for accessing primtive attribute data
441  /// if the polygon vertex counts vary (use getPrimVertexBuffer() after
442  // calling populateBuffers() to fill it).
443  void setConnectUsePrimInfo(int connect_index, int base_prim= 0);
444 
445  /// Set a PrimInfo buffer to be shared across connect groups with same
446  /// primitive type. Attribute must already exist in geometry.
447  void setPrimitiveInfoAttrib(RV_TopologyClass prim_type,
448  const UT_StringHolder &name);
449  /// return the number of primitives that are rendered for a connect group
450  int getNumRenderPrims(int connect_index) const;
451 
452  /// return the type of primitives that are rendered for a connect group
453  RV_PrimType getRenderPrimType(int connect_index) const;
454 
455  /// Fetch the index buffer to fill (after populateBuffers())
456  RV_Buffer *getIndexBuffer(int connect_index) const;
457  /// Fetch the primitive buffer to fill (after populateBuffers())
458  RV_Buffer *getPrimBuffer(int connect_index) const;
459  /// Fetch the primitive/vertex buffer to fill (after populateBuffers())
460  RV_Buffer *getPrimVertexBuffer(int connect_index) const;
461 
462  /// Return true if the connect group exists
463  bool hasConnectGroup(int connect_index) const;
464  /// Return true if the connect group isn't empty
465  bool hasNonEmptyConnectGroup(int connect_index) const;
466  /// Return the maximum connect group index
467  int getMaxConnectGroup() const;
468 
469  /// Remove a connect group
470  bool removeConnectedPrims(int connect_index);
471  /// Remove all connect groups.
472  void resetConnectedPrims(); // remove all
473 
474  // -------------------------------------------------------------
475  /// Populates all RV_Buffers declared above which haven't been populated yet.
476  bool populateBuffers(RV_Render *r);
477 
478  // --------------------------------------------------------------
479  // Drawing
480 
481  /// Setup Uniform buffers and Descriptor Set to be used by current shader
482  void prepareForDraw(RV_Render *r,
483  int connect_index,
484  const RV_OverrideList *overrides = nullptr);
485  /// Setup Uniform buffers and Descriptor Set to be used by current shader,
486  /// when drawing with instances
487  void prepareForDrawInstance( RV_Render* r,
488  int connect_index,
489  int instance_group,
490  const RV_OverrideList *overrides = nullptr);
491 
492  /// draw a single connection group
493  void draw(
494  RV_Render *r,
495  int connect_index,
496  const RV_OverrideList *overrides = nullptr,
497  bool force_point_prims = false);
498 
499  /// draw a single connection group using with instancing, using the indices
500  /// in instance_group
501  void drawInstanceGroup(
502  RV_Render *r,
503  int connect_index,
504  int instance_group,
505  const RV_OverrideList *overrides = nullptr,
506  bool force_point_prims = false);
507 
508  /// draw multiple connection groups (really just a loop over draw()).
509  void drawRange(
510  RV_Render *r,
511  int connect_index_start,
512  int num_connect_indexs,
513  const RV_OverrideList *overrides = nullptr,
514  bool force_point_prims = false);
515 
516  /// draw instanced over multiple connection groups.
517  void drawInstanceGroupRange(
518  RV_Render *r,
519  int connect_start,
520  int num_connect,
521  int instance_group,
522  const RV_OverrideList *overrides = nullptr,
523  bool force_point_prims = false);
524 
525  /// draw indirectly from a buffer
526  void drawIndirect(
527  RV_Render *r,
528  int connect_index,
529  RV_Buffer &indirect_buffer);
530 
531  /// dispatch a compute shader for a single connect group
532  void dispatch(RV_Render *r,
533  int connect_index,
534  int instance_group,
535  const RV_OverrideList *overrides = nullptr);
536 
537  /// dispatch compute shader for multiple connect groups
538  void dispatchRange(RV_Render *r,
539  int connect_index,
540  int num_connect,
541  int instance_group,
542  const RV_OverrideList *overrides = nullptr);
543 
544  static void initResources(RV_Instance* inst);
545  static void cleanupResources();
546 
547  // -------------------------------------------------------------------
548  // DEBUG
549 
550  /// @brief Debug output
551  /// Debug methd to print information about all attributes, connect groups,
552  /// and instance groups
553  void print() const;
554  // TODO: setDebugDraw() to print shader state during draw
555 
556 private:
557 
558  // ------------------------------------------------------------------
559  // CONNECTIVITY
560  rv_Connectivity* getConnect(int group_idx, bool do_create);
561 
562  // ------------------------------------------------------------------
563  // INSTANCE
564  static void getInstanceAttribName(UT_WorkBuffer &out_name,
565  const char *base_name,
566  int instance_group);
567 
568  // ------------------------------------------------------------------
569  // ATTRIBUTES
570  const rv_Attribute* findAttribute(const UT_StringRef& name,
571  const RV_OverrideList *overrides,
572  int instance_group,
573  int* out_idx = nullptr) const;
574 
575  bool privCreateAttribute( const UT_StringHolder& name,
576  RV_GPUType data_format,
577  int vector_size,
578  bool normalize,
579  RV_AttributeType usage,
580  exint capacity = -1,
581  int inst_group = -1,
582  bool attr_owned = false,
583  bool allow_gpu_write = false);
584  bool privFreeAttrib(RV_Render* r, rv_Attribute &attr);
585 
586  // ------------------------------------------------------------------
587  // BUFFERS
588  RV_Buffer *allocateAttributeBuffer(
589  RV_Render *r,
590  rv_Attribute &attr,
591  UT_Array<RV_BufferPtr> *opt_old_buffers = nullptr);
592  bool allocateConnectBuffers(RV_Render* r, rv_Connectivity& c,
593  UT_Array<RV_BufferPtr>* opt_old_buffers);
594  bool allocateInstIndexBuffer(RV_Render* r, rv_InstanceGroup& g,
595  UT_Array<RV_BufferPtr>* opt_old_buffers);
596 
597  RV_BufferPtr allocOrReuseBuffer( RV_Render *r, rv_Attribute &attr,
598  exint length, VkBufferUsageFlags vk_usage,
599  UT_Array<RV_BufferPtr> *old_buffers);
600 
601  void resetAttribBuffers(RV_Render* r);
602  void resetConnectBuffers(RV_Render* r);
603  void resetCachedSets(RV_Render* r);
604 
605  bool privPrepareDraw(
606  RV_Render* r,
607  const rv_Connectivity *connect,
608  int instance_group_idx,
609  const RV_OverrideList* overrides
610  );
611 
612  void privDraw(
613  RV_Render *r,
614  const rv_Connectivity *connect,
615  int instance_group_idx,
616  const RV_OverrideList *overrides,
617  RV_Buffer* indirect_buf,
618  bool force_point_prims
619  );
620 
621  void privDispatch(
622  RV_Render *r,
623  const rv_Connectivity *connect,
624  int instance_group_idx,
625  const RV_OverrideList *overrides,
626  RV_Buffer *indirect_buf
627  );
628 
629  void fillInstanceInfoBlock(RV_Render *r, int instance_group_idx, RV_ShaderBlock* block);
630  void fillGeometryInfoBlock(RV_Render *r, const rv_Connectivity* connect, RV_ShaderBlock* geo);
631 
632  // ------------------------------------------------------------------
633  // DATA
634  RV_Render* myR = nullptr;
635 
636  uint32_t myNumPoints = 0;
637  uint32_t myVertBufferSize = 0;
638  uint32_t myPrimBufferSize = 0;
639 
640  bool myAttributesValid = false;
641 
642  // TODO: Make sure nothing name-to-idx mapping is stable
643  // (i.e. attrib names can't be removed)
644  UT_StringMap<int> myAttributeTable;
645  UT_Array<int> myDefaultAttribTable;
646  UT_Array<int> myPrimInfoAttribTable;
647  UT_Array<rv_Attribute> myAttributeList;
648 
649  // own directly so helper structs can be passed around more easily
650  UT_Array<RV_BufferPtr> myOwnedAttribBuffers;
651  UT_Array<RV_BufferPtr> myOwnedConnectBuffers;
652  UT_Array<RV_BufferPtr> myOwnedFallbackBuffers;
653  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedGeoBuffers;
654  UT_Array<UT_UniquePtr<RV_ShaderBlock>> myOwnedInstBuffers;
655 
656  // TODO: allocate buffers from single block of memory
657  //UT_UniquePtr<RV_VKMemory> myMemBlock;
658 
659  UT_Array<rv_Connectivity> myConnectivityGroups;
660 
661  UT_Array<rv_InstanceGroupPtr> myInstanceGroups;
662 
663  struct rv_DrawSetInfo
664  {
665  // track the override list used
666  RV_OverrideList myOverrideList;
667  int myConnectGroupIdx;
668  int myInstanceGroupIdx;
669 
670  bool myIsValid = false;
671 
672  UT_UniquePtr<RV_ShaderVariableSet> myDescriptorSet;
673  UT_UniquePtr<RV_ShaderBlock> myUniformBlock;
674 
675  // TODO: move into connect group
676  UT_UniquePtr<RV_ShaderBlock> myGeometryBlock;
677 
678  int myInstTransformUniformIdx = -1;
679  int myInstNestLevelUniformIdx = -1;
680 
681  // TODO: keep a list of the [attrib ID, binding ID] pairs
682  // and check if they are up-to-date per-frame
683  // TODO: requires RV_Geo and RV_ShaderVariableSet
684  // be setup to refer to attribs by consistent
685  // idx/binding num
686  // currently invalidating any time the interface
687  // may have changed
688  };
689 
690  // Set Used for drawing
691  // cached by (connect group, instance group, set id)
692  typedef UT_Map<std::tuple<int, int, int>, rv_DrawSetInfo> DrawSetCache;
693  DrawSetCache myDrawSet;
694 
695  // Get the set that is compatible with the passed in shader
696  // creating it if necessary
697  rv_DrawSetInfo* getDrawSet(
698  RV_Render* r,
700  const rv_Connectivity *connect,
701  int instance_group_idx,
702  const RV_OverrideList* overrides);
703 
704  // Prepare a set, making sure all attributes are attached and
705  // up-to-date
706  bool prepareDrawSet(
707  RV_Render* r,
708  rv_DrawSetInfo& set_info,
709  const rv_Connectivity *connect,
710  int instance_group_idx,
711  const RV_OverrideList* overrides
712  );
713 
714  bool bindInputAttribute(
715  RV_Render* r,
716  RV_VKPipelineInputInfo& pipe_input,
717  const rv_Connectivity *connect,
718  const rv_Attribute *attrib,
719  bool instance,
720  int location,
722  int vec_size);
723  //rv_DrawSetCache myDrawSets;
724 
725  // Zero-valued constant buffers to fill attribs we don't have values for
726  // TODO: use nullDescriptor bindings if VK_EXT_robustness2 is available
727  void populateFallbackAttribs(RV_Render* r);
728  void resetFallbackAttribs(RV_Render* r);
729  rv_Attribute* getFallbackVertAttrib(RV_GPUType type);
730  rv_Attribute* getFallbackTexBufAttrib(RV_UniformType type);
731  UT_UniquePtr<rv_Attribute> myDefaultVertexAttrib;
732  UT_UniquePtr<rv_Attribute> myDefaultIntVertexAttrib;
733  UT_UniquePtr<rv_Attribute> myDefaultUIntVertexAttrib;
734  UT_UniquePtr<rv_Attribute> myDefaultSamplerAttrib;
735  UT_UniquePtr<rv_Attribute> myDefaultIntSamplerAttrib;
736  UT_UniquePtr<rv_Attribute> myDefaultUIntSamplerAttrib;
737  UT_UniquePtr<rv_Attribute> myDefaultIndexSamplerAttrib;
738  UT_UniquePtr<rv_Attribute> myDefaultIndexVertexAttrib;
739 };
740 
741 #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