Skip to content

Commit de714be

Browse files
mvaligurskyMartin Valigursky
andauthored
feat(gsplat): auto-select GPU sort on WebGPU and promote it to stable (#8941)
GSPLAT_RENDERER_AUTO now resolves to GSPLAT_RENDERER_RASTER_GPU_SORT on WebGPU (CPU sort on WebGL). Extracted the resolution into a shared _resolveRenderer helper used by both the constructor and the renderer setter, so the default (untouched) AUTO path resolves correctly. Promoted GSPLAT_RENDERER_RASTER_GPU_SORT from experimental/alpha to a public, stable API. Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent 37ecd65 commit de714be

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

src/scene/constants.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,12 +1225,10 @@ export const GSPLAT_RENDERER_AUTO = 0;
12251225
export const GSPLAT_RENDERER_RASTER_CPU_SORT = 1;
12261226

12271227
/**
1228-
* Rasterization-based rendering with GPU-side culling and sorting. WebGPU only. Experimental with
1229-
* limited functionality.
1228+
* Rasterization-based rendering with GPU-side culling and sorting. WebGPU only.
12301229
*
12311230
* @type {number}
12321231
* @category Graphics
1233-
* @alpha
12341232
*/
12351233
export const GSPLAT_RENDERER_RASTER_GPU_SORT = 2;
12361234

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class GSplatParams {
6767
*/
6868
constructor(device) {
6969
this._device = device;
70+
this._currentRenderer = this._resolveRenderer(this._renderer);
7071
this._format = this._createFormat(GSPLATDATA_COMPACT);
7172
this._varyings = new GSplatVaryings(device);
7273

@@ -140,18 +141,42 @@ class GSplatParams {
140141
_renderer = GSPLAT_RENDERER_AUTO;
141142

142143
/**
144+
* Resolved renderer in effect; computed from {@link _renderer} and the device in the
145+
* constructor and the {@link renderer} setter.
146+
*
143147
* @type {number}
144148
* @private
145149
*/
146150
_currentRenderer = GSPLAT_RENDERER_RASTER_CPU_SORT;
147151

152+
/**
153+
* Resolves a requested renderer mode to the concrete one used on this device.
154+
*
155+
* @param {number} value - The requested renderer mode.
156+
* @returns {number} The resolved renderer mode.
157+
* @private
158+
*/
159+
_resolveRenderer(value) {
160+
// AUTO picks GPU-side sorting on WebGPU, CPU-side sorting elsewhere.
161+
if (value === GSPLAT_RENDERER_AUTO) {
162+
return this._device.isWebGPU ?
163+
GSPLAT_RENDERER_RASTER_GPU_SORT : GSPLAT_RENDERER_RASTER_CPU_SORT;
164+
}
165+
// GPU sort requires WebGPU; fall back to CPU sort on WebGL.
166+
if (value === GSPLAT_RENDERER_RASTER_GPU_SORT && !this._device.isWebGPU) {
167+
return GSPLAT_RENDERER_RASTER_CPU_SORT;
168+
}
169+
return value;
170+
}
171+
148172
/**
149173
* Sets the rendering pipeline used for gaussian splatting. Can be:
150174
*
151175
* - {@link GSPLAT_RENDERER_AUTO}: Automatically selects the best pipeline for the platform.
176+
* Selects {@link GSPLAT_RENDERER_RASTER_GPU_SORT} on WebGPU and
177+
* {@link GSPLAT_RENDERER_RASTER_CPU_SORT} on WebGL.
152178
* - {@link GSPLAT_RENDERER_RASTER_CPU_SORT}: Rasterization with CPU-side sorting.
153-
* - {@link GSPLAT_RENDERER_RASTER_GPU_SORT}: Rasterization with GPU-side sorting (WebGPU only,
154-
* experimental).
179+
* - {@link GSPLAT_RENDERER_RASTER_GPU_SORT}: Rasterization with GPU-side sorting (WebGPU only).
155180
*
156181
* Defaults to {@link GSPLAT_RENDERER_AUTO}. Modes requiring WebGPU fall back to
157182
* {@link GSPLAT_RENDERER_RASTER_CPU_SORT} on WebGL devices. The resolved mode actually used
@@ -167,14 +192,7 @@ class GSplatParams {
167192

168193
if (this._renderer !== value) {
169194
this._renderer = value;
170-
171-
if (value === GSPLAT_RENDERER_AUTO) {
172-
this._currentRenderer = GSPLAT_RENDERER_RASTER_CPU_SORT;
173-
} else if (value === GSPLAT_RENDERER_RASTER_GPU_SORT && !this._device.isWebGPU) {
174-
this._currentRenderer = GSPLAT_RENDERER_RASTER_CPU_SORT;
175-
} else {
176-
this._currentRenderer = value;
177-
}
195+
this._currentRenderer = this._resolveRenderer(value);
178196
}
179197
}
180198

0 commit comments

Comments
 (0)