Skip to content

Commit e76e37e

Browse files
mvaligurskyMartin Valigursky
andauthored
refactor: rename GSplatRenderer methods for clarity (#8522)
Rename configureMaterial() to onWorkBufferFormatChanged(), merge setIndirectDraw()+updateIndirect() into setGpuSortedRendering(), and rename disableIndirectDraw() to setCpuSortedRendering(). Made-with: Cursor Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 0fb1c97 commit e76e37e

File tree

3 files changed

+58
-69
lines changed

3 files changed

+58
-69
lines changed

src/scene/gsplat-unified/gsplat-manager.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -450,37 +450,40 @@ class GSplatManager {
450450
this.keyGenerator = null;
451451
this.gpuSorter?.destroy();
452452
this.gpuSorter = null;
453-
// Disable once when destroying both compaction systems together.
454-
const disableIndirectDraw = false;
455-
this.renderer.disableIndirectDraw();
456-
this.destroyIntervalCompaction(disableIndirectDraw);
457-
this.destroyCompaction(disableIndirectDraw);
453+
454+
// Switch renderer to CPU mode once, before destroying both compaction systems.
455+
const useCpuSort = false;
456+
this.renderer.setCpuSortedRendering();
457+
this.destroyIntervalCompaction(useCpuSort);
458+
this.destroyCompaction(useCpuSort);
458459
}
459460

460461
/**
461-
* Destroys interval compaction resources and disables indirect draw on the renderer.
462+
* Destroys interval compaction resources.
462463
*
464+
* @param {boolean} [useCpuSort] - Whether to switch the renderer to CPU-sorted mode.
463465
* @private
464466
*/
465-
destroyIntervalCompaction(disableIndirectDraw = true) {
467+
destroyIntervalCompaction(useCpuSort = true) {
466468
if (this.intervalCompaction) {
467-
if (disableIndirectDraw) {
468-
this.renderer.disableIndirectDraw();
469+
if (useCpuSort) {
470+
this.renderer.setCpuSortedRendering();
469471
}
470472
this.intervalCompaction.destroy();
471473
this.intervalCompaction = null;
472474
}
473475
}
474476

475477
/**
476-
* Destroys compaction resources and disables indirect draw on the renderer.
478+
* Destroys compaction resources.
477479
*
480+
* @param {boolean} [useCpuSort] - Whether to switch the renderer to CPU-sorted mode.
478481
* @private
479482
*/
480-
destroyCompaction(disableIndirectDraw = true) {
483+
destroyCompaction(useCpuSort = true) {
481484
if (this.compaction) {
482-
if (disableIndirectDraw) {
483-
this.renderer.disableIndirectDraw();
485+
if (useCpuSort) {
486+
this.renderer.setCpuSortedRendering();
484487
}
485488
this.compaction.destroy();
486489
this.compaction = null;
@@ -531,8 +534,8 @@ class GSplatManager {
531534
this.cpuSorter.updateCentersForSplats(currentState.splats);
532535
}
533536

534-
// Disable indirect draw on the renderer (also hides until update() restores visibility)
535-
this.renderer.disableIndirectDraw();
537+
// Switch renderer to CPU-sorted mode (also hides until update() restores visibility)
538+
this.renderer.setCpuSortedRendering();
536539
}
537540

538541
get material() {
@@ -1281,7 +1284,7 @@ class GSplatManager {
12811284
this.workBuffer.destroy();
12821285
this.workBuffer = new GSplatWorkBuffer(this.device, currentFormat);
12831286
this.renderer.workBuffer = this.workBuffer;
1284-
this.renderer.configureMaterial();
1287+
this.renderer.onWorkBufferFormatChanged();
12851288
this._workBufferFormatVersion = this.workBuffer.format.extraStreamsVersion;
12861289
this._workBufferRebuildRequired = true;
12871290
this.sortNeeded = true;
@@ -1723,10 +1726,7 @@ class GSplatManager {
17231726
*/
17241727
applyGpuSortResults(worldState, sortedIndices) {
17251728
const ic = /** @type {GSplatIntervalCompaction} */ (this.intervalCompaction);
1726-
this.renderer.setIndirectDraw(this.indirectDrawSlot, sortedIndices, /** @type {StorageBuffer} */ (ic.numSplatsBuffer));
1727-
1728-
// Update renderer for indirect draw (instancingCount and numSplats are GPU-driven)
1729-
this.renderer.updateIndirect(worldState.textureSize);
1729+
this.renderer.setGpuSortedRendering(this.indirectDrawSlot, sortedIndices, /** @type {StorageBuffer} */ (ic.numSplatsBuffer), worldState.textureSize);
17301730
}
17311731

17321732
/**
@@ -1775,14 +1775,13 @@ class GSplatManager {
17751775
this.allocateAndWriteIntervalIndirectArgs(this.lastCompactedNumIntervals);
17761776
const gpuSorter = /** @type {ComputeRadixSort} */ (this.gpuSorter);
17771777
const ic = /** @type {GSplatIntervalCompaction} */ (this.intervalCompaction);
1778-
this.renderer.setIndirectDraw(this.indirectDrawSlot, /** @type {StorageBuffer} */ (gpuSorter.sortedIndices), /** @type {StorageBuffer} */ (ic.numSplatsBuffer));
1778+
this.renderer.setGpuSortedRendering(this.indirectDrawSlot, /** @type {StorageBuffer} */ (gpuSorter.sortedIndices), /** @type {StorageBuffer} */ (ic.numSplatsBuffer), sortedState.textureSize);
17791779
} else {
17801780
// CPU sort path: compacted buffer already contains sorted visible splat IDs
17811781
this.allocateAndWriteIndirectArgs(this.lastCompactedTotalSplats);
17821782
const compaction = /** @type {GSplatCompaction} */ (this.compaction);
1783-
this.renderer.setIndirectDraw(this.indirectDrawSlot, /** @type {StorageBuffer} */ (compaction.compactedSplatIds), /** @type {StorageBuffer} */ (compaction.numSplatsBuffer));
1783+
this.renderer.setGpuSortedRendering(this.indirectDrawSlot, /** @type {StorageBuffer} */ (compaction.compactedSplatIds), /** @type {StorageBuffer} */ (compaction.numSplatsBuffer), sortedState.textureSize);
17841784
}
1785-
this.renderer.updateIndirect(sortedState.textureSize);
17861785
}
17871786

17881787
/**
@@ -1824,13 +1823,13 @@ class GSplatManager {
18241823

18251824
this.allocateAndWriteIndirectArgs(elementCount);
18261825

1827-
// Set up indirect draw: compacted buffer already contains sorted visible splatIds
1828-
this.renderer.setIndirectDraw(
1826+
// Set up GPU-sorted rendering: compacted buffer already contains sorted visible splatIds
1827+
this.renderer.setGpuSortedRendering(
18291828
this.indirectDrawSlot,
18301829
/** @type {StorageBuffer} */ (this.compaction.compactedSplatIds),
1831-
/** @type {StorageBuffer} */ (this.compaction.numSplatsBuffer)
1830+
/** @type {StorageBuffer} */ (this.compaction.numSplatsBuffer),
1831+
sortedState.textureSize
18321832
);
1833-
this.renderer.updateIndirect(sortedState.textureSize);
18341833
}
18351834

18361835
/**

src/scene/gsplat-unified/gsplat-quad-renderer.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class GSplatQuadRenderer extends GSplatRenderer {
133133
return this._material;
134134
}
135135

136+
onWorkBufferFormatChanged() {
137+
this.configureMaterial();
138+
}
139+
136140
configureMaterial() {
137141
const { workBuffer } = this;
138142

@@ -213,48 +217,40 @@ class GSplatQuadRenderer extends GSplatRenderer {
213217
}
214218

215219
/**
216-
* Updates renderer for indirect draw mode. The instance count and numSplats
217-
* are GPU-driven via indirect draw args and a storage buffer.
218-
*
219-
* @param {number} textureSize - The work buffer texture size.
220-
*/
221-
updateIndirect(textureSize) {
222-
this._material.setParameter('splatTextureSize', textureSize);
223-
this.meshInstance.visible = true;
224-
225-
// Ensure instancingCount is non-zero so the forward/shadow renderers don't
226-
// skip this draw call. The actual instance count is GPU-driven via indirect args.
227-
if (this.meshInstance.instancingCount <= 0) {
228-
this.meshInstance.instancingCount = 1;
229-
}
230-
}
231-
232-
/**
233-
* Configures indirect draw on the mesh instance and binds compaction buffers.
234-
* Must be called each frame when compaction is active (slots are per-frame).
220+
* Configures the renderer to use GPU-sorted data for rendering.
235221
*
236222
* @param {number} drawSlot - The indirect draw slot index in the device's buffer.
237-
* @param {StorageBuffer} compactedSplatIds - Buffer containing sorted visible splat IDs.
223+
* @param {StorageBuffer} sortedIds - Buffer containing sorted visible splat IDs.
238224
* @param {StorageBuffer} numSplatsBuffer - Buffer containing numSplats for vertex shader.
225+
* @param {number} textureSize - The work buffer texture size.
239226
*/
240-
setIndirectDraw(drawSlot, compactedSplatIds, numSplatsBuffer) {
227+
setGpuSortedRendering(drawSlot, sortedIds, numSplatsBuffer, textureSize) {
241228
this.meshInstance.setIndirect(null, drawSlot, 1);
242229

243230
// Bind compaction buffers for vertex shader
244-
this._material.setParameter('compactedSplatIds', compactedSplatIds);
231+
this._material.setParameter('compactedSplatIds', sortedIds);
245232
this._material.setParameter('numSplatsStorage', numSplatsBuffer);
246233

247234
// Set GSPLAT_INDIRECT_DRAW define if not already set
248235
if (!this._material.getDefine('GSPLAT_INDIRECT_DRAW')) {
249236
this._material.setDefine('GSPLAT_INDIRECT_DRAW', true);
250237
this._material.update();
251238
}
239+
240+
this._material.setParameter('splatTextureSize', textureSize);
241+
this.meshInstance.visible = true;
242+
243+
// Ensure instancingCount is non-zero so the forward/shadow renderers don't
244+
// skip this draw call. The actual instance count is GPU-driven via indirect args.
245+
if (this.meshInstance.instancingCount <= 0) {
246+
this.meshInstance.instancingCount = 1;
247+
}
252248
}
253249

254250
/**
255-
* Disables indirect draw, restoring the renderer to direct (CPU-sorted) mode.
251+
* Switches the renderer to CPU-sorted rendering mode.
256252
*/
257-
disableIndirectDraw() {
253+
setCpuSortedRendering() {
258254
this.meshInstance.setIndirect(null, -1);
259255

260256
if (this._material.getDefine('GSPLAT_INDIRECT_DRAW')) {

src/scene/gsplat-unified/gsplat-renderer.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class GSplatRenderer {
5757
this._workBufferFormatVersion = workBuffer.format.extraStreamsVersion;
5858
}
5959

60+
destroy() {
61+
}
62+
6063
/**
6164
* Sets the render mode for this renderer.
6265
*
@@ -76,9 +79,10 @@ class GSplatRenderer {
7679
}
7780

7881
/**
79-
* Configures the renderer's material after a work buffer format change.
82+
* Called when the work buffer format has changed. Derived classes reconfigure
83+
* their rendering resources (materials, pipelines, bindings, etc.).
8084
*/
81-
configureMaterial() {
85+
onWorkBufferFormatChanged() {
8286
}
8387

8488
/**
@@ -91,27 +95,20 @@ class GSplatRenderer {
9195
}
9296

9397
/**
94-
* Updates the renderer for indirect (GPU-driven) draw mode.
95-
*
96-
* @param {number} textureSize - The work buffer texture size.
97-
*/
98-
updateIndirect(textureSize) {
99-
}
100-
101-
/**
102-
* Configures indirect draw and binds compaction buffers.
98+
* Configures the renderer to use GPU-sorted data for rendering.
10399
*
104100
* @param {number} drawSlot - The indirect draw slot index.
105-
* @param {StorageBuffer} compactedSplatIds - Buffer containing sorted visible splat IDs.
101+
* @param {StorageBuffer} sortedIds - Buffer containing sorted visible splat IDs.
106102
* @param {StorageBuffer} numSplatsBuffer - Buffer containing the visible splat count.
103+
* @param {number} textureSize - The work buffer texture size.
107104
*/
108-
setIndirectDraw(drawSlot, compactedSplatIds, numSplatsBuffer) {
105+
setGpuSortedRendering(drawSlot, sortedIds, numSplatsBuffer, textureSize) {
109106
}
110107

111108
/**
112-
* Disables indirect draw, restoring the renderer to direct (CPU-sorted) mode.
109+
* Switches the renderer to CPU-sorted rendering mode.
113110
*/
114-
disableIndirectDraw() {
111+
setCpuSortedRendering() {
115112
}
116113

117114
/**
@@ -135,9 +132,6 @@ class GSplatRenderer {
135132
*/
136133
updateOverdrawMode(params) {
137134
}
138-
139-
destroy() {
140-
}
141135
}
142136

143137
export { GSplatRenderer };

0 commit comments

Comments
 (0)