Blender V5.3
draw_gsplat_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "GPU_shader.hh"
12#include "GPU_vertex_buffer.hh"
13
14#include "draw_pass.hh"
15
16namespace blender {
17
18namespace gpu {
19class Batch;
20class VertBuf;
21class UniformBuf;
22} // namespace gpu
23
24struct Object;
25struct PointCloud;
26struct GPUMaterial;
27
28namespace draw {
29
30struct GSplatModule;
31struct GSplatBatchCache;
32
37enum class GSplatEvalShader {
38 /* Ellipse computation only. */
40 /* Degree 0-3 spherical harmonics. */
42 /* Ellipses, and degree 0-3 spherical harmonics. */
44};
45
56
57 /* --- Batches. --- */
58
59 /* Triangle primitive types. */
60 gpu::Batch *surface;
61 gpu::Batch **surface_per_mat;
62 /* Dot primitive types. */
63 gpu::Batch *dots;
64 gpu::Batch *edit_dots;
65
66 /* --- Builtin attribute buffers. --- */
67
68 /* Packed mean, quaternion, scaling per unit: 4x32ui. */
70 /* Packed opacity and spherical harmonics per unit: 16x32ui. */
72 /* Miscellaneous data, mostly for shader-side unpacking. */
74
75 /* --- Intermediate compute buffers. --- */
76
77 /* Compute intermediate output: per-splat ellipse data. */
79 /* Compute intermediate output: per-splat radiance value. */
81
82 /* --- Other attribute buffers. --- */
83
84 /* Active attribute in 3D view. */
86 /* Requested attributes. */
88 /* Index buffer for selection dots. */
90
91 /* --- Internal batch/buffer builders. --- */
92
93 void ensure_builtin_buffers(PointCloud &pointcloud);
94 void ensure_compute_buffers(PointCloud &pointcloud);
95 void ensure_edit_dots_indices(PointCloud &pointcloud);
96 void ensure_attribute(PointCloud &pointcloud, int attrib_i);
97
98 public:
99 /* --- Generic attribute infos. --- */
100
103
109
116
117 /* Nr. of batches in surface_per_mat. */
119
120 /* --- API --- */
121
122 /* Get the eval cache for a object. */
123 static GSplatEvalCache &get(PointCloud &pointcloud);
124
125 /* Request pointers to buffers that may not be filled yet, see `ensure_requested()`. */
131 gpu::VertBuf **attributes_get(uint request_i);
132
133 /* Request pointers to batches that may not be filled yet, see `ensure_requested()`. */
134 gpu::Batch *dots_get();
135 gpu::Batch *edit_dots_get();
136 gpu::Batch *surface_get(const PointCloud &pointcloud);
137
139 void ensure_requested(PointCloud &pointcloud);
140
141 /* Safely discard buffers, batches, etc. */
142 void discard_buffers();
143 void discard_attributes();
144};
145
146/* Stored in DRWData. */
148 gpu::VertBuf *dummy_vbo = create_dummy_vbo();
149 gpu::UniformBuf *dummy_ubo = create_dummy_ubo();
150
156
157 void begin_sync();
158 void sync_object(const ObjectRef &ob_ref, const ResourceHandleRange &res_handle);
159 void update(draw::Manager &manager, draw::View &view, GSplatEvalShader type);
160
161 private:
162 Set<ObjectKey> compute_objects_;
163
164 /* Passes matching `GSplatEvalShader` selection. */
165 PassSimple compute_dummy_ps_ = {"GSplatPassEmpty"};
166 PassSimple compute_ellipses_ps_ = {"GSplatPassEllipses"};
167 PassSimple compute_radiance_ps_ = {"GSplatPassRadiance"};
168 PassSimple compute_ellipses_radiance_ps_ = {"GSplatPassEllipsesRadiance"};
169
170 PassSimple &get_ps(GSplatEvalShader type)
171 {
172 switch (type) {
174 return compute_ellipses_ps_;
176 return compute_radiance_ps_;
178 return compute_ellipses_radiance_ps_;
179 default:
180 return compute_dummy_ps_;
181 }
182 }
183
184 gpu::VertBuf *create_dummy_vbo()
185 {
186 GPUVertFormat format = {0};
187 uint dummy_id = GPU_vertformat_attr_add(
188 &format, "dummy", gpu::VertAttrType::SFLOAT_32_32_32_32);
189
190 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format_ex(
192
193 const float vert[4] = {0.0f, 0.0f, 0.0f, 0.0f};
194 GPU_vertbuf_data_alloc(*vbo, 1);
195 GPU_vertbuf_attr_fill(vbo, dummy_id, vert);
196 return vbo;
197 }
198
199 gpu::UniformBuf *create_dummy_ubo()
200 {
201 const uint4 data = uint4(0u);
202 gpu::UniformBuf *ubo = GPU_uniformbuf_create_ex(sizeof(uint4), &data, "DummyUBO");
203 return ubo;
204 }
205};
206
207} // namespace draw
208} // namespace blender
#define GPU_UBO_FREE_SAFE(ubo)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
detail::Pass< command::DrawCommandBuf > PassSimple
BMesh Iterators.
unsigned int uint
Definition BKE_text.h:55
VecBase< uint32_t, 4 > uint4
BMesh const char void * data
gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
std::string format(const std::string &fmt, Args &&...args)
Definition diagnostic.hh:43
void vert(const int vert_id, float4 &position)
VectorSet< std::string > attr_used
void ensure_compute_buffers(PointCloud &pointcloud)
void ensure_builtin_buffers(PointCloud &pointcloud)
VectorSet< std::string > attr_used_over_time
void ensure_requested(PointCloud &pointcloud)
void ensure_attribute(PointCloud &pointcloud, int attrib_i)
gpu::Batch * surface_get(const PointCloud &pointcloud)
gpu::VertBuf ** attributes_get(uint request_i)
void ensure_edit_dots_indices(PointCloud &pointcloud)
static GSplatEvalCache & get(PointCloud &pointcloud)
gpu::VertBuf * attributes_buf[GPU_MAX_ATTR]
void update(draw::Manager &manager, draw::View &view, GSplatEvalShader type)
void sync_object(const ObjectRef &ob_ref, const ResourceHandleRange &res_handle)