Commit Graph
31 Commits
Author SHA1 Message Date
Bruce Mitchener bae0e70e8d Fix clippy::unneeded_struct_pattern lints (#7136) 2025-02-14 01:32:21 -05:00
Jamie Nicol b477c66a9d [naga wgsl-in] Do not attempt automatic type conversion for non-abstract types
Attempting to convert a non-abstract type will always fail, which can
result in unrelated errors being misreported as type conversion
errors. For example, in #7035 we made it so that abstract types can be
used as return values. This changed the final testcase in the
invalid_functions() test to fail due to failing to convert a u32 to an
atomic<u32>, rather than with a NonConstructibleReturnType error.

This patch makes it so that we do not attempt to convert non-abstract
types in the first place. This avoids the AutoConversion error for
that testcase, meaning the NonConstructibleReturnType is once again
reported.

Various callsites of try_automatic_conversions() have been updated to
ensure they still return an InitializationTypeMismatch error if the
types are mismatched, even if try_automatic_conversions() succeeds (eg
when conversion was not attempted due to the type being concrete). To
reduce code duplication these callsites were all adapted to use the
existing type_and_init() helper function.

Lastly, a couple of tests that expected to result in a AutoConversion
error have been adjusted to ensure this still occurs, by ensuring the
type used is abstract.
2025-02-12 15:10:57 +00:00
Shaye Garg d7a42933a5 [naga] Error on duplicate fields in structs (#7088)
* error in wgsl-in

* changelog

* add test
2025-02-12 03:27:55 +00:00
Jamie Nicol c07fab2c12 [naga wgsl-in] Allow abstract literals to be used as return values
When lowering a return statement, call expression_for_abstract()
rather than expression() to avoid concretizing the return value. Then,
if the function has a return type, call try_automatic_conversions() to
attempt to convert our return value to the correct type.

This has the unfortunate side effect that some errors that would have
been caught by the validator are instead encountered as conversion
errors by the parser. This may result in a slightly less descriptive
error message in some cases. (See the change to the invalid_functions()
test, for example.)
2025-02-07 11:44:03 -08:00
Jamie Nicol b245b358f5 [naga] Don't treat Emit statements as return statements during ensure_block_returns() (#7013) 2025-01-28 10:48:40 -05:00
SamsonandErich Gubler 04aff59a14 [naga] implement pointer_composite_access WGSL language extension (#6913)
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
2025-01-23 13:29:17 -05:00
b626020769 [naga] parse and validate @must_use attribute (#6801)
* feat: parse and enforce `@must_use` attribute

* feat: refuse `@must_use` of void function

* generated naga/tests/out/ir

* revert extraneous changes

* fix clippy

* update repeated attribute error to trunk format

* struct members can't have `@must_use`

* review fixes

* Remove must_use from FunctionResult and revert the related changes

---------

Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
Co-authored-by: Jamie Nicol <jnicol@mozilla.com>
2025-01-20 18:09:36 +00:00
Erich Gubler 1963eb7c3f diag(wgsl-in): use backticks for code-like text in WGSL FE errors (#6908) 2025-01-13 22:13:40 +00:00
Erich Gubler cc741735df fix(wgsl-in): print debug repr. of unexpected tokens (#6907) 2025-01-13 16:43:41 -05:00
Jamie Nicol 78e35c4a7e [naga wgsl-in] Disallow named component expression for matrix types
The WGSL spec only allows named component expressions when the base
type is a vector or a structure, so this patch removes support for it
for matrices. Additionally tests which used this for matrices have
been updated to use indexing expressions instead, and a test has been
added to ensure a named component expression on a matrix results in an
error.
2025-01-07 13:46:41 +01:00
Jim Blandy 4f22f8d7b6 [naga wgsl-in] Apply automatic conversions to values being assigned.
Apply automatic conversions to the right-hand sides of assignment and
compound assignment statements.

Fix `try_automatic_conversion_for_leaf_scalar` to handle arrays,
not just scalars, vectors, and matrices. Previously this was only used
for converting the right-hand sides of bit shift operators to `u32`,
and bit shift operators don't support arrays. But now we're using
`try_automatic_conversion_for_leaf_scalar` for ordinary assignments,
and you can assign arrays.

Update a test of propagating source code spans through compaction.
This test needs validation to report an error, but this commit's fix
causes the error in the test to be detected in the front end, which is
too early to exercise compaction. Use a new error that the front end
still won't notice.
2025-01-06 17:29:58 -05:00
Erich Gubler 6c9f93b7de diag(naga): clarify select built-in type mismatch messages 2024-12-20 10:34:20 -05:00
Jim Blandy ed3006ccc6 [naga spv-out] Spill arrays and matrices for runtime indexing.
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga::back::spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes #6358.
Fixes #4337.
Alternative to #6362.
2024-10-11 08:27:15 -07:00
2d82054ae4 [wgsl-in, spv-out] Allow dynamic indexing of arrays by value.
Bring https://github.com/gfx-rs/naga/pull/723 back from the dead.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-10-02 18:07:02 -07:00
Samson 4e9a2a5003 [naga wgsl] Impl const_assert (#6198)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-02 17:37:04 +00:00
Samson 105cb9db31 [naga wgsl-in] Proper singular generic in vec and matrix (#6189)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-02 14:04:51 +02:00
Samson 585f4a1036 [naga wgsl] all swizzle components must be either color or dimension (#6187) 2024-08-31 11:08:34 +02:00
Samson 34bb9e4ceb [naga wgsl] Implement local const declarations (#6156) 2024-08-30 11:55:03 +02:00
Teodor TanasoaiaandJim Blandy f949ea69c4 [wgsl-in] add support for override declarations (#4793)
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-04-05 18:07:41 +02:00
Erich Gubler b21a3265de fix(wgsl-in)!: limit brace recursion 2024-04-03 15:54:43 -04:00
veroandConnor Fitzgerald 4e6f873da5 Add shader I64 and U64 support (#5154)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-03-12 12:34:06 +01:00
dependabot[bot]andConnor Fitzgerald 744454b9e2 Bump Many Dependencies and MSRV (#5241)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2024-02-27 14:43:05 -05:00
Connor FitzgeraldandAndreas Reich faed98b45c Add typos to Repository CI (#5191)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-02-05 12:30:29 -05:00
Jim Blandy d9d051b7a5 [naga wgsl] Let unary operators accept and produce abstract types.
Fixes #4445.
Fixes #4492.
Fixes #4435.
2023-12-14 10:54:46 +01:00
Jim Blandy 1676ee0dc0 [naga wgsl-in] Automatic conversions for global var initializers. 2023-12-06 10:35:21 +01:00
Teodor Tanasoaia dd7e33250b fix expected error message 2023-12-04 14:06:33 +01:00
Jim Blandy 33339e46ce [naga wgsl-in] Drop spanless labels from front-end error messages.
When a label in a WGSL front end error has an undefined span, omit the
label from the error message. This is not great, but because of the
way Naga IR represents local variable references it is hard to get the
right span, and omitting the label better than panicking in `unwrap`,
since the error message has a general message anyway.
2023-12-04 12:22:13 +01:00
Jim Blandy 07b83ab6c0 [naga wgsl-in] Use a better span for errors in constructors.
When reporting errors in construction expressions, use the span of the
constructor itself (that is, the type name) in preference to the span
of the overall expression. This makes errors easier to follow.
2023-12-04 12:20:22 +01:00
Jim Blandy 5a3887a49f [naga wgsl-in] Constructors with types don't make abstract values.
When a constructor builtin has an explicit type parameter, like
`mat2x2<f32>`, it should not produce an abstract matrix, even if its
arguments are abstract.
2023-11-29 08:58:47 +01:00
Jim Blandy 601f235b34 [naga wgsl-in] Implement abstract types for consts, constructors. 2023-11-29 08:58:47 +01:00
Connor Fitzgerald 06e9876adf Move to A Single Example Executable (#4756)
* Move to combined examples

* Fix paths

* Curtail some tests

* Format

* Clippy

* Fix wasm

* Refactor main for wasm

* Style sheet

* Readme

* Lock
2023-11-23 05:26:42 -05:00