Commit Graph
754 Commits
Author SHA1 Message Date
atlv ddcd89fd69 Implement shader barycentrics (#8320) 2025-10-29 13:15:21 -04:00
Erich Gubler 18f4ed66c0 chore: satisfy unused_parens lint (#8424) 2025-10-23 18:35:18 -04:00
withtimezone 4ea04a69c9 chore: remove repetitive words in comment (#8385) 2025-10-20 14:42:54 -04:00
SamandSelkoSays 6e76a98c99 [naga const-eval] LiteralVector and some demo builtins (#8223)
* [naga] Add `LiteralVector` and `match_literal_vector!`

Co-authored-by: SelkoSays <70065171+SelkoSays@users.noreply.github.com>
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* [naga] Implement builtins dot, length, distance, normalize in const using LiteralVector

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Update snapshots

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: SelkoSays <70065171+SelkoSays@users.noreply.github.com>
2025-10-18 07:28:09 -04:00
Teodor Tanasoaia 1072b87894 Fix stray comma in function signatures in Metal (#8311)
Fixes a regression introduced by #8265 where we were mistakenly writing a comma before the first buffer argument (if no other arguments were printed before it).
2025-10-06 18:59:45 +00:00
Connor Fitzgerald ad15442b89 Improve error message when image write without format used (#8294) 2025-10-06 19:25:25 +02:00
Jim Blandy 43eccd28f8 [naga] Remove naga::path_like. Use String instead. (#8284)
Delete the `naga::path_like` module, and simply using `String` and
`str` instead.

Nothing in Naga uses `Path` or `PathBuf` methods; indeed, Naga only
converts these values back and forth from string-like types with
`to_string_lossy` and `into`, such that using string-like, rather than
path-like, types actually simplifies the code.

This also avoids dead code warnings starting in Rust 1.89 that would
otherwise require distracting `#[cfg_attr]` conditionals.
2025-10-01 18:08:18 +02:00
Erich Gubler 5146b3f8ae fix(namer): normalize ":<>," characters to a snake case separator 2025-10-01 08:50:37 -04:00
Erich Gubler 90702156af fix(namer): escape, rather than strip, non-ASCII ident. characters
Escape non-ASCII identifier characters with `write!(…, "u{:04x}", …)`,
surrounding with `_` as appropriate. This solves (1) a debugging issue
where stripped characters would otherwise be invisible, and (2) failure
to re-validate that stripped identifiers didn't start with an ASCII
digit.

I've confirmed that this fixes [bug
1978197](https://bugzilla.mozilla.org/show_bug.cgi?id=1978197) on the
Firefox side.
2025-10-01 08:50:37 -04:00
Erich Gubler 06fc6f7345 feat(wgsl): recognize enable primitive-index; (#8237) 2025-09-30 22:02:10 +00:00
Nils Hasenbanck 8c4aebc0c1 (Naga) Implement OpImageGather and OpImageDrefGather when ingesting SPIR-V (#8280) 2025-09-29 13:15:32 -04:00
Nils Hasenbanck 8cb94db802 (Naga) Add support for Storage Image Multisample when ingesting SPIR-V (#8270) 2025-09-29 11:45:39 -04:00
Andy Leiserson a01ffb7967 Fix unused warning in a specific feature config (#8271) 2025-09-29 11:44:05 -04:00
Teodor Tanasoaia ce96254f4f [msl] fix vertex pulling with a stride of 0 (#8265) 2025-09-26 13:37:37 -04:00
Nils Hasenbanck 2f7ebf1401 (Naga) Add support for Descriptor Runtime Indexing when ingesting SPIR-V (#8256) 2025-09-25 08:25:04 -04:00
05cc6dca82 [hal/dx12] Mesh Shaders (#8110)
* Features and draw commands added

* Tried to implement the pipeline creation (completely untested)

* Fixed clippy issues

* Fixed something I think

* A little bit of work on the mesh shader example (currently doesn't work on dx12)

* Reached a new kind of error state

* Fixed an alignment issue

* DirectX 12 mesh shaders working :party:

* Removed stupid change and updated changelog

* Fixed typo

* Added backends option to example framework

* Removed silly no write fragment shader from tests to see if anything breaks

* Tried to make mesh shader tests run elsewhere too

* Removed printlns and checked that dx12 mesh shader tests run

* Documented very strange issue

* I'm so lost

* Fixed stupid typos

* Fixed all issues

* Removed unnecessary example stuff, updated tests

* Updated typos.toml

* Updated limits

* Apply suggestion from @cwfitzgerald

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* Apply suggestion from @cwfitzgerald

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* Removed supported backends, made example & tests always pass the filename to shader compilers

* Removed excessive bools in test params

* Added new tests to the list

* I'm a sinner for this one (unused import)

* Replaced random stuff with test params hashing

* Updated typos.toml

* Updated -Fo typo thing

* Actually fixed typo issue this time

* Update CHANGELOG.md

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* Update tests/tests/wgpu-gpu/mesh_shader/mod.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update wgpu-hal/src/dx12/mod.rs

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>

* Addressed comments

* Lmao

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-25 03:24:56 +00:00
Andy Leiserson 1f10d0ce8a [naga] Don't report shader errors as their own source (#8258) 2025-09-24 22:42:24 -04:00
Sam 084431b548 [naga] Implement atan2 in const (#8222)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-09-24 11:23:25 -07:00
Cai Bear d2ee4b8be5 Fix #8151. (#8215) 2025-09-24 16:03:58 +00:00
Jamie Nicol ba0b6b9b0e [vulkan, naga spv-out] Remap resource bindings
In order to support external textures, we must be able to map a single
external texture resource binding to multiple Vulkan descriptors. This
means we must be able to override the `Binding` and `DescriptorSet`
values for global variables when generating SPIR-V, rather than simply
passing through the group and binding values from Naga IR.

This patch extends the existing SPIR-V Naga backend's `BindingMap` to
contain a descriptor set and binding value in addition to the existing
array size. When creating BindGroupLayouts/BindGroups we use a
sequentially incrementing value for each entry's binding value,
continuing to just use the bind group index as the descriptor set
value.

The Naga backend looks up each resource in the map when emitting its
`Binding` and `DescriptorSet` decorations. If the entry cannot be
found in the map, it will either error or emit fake bindings based on
its configuration.
2025-09-24 17:55:35 +02:00
EriKWDev 3efd640178 naga: Correct spelling in wgsl parsing rg11b10float -> rg11b10ufloat (#8219) 2025-09-21 10:41:17 +00:00
Teodor Tanasoaia 0b38e96379 [msl] vertex pulling: fix unpacking snorm16x2 & snorm16x4 (#8249) 2025-09-19 18:11:31 -04:00
Matthias Reitinger b55c24cf27 [naga wgsl-in] Allow trailing comma in switch cases (#8165) 2025-09-16 07:58:23 -04:00
MagnusandConnor Fitzgerald 54ce9f7f98 Update shader bencher to share some logic with snapshots (#8108)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-09-11 00:55:42 +00:00
Andy Leiserson d31d944ed5 Clarify the effect of the SUBGROUP features and capabilities (#8203) 2025-09-10 20:53:56 -04:00
Jamie Nicol 12c8b378a1 [naga wgsl-in] add "texture_external" to reserved keyword list (#8178) 2025-09-01 08:37:42 -04:00
Andy LeisersonandErich Gubler 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
Andy Leiserson e939bf273a feat(naga): expose {,Implemented}EnableExtension 2025-08-28 13:58:36 -07:00
Kevin Reid 1c8d769b67 [naga] Introduce KeywordSet and CaseInsensitiveKeywordSet. (#8136) 2025-08-27 23:42:02 -04:00
Erich Gubler dd73743e78 fix(wgsl-in): accept trailing comma in @blend_src(…) attr. (#8137) 2025-08-24 11:37:19 -07:00
Jamie Nicol 2c6f06a82b [naga msl-out] Implement support for external textures
This adds MSL backend support for `ImageClass::External`. (ie WGSL's
`external_texture` texture type). This is implemented very similarily
to the HLSL implementation in #7826.

Each external texture global variable is lowered to 3 `texture2d`s and
a buffer of type NagaExternalTextureParams. As usual in Naga's MSL
backend, these are passed as arguments to the entry point. The
bindings for each of these arguments are provided via the usual
binding map, using a new `BindExternalTextureTarget` variant of
`BindTarget`.

Unlike HLSL, MSL allows textures to be used as fields in structs. We
therefore immediately wrap these variables in a
`NagaExternalTextureWrapper` struct. This wrapper can then
conveniently be passed to either user-defined functions or builtin
implementations that accept an external texture.

The WGSL builtins `textureDimensions()`, `textureLoad()`, and
`textureSampleBaseClampToEdge()` are implemented using wrapper
functions using the regular `write_wrapped_functions()` machinery.
2025-08-21 12:35:19 +01:00
Jamie Nicol bb21da3014 [naga msl-out] Split up write_wrapped_functions()
It was getting unwieldy, and upcoming commits are going to add
additional functions that will be wrapped.
2025-08-21 12:35:19 +01:00
cryvosh 4b5e38ab49 [naga spv-out] Add f16 io polyfill (#7884) 2025-08-21 10:50:32 +02:00
Jamie Nicol 9aaed2c0cc [naga] Ensure validation rejects invalid sample operations of ImageClass::External images. (#8121)
textureSampleBaseClampToEdge() is valid when called on a
`texture_external` texture, but all other sample operations are
invalid. Previously validation was succeeding for these operations on
an external texture in cases where the same operation on a
`texture_2d<f32>` would be allowed. We must therefore explicitly check
for ImageClass::External and disallow invalid sample operations.
2025-08-20 08:30:54 +01:00
Vecvec 54be6a2b5b Fix empty ifs causing errors on spirv 1.6 (#7883) 2025-08-13 15:27:51 +00:00
Andy Leiserson 0cc8c11afe Escape control chars in source when printing diagnostics (#8049) 2025-08-11 12:16:46 -07: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
Jamie Nicol 59f815a9b9 [naga] Have validation reject shaders containing binding arrays of external textures
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.
2025-07-30 14:33:00 -07: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 0448b46033 [naga] Reserve names for each plane and params buffer of external texture
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.
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
Jim Blandy dbe64a769b [naga hlsl-out] Fix odd name for a Handle<GlobalVariable>. (#7996) 2025-07-23 16:48:49 -04:00
Jim Blandy d9a6b4fa4a [naga, wgpu-core] Add some docs for Naga validator creation. 2025-07-23 08:51:13 -07:00
Jamie NicolandJim Blandy 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 942e59eabc [naga] Enforce a maximum size for any type (#7950)
* [naga] Enforce a maximum size for any type

Fixes #4339
Fixes #7383

* Doc fix and changelog entry
2025-07-21 13:52:50 +02:00
Andy Leiserson 9a596fa1dc Fix warnings from the nightly Rust compiler (#7964) 2025-07-17 16:08:06 -04:00
Connor Fitzgerald ff0de91ad7 Bump REPO_MSRV to 1.88 (#7960) 2025-07-17 13:00:40 -04:00
Teodor Tanasoaia 33b9f86cc4 Fix detection of local_invocation_id for zero initialization of workgroup memory (#7962) 2025-07-17 12:47:59 -04:00
Andy Leiserson 1b4eca97cf [naga hlsl-out] Factor out some repetitive code 2025-07-11 16:55:46 -07:00
Andy Leiserson bfa7ee8de5 [naga hlsl-out] Handle additional cases of Cx2 matrices
Fixes #4423
2025-07-11 16:55:46 -07:00