678 Commits

Author SHA1 Message Date
Kevin Reid
c1254b4c80 Add more overview documentation to Buffer and usages. 2025-08-24 17:30:48 -04: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
Andy Leiserson
e7a99be058
[deno] Fix some problems in the handling of device limits (#8085)
* Correct error type when a requested limit is too high
* Clamp requested limits to the WebGPU defaults

Fixes #8084
2025-08-20 14:58:56 -07: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
Marc Pabst
e7cdfc436a
Allow disabling waiting for latency waitable object (#7400) 2025-08-10 10:01:25 +00:00
Jamie Nicol
b3a3dc33b6 [dx12] Support external textures on DX12
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.
2025-08-06 17:31:50 +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
sagudev
45e96e593f
docs: Fix comment in COPY_BYTES_PER_ROW_ALIGNMENT to include copy_texture_to_buffer (#8029) 2025-07-31 16:05:05 -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
SupaMaggie70Incorporated
d8b7e81a02
Updated mesh shader limits to be llvmpipe compatible (#8004)
Co-authored-by: Andy Leiserson <aleiserson@mozilla.com>
2025-07-25 00:05:12 -04:00
SupaMaggie70Incorporated
074c0e7191
Add mesh shading api to wgpu & wgpu-core (#7345) 2025-07-24 20:58:56 -04: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
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
Connor Fitzgerald
ff0de91ad7
Bump REPO_MSRV to 1.88 (#7960) 2025-07-17 13:00:40 -04:00
Connor Fitzgerald
e5b10e07e8 Adjust InstanceDescriptor docs 2025-07-16 15:10:00 -04:00
Jim Blandy
c51fe577dc
Improve docs for wgpu_types::InstanceFlags::VALIDATION. (#7939) 2025-07-13 01:04:19 -04:00
Andy Leiserson
c868142709
Validate vertex and index buffer alignment (#7929) 2025-07-11 14:43:03 -07:00
Vecvec
4844fa6b5e
Merge acceleration structure feature and ray query feature. (#7913)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-07-10 19:53:32 +00:00
Andy Leiserson
468632f207 Restore plumbing of implicit remainder-of-buffer size to backends 2025-07-10 09:52:20 -07:00
Andy Leiserson
27e7408f16 Restore the buffer size changes 2025-07-10 09:52:20 -07:00
Andy Leiserson
b0527800a1 Revert "Restore unintentional support for zero-size buffers"
This reverts commit c0a580d6f0343a725b3defa8be4fdf0a9691eaad.
2025-07-09 16:29:41 -04:00
Andy Leiserson
c0a580d6f0 Restore unintentional support for zero-size buffers 2025-07-08 14:45:12 -07:00
Andy Leiserson
3d0fe3a003 Check the math for buffer-texture copies 2025-07-08 12:11:56 -07:00
Andy Leiserson
b695317a9b
Rg11b10ufloat should be resolvable when it is renderable (#7878) 2025-07-03 17:51:48 -04:00
teoxoy
918fdc98b5 remove reason from ErrorType::DeviceLost since it's always "unknown" and users should register the lost callback instead 2025-07-02 11:11:37 +02:00
Erich Gubler
7ff0bd784e fix!: remove WebGpuError impl. for Request{Adapter,Device}Error 2025-06-30 10:58:56 -04:00
Erich Gubler
964c5bbf4c feat(core): impl WebGpuError for API errors 2025-06-30 10:58:56 -04:00
Erich Gubler
c8752e5118 feat(types): add error::{ErrorType, WebGpuError} APIs 2025-06-30 10:58:56 -04:00
Erich Gubler
c3922d53d7 docs(types): Make docs. on DeviceLostReason variants less terse 2025-06-30 10:58:56 -04:00
SupaMaggie70Incorporated
e40e66d205
DXIL & HLSL passthrough (#7831)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-06-25 18:12:58 -04:00
Vecvec
dc0d457a9a
Add limits for acceleration structures (#7845) 2025-06-25 14:49:55 -04:00
Jamie Nicol
8cdbcc1755 Add ExternalTexture BindingType behind new Feature flag
Adds a new feature flag, `EXTERNAL_TEXTURE`, indicating device support
for our implementation of WebGPU's `GPUExternalTexture` [1] which will
land in upcoming patches. Conceptually this would make more sense as a
downlevel flag, as it is a core part of the WebGPU spec which we do not
yet support. We do not want, however, to cause applications to reject
adapters because we have not finished implementing this, so for now we
are making it an opt-in feature.

As an initial step towards supporting this feature, this patch adds a
new `BindingType` corresponding to WebGPU's
`GPUExternalTextureBindingLayout` [2]. This binding type dictates that
when creating a bind group the corresponding entry must be either an
external texture or a texture view with certain additional requirements
[3].

As of yet wgpu has no concept of an external texture (that will follow
in later patches) but for now this patch ensures that texture views
corresponding to an external texture binding type are validated
correctly. Note that as the feature flag is not yet supported on any
real backends, bind group layout creation will fail before getting the
chance to attempt to create a bind group. But in the added tests using
the noop backend we can see this validation taking place.

[1] https://www.w3.org/TR/webgpu/#gpuexternaltexture
[1] https://www.w3.org/TR/webgpu/#dictdef-gpuexternaltexturebindinglayout
[2] https://gpuweb.github.io/gpuweb/#bind-group-creation
2025-06-17 15:00:29 -07:00
Dmitry Zamkov
bbb7cc79ef
Implement clip-distances extension for GL and Vulkan backends (#7730)
* Basic implementation of `clip_distances` for Vulkan and GL backends

* Added GPU test for `clip-distances`

* Update feature array size

* Add changelog entry

* Validate `clip_distances` array size

* Check for `clip_distances` enable directive

* Consolidate code for generating `enable` directives in WGSL backend and add `clip_distances`.
2025-06-16 10:33:31 +02:00
Erich Gubler
cf83de3a5d
chore!: remove deprecated type aliases for idents. in 2024-08 spec. rename (#7790)
This backs out commit 9436d56271c6f3141ee5da882355ea45784c446c.
2025-06-12 09:55:00 -04:00
Vecvec
73eb83ded1
[wgpu] Blas compaction (#7285)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-06-11 21:40:10 -04:00
Vecvec
efbac5dfba
Add extra acceleration structure vertex formats. (#7580) 2025-06-11 18:17:14 -04:00
andristarr
0e1baff277
Navigatable docs for BufferUsages::MAP_WRITE (#7742) 2025-06-01 20:22:56 +09:00
Raphael Hetzel
0d569d5550
Optional web-specific deps for wasm32 (#7565) 2025-05-29 22:26:01 +00:00
Dmitry Zamkov
44957709ff
Vulkan support for SHADER_EARLY_DEPTH_TEST and fix to conservative depth optimizations (#7676)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2025-05-24 09:52:39 +00:00
Mehmet Oguz Derin
2a62299a84
Support Sliced 3D for ASTC (#7577)
Enables "texture-compression-astc-sliced-3d" for backends that support ASTC (such as excluding D3D12).
2025-05-04 12:48:16 +02:00
Connor Fitzgerald
9fccdf5cf3
Extract texture <-> buffer copy logic to wgpu-types (#7553) 2025-04-28 21:15:59 +00:00
Florian Denis
1806414771
[wgpu-types]: Expose wgpu::Limits::defaults() (#7622) 2025-04-24 09:56:14 -04:00
teoxoy
3b72d59a3c make memory pressure detection optional and configurable 2025-04-22 09:21:27 +02:00
Teodor Tanasoaia
6ea7962da7
[d3d12] remove the need for dxil.dll (#7566) 2025-04-17 16:21:36 +02:00
teoxoy
edbadd2b99 expand on InstanceFlags::VALIDATION_INDIRECT_CALL docs 2025-04-15 17:56:17 +02:00
teoxoy
45d78e2fb4 remove DownlevelFlags::VERTEX_AND_INSTANCE_INDEX_RESPECTS_RESPECTIVE_FIRST_VALUE_IN_INDIRECT_DRAW 2025-04-15 17:56:17 +02:00
Connor Fitzgerald
45d8f42513 Use workspace package information everywhere 2025-04-10 20:41:28 -04:00
Connor Fitzgerald
8c2c2ce203
Release v25 (#7505) 2025-04-10 16:13:02 +00:00
Sylvain Benner
14690470bb
[metal] Metal compute shader passthrough (#7326)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-04-09 14:25:41 +00:00