feat: radix sort facade, indirect mode, and WebGPU subgroup sizing#8647
Merged
Conversation
Refactor compute radix sort behind ComputeRadixSort with portable and OneSweep backends, indirect dispatch metadata, WGSL sort-indirect-args chunk, and fix subgroup min/max from adapter info.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the WebGPU compute radix sort into a unified ComputeRadixSort facade with selectable backends, adds an optional indirect-dispatch mode for GSplat integration, and updates WebGPU subgroup sizing to read from adapter info.
Changes:
- Introduces
ComputeRadixSortfacade + sharedComputeRadixSortBase, moving multipass/OneSweep implementations undersrc/scene/graphics/radix-sort/. - Adds indirect-dispatch support end-to-end (new WGSL helper chunk
sortIndirectArgsCS, GSplat write-args shader + interval compaction wiring,prepareIndirect()/sortIndirect()APIs). - Updates OneSweep shaders for indirect-mode element-count handling and ragged-tail histogram, and switches subgroup size reads to
gpuAdapter.info.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/scene/shader-lib/wgsl/collections/shader-chunks-wgsl.js | Registers the new WGSL helper chunk for indirect sort dispatch args. |
| src/scene/shader-lib/wgsl/chunks/radix-sort/onesweep-scan.js | Adds indirect-mode element-count binding and derives threadBlocks from GPU count. |
| src/scene/shader-lib/wgsl/chunks/radix-sort/onesweep-global-hist.js | Adds indirect-mode numKeys source and ragged-tail handling for non-vec4-multiple counts. |
| src/scene/shader-lib/wgsl/chunks/radix-sort/onesweep-binning.js | Adds indirect-mode element-count binding and localizes threadBlocks usage. |
| src/scene/shader-lib/wgsl/chunks/gsplat/compute-gsplat-write-indirect-args.js | Delegates sort dispatch-slot writes to writeSortIndirectArgs using sorter metadata. |
| src/scene/shader-lib/wgsl/chunks/common/comp/sort-indirect-args.js | New WGSL helper to write sorter dispatch args from stable metadata. |
| src/scene/gsplat-unified/gsplat-manager.js | Switches GSplat to ComputeRadixSort(..., { indirect: true }) and reserves variable slot counts. |
| src/scene/gsplat-unified/gsplat-interval-compaction.js | Extends indirect-args write path to pass sorter metadata (uvec4) into the shader. |
| src/scene/graphics/radix-sort/compute-radix-sort.js | New public facade selecting multipass vs OneSweep and exposing direct/indirect APIs. |
| src/scene/graphics/radix-sort/compute-radix-sort-onesweep.js | Relocates/refactors OneSweep under the new base class and adds indirect-dispatch variant. |
| src/scene/graphics/radix-sort/compute-radix-sort-multipass.js | Relocates/refactors portable multipass backend under the new base class and indirect-only mode. |
| src/scene/graphics/radix-sort/compute-radix-sort-base.js | New shared base for buffer lifecycle + indirect metadata plumbing. |
| src/scene/constants.js | Adds RADIX_SORT_AUTO / RADIX_SORT_PORTABLE / RADIX_SORT_ONESWEEP constants. |
| src/platform/graphics/webgpu/webgpu-graphics-device.js | Reads minSubgroupSize/maxSubgroupSize from gpuAdapter.info fields. |
| src/index.js | Re-exports ComputeRadixSort from the new path and removes the OneSweep export. |
| examples/src/examples/test/radix-sort-compute.example.mjs | Updates the example to use the new facade + kind option. |
Comments suppressed due to low confidence (1)
src/scene/graphics/radix-sort/compute-radix-sort-onesweep.js:231
elementCountBindingis a singleBindStorageBufferFormatinstance that gets pushed into 3 differentBindGroupFormats.BindGroupFormatmutatesformat.slotduring construction, so reusing the same instance will leave earlier bind group formats with the wrong slot index forb_sortElementCount(likely causing a bind group / pipeline layout mismatch at runtime). Create a freshBindStorageBufferFormat('b_sortElementCount', ...)per bind group instead of sharing one object.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactors WebGPU compute radix sort behind a single
ComputeRadixSortentry point, adds optional indirect-dispatch integration for GSplat, and fixes subgroup size fields read from the adapter.Changes:
src/scene/graphics/radix-sort/with a sharedComputeRadixSortBaseand publicComputeRadixSortfacade; backend selection usesRADIX_SORT_AUTO/RADIX_SORT_PORTABLE/RADIX_SORT_ONESWEEPconstants.indirectconstructor option so only the needed shader variant is compiled;prepareIndirect/sortIndirectassert when used without it.sortIndirectArgsCSWGSL chunk (writeSortIndirectArgs) and wire GSplat indirect-arg shaders toprepareIndirect()metadata.minSubgroupSize.minSubgroupSize/maxSubgroupSizefromgpuAdapter.info(subgroupMinSize/subgroupMaxSize), notlimits.kindoption.Examples:
examples/src/examples/test/radix-sort-compute.example.mjs