Commit Graph
264 Commits
Author SHA1 Message Date
Thierry Bergerandteoxoy 28af245d51 [wgsl-in,ir] Add support for parsing rust-style doc comments (#6364)
* [wgsl-in,ir] add support for parsing rust-style doc comments

* rename relevant items to `doc_comments` (or variations of it)

* address comments

* remove `next_until`

* rename `save_doc_comments` to `ignore_doc_comments`

* expand snapshot test and ignore blankspace when accumulating doc comments

* make tokenizer more straightforward

---------

Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2025-06-05 15:13:11 +02:00
Dmitry Zamkovandvalaphee 9c023e5e29 Implement subgroup quad ops (#7683)
* Rudimentary impl of quad ops, impl quad ops for spirv

* Impl quad swap for hlsl, msl and wgsl, finish spv front

* Cargo clippy & cargo fmt, impl valid for quad ops

* Enable quad feature

* Add missing feature to glsl

* Simplifying code by making `SubgroupQuadSwap` an instance of `SubgroupGather`

* Add `GroupNonUniformQuad` spv capability to Vulkan

* Adding GPU tests for quad operations

* Validate that broadcast operations use const invocation ids

* Added changelog entry

---------

Co-authored-by: valaphee <32491319+valaphee@users.noreply.github.com>
2025-05-26 09:32:01 +02:00
Dmitry ZamkovandAndreas Reich 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
Zachary Harrold 35f131ff10 Remove default features from petgraph (#7591) 2025-04-23 03:30:36 +00:00
Jim Blandy 5573c57393 [naga wgsl-in] Properly convert arguments to atomic operations. (#7573) 2025-04-21 12:27:02 -04:00
Phena Ildanach d2ab981a76 [naga spv-in] Update supported capabilities list (#7575) 2025-04-18 21:26:45 +00:00
bf8cc43a15 Add stderr and termcolor features to Naga (#7482)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
2025-04-18 21:06:22 +00:00
Jim Blandy a9a3ea3a41 [naga wgsl-in] Convert textureStore values correctly.
Apply necessary automatic conversions to the `value` argument of
`textureStore`.
2025-04-18 12:56:51 -07:00
Jim Blandy 5304c3ca4a [naga wgsl-in] Apply automatic conversions to sampling arguments.
Properly apply WGSL's automatic conversions to the arguments
to texture sampling functions.

Introduce helper function `Lowerer::expression_with_leaf_scalar`.

Although this can't affect behavior, use
`Lowerer::expression_for_abstract` for the `image` and `sampler`
arguments, simply because we want to move away from
`Lower::expression`'s automatic concretization, and move towards
having callers say explicitly what sort of conversions they need.

Although this can't affect behavior, use
`Lowerer::expression_with_leaf_scalar` for the `offset` argument, so
that the code spells out that this requires an `i32` value, rather
than depending on blind concretization giving it that.

Continue to use `Lowerer::expression` for `gather` and `array_index`,
since those happen to behave correctly with blind concretization, and
can be cleaned up later.

Fixes #7427.
2025-04-18 11:56:34 -07:00
Jim Blandy 6cd6561884 [naga wgsl-in] Minor cleanup to Lowerer::texture_sample_helper.
Use deferred initialization instead of building tuples, so that match
arms can provide values by name, not by position within a tuple.
2025-04-18 11:56:34 -07:00
Erich Gubler 65c06c2b21 feat(naga): add pack4x{I,U}8Clamp built-ins 2025-04-16 15:07:11 -04:00
Jim Blandy fd4eb67877 [naga wgsl-in] Try out new use convention.
Change `naga::front::wgsl::lower` to `use` `ir` and `proc`,
and then qualify identifiers with that instead of `crate`.

This is strictly fiddling with `use` directives and name
qualification, with the concomitant formatting changes; there should
be no change to the module's behavior or meaning.
2025-04-16 08:25:14 -07:00
Andy Leiserson 09178f2400 [naga] Track globals used directly by a named expression (#7540) 2025-04-15 15:01:19 -04:00
Teodor Tanasoaia 3805768cb4 [naga] mark readonly_and_readwrite_storage_textures & packed_4x8_integer_dot_product language extensions as implemented (#7543) 2025-04-15 09:30:56 -04:00
Robert Bamler c7d0af156d Implement dot4I8Packed and dot4U8Packed
Closes #7481.

This implementation roughly follows approach 2 outlined in #7481, i.e.,
it adds a polyfill for the signed and unsigned dot product of packed
vectors for each platform. It doesn't use the specialized instructions
that are available for this operation on SPIR-V (with capability
DotProductInput4x8BitPacked).
2025-04-11 13:32:10 +02:00
Andy Leiserson 2a2c851c40 [naga] Two structs with the same members are not equivalent
Fixes #5796
2025-04-10 19:11:56 +02:00
Andy Leiserson 14b5838a00 [naga] Rename TypeInner::equivalent to non_struct_equivalent 2025-04-10 19:11:56 +02:00
Jim Blandy aad187f52f [naga wgsl] New TypeContext method write_unnamed_struct.
When asked to generate WGSL for `TypeInner::Struct`, rather than
unconditionally calling `unreachable!`, defer to a new `TypeContext`
method, `write_unnamed_struct`.

Provide appropriate `write_unnamed_struct` implementations:

- In the WGSL backend, implement this as `unreachable!`, since the WGSL
  backend should always know the proper name to use for a struct.

- For diagnostic messages, generate something human-readable that
  indicates that some struct type was encountered.

- For logging and debugging, defer to `TypeInner`'s `Debug`
  implementation.
2025-04-09 16:48:49 -04:00
Jim Blandy e3b005ea82 [naga wgsl-in] Avoid crashes when logging types.
In `naga::front::wgsl::lower`, change logging in
`ExpressionContext::automatic_conversion_consensus` to use
`TypeResolution`s instead of `TypeInner`s, so that structs don't cause
a crash.
2025-04-09 16:48:49 -04:00
Jim Blandy 59db4a6d62 [naga wgsl-in] Don't panic printing struct types for initializers.
When an initializer has the wrong type and it's a struct, don't panic
trying to format its type for the error message.
2025-04-09 16:48:49 -04:00
Jim Blandy 2f7698d390 [naga wgsl-in] Don't panic printing struct types for conversions.
When a type conversion expression is ill-formed and the operand is a
struct type, don't panic trying to format the operand's type for the
error message.
2025-04-09 16:48:49 -04:00
Jim Blandy b837db37ad [naga wgsl-in] Handle struct types in error messages properly.
Don't try to use `&TypeInner` values to generate error messages, since
`&TypeInner` cannot represent struct types in WGSL - they must be
referred to by name, and only `Type` knows the type's name. Using
`Handle<Type>` or `TypeResolution` works fine, so use that instead.

Add a new `Display` impl for `DiagnosticDisplay` for `TypeResolution`.

Fixes #7495.
2025-04-09 16:48:49 -04:00
Jim Blandy a611f72e56 [naga wgsl-in] Move Expression::Math construction into a helper.
In `naga::front::wgsl`, add a new helper method,
`Lowerer::math_function_helper`, that constructs `Expression::Math`
expressions for calls to `MathFunction` builtins. Use this helper in
`Lowerer::call`.
2025-04-07 16:53:50 -04:00
Jim Blandy b9ac282518 [naga wgsl-in] In Lowerer, rename some argument types.
Since we have moved some code out into separate functions, we have
less context to compete with, so we can use simpler names for the
arguments.

This commit is just renaming.
2025-04-07 16:53:50 -04:00
Jim Blandy 10145efed4 [naga wgsl-in] In Lowerer, abstract out overload resolution.
In `naga::front::wgsl::lower::Lowerer`, add a new helper method,
`resolve_overloads`, that selects the appropriate rule for a given
list of of arguments from an overload set.

Use this helper in the `call` method when building `Math`
expressions.

This is just code motion, and should have no effect on behavior.
2025-04-07 16:53:50 -04:00
Jim Blandy f7dde7e9a0 [naga wgsl-in] In Lowerer, add helper for automatic conversions.
In `naga::front::wgsl::lower::Lowerer`, add a new helper method,
`apply_automatic_conversions_for_call`, that applies the conversions
necessary to pass a given set of arguments to a given overload.

Use this helper in the `call` method when building `Math`
expressions.

This is just code motion, and should have no effect on behavior.
2025-04-07 16:53:50 -04:00
Jim Blandy 62e0272537 [naga wgsl-in] In Lowerer, expand role of lowered arguments vector.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, use `lowered_arguments` for both the original Naga IR
argument expressions and their counterparts after applying automatic
conversions.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy fc1ebc481d [naga wgsl-in] In Lowerer, rename unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, rename `unconverted_arguments` to `lowered_arguments`.

No change to behavior. This is a minor refactor that prepares for
later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy c50f8c32ea [naga wgsl-in] In Lowerer, check arity with unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, use `unconverted_arguments` to check the number of
arguments to the call. This means that `arguments` is never used in
this branch once we have built `unconverted_arguments`.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy f06ba9a528 [naga wgsl-in] In Lowerer::call, prefer unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, replace some uses of the `arguments` vector with
uses of `unconverted_arguments`.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy 20c2f8d8c1 [naga wgsl-in] In Lowerer::call, precompute unconverted arg list.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, build the vector of lowered but not yet converted
argument expressions completely before starting overload resolution.
Then iterate over those lowered arguments, not the ast arguments.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy dec819899a [naga wgsl-in] Minor cleanup to math function lowering.
In `naga::front::wgsl::lower::Lowerer::call`, use only the
`unconverted_arguments` vector, rather that using both `arguments` and
`unconverted_arguments`.
2025-04-07 16:53:50 -04:00
Erich Gubler 1b51f0aa40 feat(naga): add UnimplementedEnableExtension::Subgroups 2025-04-07 11:48:41 -07:00
Erich Gubler b7711e56ad refactor(naga): order ImplementedEnableExtension::F16 first 2025-04-07 11:48:41 -07:00
Jim Blandy 7da699608d [naga] Support MathFunction overloads correctly.
Define a new trait, `proc::builtins::OverloadSet`, for types that
represent a Naga IR builtin function's set of overloads. The
`OverloadSet` trait includes operations needed to validate calls,
choose automatic type conversions, and generate diagnostics.

Add a new function, `ir::MathFunction::overloads`, which returns the
given `MathFunction`'s set of overloads as an `impl OverloadSet`
value. Use this in the WGSL front end, the validator, and the
typifier.

To support `MathFunction::overloads`, provide two implementations
of `OverloadSet`:

- `List` is flexible but verbose.

- `Regular` is concise but more restrictive.

Some snapshot output is affected because `TypeResolution::Handle`
values turn into `TypeResolution::Value`, since the function database
constructs the return type directly.

To work around #7405, avoid offering abstract-typed overloads of some
functions.

This addresses #6443 for `MathFunction`, although that issue covers
other categories of operations as well.
2025-04-02 18:27:19 -04:00
Jim Blandy d19e3b2b3e [naga wgsl-in] Minor doc fix. 2025-04-02 18:27:19 -04:00
Jim Blandy def9d7142a [naga wgsl-in] Introduce ExpressionContext::is_const helper.
In `naga::front::wgsl::lower`, add a new method,
`ExpressionContext::is_const`, for looking up the constness of a given
expression. Change existing code to use it.
2025-04-02 18:27:19 -04:00
Jim Blandy 6dcccc40a1 [naga] Move predeclared type name generation to common code.
Add a new module, `naga::common::predeclared`, which implements a new
`struct_name` method on `naga::ir::PredeclaredType`, to produce the
name of the struct type corresponding to that `PredeclaredType` value.
Use this new method in `naga::front::type_gen`.
2025-04-02 18:27:19 -04:00
Jim Blandy f11b3b98e3 [naga] Move TypeInner::automatically_converts_to into proc.
Make the associated function `TypeInner::automatically_converts_to`
available outside the WGSL front end by moving it into the
`proc::type_methods` module.
2025-04-02 18:27:19 -04:00
Andy Leiserson 2c777f79f0 [naga wgsl-in] vecN() constructors and let type conversions (#7367)
* Support `vecN()` constructors (fixes #7356)
* Apply automatic conversions to the initializer for `let` bindings
2025-04-02 15:52:40 +00:00
sagudev 801b29cf01 Do not add local const to named expr
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-04-02 07:53:13 -07:00
Andy Leiserson c7c79a0dc9 Disallow taking the address of a vector component (#7284) 2025-03-28 11:32:06 +01:00
Zachary Harrold 175b66c796 Update codespan-reporting to 0.12 (#7398)
* Update `codespan-reporting` to 0.12

* Use explicit path for `term::termcolor`

* Revert changes to `Cargo.lock`
2025-03-26 02:10:30 +00:00
Erich Gubler 958528fb14 fix(wgsl-in): increase brace limit to 127 (#7412) 2025-03-24 21:43:21 +00:00
Christian Legnitto 10cd1ccd8c [spv_in] Finish emitter after function arguments (#7397)
Fixes https://github.com/gfx-rs/wgpu/issues/7358.
2025-03-24 10:36:30 +01:00
Bruce Mitchener edd0ef80af Fix clippy::manual_repeat_n lints (#7394) 2025-03-22 16:18:34 +00:00
c6286791fe feat: implement F16 support in shaders (#5701)
Co-authored-by: FL33TW00D <fleetwoodpersonal@gmail.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: ErichDonGubler <erichdongubler@gmail.com>
2025-03-19 16:26:50 +00:00
Jim Blandy 45b0df6adf [naga wgsl-in] Tweak logging in front::wgsl::lower::conversion. 2025-03-19 11:21:02 -04:00
Jim Blandy e82f52135b [naga wgsl-in] Use common type-formatting code.
Remove the `naga::front::wgsl::to_wgsl` module. Instead, use the
implementations of `naga::common::wgsl`'s `TryToWgsl` and
`TypeContext` traits.
2025-03-19 11:21:02 -04:00
Jim Blandy 3b401670ae [naga wgsl-in] Clean up use directives in front::wgsl::error.
Put the `use` directives at the top of `front::wgsl::error` in the
usual order:
- identifiers defined by this crate itself
- identifiers defined  by other crates
- identifiers from the standard library

This commit should cause no change in behavior.
2025-03-19 11:21:02 -04:00