wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Inconsistent rendering between Web and Native on 0.19

Open sotrh opened this issue 1 year ago • 3 comments

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: image

Web: image

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-lighting to see the native demo shown above
  • To see the web version run yarn dev then 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)

sotrh avatar Apr 01 '24 04:04 sotrh

… 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

kpreid avatar Apr 01 '24 19:04 kpreid

Is there any reason why the code works as expected on native and WebGL?

sotrh avatar Apr 22 '24 16:04 sotrh

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.

grovesNL avatar Apr 22 '24 16:04 grovesNL