HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_GeoRenderVK.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: GR_GeoRenderVK.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Base class for all drawing methds that Houdini is natively capable of
10  * rendering with Vulkan.
11  */
12 
13 #ifndef GR_GeoRenderVK_h
14 #define GR_GeoRenderVK_h
15 
16 #include "GR_API.h"
17 
18 #include "GR_GeoRender.h"
19 
20 #include <GT/GT_Handles.h>
21 
22 #include <RV/RV_Type.h>
23 #include <RV/RV_Geometry.h> // for `RV_OverrideList`
24 
25 #include <UT/UT_Array.h>
26 #include <UT/UT_BoundingBox.h>
27 #include <UT/UT_UniquePtr.h>
28 #include <UT/UT_Options.h>
29 #include <UT/UT_UniquePtr.h>
30 
31 #include "GR_DecorationRender.h"
32 
33 class RV_Geometry;
34 class RV_Render;
36 class RV_ShaderBlock;
38 class RV_ShaderAtlas;
39 class RV_VKBuffer;
40 class RV_VKImage;
42 
43 class GR_InstanceBuffer;
44 class GR_Uniforms;
46 class gr_AttribInfoVK;
48 
49 // Multithreaded filling of attribute arrays
50 // TODO: replace with function pointer?
51 // or override?
53 {
66 };
67 
69 {
70 public:
71  GR_GeoRenderVK(GR_Primitive *parent_prim);
72  ~GR_GeoRenderVK() override;
73 
74  virtual bool supportsRayTrace() const
75  {
76  return false;
77  }
78 
79  RV_Geometry* createGeometryVK(exint num_points);
80 
82  {
83  return nullptr;
84  }
85 
87  {
88  return myGeometryVk.get();
89  }
90 
92  PrimitiveType prim_type,
93  RV_PrimType render_prim,
94  RV_Geometry &geo,
95  int &out_connect_start,
96  int &out_connect_num) {} // = 0;
97 
98  static void fillGeoAttribs( RV_Render *r,
99  const GT_Primitive *prim,
100  const GR_UpdateParms&p,
101  RV_Geometry *geo,
102  GR_FillAttributesVK *attrib_fill,
103  bool needs_normal,
104  bool needs_uv,
105  bool needs_tangent,
106  bool need_prim_vert_info,
107  const GT_DataArrayHandle &point_normals,
108  GR_BasePrimType packed_type,
109  bool build_point_id,
110  bool build_prim_id,
111  GR_GeoRenderVK *geo_ren,
112  bool *has_detail_prim_id,
113  int *detail_prim_id,
114  int *num_bone_deform);
115 
116  void fillAttributesVK( RV_Render *r,
117  const GT_Primitive *prim,
118  const GR_UpdateParms &p,
119  RV_Geometry *geo,
120  GR_FillAttributesVK *attrib_fill,
121  bool needs_nml,
122  bool needs_uv,
123  bool needs_tangent,
124  bool need_prim_vert_info,
125  const GT_DataArrayHandle &point_norm);
126 
127  void buildPointID( RV_Render *r,
128  const GR_DisplayOption &dopts,
129  RV_Geometry *rv_geo,
130  GR_FillAttributesVK *attrib_fill,
131  const GT_Primitive &prim,
132  const GU_ConstDetailHandle &geo,
133  const RE_CacheVersion &ver);
134 
135  bool buildInstanceObjectAttrib( RV_Render *r,
136  const GT_PrimitiveHandle &h,
137  const GR_UpdateParms &p,
138  RV_Geometry *geo,
139  GR_FillAttributesVK *attrib_fill,
140  const UT_Matrix4DArray *instance_trans,
141  const RE_CacheVersion &instance_version,
142  int instance_group,
143  UT_Matrix4D *out_transform);
144 
145  static void addAttribArray( RV_Render *r,
146  RV_Geometry *geo,
147  GR_FillAttributesVK *attrib_fill,
148  const char *attrib_name,
149  RV_AttributeType array_type,
150  const GT_DataArrayHandle &dh,
151  const GR_DisplayOption &opts,
152  const RE_CacheVersion &geo_ver,
153  const gr_FillType &fill_type,
154  const GT_Owner original_type = GT_OWNER_INVALID,
155  bool *is_ce_attrib = nullptr);
156  static void addAttribArray( RV_Render *r,
157  RV_Geometry *geo,
158  GR_FillAttributesVK *attrib_fill,
159  const char *attrib_name,
160  RV_AttributeType array_type,
161  const GT_DataArrayHandle &dh,
162  const GT_DataArrayHandle &dhn,
163  const GT_DataArrayHandle &dhv,
164  const GT_DataArrayHandle &dhvid,
165  const GR_DisplayOption &opts,
166  const RE_CacheVersion &geo_ver,
167  const gr_FillType &fill_type,
168  const GT_Owner original_type = GT_OWNER_INVALID,
169  bool *is_ce_attrib = nullptr);
170 
171  void addExternalAttribArray( RV_Render *r,
172  RV_Geometry *geo,
173  GR_FillAttributesVK *attrib_fill,
174  const char *attrib_name,
175  RV_AttributeType array_type,
176  const GT_DataArrayHandle &dh,
177  const GR_DisplayOption &opts,
178  bool fill_immediately);
179 
180  void addInstAttribArray( RV_Render *r,
181  RV_Geometry *geo,
182  GR_FillAttributesVK *attrib_fill,
183  const char *attrib_name,
184  int inst_group,
185  RV_AttributeType array_type,
186  const GT_DataArrayHandle &dh,
187  const GR_DisplayOption &opts,
188  const RE_CacheVersion &geo_ver,
189  const gr_FillType &fill_type);
190 
191  void cleanupGeoOverride( RV_Render *r,
192  const GR_DisplayOption *opt,
193  RV_Geometry *geo);
194 
195  void setupGeoOverride( RV_Render *r,
196  const GR_DisplayOption *opt,
197  RV_Geometry *geo,
199  override_list);
200 
201  void setupGeoOverride( RV_Render *r,
202  const GR_DisplayOption *opt,
203  RV_Geometry *geo,
205  override_list);
206 
207  // Called by wire primitives (curves and points) to add a Cd override
208  // if the Geometry is supposed to have a special color
209  void updateWireColor(RV_Render *r,
210  GR_Uniforms *u,
211  RV_Geometry *geo,
212  const GR_DisplayOption *opt,
213  bool allow_color_override,
214  RV_OverrideList& overrides) const;
215 
216  void updateWireOverColor(RV_Render *r,
217  GR_Uniforms *u,
218  RV_Geometry *geo,
219  const GR_DisplayOption *opt,
220  bool allow_color_override,
221  RV_OverrideList& overrides) const;
222 
223  GR_FillAttributesVKPtr createFillTask( RV_Render *r,
224  GR_GeoRenderVK *gr,
225  const GT_Primitive *prim,
226  const GU_Detail *geo,
227  const GR_DisplayOption *opts,
228  int num_points);
229  void runFillTask( RV_Render *r,
230  RV_Geometry *geo,
231  GR_FillAttributesVK *attrib_fill
232  );
233 
234  void updateInstanceGroupBuffer(const GR_InstanceBuffer *buffer,
235  int instance_group);
236 
237  void gpuMemoryUsage(exint &used_bytes,
238  exint &unused_bytes,
239  exint &pinned_bytes) override;
240 
241  // Optionally overriden by geometries that should be traced against
242  virtual void updateAccelerationStructure(RV_Render *r,
243  int tag,
244  int light_id,
245  const UT_Matrix4F &obj_mat);
246 
247  virtual RV_VKAccelerationStructure* getAccelerationStructure();
248 
249  void prepareForRayTrace(RV_Render *r,
250  int tag,
251  int light_id,
252  const UT_Matrix4F &obj_mat);
253 
254 protected:
255 
256  bool initTransformAndPassInfo(RV_Render *r,
257  GR_Uniforms *u,
258  const RV_ShaderProgram *shader);
259 
261  const GR_UpdateParms &p,
262  RV_Geometry *geo,
263  GR_FillAttributesVK *attrib_fill,
264  const GT_PrimitiveHandle &primh,
265  const GT_DataArrayHandle &vertex_list);
266 
267  // --------------------------------------------------
268  // gr_SetCache
269  //
270  // Sets keyed by their pipeline
271  // TOOD: not enforced, but ideally should be a small number of sets
272  // e.g. sets with same/similar layout but used with pipelines that
273  // have different usage state (e.g. Vertex-Only, or Frag-and-Vertex)
274  // TODO: could also have a mechanism in RV_ShaderAtlas to enforce that all
275  // sets with the same members and per-set locations also have the same
276  // per-layout locations
277  // TODO: per-frame use counting and reset function
278  struct gr_SetCache
279  {
280 
281  // Array doing linear lookup, fine if number of sets small
282  // TODO: could do a hashmap
284  RV_ShaderVariableSet* myLastSet = nullptr;
285 
287  RV_Render *r,
288  int set_num,
290  bool* out_is_new);
291  };
294 
295  // NOTE: individual shader blocks may not work if object
296  // drawn multiple times
297  //
298  // In the ideal case: the Specific GR_GeoRender child class
299  // knows/controls the Shaders it will be using and
300  // knows how many Descriptor Sets / memory blocks that requires
301  // (and minus those managed by the RV_Geometry)
302  // ..
303  // Note this ONLY works for the case where the object is drawn once
304  // because:
305  // - uploads can't be done inside a render pass
306  // - so uniforms can't be updated during a render pass
307  // - so all uniforms have to be setup pre-render pass
308  // - so, if some GeoRender needs to be updated/drawn multiple
309  // times in a single pass, will need multiple allocated ubo's
310  // could fix by baking some re-allocation on-upload functionality into
311  // ShaderBlock (like is already done in the Descriptor Set class)
312  //UT_UniquePtr<RV_ShaderVariableSet> myObjectSet;
313  //UT_UniquePtr<RV_ShaderVariableSet> myGlobalSet;
314  //UT_UniquePtr<RV_ShaderVariableSet> myShaderSet;
315 
316 
320 
321 
323 
325 };
326 
327 
328 // --------------------------------------------------
329 // GR_FillAttributesVK
330 //
331 // Helper class to fill attributes, represented as gr_AttribInfoVK
333 {
334 public:
335 
337  const GT_Primitive *prim,
338  const GU_Detail *geo,
339  const GR_DisplayOption *opts,
340  int num_points);
342 
343  int entries() const { return myAttribs.entries(); }
344 
345  bool hasBounds() const { return myHasPosBounds || myHasDetailBounds; }
346  bool hasCLNormal() const { return myHasCLNormal; }
347  const UT_BoundingBox getBounds() const
348  {
349  if (myHasPosBounds)
350  {
351  return myPosBounds;
352  }
353  if (myHasDetailBounds)
354  {
355  return myDetailBounds;
356  }
357  return UT_BoundingBox();
358  }
359 
360  void allocateStagingBuffer(RV_Render* r);
361 
362  void process(const UT_BlockedRange<int> &range) const;
363 
364  gr_AttribInfoVK *append(
365  const char *name,
366  gr_FillType t,
367  RV_AttributeType at,
368  const GT_DataArrayHandle &h,
370  int size = 0,
374  int instance_group = -1);
375 
376  void upload(RV_Render *r, RV_Geometry *geo);
377 
379  { return myFillAmount; }
380  void addToFillAmount(int n)
381  { myFillAmount += n; }
382 
383  // Attribute default values (if they don't exist).
384  void setFallbacks(const UT_Options *fallbacks);
385  void addIntFallback(const UT_StringHolder &name, int value);
386  void addFallback(const UT_StringHolder &name, fpreal value);
387  void addFallback(const UT_StringHolder &name, const UT_Vector2F &value);
388  void addFallback(const UT_StringHolder &name, const UT_Vector3F &value);
389  void addFallback(const UT_StringHolder &name, const UT_Vector4F &value);
390 
391  bool getFallback(const UT_StringHolder &name, int &value) const;
392  bool getFallback(const UT_StringHolder &name, fpreal &value) const;
393  bool getFallback(const UT_StringHolder &name, UT_Vector2F &value) const;
394  bool getFallback(const UT_StringHolder &name, UT_Vector3F &value) const;
395  bool getFallback(const UT_StringHolder &name, UT_Vector4F &value) const;
396  UT_OptionType getFallbackType(const UT_StringHolder &name) const;
397 
398  bool usedFallback() const { return myUsedFallback; }
399  void setUsedFallback(bool used) { myUsedFallback = used; }
400 
401 private:
402  const void *fillConstAttribute(gr_AttribInfoVK *attrib) const;
403  const void *fillRegularAttribute(gr_AttribInfoVK *attrib) const;
404  const void *fillPointAttribute(gr_AttribInfoVK *attrib) const;
405  const void *fillPointIDAttribute(gr_AttribInfoVK *attrib) const;
406  const void *fillPrimIDAttribute(gr_AttribInfoVK *attrib) const;
407  const void *fillStringAttribute(gr_AttribInfoVK *attrib) const;
408  const void *fillMaterialAttribute(gr_AttribInfoVK *attrib) const;
409  const void *fillTangentAttribute(gr_AttribInfoVK *attrib) const;
410  const void *fillBoneAttributes(gr_AttribInfoVK *attrib) const;
411 
412  void createNormalAttribute(gr_AttribInfoVK *attrib) const;
413 
414  RV_Render *myRender;
415  const GU_Detail *myDetail;
416  const GR_DisplayOption *myDisplayOpts;
417  const GT_Primitive *myPrim;
418  UT_Array<gr_AttribInfoVK *> myAttribs;
419  int myNumPoints;
420 
421  UT_UniquePtr<RV_VKBuffer> myStagingBuffer;
422 
423  void computeDetailBounds();
424  bool myHasDetailBounds;
425  UT_BoundingBox myDetailBounds;
426 
427  bool myHasPosBounds;
428  UT_BoundingBox myPosBounds;
429 
430  UT_Array<GT_DataArrayHandle> myDataHandles;
431  int myFillAmount;
432 
433  UT_Options myFallbacks;
434  bool myUsedFallback = false;
435  bool myHasCLNormal = false;
436 };
437 
438 
439 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
UT_UniquePtr< RV_VKImage > myColorOverrideRampBuffer
bool hasCLNormal() const
virtual void gpuMemoryUsage(exint &used_bytes, exint &unused_bytes, exint &pinned_bytes)
Definition: GR_GeoRender.h:194
GLenum GLint * range
Definition: glcorearb.h:1925
void addToFillAmount(int n)
const GLdouble * v
Definition: glcorearb.h:837
GLsizei const GLfloat * value
Definition: glcorearb.h:824
UT_OptionType
Definition: UT_Options.h:44
virtual void getVkDecorGeometry(GR_DecorationRender::PrimitiveType prim_type, RV_PrimType render_prim, RV_Geometry &geo, int &out_connect_start, int &out_connect_num)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:52
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
gr_SetCache myObjectSet
GLuint buffer
Definition: glcorearb.h:660
GR_API bool createOrReuseSet(RV_Render *r, UT_UniquePtr< RV_ShaderVariableSet > &set, int set_num, const RV_ShaderProgramBase *shader, bool *created=nullptr, const char *name=nullptr)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
set of parameters sent to GR_Primitive::update()
UT_Array< UT_UniquePtr< RV_ShaderVariableSet > > mySets
const UT_BoundingBox getBounds() const
GLdouble n
Definition: glcorearb.h:2008
GR_BasePrimType
Definition: GR_Defines.h:368
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
RV_AttributeType
Definition: RV_Type.h:99
UT_BoundingBoxT< float > UT_BoundingBox
Definition: GEO_Detail.h:41
UT_UniquePtr< RV_ShaderBlock > myColorOverrideBlock
int entries() const
#define GR_API
Definition: GR_API.h:10
GR_API GR_SelectMode buildSelection(UT_Array< uint8 > &selected, const GR_UpdateParms &p, GT_DataArrayHandle prim_id, GT_DataArrayHandle pnt_id, GT_DataArrayHandle vert_id, bool is_offset, int repeat_count)
GLuint const GLchar * name
Definition: glcorearb.h:786
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GLdouble t
Definition: glad.h:2397
GT_Owner
Definition: GT_Types.h:90
RE_Geometry * getGeometry() override
gr_SetCache myShaderSet
RV_PrimType
Definition: RV_Type.h:424
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLuint shader
Definition: glcorearb.h:785
A map of string to various well defined value types.
Definition: UT_Options.h:84
UT_UniquePtr< GR_FillAttributesVK > GR_FillAttributesVKPtr
UT_UniquePtr< RV_ShaderBlock > myTransformBlock
fpreal64 fpreal
Definition: SYS_Types.h:278
bool hasBounds() const
void setUsedFallback(bool used)
bool usedFallback() const
virtual bool supportsRayTrace() const
bool process(T &func, UT_WorkBuffer &fullpath, exint fullpath_len, const UT_StringArray &paths, const UT_Array< FS_Stat > &stats)
Utility function to process the contents of the traverse() function.
Definition: FS_Traverse.h:24
Simple class for a mutli-integer cache tag.
gr_FillType
GLboolean r
Definition: glcorearb.h:1222
set of parameters sent to GR_Primitive::update()
Definition: GR_Uniforms.h:56
A vulkan buffer object.
Definition: RV_VKBuffer.h:81
UT_UniquePtr< RV_Geometry > myGeometryVk
Declare prior to use.
RV_Geometry * getVkGeometry() override
GR_SelectMode
Definition: GR_Defines.h:243