Skip to content

3 channel formats #66

Closed
Closed

Description

@JiangYizhou

3 channel formats for WebGPU are not supported since they are often implemented as 4 channel formats in hardware. But it’s not convenient for developers to convert the RGB images to RGBA such as jpeg images only contains 3 channels. Developers may have to use a third party lib to convert format for them.

Questions:

  1. Will WebGPU support 3 channel formats or leave the conversion to developers?

  2. Analysis which formats are portable?

Activity

  1. kvark commented on Aug 2, 2018

    @kvark
    Contributor

    I believe this conversion is going to be covered by WebGPU implementation upon filling up the mapped memory. It's not able to use the given set of bytes directly anyway - in Vulkan and D3D12 you need to first allocate a CPU-visible chunk, map it, fill it up, and then copy from it into device local memory. So the copy from user-provided image data into this CPU-mapped memory needs to happen, and whoever does the copy (namely, the WebGPU implementation or the user) may as well convert from RGB to RGBA. The copy would have to take into account other constraints as well, like the row/slice alignment.

  2. Kangz commented on Aug 2, 2018

    @Kangz
    Contributor

    We definitely need to make an analysis of available texture formats in all three APIs at some point.

    The problem we have for 3-channel formats is that at least Metal doesn't support them. Emulation is hard because if, for example you do a copy from a WebGPUBuffer to a WebGPUTexture, it isn't clear what needs to happen. Either the texels in the buffer are packed and we need to use a compute shader to copy because Metal doesn't support unpacking in its copy operation. Or the texels need to have 4 channels which removes the usefulness of using a three channel format.

    That's why I think it is clear that WebGPU won't be able to support 3-channel formats.

  3. kainino0x commented on Aug 2, 2018

    @kainino0x
    Contributor

    I think the key question here is whether we will allow uploading 3-channel packed ArrayBuffer data into a 4-channel texture. As @kvark points out, if an application can decode directly into a cpu-mappable WebGPUBuffer, it seems okay to make the application do it.

  4. JiangYizhou commented on Aug 3, 2018

    @JiangYizhou
    Author

    Some formats are converted through shaders in angle, https://cs.chromium.org/chromium/src/third_party/angle/src/libANGLE/renderer/d3d/d3d11/Blit11.cpp?type=cs&g=0, though this looks inefficient.

    How about do the conversion on the cpu side like what stb does? https://github.com/nothings/stb/blob/e6afb9cbae4064da8c3e69af3ff5c4629579c1d2/stb_image.h
    (line 1519, stbi__convert_format). This is the same as making application do the convertion.

  5. Kangz commented on Aug 3, 2018

    @Kangz
    Contributor

    (You can click on a line number in github to have a direct link to it in your address bar.)

    In WebGL you pass texture data directly in glTexImage2D but in WebGPU you have to put the data in a buffer and then do a copy into the texture (this actually close to what the driver does in OpenGL). This means that in WebGPU there is no place where we can say "unpack this 3channel into 4channel for me please" because that would need to happen when putting data in the buffer. First buffers don't have a notion of format, and also we would need to be able to do the same when producing data for the buffer on the GPU, which would be very expensive.

  6. JiangYizhou commented on Aug 6, 2018

    @JiangYizhou
    Author

    Yes, this make sense!

  7. dmikis commented on Aug 6, 2018

    @dmikis

    ...but in WebGPU you have to put the data in a buffer and then do a copy into the texture...

    What about "opaque" image objects like Image and ImageBitmap?

  8. Kangz commented on Aug 6, 2018

    @Kangz
    Contributor

    We didn't discuss it in details but I assume there will be an API to fill a texture from an element directly, and that it will handle conversion to the texture format specified (including filling the alpha channel with 1.0).

  9. dmikis commented on Aug 6, 2018

    @dmikis

    I think there also may be a point in introducing an option (options) for createImageBitmap so it will do necessary conversion as it decodes an image, as it's done with premultiplies alpha and flipping for WebGL.

  10. warvstar commented on Oct 24, 2023

    @warvstar

    I believe the 3 channel (packed) RG11B10Ufloat format is supported on every platform supported by WebGPU as a writable storage texture. It would be great if WebGPU and wgsl could utilize it.
    The Unreal Engine uses the RG11B10Ufloat format for volumetric lightmaps among other places, and changing that to RGBA16F will of course double the memory, so not ideal if it can be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions