ContrastAdaptiveSharpening fails on WebGL2: its 4-byte uniform isn't padded to 16 bytes

Open Beginner friendly
#26,641 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, wasm

Research direction

Start with CasUniform in crates/bevy_anti_alias/src/contrast_adaptive_sharpening/mod.rs and the CASUniforms struct in robust_contrast_adaptive_sharpening.wesl. Copy the WebGL2 padding pattern used by SkyboxUniforms (the _webgl2_padding_*b fields behind the same cfg), and mirror it in the shader struct. Done when the CAS pipeline builds on a wasm32 WebGL2 build without the 16-byte alignment validation error.

Written by the indexing model from the issue text.

Description

Bevy version and features

  • 0.20.1. CasUniform is unchanged on main.
  • default-features = false, features 2d, 3d, ui (which pull in webgl2), built for wasm32-unknown-unknown.

[Optional] Relevant system information

  • Rust 1.97.1, Chromium 156 on Linux.
AdapterInfo { name: "ANGLE (AMD, AMD Radeon RX 6650 XT (radeonsi navi23 ACO), OpenGL ES 3.2)", vendor: 4098, device: 0, device_type: Other, driver_info: "WebGL 2.0 (OpenGL ES 3.0 Chromium)", backend: Gl, .. }

What you did

Added ContrastAdaptiveSharpening::default() to a camera in a WebGL2 build.

What went wrong

Expected: the camera's output is sharpened, as it is natively.

Actual: creating the CAS pipeline fails validation, and Bevy quits:

Caught rendering error: Validation Error

Caused by:
  In Device::create_render_pipeline, label = 'contrast_adaptive_sharpening'
    In the provided shader, the type given for group 0 binding 2 has a size of 4. As the device does not support `DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED`, the type must have a size that is a multiple of 16 bytes.

Caught rendering error: Validation Error
Caused by:
  In a CommandEncoder ...
    In a set_pipeline command
      RenderPipeline with 'contrast_adaptive_sharpening' label is invalid

Quitting the application due to Validation RenderError

Additional information

CasUniform (crates/bevy_anti_alias/src/contrast_adaptive_sharpening/mod.rs) and CASUniforms in robust_contrast_adaptive_sharpening.wesl hold a single f32. Other uniforms are padded for WebGL2 behind cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu"))); SkyboxUniforms is one example, with its _webgl2_padding_*b fields. The same padding here, mirrored in the shader struct, should fix it.

Workaround: we run the same RCAS math in our own Material2d, with a vec4 uniform.

Dominant language
Rust
Stars
49.8k
Forks
5.1k
Avg merge
3d 4h
Merged PRs (30d)
136

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.