Repository navigation
Description
Background
(If you already understand color theory, please feel free to skip this section.)
Let's discuss wide color. This is a term that probably requires some explanation.
For the sake of simplicity, let's pretend that sRGB is a 2-dimensional color space - just so we can visualize it a bit easier. Here's our visualization of all the colors in sRGB:
Note how bottom left is black, top right is white, the Y axis is increasing red, and the X axis is increasing blue. The origin is at the bottom left of the image.
The "gamut" of sRGB represents the set of colors present in sRGB. Here's a visualization of the boundary of the gamut:
Okay. The goal here is to be able to represent colors more highly saturated than possible in sRGB. Here's a visualization of the colors we want to represent (also showing the gamut of sRGB as a reference):
This is wide color. (It looks "wide" if you tilt your head to the side a bit...) We are essentially defining a new gamut, which is bigger than sRGB's gamut. All the colors within sRGB are present within our new "wide" color space, and then some.
Note that the black point and the white point are the same - we haven't changed what black means, and we aren't supporting any brighter whites; we're only trying to represent more saturated colors: bluer blues, and redder reds.
(Aside: This is different than HDR, which would have a picture like this:)
(The same colors are present in HDR, but the values can go (much) beyond 1.0.)
Anyway, back to wide color. Let's imagine that our sRGB colors are represented with only 2 bits per channel. That would mean only these specific dots are representable:
Okay, so what do we do for wide color? It would be tempting to just move the dots around to cover the new larger gamut, like this:
... But that's bad. The new gamut is bigger than the old gamut, so if we use the same number of dots, they get farther apart. This is bad because the distance between the dots is an intentional result of the biologic makeup of human eyes. Human eyes only have so much fidelity to distinguish adjacent colors, so there is an upper bound on how far adjacent representable colors can be in our color system. If the dots are too far apart, there become colors which are discernible by humans which are not representable in our system; whereas if the dots are too close together, you're just wasting information/bandwidth.
Okay, so we need more dots. So we want our system to look like this, instead:
The fact that there are more dots than there were before is called "deep color."
Okay, so now we have to map values to those points. It is tempting to just map the entire gamut from 0 to 1, like this:
But there's another way possible to do it, like this:
This second way is a bit less intuitive, but the benefit is that compositing with sRGB content becomes trivial. If you use the first way, the compositor has to find a common color space, then map each color into it, then blend. However, if you use the second way instead, the color system is backwards compatible with sRGB, so you don't have to do any colorspace conversion to blend. Just blend on the values you've got.
Motivation
We already have FP32 and FP16 pixel formats. However, the downside to those is that, to hold an RGB color, you'd need 64 (or even 128) bits to do so. This is compared to the 32 bits that authors use today to hold RGB8 colors.
But doubling the memory use is a real shame, because the wide color gamut is only a little bit bigger than the sRGB gamut. It's nowhere near twice as big.
FP16 makes total sense for HDR rendering, where the new gamut really is multiple times as big as the sRGB gamut. But for wide color, it's a big waste.
This is particularly important because, in order for wide color to be useful during rendering, the materials in the world need to be authored in wide color too. This means that, not just the render targets would need to support wide color, but all texture assets would need it too. So we're not talking about a potential doubling of size of just a few resources; instead, we're talking about a doubling of size of potentially every texture. Doubling video memory use would probably be a dealbreaker for many content creators.
Prior Art
Metal has a family of pixel formats that match the behavior described above:
- They are 10 bits per channel, meaning you get more representable values, therefore preserving the max distance between adjacent representable values, and avoiding banding
- Backwards compatible. If you sample these new pixel formats and you get a value of (1, 0, 0), that means the same thing as if you had sampled a regular RGB texture and gotten the same value
- The range of each channel is between -0.752941 to 1.25098. This is good because it goes beyond 0-1 by just enough but not a huge amount
- The non-alpha formats are still 32-bits-per-texel, just like RGB8. The extra bits necessary for the extended range are taken from the alpha channel.
The specific texture formats are:
MTLPixelFormatBGRA10_XR64-bit, but has alpha channelMTLPixelFormatBGRA10_XR_sRGB64-bit, but has alpha channel, with gamma supportMTLPixelFormatBGR10_XR32-bit, no alpha channelMTLPixelFormatBGR10_XR_sRGB32-bit, no alpha channel, with gamma support
These Metal formats can be used for anything (including blitting) on Apple Silicon devices, but are not supported on Intel-based Macs. When blitting, they have a particular bit pattern, described in the docs above.
DirectX has just a single format like this: DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM. The docs say:
A four-component, 32-bit 2.8-biased fixed-point format that supports 10 bits for each color channel and 2-bit alpha.
I didn't test this, but this would seem to indicate a range from -2 to +2.
Also, it looks like support is behind a hardware capability bit somewhere, but the docs aren't very clear about this. It doesn't appear on the "Required DXGI Formats" documentation page. I couldn't find any documentation about which operations are supported on textures of this format.
Challenges
The XR formats do not have the same behavior in Metal and D3D12:
- The Metal formats are BGR, not RGB
- The 32-bit Metal formats don't have an alpha channel, but the D3D12 one does
- The bit pattern for blitting is almost certainly different
- D3D12 doesn't have sRGB variants (for gamma)
Possible paths forward
- (The null path) Throw up our hands and admit defeat. Tell authors that they need to double their memory use if they want wide color.
- Expose multiple distinct optional features, with the Metal formats behind a different feature than the D3D12 format.
- I think this would violate the "Requirements for Additional Functionality" document
- Invent our own meta format which turns into
DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORMon D3D12 andMTLPixelFormatBGR10_XR(the closest option) on Metal. Restrict the use of these textures to just situations where the differences are unobservable.- This is probably too restrictive to be useful; I expect the only operation they would have in common would be usable as a render target
- Invent our own meta format (like (3) above), but try to claw back some of that functionality by polyfilling it. E.g. implement blits via a compute shader.
- Invent our own meta format (like (3) above), but intentionally give up on the goal of portability. Spec the new meta format as "it behaves either like
DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORMor likeMTLPixelFormatBGR10_XR." Tell authors to write their code in a way that works for both (somehow).
There is a related question about how to actually show wide colors in canvas, but that isn't an issue for the WebGPU standardization group.










Activity
kainino0x commentedon May 12, 2023
I think your option 1, which only goes from 0 to 1, is rgb10a2unorm, which we already have (unfortunately there's no srgb version of it though).
About the D3D format's usages, it can't be sampled or used as a render target. It's actually just rgb10a2, but with a bit of metadata about how it should be used for scan-out.
In WebGPU we could express this using
configurewithformat: 'rgb10a2'andcolorSpaceset to a new color space that encodes the bias and scale of this format.I think it would also be theoretically possible to make a new format that's bound in a special way that lets us inject conversions from/to the format when sampled/written. But this adds some complexities, for example it wouldn't be blendable.
The encoding appears to be exactly the same as Metal except possibly with one extra value at the end.
https://learn.microsoft.com/en-us/windows-hardware/drivers/display/xr-bias-to-float-conversion-rules
[1] I'm not sure whether this is actually allowed, the d3d12 docs just don't seem to say it's not.
[2] This is a guess based on the 1.25098 value in the Metal docs. That's exactly 0b1111111110 with the same bias and scale factor that D3D12 use.
(510 = 255 * 2)
litherum commentedon May 12, 2023
nit: rgb10a2unorm is deep color, but not wide color. It can't represent values outside of 0-1. If an author wants wide color, they can’t use rgb10a2unorm (unless they do the scaling and biasing themselves in software) but instead would have to use float16.
kainino0x commentedon May 15, 2023
Yes, but what I discovered was that D3D12 doesn't have a format that's wide-color throughout the pipeline. They have this format that does wide-color for scanout but you have to reinterpret it from rgb10a2unorm (non-wide-color) and therefore must do the scaling and biasing in software to use it, AFAICT.
kainino0x commentedon May 15, 2023
(And that we could achieve what D3D12 has with a new colorSpace option.)
litherum commentedon May 17, 2023
OK. We're going to pursue this at the canvas level, then. We're going to see if it's possible for the canvas to be backed by one of:
Closing this issue, because this issue is WebGPU-specific, and we're going to migrate to canvas instead.
kainino0x commentedon May 18, 2023
Each of the canvas context types specifies its pixel formats independently (ours is in GPUCanvasConfiguration, and we have float16 already) so I think this should be left open.
kainino0x commentedon Jun 6, 2023
Editors discussed today. We think there are two possible designs within what's possible in D3D12:
Open questions:
litherum commentedon Jun 7, 2023
Metal has MTLPixelFormatRGB10A2Unorm
kainino0x commentedon Jun 7, 2023
Unsure which of the 2 things above this was a reply to:
This was referring to the XR formats specifically.
This was referring to D3D12/Vulkan. In bits 0..31 order:
Vulkan VK_FORMAT_A2B10G10R10_UNORM_PACK32: RGBA
kdashg commentedon Jun 8, 2023
GPU Web 2023-06-07/08 (Pacific time)
aleino-nv commentedon Jun 8, 2023
@litherum Coordinate system question:
In this picture, would e.g. the value (-0.2, 1.2) be the value you got in the pixel shader when sampling a completely red wide color texture?
litherum commentedon Jun 14, 2023
When you say “completely red” I’m assuming you mean “the most saturated red that wide color can represent”
If so, then the answer is yes.
Another way to describe this is: imagine there was an oracle that could observe the contents of memory. Imagine we had a texture that was using one of these XR formats. Imagine the oracle observes the bits in memory for a particular texel, and sees that they are 0000000000b. If you sampled the texture from a shader at this particular location, the float value you would receive would be -0.752941. Likewise, imagine the oracle observes that another particular texel contains the bits 1111111111b in memory. If you then sampled that location from a shader, the float result you would receive would be 1.25098.
The idea is that if your rendering destination is tagged as being in the “extended sRGB” color space, then the values in these XR formats cover the gamut of display-p3 (since they go just a bit below zero and a bit above 1). That’s the image you linked to.
If, however, you used the non-XR 10A2 formats (and kept your rendering destination tagged as “extended sRGB”) then that would cover just the sRGB gamut - albeit with more representable values within that gamut. This is because, with the 10A2 formats, if the oracle observes a bit pattern of 1111111111b, then it means 1.0, and extended sRGB’s 1.0 position is exactly the boundary of the sRGB gamut. The whole point of “extended sRGB” is that it’s just like sRGB, but has infinite gamut.
The approach we’re currently pursuing is to not tag rendering destinations as extended sRGB, and instead just tag them as display-p3. Doing it this way causes a meaning of 1.0 to be mapped to p3’s gamut, which means the existing 10A2 formats will work great. The downside here is that the window server is going to have to do color matching if there is other content on the screen that isn’t tagged as being in the P3 color space (which will essentially always be the case). The benefit of the XR formats is that, because it’s backwards-compatible with sRGB, no color conversion has to be done to blend windows / layers together, even if some content on the screen is wide color and some is normal sRGB.
aleino-nv commentedon Jun 14, 2023
Thanks! Yeah, I meant the "wide color red" in the very corner of the wide color gamut.
That would then mean that the transform from texture colors to shader colors is non-diagonal (i.e. not just "axis-aligned scaling"). I believe that's not the case for e.g. any of the Vulkan RGB formats.
Also, I assume on most hardware you'd have to do some math in the shader after the texture fetch, to implement this transformation.
That would be a downside for the sRGB-compatible option corresponding to this picture.
Question on how the compatibility with sRGB would work.
Commenting on the same picture again, what would the grid of sample points look like? Would it be aligned with the green sRGB square, or with the "tilted" wide-color gamut? (I would attach a picture but I can't figure out how to do it.)
RafaelCintron commentedon Jun 15, 2023
On Windows, while you can instantiate textures with XR formats, you can't sample from them, render to them, or make a swap chains in the format. Conformance test coverage is limited. We should avoid using them.
Since that format was introduced, color management on Windows has evolved in the direction of separating out the storage (bits per pixel, float vs unorm, etc) from the color space. You provide these to Windows via separate APIs. The developer is responsible for ensuring that colors are stored in the color space you declare.
For instance, you can use DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 to get 2020 primaries with 2.2 gamma. It's different from the space specified by XR_BIAS but effectively gives you wide gamut 10bpc, non-HDR content.
litherum commentedon Jun 16, 2023
This happens in hardware for us. The Metal feature set tables indicate that these formats are only present on Apple devices - not Intel-based Macs. Indeed; it must happen in hardware, because the shader compiler doesn’t know at compile time which format is being used. It’s possible to run the same shader twice, once with an XR format, and one with a non-XR format, without recompiling.
If we wanted to polyfill these formats on devices which don’t support them in hardware, we’d either have to require the shader compiler to know which resources will be set to XR textures so it can emit the extra instructions (this is what we did with BGR vs RGB storage textures) OR it would have to unconditionally emit the extra instructions at every sample() call but also pass in some side-channel data at setBindGroup() time that has the effect of making the extra instructions do nothing when bound to non-XR formats.
But I’m not even sure that we’d want to polyfill this in the first place. It would already be an optional feature, so I think it would make sense to just say “the optional feature would only be present on devices which have support for it.”
They’d be axis-aligned (parallel to the green box) but the grid of points would extend a little bit beyond the edges of the green box. The colored area would be entirely contained within the space the points occupy.
There are representable points in the XR formats that are outside both the sRGB and the P3 wide color gamut. Those get clipped or otherwise tonemapped.
Well that makes it pretty clear, doesn’t it.
Understanding that, just for my own curiosity: if a Windows app does render to one of these formats, how does the window server composite that window with all the other windows, if the format can’t be sampled from?
RafaelCintron commentedon Jun 16, 2023
@litherum developers can't make a swap chain with these formats because there is no support in the Desktop Window Manager (DWM) for them. Without support in the DWM, you can't use them as the contents of a window.
You also can't make a render target view (RTV) of this format so you can't draw to textures with it either.
kainino0x commentedon Jun 16, 2023
This may not be important anymore if we're not going to use these D3D formats, but if they can't be used in DWM then what does "display scan-out" support mean you can do?
In any case, even if we shouldn't use these on Windows, I think both options 1/2 above (#4108 (comment)) are still viable, though 2 becomes an Apple-specific optimization sadly.
Even if we give up on the idea of D3D support, I think it still doesn't make sense to do what I'll call option 3 (just so it has a name):
Given the state of things I'd like to propose we do option 1 for now. It's very straightforward, IMO we want it anyway, and it doesn't prevent us from doing 2 or 3 later on.
kainino0x commentedon Jun 16, 2023
As a side note, I somehow misread something in the Vulkan spec. It does have both RGB10A2 (
VK_FORMAT_A2B10G10R10_UNORM_PACK32) and BGR10A2 (VK_FORMAT_A2R10G10B10_UNORM_PACK32) formats.litherum commentedon Jun 17, 2023
(In case I wasn’t clear, we do not want to make any Apple-specific optional features; I spent quite a while in the group making sure there would be no vendor-specific optional features.)
We think the best way to proceed, given the discussion in this thread, is not to standardize any XR formats, but instead to add 10A2 backing store support to canvas.
For WebGPU, the only change would be adding the 10A2 formats to the supported context formats set.
litherum commentedon Jun 17, 2023
(Also, @RafaelCintron, +1 to Kai’s question about what the D3D formats are meant for. What is their use case?)
litherum commentedon Jun 28, 2023
Resolution:
Follow-up items:
Add rgb10a2unorm as a canvas format
RafaelCintron commentedon Jul 3, 2023
@kainino0x For our WebGPU purposes, we should consider the XR formats as unsupported on Windows.