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 
18 #include <GT/GT_PrimPointMesh.h>
19 
20 #include <UT/UT_RadixSort.h>
21 
22 class RV_Geometry;
23 class RV_Render;
25 class RV_ShaderBlock;
26 
27 const uint K_WORKGROUP_SIZE = 256;
28 const uint K_RADIX_SORT_BINS = 256;
29 const uint K_RADIX_PASS = 4;
30 
31 enum ConnectIndex : uint8_t
32 {
33  TriangleIndex, // for gsplat and fullscreen drawing (quad)
34  PointIndex // for point marker decoration
35 };
36 
37 // Unified structure for indirect draw and compute dispatch commands.
38 // This allows reuse of a single buffer across different pipeline stages
40 {
41  // Indirect draw
46 
47  // Indirect compute
54 };
55 
56 struct MVPUboCPU
57 {
61 };
62 
64 {
65  bool useSph;
66 };
67 
69 {
72 
75 };
76 
78 {
82 };
83 
85 {
86 public:
88  ~GR_GaussianSplatVK() override;
89 
90  const char *className() const override { return "GR_GaussianSplatVK"; }
91 
92  void update(RE_RenderContext rc,
93  const GT_PrimitiveHandle &primh,
94  const GR_UpdateParms &parms,
95  const char *cache_name) override;
96 
98  const GR_DisplayOption &opts,
99  const char *cache_name,
100  RE_CacheVersion geo_version,
101  RE_CacheVersion select_version) override;
102 
103  void draw(RE_RenderContext rc,
106  GR_DrawParms dp) override;
107 
108  void getPickConnectGroup(unsigned int pick_mode,
109  GR_PickGeometry pick_geo,
110  int &out_connect_start,
111  int &out_connect_num) override;
112 
113  void getVkDecorGeometry(
115  RV_PrimType render_prim,
116  RV_Geometry &geo,
117  int &out_connect_start,
118  int &out_connect_num) override;
119 
120  exint getNumGLPrimitives() const override;
121  bool hasTransparency() const override { return true; }
122  bool supportsInstances() const override { return myUseCPUSort; }
123 
124  static bool initShaders(RV_Instance* inst);
125  static void cleanupShaders();
126 
127 private:
128  void sortGaussians(RV_Render *rv, const GR_Uniforms &uniforms);
129 
130  void drawGaussians(RV_Render* rv, GR_Uniforms* uniforms,
132  GR_DrawParms dp);
133 
134  void createGSplatGeom(RV_Render *rv);
135  void createFullScreenGeom(RV_Render *rv);
136 
137  void fillPointAttrib(RV_Render *rv,
138  const GT_PrimitiveHandle &primh,
139  const GT_PrimPointMesh *pmesh,
140  const GR_UpdateParms &parms);
141 
142  void createGSplatFramebuffer(RV_Render *rv,
143  const GR_Uniforms &uniforms);
144  void transitionToSampling(RV_Render* rv);
145 
146  void initIndirectBuffer(RV_Render *rv);
147  // draw
148  void prepareGaussiansData(const GT_PrimPointMesh& pmesh);
149  void setupDrawSet(RV_Render *rv);
150  void uploadStaticDrawBuffer(RV_Render *rv);
151  void updateDrawBuffer(RV_Render *rv);
152  // keys
153  void setupKeysSets(RV_Render *rv);
154  void uploadStaticKeysBuffer(RV_Render *rv);
155  void updateKeysBuffer(RV_Render *rv, const GR_Uniforms& uniforms);
156  bool computeKeys(RV_Render *rv);
157  // update dispatch params
158  void setupIndirectParamsSet(RV_Render *rv);
159  bool computeIndirectParams(RV_Render *rv);
160  // hist
161  void setupHistSets(RV_Render *rv);
162  bool computeHist(RV_Render *rv);
163  // prefix sum
164  void setupPrefixSumSets(RV_Render *rv);
165  bool computePrefixSum(RV_Render *rv);
166  // sort
167  void setupSortSets(RV_Render *rv);
168  void clearSortBuffer(RV_Render *rv);
169  void updateSortBuffer(RV_Render *rv, uint pass);
170  bool computeSort(RV_Render *rv);
171  void pingPongBuffer(RV_Render *rv, uint pass);
172 
173  // full screen with color image and depth reconstruction
174  void setupDepthSet(RV_Render *rv);
175  void drawDepth(RV_Render* rv, GR_Uniforms* uniforms,
177  GR_DrawParms dp);
178 
179  void sortOnCPU(RV_Render *rv,
180  const GR_Uniforms &uniforms);
181 
182  static RV_ShaderProgram *theGSplatDrawShader;
183  static RV_ShaderProgram *theDepthDrawShader;
184 
185  static RV_ShaderCompute *theKeysComputeShader;
186  static RV_ShaderCompute *theIndirectParamsComputeShader;
187  static RV_ShaderCompute *theHistComputeShader;
188  static RV_ShaderCompute *thePrefixSumComputeShader;
189  static RV_ShaderCompute *theSortComputeShader;
190 
191  // Options
192  bool myUseCPUSort;
193  bool myUseSPH;
194  bool myObjectSelected;
195 
196  std::mutex myMutex;
197 
198  exint myNumInstances;
199  exint myNumVisibles;
200 
201  UT_UniquePtr<RV_Geometry> myFullScreenGeoVK;
202 
203  UT_UniquePtr<RV_Framebuffer> myFramebuffer;
204  UT_UniquePtr<RV_VKImage> myColorImage;
205  UT_UniquePtr<RV_VKImage> myDepthDataImage;
206 
207  // indirect draw
208  IndirectCmd myIndirectCmd;
209  UT_UniquePtr<RV_ShaderBlock> myIndirectBlock;
210 
211  // gaussians data on CPU
212  MVPUboCPU myMVPUboCPU;
213  DrawSettingsCPU myDrawSettingsCPU;
214  UT_Array<GaussianSphCPU> mySphArray;
215  UT_Array<GaussianCPU> myGaussianArray;
216 
217  // depth sorting data on CPU
218  UT_Array<UT_Vector4F> myMeanArray;
219  UT_Array<uint> myKeysArray;
220  UT_Array<uint> myIndicesArray;
221 
222  // draw shader
224  UT_UniquePtr<RV_ShaderBlock> myDrawBlock;
225  UT_UniquePtr<RV_ShaderBlock> myDrawSphBlock;
226  UT_UniquePtr<RV_ShaderBlock> myDrawSettingsBlock;
227 
228  // keys generation compute shader
231 
232  UT_UniquePtr<RV_ShaderBlock> myMVPBlock;
233  UT_UniquePtr<RV_ShaderBlock> myMeanBlock;
234  UT_UniquePtr<RV_ShaderBlock> myKeysBlock;
235  UT_UniquePtr<RV_ShaderBlock> myIndicesBlock;
236  UT_UniquePtr<RV_ShaderBlock> myPushConstBlock;
237  UT_UniquePtr<RV_ShaderBlock> myIndirectParamsBlock;
238 
239  UT_UniquePtr<RV_ShaderVariableSet> myIndirectParamsSet;
240 
241  // depth-sorting compute shader
243 
244  UT_UniquePtr<RV_ShaderVariableSet> myPrefixSumSet;
245 
248  UT_UniquePtr<RV_ShaderVariableSet> mySortPingPongSet;
249 
250  UT_UniquePtr<RV_ShaderBlock> myHistogramBlock;
251  UT_UniquePtr<RV_ShaderBlock> myGlobalHistBlock;
252  UT_UniquePtr<RV_ShaderBlock> mySortedKeysBlock;
253  UT_UniquePtr<RV_ShaderBlock> mySortedIndicesBlock;
254  UT_UniquePtr<RV_ShaderBlock> mySortPushConstBlock;
255 
257 };
258 
259 #endif
const uint K_WORKGROUP_SIZE
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
UT_Matrix4F obj
const uint K_RADIX_PASS
GLbitfield flags
Definition: glcorearb.h:1596
virtual void draw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, GR_DrawParms draw_parms)=0
Normal drawing method. Only issue rendering commands.
const uint K_RADIX_SORT_BINS
virtual void getVkDecorGeometry(GR_DecorationRender::PrimitiveType prim_type, RV_PrimType render_prim, RV_Geometry &geo, int &out_connect_start, int &out_connect_num)
UT_Vector4F cdAlpha
int64 exint
Definition: SYS_Types.h:125
GT_API const UT_StringHolder cache_name
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
UT_Vector4F scale
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
bool supportsInstances() const override
By default, no instanced drawing support.
UT_Vector4F mean
RV_API void cleanupShaders()
#define GR_API
Definition: GR_API.h:10
A mesh of unconnected points.
UT_Matrix4F proj
GR_RenderFlags
Definition: GR_Defines.h:88
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:44
UT_Matrix4F view
GLenum mode
Definition: glcorearb.h:99
RV_API bool initShaders(RV_Instance *inst)
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:424
GA_API const UT_StringHolder parms
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
UT_Vector4F rotate
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