You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Will WebGPU support 3 channel formats or leave the conversion to developers?
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.
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.
Reacted by Dzmitry Malyshau, Yizhou Jiang, MK and Samuel Hurel
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.
(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.
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).
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.
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.
Activity
kvark commentedon Aug 2, 2018
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.
Kangz commentedon Aug 2, 2018
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.
kainino0x commentedon Aug 2, 2018
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.
JiangYizhou commentedon Aug 3, 2018
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.
Kangz commentedon Aug 3, 2018
(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
glTexImage2Dbut 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.JiangYizhou commentedon Aug 6, 2018
Yes, this make sense!
dmikis commentedon Aug 6, 2018
What about "opaque" image objects like Image and ImageBitmap?
Kangz commentedon Aug 6, 2018
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).
dmikis commentedon Aug 6, 2018
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.
warvstar commentedon Oct 24, 2023
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.