Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be3d31f

Browse files
authored
Allow using depth textures with texture_2d (gpuweb#3038)
And update the "Reading and Sampling Depth/Stencil Textures" section. Fixes gpuweb#2094
1 parent cd260d6 commit be3d31f

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

spec/index.bs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6063,7 +6063,7 @@ typedef double GPUPipelineConstantValue; // May represent WGSL's bool, f32, i32,
60636063

60646064
: {{GPUTextureSampleType/"depth"}}
60656065
::
6066-
|variable| has type `texture_depth_2d`, `texture_depth_2d_array`,
6066+
|variable| has type `texture_2d<f32>`, `texture_depth_2d`, `texture_depth_2d_array`,
60676067
`texture_depth_cube`, `texture_depth_cube_array`, or `texture_depth_multisampled_2d`.
60686068
</dl>
60696069
::
@@ -13264,22 +13264,33 @@ be used with {{GPUSamplerBindingType/"comparison"}} samplers (which may use filt
1326413264

1326513265
#### Reading and Sampling Depth/Stencil Textures #### {#reading-depth-stencil}
1326613266

13267-
When reading or sampling a depth component via a `texture_depth_*`-typed binding, the value is
13268-
returned as an `f32` value.
13267+
It is possible to bind a depth-aspect {{GPUTextureView}} to either a `texture_depth_*` binding
13268+
or a `texture_2d<f32>` binding. In both cases, the {{GPUTextureBindingLayout/sampleType}} must
13269+
be {{GPUTextureSampleType/"depth"}}.
1326913270

13270-
Issue(gpuweb/gpuweb#2094): Depending on the resolution of this issue, allow reading/sampling via
13271-
`texture_2d` etc. in the table above and specify the behavior. (`vec4<f32>(D, X, X, X)`?)
13272-
Update the note below which would become slightly outdated.
13271+
When reading or sampling a depth aspect via a binding with type `texture_2d<f32>`,
13272+
it behaves as if the texture contains the values `(D, X, X, X)`, where D is the depth value
13273+
and each X is an implementation-defined unspecified value.
1327313274

13274-
Reading or sampling a stencil component must be done via a normal texture binding
13275-
(`texture_2d`, `texture_2d_array`, `texture_cube`, or `texture_cube_array`).
13276-
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.
13277-
Authors must not rely on these `.y`, `.z`, and `.w` components, as their behavior is non-portable.
13275+
Reading or sampling a stencil aspect must be done via a normal texture binding
13276+
(`texture_2d`, `texture_2d_array`, `texture_cube`, or `texture_cube_array`). When doing so,
13277+
it behaves as if the texture contains the values `(S, X, X, X)`, where S is the stencil value
13278+
and each X is an implementation-defined unspecified value.
13279+
13280+
<div class=example>
13281+
If a depth texture is bound to `tex` with type `texture_2d<f32>`:
13282+
13283+
- `textureSample(tex, ...)` will return `vec4<f32>(D, X, X, X)`.
13284+
- `textureGather(0, tex, ...)` will return `vec4<f32>(D1, D2, D3, D4)`.
13285+
- `textureGather(2, tex, ...)` will return `vec4<f32>(X1, X2, X3, X4)` (a completely unspecified value).
13286+
</div>
1327813287

1327913288
Note:
13280-
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.
13289+
Short of adding a new more constrained stencil sampler type (like depth), it's infeasible for
13290+
implementations to efficiently paper over the driver differences for depth/stencil reads.
1328113291
As this was not a portability pain point for WebGL, it's not expected to be problematic in WebGPU.
13282-
In practice, expect either `vec4<u32>(S, S, S, S)` or `vec4<u32>(S, 0, 0, 1)`, depending on hardware.
13292+
In practice, expect either `(V, V, V, V)` or `(V, 0, 0, 1)` (where `V` is the depth or stencil
13293+
value), depending on hardware.
1328313294

1328413295
#### Copying Depth/Stencil Textures #### {#copying-depth-stencil}
1328513296

0 commit comments

Comments
 (0)