These tests cover the external texture binding resource. They ensure
the WGSL functions `textureDimensions()`, `textureLoad()`, and
`textureSampleBaseClampToEdge()` work as expected for both
`TextureView`s and `ExternalTexture`s bound to external texture
resource bindings.
For external textures, they ensure multiplanar YUV formats work as
expected including handling color space transformation. And that the
provided sample and load transforms correctly handle cropping,
flipping, and rotation.
These existing tests cover `Queue::copy_external_image_to_texture()`
which, despite the similar name, is unrelated to the external texture
binding resource.
The following patch is going to add some tests for the latter, so we
are taking this opportunity to rename the former to help avoid
confusion.
This implements the DX12 HAL part of external texture support, which is
the final piece of the puzzle for external textures on DirectX 12.
When creating a pipeline layout, HAL is responsible for mapping a
single BindingType::ExternalTexture bind group entry to multiple
descriptor ranges in the root signature it creates: 3 SRVs (one for
each texture plane) and a CBV for the parameters buffer. Additionally
we must expose the additional bindings to the Naga backend via the
`external_texture_binding_map`. Lastly, when creating a bind group we
write the descriptors for each of these bindings to the heap.
And with that, we can finally enable the `EXTERNAL_TEXTURE` feature
for the dx12 backend.
The WebGPU spec. `createBindGroup` [states][spec-ref] (emphasis mine):
> Device timeline initialization steps:
>
> …
>
> 2. If any of the following conditions are unsatisfied generate a
> validation error, invalidate _bindGroup_ and return.
>
> …
>
> For each `GPUBindGroupEntry` _bindingDescriptor_ in
> _descriptor_.`entries`:
>
> - …
>
> - If the defined binding member for _layoutBinding_ is:
>
> - …
>
> - `buffer`
>
> - …
>
> - If _layoutBinding_.`buffer`.`type` is
>
> - …
>
> - `"storage"` or `"read-only-storage"`
>
> - …
>
> - effective buffer binding size(_bufferBinding_) is a multiple of 4.
[spec-ref]: https://www.w3.org/TR/webgpu/#dom-gpudevice-createbindgroup
We were not implementing this check of effective buffer binding size.
Check that it's a multiple of 4, including
`webgpu:api,validation,createBindGroup:buffer,effective_buffer_binding_size:*`
that this is now implemented as intended.
This adds several fields to `ExternalTextureDescriptor`, specifying
how to handle color space conversion for an external texture. These
fields consist of transfer functions for the source and destination
color spaces, and a matrix for converting between gamuts. This allows
`ImageSample` and `ImageLoad` operations on external textures to
return values in a desired destination color space rather than the
source color space of the underlying planes.
These fields are plumbed through to the `ExternalTextureParams`
uniform buffer from which they are exposed to the shader. Following
conversion from YUV to RGB after sampling/loading from the external
texture planes, the shader uses them to gamma decode to linear RGB in
the source color space, convert from source to destination gamut, then
finally gamma encode to non-linear RGB in the destination color space.
For simplicity's sake our initial implementation of external textures
will not support binding arrays of external textures. We should
therefore reject any shaders which use them during validation.
Their implementation will be tracked in #8027.
naga/src/valid/type.rs JJ: JJ: Lines starting with "JJ:" (like this
one) will be removed.
This adds HLSL backend support for `ImageClass::External` (ie WGSL's
`external_texture` texture type).
For each external texture global variable in the IR, we declare 3
`Texture2D` globals as well as a `cbuffer` for the params. The
additional bindings required by these are found in the newly added
`external_texture_binding_map`. Unique names for each can be obtained
using `NameKey::ExternalTextureGlobalVariable`.
For functions that contain ImageQuery::Size, ImageLoad, or ImageSample
expressions for external textures, ensure we have generated wrapper
functions for those expressions. When emitting code for the
expressions themselves, simply insert a call to the wrapper function.
For size queries, we return the value provided in the params
struct. If that value is [0, 0] then we query the size of the plane 0
texture and return that.
For load and sample, we sample the textures based on the number of
planes specified in the params struct. If there is more than one plane
we additionally perform YUV to RGB conversion using the provided
matrix.
Unfortunately HLSL does not allow structs to contain textures, meaning
we are unable to wrap the 3 textures and params struct variables in a
single variable that can be passed around.
For our wrapper functions we therefore ensure they take the three
textures and the params as consecutive arguments. Likewise, when
declaring user-defined functions with external texture arguments, we
expand the single external texture argument into 4 consecutive
arguments. (Using NameKey::ExternalTextureFunctionArgument to ensure
unique names for each.)
Thankfully external textures can only be used as either global
variables or function arguments. This means we only have to handle the
`Expression::GlobalVariable` and `Expression::FunctionArgument` cases
of `write_expr()`. Since in both cases we know the external texture
can only be an argument to either a user-defined function or one of
our wrapper functions, we can simply emit the names of the variables
for each three textures and the params struct in a comma-separated
list.
Adds new `NameKey` variants `ExternalTextureGlobalVariable` and
`ExternalTextureFunctionArgument`, like their non-external-texture
cousins but additionally keyed by either being a specific plane index
or params buffer.
For each external texture global variable or function argument reserve
additional names for 3 planes and the params buffer. For Naga backends
which must represent external textures as multiple variables/arguments,
this will allow them to uniquely name each one.
During wgsl lowering, if we encounter an external texture type then
generate the `ExternalTextureParams` struct. This will be required by
most Naga backends to implement external textures.
This type is not actually used by wgsl-in or the IR. However,
generating it in Naga IR ensures tricky details such as member
alignment are handled for us.
wgsl-out must ensure it does *not* generate code for this type, as it
handles external textures natively.
* Restore allowance of unaligned buffer-texture copies
This fixes a regression introduced by #7948. However, it makes it
possible to reach a panic in initialize_buffer_memory if the copy
requires initializing a region of memory that is not 4B aligned.
* Fix CopyT2T of multi-layer depth/stencil textures
* Adjust test list
* Additional validation of buffer-texture copies
Fixes#7936, but leaves a TODO for #7947
* Skip tests failing on dx12
* Update comments and change unwrap_or to expect