@@ -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 /**
0 commit comments