Skip to content

Firefox error in WebGL backend when using queue::write_texture with a 2D texture #8668

@tgecho

Description

@tgecho

Description
I'm writing to a 2D texture with Queue::write_texture. In FireFox, when running with the GL backend I get the following error the SECOND time I try to write a texture (not necessarily the same one): WebGL warning: texSubImage: height > UNPACK_IMAGE_HEIGHT. and the write doesn't seem to happen.

Repro steps
Working on extracting an MRE

Expected vs observed behavior
According to the section on GL_UNPACK_IMAGE_HEIGHT in https://docs.gl/gl3/glPixelStore

If greater than 0, GL_UNPACK_IMAGE_HEIGHT defines the number of pixels in an image of a three-dimensional texture volume.

In https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-hal/src/gles/queue.rs#L748-L755 we set UNPACK_IMAGE_HEIGHT based on the passed in rows_per_image, defaulting to 0 if None. This seems correct AFAICT, and I am sending None in my wgpu::TexelCopyBufferLayout.

However, in Queue::write_texture we calculate a fallback rows_per_image using the image size. https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-core/src/device/queue.rs#L861

Other browsers don't seem to care, so I don't know if this is arguably overeager validation on Firefox's side (which should just ignore it when texSubImage2D is called), but 0 does seem like the appropriate value to use here.

I've locally patched wgpu by adding this to Queue::write_texture (leaving all the other places rows_per_image is used intact). It seems to work and not regress other browsers or the WebGPU backend. I'm happy to PR it, but I'm not sure if it's strictly correct or could break something else.

let copy_rows_per_image =
    if array_layer_count > 1 || dst.desc.dimension == wgt::TextureDimension::D3 {
        Some(rows_per_image)
    } else {
        None
    };

Platform
Firefox 146, macOS 26.1, M4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions