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 
29 #include "GR_DecorationRender.h"
30 
31 class RV_Geometry;
32 class RV_Render;
34 class RV_ShaderBlock;
36 class RV_ShaderAtlas;
37 class RV_VKImage;
38 
39 class GR_InstanceBuffer;
40 class GR_Uniforms;
42 class gr_AttribInfoVK;
44 
45 // Multithreaded filling of attribute arrays
46 // TODO: replace with function pointer?
47 // or override?
49 {
60 };
61 
63 {
64 public:
65  GR_GeoRenderVK(GR_Primitive *parent_prim);
66  ~GR_GeoRenderVK() override;
67 
68  RV_Geometry* createGeometryVK(exint num_points);
69 
71  {
72  return nullptr;
73  }
74 
76  {
77  return myGeometryVk.get();
78  }
79 
81  PrimitiveType prim_type,
82  RV_PrimType render_prim,
83  RV_Geometry &geo,
84  int &out_connect_start,
85  int &out_connect_num) {} // = 0;
86 
87  static void fillGeoAttribs( RV_Render *r,
88  const GT_Primitive *prim,
89  const GR_UpdateParms&p,
90  RV_Geometry *geo,
91  GR_FillAttributesVK *attrib_fill,
92  bool needs_normal,
93  bool needs_uv,
94  bool needs_tangent,
95  bool need_prim_vert_info,
96  const GT_DataArrayHandle &point_normals,
97  GR_BasePrimType packed_type,
98  bool build_point_id,
99  bool build_prim_id,
100  GR_GeoRenderVK *geo_ren,
101  bool *has_detail_prim_id,
102  int *detail_prim_id,
103  int *num_bone_deform);
104 
105  void fillAttributesVK( RV_Render *r,
106  const GT_Primitive *prim,
107  const GR_UpdateParms &p,
108  RV_Geometry *geo,
109  GR_FillAttributesVK *attrib_fill,
110  bool needs_nml,
111  bool needs_uv,
112  bool needs_tangent,
113  bool need_prim_vert_info,
114  const GT_DataArrayHandle &point_norm);
115 
116  void buildPointID( RV_Render *r,
117  RV_Geometry *rv_geo,
118  GR_FillAttributesVK *attrib_fill,
119  const GT_Primitive &prim,
120  const GU_ConstDetailHandle &geo,
121  const RE_CacheVersion &ver);
122 
123  bool buildInstanceObjectAttrib( RV_Render *r,
124  const GT_PrimitiveHandle &h,
125  const GR_UpdateParms &p,
126  RV_Geometry *geo,
127  GR_FillAttributesVK *attrib_fill,
128  const UT_Matrix4DArray *instance_trans,
129  const RE_CacheVersion &instance_version,
130  int instance_group,
131  UT_Matrix4D *out_transform);
132 
133  static void addAttribArray( RV_Render *r,
134  RV_Geometry *geo,
135  GR_FillAttributesVK *attrib_fill,
136  const char *attrib_name,
137  RV_AttributeType array_type,
138  const GT_DataArrayHandle &dh,
139  const GR_DisplayOption &opts,
140  const RE_CacheVersion &geo_ver,
141  const gr_FillType &fill_type,
142  const GT_Owner original_type = GT_OWNER_INVALID);
143 
144  void addExternalAttribArray( RV_Render *r,
145  RV_Geometry *geo,
146  GR_FillAttributesVK *attrib_fill,
147  const char *attrib_name,
148  RV_AttributeType array_type,
149  const GT_DataArrayHandle &dh,
150  const GR_DisplayOption &opts,
151  bool fill_immediately);
152 
153  void addInstAttribArray( RV_Render *r,
154  RV_Geometry *geo,
155  GR_FillAttributesVK *attrib_fill,
156  const char *attrib_name,
157  int inst_group,
158  RV_AttributeType array_type,
159  const GT_DataArrayHandle &dh,
160  const GR_DisplayOption &opts,
161  const RE_CacheVersion &geo_ver,
162  const gr_FillType &fill_type);
163 
164  void cleanupGeoOverride( RV_Render *r,
165  const GR_DisplayOption *opt,
166  RV_Geometry *geo);
167 
168  void setupGeoOverride( RV_Render *r,
169  const GR_DisplayOption *opt,
170  RV_Geometry *geo,
171  UT_UniquePtr<RV_OverrideList> &override_list);
172 
173  // Called by wire primitives (curves and points) to add a Cd override
174  // if the Geometry is supposed to have a special color
175  void updateWireColor( RV_Render *r,
176  GR_Uniforms *u,
177  RV_Geometry *geo,
178  const GR_DisplayOption *opt,
179  RV_OverrideList& overrides) const;
180 
181  GR_FillAttributesVKPtr createFillTask( RV_Render *r,
182  GR_GeoRenderVK *gr,
183  const GT_Primitive *prim,
184  const GU_Detail *geo,
185  const GR_DisplayOption *opts,
186  int num_points);
187  void runFillTask( RV_Render *r,
188  RV_Geometry *geo,
189  GR_FillAttributesVK *attrib_fill
190  );
191 
192  void updateInstanceGroupBuffer(const GR_InstanceBuffer *buffer,
193  int instance_group);
194 
195 protected:
196 
197  bool initTransformAndPassInfo(RV_Render *r,
198  GR_Uniforms *u,
199  const RV_ShaderProgram *shader);
200 
202  const GR_UpdateParms &p,
203  RV_Geometry *geo,
204  GR_FillAttributesVK *attrib_fill,
205  const GT_PrimitiveHandle &primh,
206  const GT_DataArrayHandle &vertex_list);
207 
208  // --------------------------------------------------
209  // gr_SetCache
210  //
211  // Sets keyed by their pipeline
212  // TOOD: not enforced, but ideally should be a small number of sets
213  // e.g. sets with same/similar layout but used with pipelines that
214  // have different usage state (e.g. Vertex-Only, or Frag-and-Vertex)
215  // TODO: could also have a mechanism in RV_ShaderAtlas to enforce that all
216  // sets with the same members and per-set locations also have the same
217  // per-layout locations
218  // TODO: per-frame use counting and reset function
219  struct gr_SetCache
220  {
221 
222  // Array doing linear lookup, fine if number of sets small
223  // TODO: could do a hashmap
225  RV_ShaderVariableSet* myLastSet = nullptr;
226 
228  RV_Render *r,
229  int set_num,
231  bool* out_is_new);
232  };
235 
236  // NOTE: individual shader blocks may not work if object
237  // drawn multiple times
238  //
239  // In the ideal case: the Specific GR_GeoRender child class
240  // knows/controls the Shaders it will be using and
241  // knows how many Descriptor Sets / memory blocks that requires
242  // (and minus those managed by the RV_Geometry)
243  // ..
244  // Note this ONLY works for the case where the object is drawn once
245  // because:
246  // - uploads can't be done inside a render pass
247  // - so uniforms can't be updated during a render pass
248  // - so all uniforms have to be setup pre-render pass
249  // - so, if some GeoRender needs to be updated/drawn multiple
250  // times in a single pass, will need multiple allocated ubo's
251  // could fix by baking some re-allocation on-upload functionality into
252  // ShaderBlock (like is already done in the Descriptor Set class)
253  //UT_UniquePtr<RV_ShaderVariableSet> myObjectSet;
254  //UT_UniquePtr<RV_ShaderVariableSet> myGlobalSet;
255  //UT_UniquePtr<RV_ShaderVariableSet> myShaderSet;
256 
257 
261 
262 
264 };
265 
266 
267 // --------------------------------------------------
268 // GR_FillAttributesVK
269 //
270 // Helper class to fill attributes, represented as gr_AttribInfoVK
272 {
273 public:
274 
276  const GT_Primitive *prim,
277  const GU_Detail *geo,
278  const GR_DisplayOption *opts,
279  int num_points);
281 
282  int entries() const { return myAttribs.entries(); }
283 
284  bool hasBounds() const { return myHasPosBounds || myHasDetailBounds; }
285  const UT_BoundingBox getBounds() const
286  {
287  if (myHasPosBounds)
288  {
289  return myPosBounds;
290  }
291  if (myHasDetailBounds)
292  {
293  return myDetailBounds;
294  }
295  return UT_BoundingBox();
296  }
297 
298  void process(const UT_BlockedRange<int> &range) const;
299 
300  void append(const char *name,
301  gr_FillType t,
302  RV_AttributeType at,
303  const GT_DataArrayHandle &h,
305  int size = 0,
309  int instance_group = -1);
310 
311  void upload(RV_Render *r, RV_Geometry *geo);
312 
314  { return myFillAmount; }
315  void addToFillAmount(int n)
316  { myFillAmount += n; }
317 
318 private:
319  const void *fillConstAttribute(gr_AttribInfoVK *attrib) const;
320  const void *fillRegularAttribute(gr_AttribInfoVK *attrib) const;
321  const void *fillPointAttribute(gr_AttribInfoVK *attrib) const;
322  const void *fillPointIDAttribute(gr_AttribInfoVK *attrib) const;
323  const void *fillPrimIDAttribute(gr_AttribInfoVK *attrib) const;
324  const void *fillStringAttribute(gr_AttribInfoVK *attrib) const;
325  const void *fillMaterialAttribute(gr_AttribInfoVK *attrib) const;
326  const void *fillTangentAttribute(gr_AttribInfoVK *attrib) const;
327  const void *fillBoneAttributes(gr_AttribInfoVK *attrib) const;
328 
329  void createNormalAttribute(gr_AttribInfoVK *attrib) const;
330 
331  RV_Render *myRender;
332  const GU_Detail *myDetail;
333  const GR_DisplayOption *myDisplayOpts;
334  const GT_Primitive *myPrim;
335  UT_Array<gr_AttribInfoVK *> myAttribs;
336  int myNumPoints;
337 
338  void computeDetailBounds();
339  bool myHasDetailBounds;
340  UT_BoundingBox myDetailBounds;
341 
342  bool myHasPosBounds;
343  UT_BoundingBox myPosBounds;
344 
345  UT_Array<GT_DataArrayHandle> myDataHandles;
346  int myFillAmount;
347 };
348 
349 
350 #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
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:164
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:352
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
RV_AttributeType
Definition: RV_Type.h:90
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:345
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLuint shader
Definition: glcorearb.h:785
UT_UniquePtr< GR_FillAttributesVK > GR_FillAttributesVKPtr
UT_UniquePtr< RV_ShaderBlock > myTransformBlock
bool hasBounds() const
Simple class for a mutli-integer cache tag.
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:229