Skip to content

fix: Dispatch each Compute instance at most once per frame - #9690

Merged
mvaligursky merged 1 commit into
mainfrom
claude/compute-dispatch-once
Oct 7, 2026
Merged

mvaligursky merged 1 commit into
mainfrom
claude/compute-dispatch-once

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

A compute instance holds a single set of uniform values, uploaded when it is dispatched, and the GPU executes the dispatches of a frame once they are submitted. Dispatching the same instance more than once in a frame therefore ran all its dispatches with the uniform values of the last one. This makes the rule explicit, warns about it in debug builds, and fixes the engine code which dispatched instances more than once, including GPU sorted gaussian splat shadows, where every light was coarse culled with the frustum of the last light.

Changes:

  • Documented on Compute: an instance is dispatched at most once in a frame. To dispatch a compute shader more than once in a frame, use a separate instance for each dispatch. The instances can share the shader, which is compiled only once.
  • Debug builds warn when a compute instance is dispatched again in the same frame.
  • The engine's internal compute work dispatched more than once per frame now uses separate compute instances for each dispatch, sharing the shaders: the prefix sum of the multipass radix sort, dispatched for each radix pass, and the interval compaction of the gaussian splat shadow renderer, dispatched for each light.
  • Fixed GPU sorted gaussian splat shadows with multiple directional lights: the coarse cull of each light uses its own frustum, instead of the frustum of the last light, which could drop shadow casting splats of the other lights.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2508.7 KB (+583 B, +0.02%) 648.4 KB (+167 B, +0.03%) 503.4 KB (+368 B, +0.07%)
playcanvas.min.mjs 2505.5 KB (+583 B, +0.02%) 647.0 KB (+166 B, +0.03%) 503.2 KB (+351 B, +0.07%)

@mvaligursky mvaligursky left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated PR review by Codex (OpenAI AI agent), reviewing commit 75f34f614a4df5fcd20a9b92ffda523883ce0a46 from scratch.

No actionable correctness, compatibility, resource-lifetime, or performance regressions found in the current diff. I checked the per-dispatch compute pools, recursive prefix-sum passes, radix-sort callers, per-light dispatch indexing (including skipped/cached lights), shared shader/buffer ownership, and destruction paths.

Validation:

  • Local unit suite: 3,963 passing, 31 pending. Declaration generation/tests and debug/release ESM builds passed. Changed-file lint and git diff --check passed. Full local lint is blocked only by the absent optional webgpu package in test/webgpu-device.mjs; PR CI, including native WebGPU tests and lint, is green.
  • Real browser WebGPU: repeated scans with distinct counts in a single submit, including three recursion levels, matched CPU results. The base revision reproduced incorrect results while the PR fixed them.
  • Perspective and fisheye interval compaction with opposing frusta/cones in a single submit produced independent, correct candidate counts and IDs. The base revision incorrectly used the final cull parameters for both dispatches.
  • Portable radix sorting matched CPU results for direct/indirect dispatch, 4/8/16/32-bit keys, and sizes from 1 to 33,001 elements. Caller-provided initial values remained unchanged.
  • The new warning fired for repeat dispatch of one instance without submission, but not for distinct instances sharing a shader or dispatches separated by a submit. Standalone compute instances were released after destruction.
  • GPU-sort splat rendering exercised one/three directional lights, one-shot/cached shadows, and disabling/re-enabling a light at two camera/modifier poses. No unexpected warnings or GPU validation errors. Single-light output matched the independently repeated base captures exactly: 0 differing pixels out of 24,576.

Non-blocking coverage suggestion: the numerical multi-dispatch prefix-sum and distinct-frustum compaction cases would be useful permanent regression tests; they directly detect the underlying uniform-buffer aliasing, beyond checking warnings and dispatch indices.

This branch was successfully deployed

2 active deployments
Preview – engine — 75f34f61 Deployed Oct 7, 2026 by vercel[bot]
Preview – engine-api-docs — 75f34f61 Deployed Oct 7, 2026 by vercel[bot]
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.

1 participant