Skip to content

Enable GPU occlusion culling on WebGPU - #26372

Open
alexander-busarov wants to merge 4 commits into
bevyengine:mainfrom
motif-io:feature/gpu-driven-on-webgpu
Open

alexander-busarov wants to merge 4 commits into
bevyengine:mainfrom
motif-io:feature/gpu-driven-on-webgpu

Conversation

@alexander-busarov

@alexander-busarov alexander-busarov commented Oct 30, 2026 •

Copy link
Copy Markdown

Objective

GPU culling requires immediates and twelve storage textures per shader stage, preventing WebGPU devices without these capabilities from using occlusion culling.

Solution

  • Add a uniform-buffer fallback for scalar parameters in mesh preprocessing (late-preprocess indirect-parameter offset) and depth downsampling (mip count) when immediates are unavailable.
  • Add a depth-pyramid fallback that generates one output mip per dispatch on devices with fewer than twelve storage textures per shader stage.
  • Replace infinite bounds in the mesh-preprocessing shader with finite values, since WebGPU shader validation rejects the non-finite constant expressions.
  • Update GPU culling capability checks to account for these fallbacks.

Testing

  • cargo check -p bevy_pbr
  • Compiled and validated 13 shader variants using WESL and Naga, including uniform fallbacks with immediate support disabled.
  • rustfmt and git diff --check passed.
  • Tested in browsers with WebGPU and confirmed the changes work.

AI Disclosure

AI assisted with porting the existing changes to current upstream, adapting the shaders to WESL and the depth-texture API, and preparing and running shader validation checks.

# Objective

GPU culling requires immediates and twelve storage textures per shader
stage, preventing WebGPU devices without these capabilities from using
occlusion culling.

## Solution

- Add a uniform-buffer fallback for scalar parameters in mesh
  preprocessing (late-preprocess indirect-parameter offset) and depth
  downsampling (mip count) when immediates are unavailable.
- Add a depth-pyramid fallback that generates one output mip per
  dispatch on devices with fewer than twelve storage textures per
  shader stage.
- Replace infinite bounds in the mesh-preprocessing shader with finite
  values, since WebGPU shader validation rejects the non-finite
  constant expressions.
- Update GPU culling capability checks to account for these fallbacks.

## Testing

- cargo check -p bevy_pbr
- Compiled and validated 13 shader variants using WESL and Naga,
  including uniform fallbacks with immediate support disabled.
- rustfmt and git diff --check passed.
- Tested in browsers with WebGPU and confirmed the changes work.

## AI Disclosure

AI assisted with porting the existing changes to current upstream,
adapting the shaders to WESL and the depth-texture API, and preparing
and running shader validation checks.
@github-actions

Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

/// parameter building passes.
#[derive(Resource)]
pub struct PreprocessPipelines {
u32_immediates: TinyU32Immediates,

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.

It's not clear to me what this is supposed to be. Could you add some docs?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a doc comment explaining the parameter’s purpose and how the uniform-buffer fallback works

@IceSentry IceSentry added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 4, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Nov 4, 2026
@kfc35 kfc35 added the AI-Assisted Discloses the use of AI in any way label Nov 5, 2026

This branch has not been deployed

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

Labels

A-Rendering Drawing game state to the screen AI-Assisted Discloses the use of AI in any way C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants