2300 Commits

Author SHA1 Message Date
Andreas Reich
00ea850d79
Allow timeouting on poll (#8282) 2025-10-01 07:19:24 +00:00
Andy Leiserson
1967900565
Encode commands on finish (#8220)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2025-09-25 14:22:51 -04:00
Andie Bradley
f6005a16c8
Include FreeBSD in conditional compile attributes (#8246) 2025-09-20 22:46:46 -04:00
Andy Leiserson
04a3401638
Extract command encoding to free functions (#8210) 2025-09-11 15:15:33 -04:00
Andy Leiserson
67bdd80a38
Add cbindgen:ignore directives (#8212) 2025-09-11 19:10:05 +00:00
Andy Leiserson
aaf52e93d9 Move some *Copy*Info types out of wgpu_core::command::transfer
In the future `transfer` will want to use the `Arc` versions of these
types. I have exported them from `wgpu_core::command::ffi`, to document
that these are used for FFI purposes, and from `wgpu_core::command`, for
backwards compatibility, although I also change the in-tree uses to
use them from `wgpu_types` instead of from `wgpu_core::command`.
2025-09-11 10:20:03 -07:00
Andy Leiserson
d79a49a060 Rename commands to trace_commands 2025-09-11 10:20:03 -07:00
Andy Leiserson
718497356c Move enum Command from device::trace to command::encoder_command. 2025-09-11 10:20:03 -07:00
Andy Leiserson
c0c16078e9 Rename and relocate ID resolution helpers 2025-09-11 10:20:03 -07:00
Andy Leiserson
885845087f Extract the parts of PassState that apply to the base encoder
And rename a few things.
2025-09-11 10:20:03 -07:00
Andy Leiserson
1791064a30
Update comments on IdentityValues (#8183) 2025-09-09 11:14:41 -07:00
Andy Leiserson
a9638c8e3a
Remove pending_query_resets from CommandBufferMutable (#8187)
It is emptied by `reset_queries` at the end of every render pass, so
it's just keeping an allocation alive, not holding any state. It seems
unlikely that there is sufficient performance gain from reusing the
memory allocation to justify the complexity of additional state at
higher layers.
2025-09-09 13:03:12 -04:00
Andy Leiserson
4853133eaa Fix buffer initialization tracking for some buffer-texture copies (#8099)
Fixes #7947
Fixes #8021
Fixes #8097
2025-09-04 14:15:31 -07:00
Andy Leiserson
989d48ccb6 Tweak the bytes_per_row alignment check
Previously, the check was skipped if the copy was a single row, which is
not correct. The check should be made whenever bytes_per_row is
specified. It is permissible not to specify bytes_per_row if the copy is
a single row, but if it is specified, it must be aligned.

Also removes a redundant check of the `offset` alignment.

Since the offset and bytesPerRow alignment checks are not part of
"validating linear texture data", I chose to remove that instance of
them. These checks are now in `validate_texture_buffer_copy`, which
does not correspond 1:1 with the spec, but has a comment explaining how
it does correspond.
2025-09-04 14:15:31 -07:00
Connor Fitzgerald
8d1f4bb5f2
Require token for experimental features (#8163) 2025-08-29 15:43:27 -04:00
Lucas Abel
5d4cf56689
[api] expose invalid submission index to PollError (#8169) 2025-08-29 12:30:55 -04:00
Matthias Reitinger
80a742094c
[wgpu-core] Improve errors for forbidden texture copy formats (#8156)
TransferError now has separate variants for texture copy formats that
are only forbidden in combination with specific aspects
(CopyFrom/ToForbiddenTextureFormatAspect), and texture copy formats that
are always forbidden, irrespective of the aspect
(CopyFrom/ToForbiddenTextureFormat).

This produces a less confusing error message by not mentioning the
aspect it is not relevant.
2025-08-29 10:03:35 +00:00
Andy Leiserson
4a7b6abb19 Add F16_IN_F32 downlevel flag for pack/unpack/quantize f16 (#8130)
Although the operation of these functions is defined in terms of f16
semantics, the input/output types are not f16, and they are generally
available even when native `f16` support is not. But in at least one
case, they are only available with `f16` support, so add a new downlevel
flag that is cleared when these functions are not available.

Add some infrastructure to simplify testing of missing
capabilities/extensions, and add tests for a few more kinds of f16
usage.

Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
2025-08-28 13:58:36 -07:00
Connor Fitzgerald
2ff46cd7cd
Remove MULTI_DRAW_INDIRECT feature (#8162) 2025-08-28 12:00:14 -04:00
Connor Fitzgerald
884cea5ad9
Narrow locks in queue::write_buffer (#8146) 2025-08-25 11:54:30 -04:00
Vecvec
c4a834e4f9
Make the compacted hal acceleration structure inherit a label from the base BLAS. #8103 2025-08-24 09:11:13 +00:00
Jamie Nicol
167ff7b952 [metal] Implement support for external textures
This contains the Metal HAL changes required to support external
textures. When creating a bind group we create resource bindings for
each of the 3 textures and parameters buffer that the external texture
has been lowered to. When creating the pipeline layout we fill the
`BindTarget` accordingly, so that the Naga MSL backend can bind each
of the global variables to which the the external texture has been
lowered to each of these resources.

We must also ensure the size of the buffer bound to the parameters
global matches the size of the MSL type, else metal validation
complains. We do this by adding a padding field to the rust-side
ExternalTextureParams struct, the size of which is used as the size of
the buffer to allocate.

Lastly we enable `Features::EXTERNAL_TEXTURE` on the Metal backend.
2025-08-21 12:35:19 +01:00
Magnus
17a17f716a
Initial precompiled shaders implementation (#7834)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-08-20 16:20:59 -04:00
Jamie Nicol
486c151772
[dx12,vulkan] Add support for P010 texture format (#8086)
P010 is a 4:2:0 chroma subsampled planar format, similar to NV12. Each
component uses 16 bits of storage, of which only the high 10 bits are
used. On DX12 this maps to DXGI_FORMAT_P010, and on Vulkan this maps to
G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16.

The existing "nv12" gpu test module has been renamed to
"planar_texture", and a new test P010_TEXTURE_CREATION_SAMPLING has
been added similar to the existing NV12_TEXTURE_CREATION_SAMPLING. The
remaining tests in this module have been converted to validation tests,
and now test both NV12 and P010 formats.
2025-08-13 15:35:20 +02:00
Lisitsa Nikita
1b948fbf42
Fix 'Read-only attachment with load' error message (#8068) 2025-08-09 17:58:32 +02:00
Lisitsa Nikita
b1bf444b7a
Fix error message when render pipeline vertex attribute location is greater or equal to the maximum number of vertex attributes (fixes #8064) (#8065) 2025-08-09 17:48:11 +02:00
Erich Gubler
b5385225ab
fix(core): validate effective buf. binding size is aligned to 4 (#8041)
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.
2025-08-06 16:19:08 +02:00
Jamie Nicol
8cd4bd602f [naga hlsl-out] Handle external texture color space conversion
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.
2025-08-06 11:18:42 +01:00
Andy Leiserson
910143d622
Check for more cases of unbalanced debug groups (#8048)
Fixes #3911
2025-08-05 16:52:50 +02:00
Vecvec
a1168613d2
Prevent resources for acceleration structures being created if they are not enabled (#8036)
* Prevent resources for acceleration structures being created if acceleration structures aren't supported.
2025-08-04 09:37:09 -07:00
Andy Leiserson
f25a79595a
Add a missing condition to viewport validation (#8040) 2025-08-01 01:10:15 -04:00
Jamie Nicol
e1ccb6632c [naga hlsl-out] Implement external texture support
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.
2025-07-30 14:33:00 -07:00
Jamie Nicol
9f654c6235 [naga] Generate special type for external texture params buffer
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.
2025-07-30 14:33:00 -07:00
Andy Leiserson
36ae215e9c
Fix image copy regressions (#8022)
* 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
2025-07-30 14:35:12 +02:00
Andy Leiserson
5089063048
Allow copying one layer of depth/stencil textures (#8020)
This fixes a regression introduced by #7935.
2025-07-29 10:18:26 -07:00
Andy Leiserson
1583c2481a
Another fix for texture copy validation (#8019) 2025-07-28 22:19:17 -04:00
SupaMaggie70Incorporated
074c0e7191
Add mesh shading api to wgpu & wgpu-core (#7345) 2025-07-24 20:58:56 -04:00
Lucas Abel
b8c462ac31
[core] fix missing applies of DISCARD_HAL_LABELS (#7991) 2025-07-23 12:06:42 -04:00
Jim Blandy
d9a6b4fa4a [naga, wgpu-core] Add some docs for Naga validator creation. 2025-07-23 08:51:13 -07:00
Andy Leiserson
1c43ac2c42
Additional validation of buffer-texture copies (#7948)
* 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
2025-07-23 17:39:42 +02:00
Jamie Nicol
f8756a6e1b [wgpu] Add external texture validation tests
Adds validation tests using the noop backend covering creation of
external textures, and creation of bind groups containing external
textures.
2025-07-22 15:38:15 -07:00
Jamie Nicol
7087f0c01f [wgpu-core] Allow creation of bind groups containing external textures
Adds a `BindingResource` variant for external textures. In core's
create_bind_group() implementation, allow binding either external
textures or texture views to `BindingType::ExternalTexture` layout
entries.

In either case, provide HAL with a `hal::ExternalTextureBinding`,
consisting of 3 `hal::TextureBinding`s and a `hal::BufferBinding`. In
the texture view case we use the device's default params buffer for
the buffer. When there are fewer than 3 planes we can simply repeat an
existing plane multiple times - the contents of the params buffer will
ensure the shader only accesses the correct number of planes anyway.

Track the view or external texture in `BindGroupStates` to ensure they
remain alive whilst required.

And finally, add the corresponding API to wgpu, with an implementation
for the wgpu-core backend.
2025-07-22 15:38:15 -07:00
Jamie Nicol
d263b1875d [wgpu-core] Create default ExternalTextureParams buffer
In upcoming patches, wgpu will allowing the creation of bind groups
with either `TextureView`s or `ExternalTexture`s bound to a
`BindingType::ExternalTexture` bind group layout entry.

Wgpu-hal and the Naga-generated shaders must be able to handle both of
these cases. For external textures they will be provided a uniform
buffer containing the external texture's `ExternalTextureParams`. For
the texture view case, we must therefore provide the same.

To do this, we create a single buffer per device which can be shared
between all texture views. We initialize it with the required values
in Device::late_init_resources_with_queue(). We know that texture
views must have a single RGBA plane, with no rotation or
crop-rect. The only thing that can vary between them is their size. We
will therefore use the value of [0, 0] in the params buffer to
indicate to the shader that it should query the actual texture's size
rather than using the value provided in the buffer.
2025-07-22 15:38:15 -07:00
Jamie Nicol
acfa8c5776 [wgpu-core] Add ExternalTexture type to wgpu-core
`ExternalTexture` will form the basis of wgpu's implementation of
WebGPU's `GPUExternalTexture`. [1]

The application will be responsible for creating `Texture`(s) and
`TextureView`(s) from the external texture source and managing their
lifecycle. It may have a single RGBA texture, or it may have multiple
textures for separate Y and Cb/Cr planes. It can then create an external
texture by calling `create_external_texture()`, providing the texture
views and a descriptor. The descriptor provides the following required
information:

  * Whether the texture data is RGBA, or multiplanar or interleaved
    YCbCr.
  * The purpoted size of the external texture, which may not match the
    actual size of the underlying textures.
  * A matrix for converting from YCbCr to RGBA, if required.
  * A transform to apply to texture sample coordinates, allowing for
    rotation and crop rects.

The external texture stores a reference to the provided texture views,
and additionally owns a `Buffer`. This buffer holds data of the type
`ExternalTextureParams`, and will be provided as a uniform buffer to
shaders containing external textures. This contains information that
will be required by the shaders to handle external textures correctly.

Note that attempting to create an external texture will fail unless the
`Feature::EXTERNAL_TEXTURE` feature is enabled, which as of yet is not
supported by any HAL backends.

Additionally add the relevant API to wgpu, implemented for the
wgpu-core backend. The web and custom backends are unimplemented.

[1] https://www.w3.org/TR/webgpu/#gpuexternaltexture
2025-07-22 15:38:15 -07:00
Jamie Nicol
43a4d53107
[naga wgsl-in wgsl-out] WGSL support for texture_external texture type (#7822)
* [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

Make wgsl-in correctly parse `texture_external` texture declarations,
and allow such textures to be used in `textureDimensions()`,
`textureSampleBaseClampToEdge()`, and `textureLoad()` function
calls. In IR these are represented by the `ImageClass::External` image
class, which is a 2D, non-multisampled, non-mipmapped, float-sampled
image.

Adds a new Capability `TEXTURE_EXTERNAL` and ensure validation rejects
shaders containing external textures if this capability flag is not
set. This capability is enabled for validation by wgpu devices which
support the `TEXTURE_EXTERNAL` feature (currently only when using the
noop backend), and by the Naga CLI when validating-only or when
outputting WGSL.

The WGSL backend can of course emit `ImageClass::External` images
directly as `texture_external` textures. Other backends are, for now,
unimplemented.

Lastly, we add a snapshot test covering all the valid uses of a
texture_external texture. These are:
  - As a global variable declaration
  - As an argument to the built-in functions `textureDimensions()`,
    `textureSampleBaseClampToEdge()`, and `textureLoad()`
  - As an argument to user-defined function declarations and calls.

We keep these in their own test so that we can control which targets
to run them against (currently WGSL and IR). When external textures
are supported by all Naga backends we can, if so inclined, integrate
these with existing texture tests.

* fixup! [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

* fixup! [naga wgsl-in wgsl-out] WGSL support for texture_external texture type

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2025-07-22 14:38:32 -07:00
Andy Leiserson
381932c601 Add CommandEncoderStatus::Consumed 2025-07-22 16:19:18 +02:00
teoxoy
b8c5c4add4 rename cmd_buf to cmd_enc where appropriate 2025-07-22 16:19:18 +02:00
teoxoy
63f3df86c8 [wgpu-core] split command encoders from command buffers 2025-07-22 16:19:18 +02:00
Andy Leiserson
f5d8a0a06a
Additional validation of texture copies (#7935)
* Additional validation of texture copies

 * Copies must not overlap.
 * Copies of multisampled or depth/stencil formats must span
   the entire texture.
 * Move no-op for zero-size copies after parameter validation.

Closes #2951
Fixes #7844

* Fix issue with combined depth+stencil copy on dx12

* PR feedback
2025-07-22 15:17:47 +02:00
Andy Leiserson
2c81896e85
Small changes to facilitate fuzzing (#7970) 2025-07-21 13:51:57 +02:00