Skip to content

Commit 84dd9a0

Browse files
authored
Specify copyTextureToTexture format compatibility (#2329)
* Specify copyTextureToTexture format compatibility Specify that copyTextureToTexture is only valid between equal formats, or if the formats diffen only in whether they have `-srgb`. Clean up a few bits of text regarding depth/stencil formats. Add the optional-feature depth/stencil formats to the format table. Fixes #2322 Fixes #1464 * subsection titles, typo
1 parent e7a48ff commit 84dd9a0

File tree

1 file changed

+55
-29
lines changed

1 file changed

+55
-29
lines changed

spec/index.bs

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,12 @@ enum GPUTextureFormat {
28192819
"depth24plus-stencil8",
28202820
"depth32float",
28212821

2822+
// "depth24unorm-stencil8" feature
2823+
"depth24unorm-stencil8",
2824+
2825+
// "depth32float-stencil8" feature
2826+
"depth32float-stencil8",
2827+
28222828
// BC compressed formats usable if "texture-compression-bc" is both
28232829
// supported by the device/user agent and enabled in requestDevice.
28242830
"bc1-rgba-unorm",
@@ -2879,29 +2885,24 @@ enum GPUTextureFormat {
28792885
"astc-12x10-unorm-srgb",
28802886
"astc-12x12-unorm",
28812887
"astc-12x12-unorm-srgb",
2882-
2883-
// "depth24unorm-stencil8" feature
2884-
"depth24unorm-stencil8",
2885-
2886-
// "depth32float-stencil8" feature
2887-
"depth32float-stencil8",
28882888
};
28892889
</script>
28902890

28912891
The depth aspect of the {{GPUTextureFormat/"depth24plus"}}) and {{GPUTextureFormat/"depth24plus-stencil8"}})
2892-
formats may be implemented as either a 24-bit unsigned normalized value ("depth24unorm")
2893-
or a 32-bit IEEE 754 floating point value ("depth32float").
2892+
formats may be implemented as either a 24-bit unsigned normalized value (like "depth24unorm" in {{GPUTextureFormat/"depth24unorm-stencil8"}})
2893+
or a 32-bit IEEE 754 floating point value (like {{GPUTextureFormat/"depth32float"}}).
28942894

2895-
Issue: add something on GPUAdapter(?) that gives an estimate of the bytes per texel of "stencil8"
2895+
Issue: add something on GPUAdapter(?) that gives an estimate of the bytes per texel of
2896+
{{GPUTextureFormat/"stencil8"}}, {{GPUTextureFormat/"depth24plus-stencil8"}}, and {{GPUTextureFormat/"depth32float-stencil8"}}.
28962897

28972898
The {{GPUTextureFormat/stencil8}} format may be implemented as
28982899
either a real "stencil8", or "depth24stencil8", where the depth aspect is
28992900
hidden and inaccessible.
29002901

29012902
Note:
2902-
While the precision of depth32float is strictly higher than the precision of
2903-
depth24unorm for all values in the representable range (0.0 to 1.0),
2904-
note that the set of representable values is not exactly the same:
2903+
While the precision of depth32float channels is strictly higher than the precision of
2904+
depth24unorm channels for all values in the representable range (0.0 to 1.0),
2905+
note that the set of representable values is not an exact superset:
29052906
for depth24unorm, 1 ULP has a constant value of 1 / (2<sup>24</sup> &minus; 1);
29062907
for depth32float, 1 ULP has a variable value no greater than 1 / (2<sup>24</sup>).
29072908

@@ -6220,8 +6221,8 @@ Issue: convert "Valid Texture Copy Range" into an algorithm with parameters, sim
62206221
- [$validating GPUImageCopyTexture$](|destination|, |copySize|) returns `true`.
62216222
- |dstTextureDesc|.{{GPUTextureDescriptor/usage}} contains {{GPUTextureUsage/COPY_DST}}.
62226223
- |srcTextureDesc|.{{GPUTextureDescriptor/sampleCount}} is equal to |dstTextureDesc|.{{GPUTextureDescriptor/sampleCount}}.
6223-
- If |srcTextureDesc|.{{GPUTextureDescriptor/format}} is not equal to |dstTextureDesc|.{{GPUTextureDescriptor/format}}:
6224-
- the [=copies of depth and stencil textures|copy configuration is allowed=]
6224+
- |srcTextureDesc|.{{GPUTextureDescriptor/format}} and |dstTextureDesc|.{{GPUTextureDescriptor/format}}
6225+
must be [=copy-compatible=].
62256226
- If |srcTextureDesc|.{{GPUTextureDescriptor/format}} is a depth-stencil format:
62266227
- |source|.{{GPUImageCopyTexture/aspect}} and |destination|.{{GPUImageCopyTexture/aspect}}
62276228
must both refer to all aspects of |srcTextureDesc|.{{GPUTextureDescriptor/format}}
@@ -9969,7 +9970,6 @@ None of the depth formats can be filtered.
99699970
<th>Bytes per texel
99709971
<th>Aspect
99719972
<th>{{GPUTextureSampleType}}
9972-
<th>Returned in shaders as...
99739973
<th>Copy aspect from Buffer
99749974
<th>Copy aspect into Buffer
99759975
</thead>
@@ -9978,65 +9978,91 @@ None of the depth formats can be filtered.
99789978
<td>1 &minus; 4
99799979
<td>stencil
99809980
<td>{{GPUTextureSampleType/"uint"}}
9981-
<td>`vec4<u32>(S, X, X, X)`
99829981
<td colspan=2>&checkmark;
99839982
<tr>
99849983
<td>{{GPUTextureFormat/depth16unorm}}
99859984
<td>2
99869985
<td>depth
99879986
<td>{{GPUTextureSampleType/"depth"}}
9988-
<td>`f32(D)`
99899987
<td colspan=2>&checkmark;
99909988
<tr>
99919989
<td>{{GPUTextureFormat/depth24plus}}
99929990
<td>4
99939991
<td>depth
99949992
<td>{{GPUTextureSampleType/"depth"}}
9995-
<td>`f32(D)`
99969993
<td colspan=2>&cross;
99979994
<tr>
99989995
<td rowspan=2 style='white-space:nowrap'>{{GPUTextureFormat/depth24plus-stencil8}}
99999996
<td rowspan=2>4 &minus; 8
100009997
<td>depth
100019998
<td>{{GPUTextureSampleType/"depth"}}
10002-
<td>`f32(D)`
100039999
<td colspan=2>&cross;
1000410000
<tr>
1000510001
<td>stencil
1000610002
<td>{{GPUTextureSampleType/"uint"}}
10007-
<td>`vec4<u32>(S, X, X, X)`
1000810003
<td colspan=2>&checkmark;
1000910004
<tr>
1001010005
<td>{{GPUTextureFormat/depth32float}}
1001110006
<td>4
1001210007
<td>depth
1001310008
<td>{{GPUTextureSampleType/"depth"}}
10014-
<td>`f32(D)`
1001510009
<td colspan=1>&cross;
1001610010
<td colspan=1>&checkmark;
10011+
<tr>
10012+
<td rowspan=2 style='white-space:nowrap'>{{GPUTextureFormat/depth24unorm-stencil8}}
10013+
<td rowspan=2>4
10014+
<td>depth
10015+
<td>{{GPUTextureSampleType/"depth"}}
10016+
<td colspan=2>&cross;
10017+
<tr>
10018+
<td>stencil
10019+
<td>{{GPUTextureSampleType/"uint"}}
10020+
<td colspan=2>&checkmark;
10021+
<tr>
10022+
<td rowspan=2 style='white-space:nowrap'>{{GPUTextureFormat/depth32float-stencil8}}
10023+
<td rowspan=2>5 &minus; 8
10024+
<td>depth
10025+
<td>{{GPUTextureSampleType/"depth"}}
10026+
<td colspan=1>&cross;
10027+
<td colspan=1>&checkmark;
10028+
<tr>
10029+
<td>stencil
10030+
<td>{{GPUTextureSampleType/"uint"}}
10031+
<td colspan=2>&checkmark;
1001710032
</table>
1001810033

10019-
Stencil formats must sample as `vec4<u32>(S, X, X, X)`, where S is the stencil value and each X is an implementation-defined unspecified value.
10034+
#### Reading and Sampling Depth/Stencil Textures #### {#reading-depth-stencil}
10035+
10036+
When reading or sampling a depth channel via a `texture_depth_*`-typed binding, the value is
10037+
returned as an `f32` value.
10038+
10039+
Issue(gpuweb/gpuweb#2094): Depending on the resolution of this issue, allow reading/sampling via
10040+
`texture_2d` etc. in the table above and specify the behavior. (`vec4<f32>(D, X, X, X)`?)
10041+
Update the note below which would become slightly outdated.
10042+
10043+
Reading or sampling a stencil channel must be done via a normal texture binding
10044+
(`texture_2d`, `texture_2d_array`, `texture_cube`, or `texture_cube_array`).
10045+
When doing so, the value is returned as `vec4<u32>(S, X, X, X)`, where S is the stencil value and each X is an implementation-defined unspecified value.
1002010046
Authors must not rely on these `.y`, `.z`, and `.w` components, as their behavior is non-portable.
1002110047

1002210048
Note:
1002310049
Short of adding a new more constrained stencil sampler type (like depth), it's infeasible for implementations to efficiently paper over the driver differences for stencil reads.
1002410050
As this was not a portability pain point for WebGL, it's not expected to be problematic in WebGPU.
1002510051
In practice, expect either `vec4<u32>(S, S, S, S)` or `vec4<u32>(S, 0, 0, 1)`, depending on hardware.
1002610052

10027-
<dfn dfn>Copies of depth and stencil textures</dfn> can only happen within the following sets of formats:
10028-
- {{GPUTextureFormat/stencil8}}, {{GPUTextureFormat/depth24plus-stencil8}} (stencil component), {{GPUTextureFormat/r8uint}}
10029-
- {{GPUTextureFormat/depth16unorm}}, {{GPUTextureFormat/r16uint}}
10030-
- {{GPUTextureFormat/depth24plus}}, {{GPUTextureFormat/depth24plus-stencil8}} (depth aspect)
10053+
#### Copying Depth/Stencil Textures #### {#copying-depth-stencil}
1003110054

10032-
Additionally, {{GPUTextureFormat/depth32float}} textures can be copied into {{GPUTextureFormat/depth32float}} and {{GPUTextureFormat/r32float}} textures.
10055+
<div algorithm>
10056+
Two {{GPUTextureFormat}}s |format1| and |format2| are <dfn dfn>copy-compatible</dfn> if:
10057+
10058+
- |format1| equals |format2|, or
10059+
- |format1| and |format2| differ only in whether they are `srgb` formats (have the `-srgb` suffix).
10060+
</div>
1003310061

1003410062
Note:
1003510063
{{GPUTextureFormat/depth32float}} texel values have a limited range. As a result, copies into
1003610064
{{GPUTextureFormat/depth32float}} textures are only valid from other {{GPUTextureFormat/depth32float}} textures.
1003710065

10038-
Issue: clarify if `depth24plus-stencil8` is copyable into `depth24plus` in all target backend APIs.
10039-
1004010066
### Packed formats ### {#packed-formats}
1004110067

1004210068
All packed texture formats support {{GPUTextureUsage/COPY_SRC}}, {{GPUTextureUsage/COPY_DST}}, and {{GPUTextureUsage/TEXTURE_BINDING}} usages. All of these formats have {{GPUTextureSampleType/"float"}} type and can be filtered on sampling.

0 commit comments

Comments
 (0)