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 
30 #include "GR_DecorationRender.h"
31 
32 class RV_Geometry;
33 class RV_Render;
35 class RV_ShaderBlock;
37 class RV_ShaderAtlas;
38 class RV_VKImage;
39 
40 class GR_InstanceBuffer;
41 class GR_Uniforms;
43 class gr_AttribInfoVK;
45 
46 // Multithreaded filling of attribute arrays
47 // TODO: replace with function pointer?
48 // or override?
50 {
61 };
62 
64 {
65 public:
66  GR_GeoRenderVK(GR_Primitive *parent_prim);
67  ~GR_GeoRenderVK() override;
68 
69  RV_Geometry* createGeometryVK(exint num_points);
70 
72  {
73  return nullptr;
74  }
75 
77  {
78  return myGeometryVk.get();
79  }
80 
82  PrimitiveType prim_type,
83  RV_PrimType render_prim,
84  RV_Geometry &geo,
85  int &out_connect_start,
86  int &out_connect_num) {} // = 0;
87 
88  static void fillGeoAttribs( RV_Render *r,
89  const GT_Primitive *prim,
90  const GR_UpdateParms&p,
91  RV_Geometry *geo,
92  GR_FillAttributesVK *attrib_fill,
93  bool needs_normal,
94  bool needs_uv,
95  bool needs_tangent,
96  bool need_prim_vert_info,
97  const GT_DataArrayHandle &point_normals,
98  GR_BasePrimType packed_type,
99  bool build_point_id,
100  bool build_prim_id,
101  GR_GeoRenderVK *geo_ren,
102  bool *has_detail_prim_id,
103  int *detail_prim_id,
104  int *num_bone_deform);
105 
106  void fillAttributesVK( RV_Render *r,
107  const GT_Primitive *prim,
108  const GR_UpdateParms &p,
109  RV_Geometry *geo,
110  GR_FillAttributesVK *attrib_fill,
111  bool needs_nml,
112  bool needs_uv,
113  bool needs_tangent,
114  bool need_prim_vert_info,
115  const GT_DataArrayHandle &point_norm);
116 
117  void buildPointID( RV_Render *r,
118  const GR_DisplayOption &dopts,
119  RV_Geometry *rv_geo,
120  GR_FillAttributesVK *attrib_fill,
121  const GT_Primitive &prim,
122  const GU_ConstDetailHandle &geo,
123  const RE_CacheVersion &ver);
124 
125  bool buildInstanceObjectAttrib( RV_Render *r,
126  const GT_PrimitiveHandle &h,
127  const GR_UpdateParms &p,
128  RV_Geometry *geo,
129  GR_FillAttributesVK *attrib_fill,
130  const UT_Matrix4DArray *instance_trans,
131  const RE_CacheVersion &instance_version,
132  int instance_group,
133  UT_Matrix4D *out_transform);
134 
135  static void addAttribArray( RV_Render *r,
136  RV_Geometry *geo,
137  GR_FillAttributesVK *attrib_fill,
138  const char *attrib_name,
139  RV_AttributeType array_type,
140  const GT_DataArrayHandle &dh,
141  const GR_DisplayOption &opts,
142  const RE_CacheVersion &geo_ver,
143  const gr_FillType &fill_type,
144  const GT_Owner original_type = GT_OWNER_INVALID);
145 
146  void addExternalAttribArray( RV_Render *r,
147  RV_Geometry *geo,
148  GR_FillAttributesVK *attrib_fill,
149  const char *attrib_name,
150  RV_AttributeType array_type,
151  const GT_DataArrayHandle &dh,
152  const GR_DisplayOption &opts,
153  bool fill_immediately);
154 
155  void addInstAttribArray( RV_Render *r,
156  RV_Geometry *geo,
157  GR_FillAttributesVK *attrib_fill,
158  const char *attrib_name,
159  int inst_group,
160  RV_AttributeType array_type,
161  const GT_DataArrayHandle &dh,
162  const GR_DisplayOption &opts,
163  const RE_CacheVersion &geo_ver,
164  const gr_FillType &fill_type);
165 
166  void cleanupGeoOverride( RV_Render *r,
167  const GR_DisplayOption *opt,
168  RV_Geometry *geo);
169 
170  void setupGeoOverride( RV_Render *r,
171  const GR_DisplayOption *opt,
172  RV_Geometry *geo,
174  override_list);
175 
176  void setupGeoOverride( RV_Render *r,
177  const GR_DisplayOption *opt,
178  RV_Geometry *geo,
180  override_list);
181 
182  // Called by wire primitives (curves and points) to add a Cd override
183  // if the Geometry is supposed to have a special color
184  void updateWireColor(RV_Render *r,
185  GR_Uniforms *u,
186  RV_Geometry *geo,
187  const GR_DisplayOption *opt,
188  bool allow_color_override,
189  RV_OverrideList& overrides) const;
190 
191  void updateWireOverColor(RV_Render *r,
192  GR_Uniforms *u,
193  RV_Geometry *geo,
194  const GR_DisplayOption *opt,
195  bool allow_color_override,
196  RV_OverrideList& overrides) const;
197 
198  GR_FillAttributesVKPtr createFillTask( RV_Render *r,
199  GR_GeoRenderVK *gr,
200  const GT_Primitive *prim,
201  const GU_Detail *geo,
202  const GR_DisplayOption *opts,
203  int num_points);
204  void runFillTask( RV_Render *r,
205  RV_Geometry *geo,
206  GR_FillAttributesVK *attrib_fill
207  );
208 
209  void updateInstanceGroupBuffer(const GR_InstanceBuffer *buffer,
210  int instance_group);
211 
212 protected:
213 
214  bool initTransformAndPassInfo(RV_Render *r,
215  GR_Uniforms *u,
216  const RV_ShaderProgram *shader);
217 
219  const GR_UpdateParms &p,
220  RV_Geometry *geo,
221  GR_FillAttributesVK *attrib_fill,
222  const GT_PrimitiveHandle &primh,
223  const GT_DataArrayHandle &vertex_list);
224 
225  // --------------------------------------------------
226  // gr_SetCache
227  //
228  // Sets keyed by their pipeline
229  // TOOD: not enforced, but ideally should be a small number of sets
230  // e.g. sets with same/similar layout but used with pipelines that
231  // have different usage state (e.g. Vertex-Only, or Frag-and-Vertex)
232  // TODO: could also have a mechanism in RV_ShaderAtlas to enforce that all
233  // sets with the same members and per-set locations also have the same
234  // per-layout locations
235  // TODO: per-frame use counting and reset function
236  struct gr_SetCache
237  {
238 
239  // Array doing linear lookup, fine if number of sets small
240  // TODO: could do a hashmap
242  RV_ShaderVariableSet* myLastSet = nullptr;
243 
245  RV_Render *r,
246  int set_num,
248  bool* out_is_new);
249  };
252 
253  // NOTE: individual shader blocks may not work if object
254  // drawn multiple times
255  //
256  // In the ideal case: the Specific GR_GeoRender child class
257  // knows/controls the Shaders it will be using and
258  // knows how many Descriptor Sets / memory blocks that requires
259  // (and minus those managed by the RV_Geometry)
260  // ..
261  // Note this ONLY works for the case where the object is drawn once
262  // because:
263  // - uploads can't be done inside a render pass
264  // - so uniforms can't be updated during a render pass
265  // - so all uniforms have to be setup pre-render pass
266  // - so, if some GeoRender needs to be updated/drawn multiple
267  // times in a single pass, will need multiple allocated ubo's
268  // could fix by baking some re-allocation on-upload functionality into
269  // ShaderBlock (like is already done in the Descriptor Set class)
270  //UT_UniquePtr<RV_ShaderVariableSet> myObjectSet;
271  //UT_UniquePtr<RV_ShaderVariableSet> myGlobalSet;
272  //UT_UniquePtr<RV_ShaderVariableSet> myShaderSet;
273 
274 
278 
279 
281 };
282 
283 
284 // --------------------------------------------------
285 // GR_FillAttributesVK
286 //
287 // Helper class to fill attributes, represented as gr_AttribInfoVK
289 {
290 public:
291 
293  const GT_Primitive *prim,
294  const GU_Detail *geo,
295  const GR_DisplayOption *opts,
296  int num_points);
298 
299  int entries() const { return myAttribs.entries(); }
300 
301  bool hasBounds() const { return myHasPosBounds || myHasDetailBounds; }
302  const UT_BoundingBox getBounds() const
303  {
304  if (myHasPosBounds)
305  {
306  return myPosBounds;
307  }
308  if (myHasDetailBounds)
309  {
310  return myDetailBounds;
311  }
312  return UT_BoundingBox();
313  }
314 
315  void process(const UT_BlockedRange<int> &range) const;
316 
317  void append(const char *name,
318  gr_FillType t,
319  RV_AttributeType at,
320  const GT_DataArrayHandle &h,
322  int size = 0,
326  int instance_group = -1);
327 
328  void upload(RV_Render *r, RV_Geometry *geo);
329 
331  { return myFillAmount; }
332  void addToFillAmount(int n)
333  { myFillAmount += n; }
334 
335  // Attribute default values (if they don't exist).
336  void setFallbacks(const UT_Options *fallbacks);
337  void addIntFallback(const UT_StringHolder &name, int value);
338  void addFallback(const UT_StringHolder &name, fpreal value);
339  void addFallback(const UT_StringHolder &name, const UT_Vector2F &value);
340  void addFallback(const UT_StringHolder &name, const UT_Vector3F &value);
341  void addFallback(const UT_StringHolder &name, const UT_Vector4F &value);
342 
343  bool getFallback(const UT_StringHolder &name, int &value) const;
344  bool getFallback(const UT_StringHolder &name, fpreal &value) const;
345  bool getFallback(const UT_StringHolder &name, UT_Vector2F &value) const;
346  bool getFallback(const UT_StringHolder &name, UT_Vector3F &value) const;
347  bool getFallback(const UT_StringHolder &name, UT_Vector4F &value) const;
348  UT_OptionType getFallbackType(const UT_StringHolder &name) const;
349 
350  bool usedFallback() const { return myUsedFallback; }
351  void setUsedFallback(bool used) { myUsedFallback = used; }
352 
353 private:
354  const void *fillConstAttribute(gr_AttribInfoVK *attrib) const;
355  const void *fillRegularAttribute(gr_AttribInfoVK *attrib) const;
356  const void *fillPointAttribute(gr_AttribInfoVK *attrib) const;
357  const void *fillPointIDAttribute(gr_AttribInfoVK *attrib) const;
358  const void *fillPrimIDAttribute(gr_AttribInfoVK *attrib) const;
359  const void *fillStringAttribute(gr_AttribInfoVK *attrib) const;
360  const void *fillMaterialAttribute(gr_AttribInfoVK *attrib) const;
361  const void *fillTangentAttribute(gr_AttribInfoVK *attrib) const;
362  const void *fillBoneAttributes(gr_AttribInfoVK *attrib) const;
363 
364  void createNormalAttribute(gr_AttribInfoVK *attrib) const;
365 
366  RV_Render *myRender;
367  const GU_Detail *myDetail;
368  const GR_DisplayOption *myDisplayOpts;
369  const GT_Primitive *myPrim;
370  UT_Array<gr_AttribInfoVK *> myAttribs;
371  int myNumPoints;
372 
373  void computeDetailBounds();
374  bool myHasDetailBounds;
375  UT_BoundingBox myDetailBounds;
376 
377  bool myHasPosBounds;
378  UT_BoundingBox myPosBounds;
379 
380  UT_Array<GT_DataArrayHandle> myDataHandles;
381  int myFillAmount;
382 
383  UT_Options myFallbacks;
384  bool myUsedFallback = false;
385 };
386 
387 
388 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
UT_UniquePtr< RV_VKImage > myColorOverrideRampBuffer
GLenum GLint * range
Definition: glcorearb.h:1925
void addToFillAmount(int n)
const GLdouble * v
Definition: glcorearb.h:837
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:53
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
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
Definition: core.h:760
GR_BasePrimType
Definition: GR_Defines.h:366
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:96
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:367
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:277
bool hasBounds() const
void setUsedFallback(bool used)
bool usedFallback() const
Simple class for a mutli-integer cache tag.
Definition: core.h:1131
gr_FillType
GLboolean r
Definition: glcorearb.h:1222
UT_UniquePtr< RV_Geometry > myGeometryVk
Declare prior to use.
RV_Geometry * getVkGeometry() override
GR_SelectMode
Definition: GR_Defines.h:241