Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebGL] copy_texture_to_buffer broken for non-rgba & non-32-bit integer formats #3644

Open
Tracked by #3674
Wumpf opened this issue Apr 3, 2023 · 1 comment
Open
Tracked by #3674
Labels
api: gles Issues with GLES or WebGL area: validation Issues related to validation, diagnostics, and error handling type: bug Something isn't working

Comments

@Wumpf
Copy link
Member

Wumpf commented Apr 3, 2023

Unclear entirely who is broken - likely a mix of missing wgpu error messages and browser bugs:

According to the WebGL2 spec the constraints on gl.readPixels are mostly the same as in WebGL 1.
Which states:

Only two combinations of format and type are accepted. The first is format RGBA and type UNSIGNED_BYTE.

This is in contrast to Mozilla's documentation
which explicitly allows GL_RED for WebGL2 as well as integer variants.
More anecdotally, this SO answer also says it's not portable to read anything but RGBA.

Empirically on my side, I get read out zeros with no warning/error on firefox when trying to read back a wgpu::TextureFormat::R32Float.

Furthermore, this also seems to mean that all RGBA_INTEGER from describe_texture_format in conv.rs are incorrect for passing them to gl.readPixels on WebGL.
Turns out this part depends on the browser & format combination (haven't checked for the float case yet):

  • rgba32uint: Works in Firefox, Chrome & Safari
  • rgba8uint: Works in Chrome & Safari. On Firefox I get something, but it's not integers (haven't digged in)
    • I hit this in particular when trying to work around the above f32 issue, by doing a bitcast + bitshifts into Rgba8Uint

(all tested on a Mac, not unlikely to behave different on different OSes)


For anyone else hitting this: My current workaround is to copy the f32 question of desire into an RgbaF32, read that back and then skip through it. It seems this is, while crazy in overhead, the most portable way of doing things, but I still have to do more testing.

Wumpf added a commit to rerun-io/rerun that referenced this issue Apr 3, 2023
* can't read depth formats
* and all the other weird things, see gfx-rs/wgpu#3644
@teoxoy teoxoy added type: bug Something isn't working area: validation Issues related to validation, diagnostics, and error handling api: gles Issues with GLES or WebGL labels Apr 4, 2023
@teoxoy
Copy link
Member

teoxoy commented Apr 4, 2023

We should at least improve our validation to catch this and see if we could work around it, although the workarounds for this sort of thing are quite involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: gles Issues with GLES or WebGL area: validation Issues related to validation, diagnostics, and error handling type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants