Inconsistent rendering between Web and Native on 0.19
Description I'm working on updating my tutorial to 0.19 and I got the native code working, but when I test it out on web SRGB surface textures aren't available and certain examples no longer render as expected.
Native:
Web:
Repro steps
- The changes are on a separate branch from the main tutorial, so if you have the repo locally you'll have to checkout the 0.19 branch.
- Once that's done you can run
cargo r --bin tutorial10-lightingto see the native demo shown above - To see the web version run
yarn devthen navigate to localhost:8080 - Navigate to the lighting demo and click on the "Try Tutorial10_lighting!" button at the bottom of the page. (note: the code is using WebGPU by default so you'll need a browser that supports WebGPU.
Expected vs observed behavior Running the code on web should behave the same as on native, but the web version isn't working.
Extra materials I have some screenshots above
Platform
- PopOS 22.04 LTS
- cargo 1.72.0 (103a7ff2e 2023-08-15)
- rustc 1.72.0 (5680fa18f 2023-08-23)
- Firefox Nightly 126.0a1 (2024-03-31) (64-bit)
… when I test it out on web SRGB surface textures aren't available …
You need to use the srgb format as a view format:
NOTE: Canvas configuration cannot use srgb formats like "bgra8unorm-srgb". Instead, use the non-srgb equivalent ("bgra8unorm"), specify the srgb format in the viewFormats, and use createView() to create a view with an srgb format.
— https://www.w3.org/TR/webgpu/#canvas-configuration
Is there any reason why the code works as expected on native and WebGL?
I believe we allow sRGB surfaces on any GL device through emulation (https://github.com/gfx-rs/wgpu/blob/v0.19/wgpu-hal/src/gles/shaders/srgb_present.frag). That was probably before that language existed in the spec though, so maybe we should reconsider it for WebGL for consistency.