Skip to content

GS WebGPU fastpath#18648

Draft
CedricGuillemet wants to merge 9 commits into
BabylonJS:masterfrom
CedricGuillemet:GSCSCulling
Draft

GS WebGPU fastpath#18648
CedricGuillemet wants to merge 9 commits into
BabylonJS:masterfrom
CedricGuillemet:GSCSCulling

Conversation

@CedricGuillemet

Copy link
Copy Markdown
Contributor

No description provided.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/18648/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18648/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18648/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18648/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18648/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18648/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18648/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18648/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

Baseline: Latest · Candidate: Dev

Metric Value
🟢 Average 2.6%25 faster
Median 2.6%25 faster
Tests 1 conclusive, 0 inconclusive
🔘 Not Significant — p ≥ 0.05 (1)
Test Baseline Candidate Diff p-value
SSAO2 [#XT1HAS#1] (webgl2) 122.6ms 119.5ms 2.6%25 faster 0.9298

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

❌ Failed Tests (1)

Test Error
SSAO2 [#XT1HAS#1] (webgpu) Error: page.evaluate: Execution context was destroyed, most likely because of a navigation.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a WebGPU compute “fast path” for Gaussian Splatting by moving depth sorting (and optional frustum culling + indirect draw) onto the GPU, supported by new WGSL compute shaders and a reusable hierarchical exclusive prefix-sum helper.

Changes:

  • Add a WebGPU compute-based Gaussian Splatting GPU sorter (counting-sort style) plus optional GPU culling + GPU-driven indirect draws.
  • Add a reusable PrefixSumCompute helper + WGSL scan shaders and wire it into the sorter/culling pipeline.
  • Extend engine/mesh plumbing for caller-owned indirect draw buffers, plus devhost validation scene and a small unit test.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/treeshaking/side-effects-manifest/core/ShadersWGSL.json Registers new WGSL compute shader side effects for tree-shaking.
scripts/treeshaking/side-effects-manifest/core/Meshes.json Registers the new GPU sorter module side effects.
scripts/treeshaking/side-effects-manifest/core/Compute.json Registers the new prefix sum compute wrapper side effects.
packages/tools/devHost/src/testScene/main.ts Switches devhost test scene to WebGPU engine setup.
packages/tools/devHost/src/testScene/createScene.ts Loads a .splat and forces GPU sort path; exposes runtime verification info.
packages/public/@babylonjs/core/package.json Publishes new JS entrypoints for prefix sum + GPU sorter.
packages/dev/core/test/unit/Meshes/babylon.gaussianSplatting.gpuSorter.test.ts Adds unit coverage for compute-support detection.
packages/dev/core/src/ShadersWGSL/prefixSumScanBlock.compute.fx Adds WGSL block-scan shader used by hierarchical exclusive scan.
packages/dev/core/src/ShadersWGSL/prefixSumAddOffsets.compute.fx Adds WGSL add-offsets shader for hierarchical exclusive scan.
packages/dev/core/src/ShadersWGSL/gaussianSplattingSortClear.compute.fx Adds histogram clear compute pass.
packages/dev/core/src/ShadersWGSL/gaussianSplattingSortDepth.compute.fx Adds depth + range reduction compute pass.
packages/dev/core/src/ShadersWGSL/gaussianSplattingSortHistogram.compute.fx Adds bucket histogram compute pass.
packages/dev/core/src/ShadersWGSL/gaussianSplattingSortScatter.compute.fx Adds scatter compute pass to produce sorted indices.
packages/dev/core/src/ShadersWGSL/gaussianSplattingCull.compute.fx Adds post-sort frustum-flag compute pass.
packages/dev/core/src/ShadersWGSL/gaussianSplattingCullCompact.compute.fx Adds compaction compute pass for visible splats.
packages/dev/core/src/ShadersWGSL/gaussianSplattingCullFinalize.compute.fx Adds indirect-args + padding finalize compute pass.
packages/dev/core/src/ShadersWGSL/gaussianSplatting.vertex.fx Clips the GPU-culling padding sentinel (-1) so partial instances render nothing.
packages/dev/core/src/Meshes/thinInstanceMesh.types.ts Adds internal API surface to bind a GPU-produced splat-index buffer.
packages/dev/core/src/Meshes/thinInstanceMesh.pure.ts Implements GPU DataBuffer binding as thin-instance splatIndex attributes.
packages/dev/core/src/Meshes/mesh.pure.ts Adds _indirectDrawBuffer plumbing and uses indirect draw when present.
packages/dev/core/src/Meshes/GaussianSplatting/pure.ts Exposes the new GPU sorter via the pure barrel.
packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMeshBase.ts Ensures GPU sorter side effects are included in the non-pure path.
packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.ts Adds GPU sort mode controls and integrates GPU sort/cull/indirect draw path.
packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.ts Side-effect wrapper importing shaders + prefix sum.
packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.pure.ts Implements compute-driven sorting, optional culling, and indirect args handling.
packages/dev/core/src/Engines/webgpuEngine.pure.ts Adds a caller-owned indirect draw path into the WebGPU fast draw pipeline.
packages/dev/core/src/Engines/abstractEngine.pure.ts Adds a base API for drawIndexedIndirect via caller-owned buffer (WebGPU-only).
packages/dev/core/src/Compute/pure.ts Exposes prefix sum helper via compute pure barrel.
packages/dev/core/src/Compute/prefixSumCompute.ts Side-effect wrapper importing prefix-sum WGSL shaders.
packages/dev/core/src/Compute/prefixSumCompute.pure.ts Implements hierarchical exclusive prefix sum driver with per-dispatch UBO ring.
Comments suppressed due to low confidence (1)

packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.ts:3285

  • When _useGpuSort switches from true to false (e.g. runtime change of GpuSortMode), any previously GPU-bound state is not cleared. In particular, per-camera meshes may still have _indirectDrawBuffer set and splatIndexBufferSet=true from the GPU path, so the worker path will call thinInstanceBufferUpdated("splatIndex") and fail to update (the GPU buffer wrapper is not updatable) and may continue issuing indirect draws. Clearing these flags/bindings when falling back to the worker path avoids stale rendering/crashes.
    }

    protected _instantiateWorker(): void {
        if (!this._vertexCount) {
            return;
        }
        if (this._disableDepthSort) {

Comment thread packages/dev/core/src/Compute/prefixSumCompute.pure.ts Outdated
Comment thread packages/dev/core/src/ShadersWGSL/prefixSumScanBlock.compute.fx Outdated
Comment thread packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.ts Outdated
Comment thread packages/dev/core/src/Engines/webgpuEngine.pure.ts
@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@sebavan sebavan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @RaananW can you validate the side effects part ?

@CedricGuillemet CedricGuillemet marked this pull request as draft July 2, 2026 18:19
Comment thread packages/dev/core/src/Compute/prefixSumCompute.ts Outdated
@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Reviewer - this PR has made changes to one or more package.json files.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Comment thread packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.ts Outdated
@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Snapshot stored with reference name:
refs/pull/18648/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18648/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18648/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/18648/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/18648/merge
https://gui.babylonjs.com/?snapshot=refs/pull/18648/merge
https://nme.babylonjs.com/?snapshot=refs/pull/18648/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/18648/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

🟢 Memory Leak Test Results

4 passed, 0 leaked out of 4 scenarios

🟢 All memory leak tests passed — no leaks detected.

Passed Scenarios (4)
Scenario Package
Core Playground #2FDQT5#1508 @babylonjs/core
Core Playground #T90MQ4#14 @babylonjs/core
Core Playground #8EDB5N#2 @babylonjs/core
Core Playground #LL5BIQ#636 @babylonjs/core

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@bjsplat

bjsplat commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

⚡ Performance Test Results

🟢 All performance tests passed — no regressions detected.

@RaananW

RaananW commented Jul 3, 2026

Copy link
Copy Markdown
Member

let me know if you need approval or is it still in draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants