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
{{ message }}
Repository navigation
investigation: texture load channel values for channels not in the texel format #1115
An r8unorm image has a red channel only. But the texture load function always returns a vec4<f32>. What are the values for the green, blue, and alpha channels?
As near as I can tell, no platform API describes the values from the extra channels in any detail. So "unspecified value" is the baseline.
With extra work in shader code, we can sanitize the result, as long as we know which components need to be sanitized. At the very least we need to know which channels are unspecified.
(For example, if blue and alpha are undefined, we can do a shuffle with a zero-vector, or alternately a type constructor that took a swizzle of the known values.)
My expectation was that the texture unit would handle this in a defined way, e.g. filling up with "0, 0, 0, 1" for floating-point textures. If it's truly undefined, we are lucky to have this way of working around by providing the format data externally, and doing the shader modifications.
I wasn't able to find anything in the specifications for Vulkan, D3D11 and OpenGL ES either. However Vulkan and D3D12 allow controlling the texture view "swizzling" with values of 0 and 1 for channels so we could force things to be (0, 0, 0, 1). Metal has that too, but it's only available on more recent version of iOS and macOS.
I updated Dawn's TextureFormatTests and it seem the default value for non-existent components if (0, 0, 0, 1) on all APIs, for all formats.
@Kangz good point about the swizzle! It's certainly a better solution than patching the shader. However, D3D12 doesn't have swizzling for UAVs, so some shader patching will still be needed.
Would be great to get some confirmation from D3D12 (@damyanp, @RafaelCintron ) and Metal (@litherum ) about what the rules are.
Note that the Swizzle feature in Metal is macOS 10.15+ and iOS 13.0+ , which is higher the baseline we want to support.
From D3D spec section "Defaults for Missing Components":
The default value for missing components in an Element format is "0" for any component except A, which gets "1". The way "1" appears in the Shader depends on the Element format, in that it takes the specified data interpretation of the first typed component that is actually present in the format (starting from the left in RGBA order). If this interpretation is UNORM or FLOAT, then 1.0f is used for missing components. If the interpretation is SINT or UINT, then 0x1 is used.
For example, when the format DXGI_FORMAT_R24_UNORM_X8_TYPELESS is read into a Shader, the values for G and B are 0, and A is 1.0f. For DXGI_FORMAT_R16G16_UINT, the B gets 0 and A gets 0x00000001. DXGI_FORMAT_R16_SINT provides 0 for G and B, and 0x00000001 for A.
Activity
kvark commentedon Sep 29, 2020
My expectation was that the texture unit would handle this in a defined way, e.g. filling up with "0, 0, 0, 1" for floating-point textures. If it's truly undefined, we are lucky to have this way of working around by providing the format data externally, and doing the shader modifications.
Kangz commentedon Sep 29, 2020
I wasn't able to find anything in the specifications for Vulkan, D3D11 and OpenGL ES either. However Vulkan and D3D12 allow controlling the texture view "swizzling" with values of 0 and 1 for channels so we could force things to be
(0, 0, 0, 1). Metal has that too, but it's only available on more recent version of iOS and macOS.I updated Dawn's TextureFormatTests and it seem the default value for non-existent components if
(0, 0, 0, 1)on all APIs, for all formats.kvark commentedon Sep 29, 2020
@Kangz good point about the swizzle! It's certainly a better solution than patching the shader. However, D3D12 doesn't have swizzling for UAVs, so some shader patching will still be needed.
dneto0 commentedon Sep 29, 2020
Ah, I found that Vulkan is very prescriptive on this point unspecified colour channels go to 0, and alpha goes to 1.
https://www.khronos.org/registry/vulkan/specs/1.0/html/chap16.html#textures-conversion-to-rgba
dneto0 commentedon Sep 29, 2020
Looks like Metal has a similar swizzle feature.
See https://developer.apple.com/documentation/metal/mtltextureswizzle and https://developer.apple.com/documentation/metal/mtltextureswizzlechannels
dneto0 commentedon Sep 29, 2020
I'll update #1112 to say that green, blue default to 0, and alpha to 1.
kvark commentedon Sep 29, 2020
Would be great to get some confirmation from D3D12 (@damyanp, @RafaelCintron ) and Metal (@litherum ) about what the rules are.
Note that the Swizzle feature in Metal is macOS 10.15+ and iOS 13.0+ , which is higher the baseline we want to support.
Specify defined shader values for missing texel format channels
Specify defined shader values for missing texel format channels
damyanp commentedon Oct 5, 2020
From D3D spec section "Defaults for Missing Components":
Describe texel formats
Describe texel formats
Describe texel formats
describe texel formats (for storage texture types) (#1112)