HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_GaussianSplatVK.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_GaussianSplatVK ( GR Library, C++)
7  *
8  * COMMENTS:
9  * 3D Gaussian Splat Renderer.
10  */
11 
12 #ifndef GR_GaussianSplatVK_h
13 #define GR_GaussianSplatVK_h
14 
15 #include "GR_API.h"
16 #include "GR_GeoRenderVK.h"
17 #include "GR_Uniforms.h"
18 #include "GR_UtilsVK.h"
19 #include "GR_Light.h"
20 
21 #include <GT/GT_PrimPointMesh.h>
22 #include <UT/UT_RadixSort.h>
23 
24 class RV_Geometry;
25 class RV_Render;
27 class RV_ShaderBlock;
28 class GR_Light;
29 
30 const uint K_WORKGROUP_SIZE = 256;
31 const uint K_RADIX_SORT_BINS = 256;
32 const uint K_RADIX_PASS = 4;
33 
34 enum ConnectIndex : uint8_t
35 {
36  TriangleIndex, // for gsplat and fullscreen drawing (quad)
37  PointIndex, // for point marker decoration
38  DispatchIndex // for compute workgroup dispatch
39 };
40 
42 {
45 };
46 
48 {
51 };
52 
54 {
58  exint size = 0;
59  std::variant<UT_Array<fpreal16>, UT_Array<fpreal32>> data;
61 };
62 
64 {
68 };
69 
71 {
73 };
74 
76 {
77 public:
79  ~GR_GaussianSplatVK() override;
80 
81  const char *className() const override { return "GR_GaussianSplatVK"; }
82 
83  void update(RE_RenderContext rc,
84  const GT_PrimitiveHandle &primh,
85  const GR_UpdateParms &parms,
86  const char *cache_name) override;
87 
89  const GR_DisplayOption &opts,
90  const char *cache_name,
91  RE_CacheVersion geo_version,
92  RE_CacheVersion select_version) override;
93 
94  void draw(RE_RenderContext rc,
97  GR_DrawParms dp) override;
98 
99  void getPickConnectGroup(unsigned int pick_mode,
100  GR_PickGeometry pick_geo,
101  int &out_connect_start,
102  int &out_connect_num) override;
103 
105  RV_PrimType render_prim,
106  bool is_uv_view,
107  int &out_connect_start,
108  int &out_connect_num) override;
109 
110  exint getNumGLPrimitives() const override;
111  bool hasTransparency() const override { return false; }
112 
113  void retireGeometry() override;
114 
115  static bool initShaders(RV_Instance* inst);
116  static void cleanupShaders();
117 
118  // True while any gsplat renderer is live. DM_RenderVulkan uses this to build
119  // the secondary "gsplat-excluded" shadow map only for scenes with gsplats.
120  static bool sceneHasGsplats();
121 
122 private:
123  void drawPrivate(RV_Render *rv, GR_Uniforms* u,
125  GR_DrawParms dp);
126 
127  void drawUtility(RV_Render *rv, GR_Uniforms* u,
129  GR_DrawParms dp);
130 
131  void refreshViewDependentState(RV_Render *rv, GR_Uniforms *uniforms);
132  void frustumCullingGPU(RV_Render *rv, GR_Uniforms *uniforms);
133  void refreshPreprocess(RV_Render *rv, GR_Uniforms *uniforms);
134 
135  void drawGaussians(RV_Render *rv, GR_Uniforms *uniforms,
137  GR_DrawParms dp);
138 
139  void drawPoints(RV_Render *rv, GR_Uniforms *uniforms,
141  GR_DrawParms dp);
142 
143  void drawDepth(RV_Render* rv, GR_Uniforms* uniforms,
145  GR_DrawParms dp);
146 
147  void drawShadow(RV_Render *rv, GR_Uniforms *uniforms,
149  GR_DrawParms dp);
150 
151  void createGSplatGeom(RV_Render *rv);
152  void createFullScreenGeom(RV_Render *rv);
153 
154  void fillPointAttrib(RV_Render *rv,
155  const GT_PrimitiveHandle &primh,
156  const GT_PrimPointMesh *pmesh,
157  const GR_UpdateParms &parms);
158 
159  void createGSplatFramebuffer(RV_Render *rv,
160  const GR_Uniforms &uniforms);
161  void transitionToSampling(RV_Render* rv);
162 
163  void initIndirectCmd(RV_Render *rv);
164 
165  void setupAllSets(RV_Render *rv);
166  void uploadAllStaticBuffer(RV_Render *rv);
167 
168  void prepareGaussiansData(const GT_PrimPointMesh& pmesh);
169 
170  void setupDrawSet(RV_Render *rv);
171  void setupDrawPointSet(RV_Render *rv);
172  void setupKeysSets(RV_Render *rv);
173  void setupDepthSet(RV_Render *rv);
174  bool bindDepthShadowLight(RV_Render *rv,
175  GR_Light *light,
176  GR_DrawParms dp,
178  void setupPreprocessBuffer(RV_Render *rv);
179 
180  void updateDrawBuffer(RV_Render *rv);
181  void updateKeysBuffer(RV_Render *rv, GR_Uniforms *uniforms);
182 
183  void uploadHintBuffer(RV_Render *rv);
184  void uploadShadowDrawIndirectBuffer(RV_Render *rv);
185  void uploadStaticPreprocessBuffer(RV_Render *rv);
186  void uploadGSplatAttribStream(RV_Render *rv,
187  const GSplatAttribStream &stream);
188 
189  bool computeKeys(RV_Render *rv, GR_Uniforms *uniforms);
190  bool computePreprocess(RV_Render *rv, GR_Uniforms *uniforms);
191 
192  exint getGSplatAttribScalarCount(const GSplatAttribStream &stream);
193  void bindGSplatAttribFormat(RV_ShaderBlock *block, const char *name,
194  const GSplatAttribStream &stream);
195  void bindGSplatGeometryAttribFormat(
196  RV_ShaderBlock *block,
197  const char *name,
198  const char *attrib_name);
199 
200  GSplatProjectionModeHint parseProjectionModeHint(const GT_DataArrayHandle &attrib);
201  GSplatSortingModeHint parseSortingModeHint(const GT_DataArrayHandle &attrib);
202 
203 
204  static RV_ShaderProgram *theGSplatDrawShader;
205  static RV_ShaderProgram *theDepthDrawShader;
206  static RV_ShaderProgram *theDepthShaderWithDistantShadow;
207  static RV_ShaderProgram *theDepthShaderWithPointShadow;
208  static RV_ShaderProgram *thePointDrawShader;
209  static RV_ShaderProgram *thePointPickShader;
210 
211  static RV_ShaderProgram *theShadowCubeShader;
212  static RV_ShaderProgram *theShadowCascadeShader;
213 
214  static RV_ShaderCompute *theKeysComputeShader;
215  static RV_ShaderCompute *thePreprocessComputeShader;
216 
217  // Options
218  bool myUseSPH;
219  bool myObjectSelected;
220  bool myIsWireframe;
221  fpreal myGSplatsAlphaCulling;
222  GSplatProjectionModeHint myProjectionModeHint;
223  GSplatSortingModeHint mySortingModeHint;
224 
225  exint myNumInstances;
226  exint myNumVisibles;
227  UT_Matrix4DArray myInstanceTransforms;
228 
229  UT_UniquePtr<RV_Geometry> myFullScreenGeoVK;
230 
231  UT_UniquePtr<RV_Framebuffer> myFramebuffer;
232  UT_UniquePtr<RV_VKImage> myColorImage;
233  UT_UniquePtr<RV_VKImage> myDepthDataImage;
234 
235  VkDrawIndirectCommand myDrawIndirectCmd;
236 
240  UT_UniquePtr<RV_ShaderVariableSet> myPointDrawSet;
241  UT_UniquePtr<RV_ShaderVariableSet> myPointPickSet;
242  UT_UniquePtr<RV_ShaderVariableSet> myDrawShadowSet;
243  UT_UniquePtr<RV_ShaderVariableSet> myPreprocessSet;
244  UT_UniquePtr<RV_ShaderVariableSet> myPreprocessShadowSet;
245 
246  UT_UniquePtr<RV_ShaderBlock> myKeysBlock;
247  UT_UniquePtr<RV_ShaderBlock> myHintsBlock;
248  UT_UniquePtr<RV_ShaderBlock> myIndicesBlock;
249  UT_UniquePtr<RV_ShaderBlock> myPreprocessBlock;
250  UT_UniquePtr<RV_ShaderBlock> myFullIndicesBlock;
251  UT_UniquePtr<RV_ShaderBlock> myDrawIndirectBlock;
252  UT_UniquePtr<RV_VKBuffer> myShadowDrawIndirectBuffer;
253  UT_UniquePtr<RV_ShaderBlock> myShadowAttribFormatsBlock;
254  UT_UniquePtr<RV_ShaderBlock> myPreprocessAttribFormatsBlock;
255 
257 
258  GSplatAttribs myGSplatAttribs;
259 };
260 
261 #endif
const uint K_WORKGROUP_SIZE
GLuint GLuint stream
Definition: glcorearb.h:1832
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
GT_Storage
Definition: GT_Types.h:19
const uint K_RADIX_PASS
GLbitfield flags
Definition: glcorearb.h:1596
GSplatSortingModeHint
virtual void draw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, GR_DrawParms draw_parms)=0
Normal drawing method. Only issue rendering commands.
static bool initShaders(RV_Instance *inst)
const uint K_RADIX_SORT_BINS
int64 exint
Definition: SYS_Types.h:125
GT_API const UT_StringHolder cache_name
UT_UniquePtr< RV_ShaderBlock > block
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
std::variant< UT_Array< fpreal16 >, UT_Array< fpreal32 > > data
GSplatAttribStream b
GSplatProjectionModeHint
bool hasTransparency() const override
returns true if this drawable renders some transparent elements
Temporary container for either a RV_Render and an RE_Render.
virtual exint getNumGLPrimitives() const =0
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()
Compute shader object.
GR_RenderMode
Definition: GR_Defines.h:48
ConnectIndex
GSplatAttribStream r
Base class for all light types.
Definition: GR_Light.h:41
virtual void getVkDecorConnectGroup(RV_PrimType render_prim, bool is_uv_view, int &out_connect_start, int &out_connect_num)
#define GR_API
Definition: GR_API.h:10
GSplatSHAttribs sh
A mesh of unconnected points.
GLuint const GLchar * name
Definition: glcorearb.h:786
GR_RenderFlags
Definition: GR_Defines.h:88
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLenum mode
Definition: glcorearb.h:99
virtual void retireGeometry()
Definition: GR_GeoRender.h:86
virtual void getPickConnectGroup(unsigned int pick_mode, GR_PickGeometry pick_geo, int &out_connect_start, int &out_connect_num)
Definition: GR_GeoRender.h:100
GR_PickGeometry
Definition: GR_PickRecord.h:60
RV_PrimType
Definition: RV_Type.h:356
GSplatAttribStream g
GLsizeiptr size
Definition: glcorearb.h:664
GLuint shader
Definition: glcorearb.h:785
GA_API const UT_StringHolder parms
RV_GPUType
Definition: RV_Type.h:40
fpreal64 fpreal
Definition: SYS_Types.h:283
Simple class for a mutli-integer cache tag.
virtual void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const char *cache_name)=0
GLboolean r
Definition: glcorearb.h:1222
set of parameters sent to GR_Primitive::update()
Definition: GR_Uniforms.h:56
const char * className() const override
unsigned int uint
Definition: SYS_Types.h:45
static void cleanupShaders()
virtual void viewUpdate(RE_RenderContext r, const GR_DisplayOption &opts, const char *cache_name, RE_CacheVersion geo_version, RE_CacheVersion select_version)
Definition: GR_GeoRender.h:64