Commit Graph
671 Commits
Author SHA1 Message Date
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
Jim Blandy 410ab29a24 [naga] Compact out unused anonymous overrides.
In compaction, remove unused anonymous overrides.

Since overrides are no longer used by definition, include override
initialization expressions in the tandem traversal of types and global
expressions.

To simplify overload processing, we plan to make all override-sized
arrays refer to their lengths via actual `Override`s. Arrays with
non-identifier override expressions as their lengths would refer to
anonymous `Override`s with interesting `init` expressions. But in
order to avoid re-introducing #6788, we need compaction to remove
anonymous overrides.
2025-02-06 19:40:04 -08:00
Jim Blandy 936d882d31 [naga] Use r#override instead of override_.
Use the standard Rust reserved identifier syntax for `override`,
rather than the non-standard trailing underscore.
2025-02-06 19:40:04 -08:00
Jim Blandy 9d7ec93d28 [naga] Simplify iterator construction in type_expression_tandem. (#7070)
Rather than reversing two iterators and then zipping them, zip them
first and then reverse the result.

However, zipped iterators are only reversible if the inputs implement
`ExactSizeIterator`, so make `UniqueArena::iter` promise that as well.

For consistency, make `Arena::iter` also promise to return an
`ExactSizeIterator`.
2025-02-06 20:41:55 -05:00
Vecvec d34707ec3f Rename instance_id & instance_custom_index to instance_index & instance_custom_data (#6780) 2025-02-05 18:23:22 +01:00
Jim Blandy 8fb94d9c08 [naga] Require hashbrown's serde feature as a dev-dependency.
Add `hashbrown` with the `"serde"` feature as a development dependency
for Naga. Regardless of whether Naga's `deserialize` feature is
enabled, the snapshot tests need to deserialize parameters saved in
files as RON text.

It would also suffice to use `std::collections::HashSet` in the
snapshot tests, although we would need to build a `naga::FashHashSet`
from the std `HashSet` at one point. Adding the dev-dependency seems
slightly simpler.

Fixes #7038.
2025-02-05 08:44:23 -08:00
Jamie NicolandTeodor Tanasoaia 4e7d892317 [naga msl-out hlsl-out] Improve workaround for infinite loops causing undefined behaviour (#6929)
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2025-01-31 15:27:52 -05:00
Vecvec 7cde4707ec Fix hlsl storage format generation (#6993) 2025-01-31 16:31:03 +01:00
Connor Fitzgerald 8caefceb8e Add rust-version to more crates (#7036) 2025-01-31 10:33:10 +01:00
@brody4hire - C. Jonathan Brody a8cc83e17a avoid default features in many dependencies (etc.) (#7031) 2025-01-30 10:30:42 -05:00
@brody4hire - C. Jonathan Brody 55c33b0372 update MapErrWithSpan to be pub(crate) trait 2025-01-29 20:22:56 -05:00
@brody4hire - C. Jonathan Brody a1185b21cc remove std::error::Error constraint not needed from AddSpan impl 2025-01-29 20:22:56 -05:00
@brody4hire - C. Jonathan Brody 58cbb93213 add blank lines & returned output type comment to MapErrWithSpan 2025-01-29 20:22:56 -05:00
@brody4hire - C. Jonathan Brody 1f2cc66f4e add blank lines & returned output type comment to AddSpan 2025-01-29 20:22:56 -05:00
@brody4hire - C. Jonathan Brody d7ed0c5290 keep internal AddSpan trait & impl together 2025-01-29 20:22:56 -05:00
Jamie Nicol 6c8d0b061c [naga] Restore return statement at end of functions without return types (#7021) 2025-01-29 13:54:49 -05:00
Erich Gubler e0ebd1b266 diag(naga): clarify ImageStore type mismatch cases (#6791) 2025-01-29 11:13:36 -05:00
Jamie Nicol d9777355c9 [naga const_eval] Ensure eval_zero_value_and_splat() lowers a Splat of a ZeroValue correctly
eval_zero_value_and_splat() is called to lower ZeroValue and Splat
expressions into Literal and Compose expressions. However, in its
current form it either calls splat() *or* eval_zero_value_impl()
depending on the expression type.

splat() will lower a Splat of a scalar ZeroValue to a vector
ZeroValue, which means eval_zero_value_and_splat() can still return a
ZeroValue. Its callers, such as binary_op(), are unable to handle this
ZeroValue, so cannot proceed with const evaluation.

This patch makes it so that eval_zero_value_and_splat() will first
call splat(), *and then* call eval_zero_value_impl(), which will lower
the vector ZeroValue returned by splat() into a Compose of Literals.
Callers such as binary_op() are perfectly able to handle this Compose,
so can now proceed with const evaluation.
2025-01-29 06:55:48 -08:00
Jim Blandy 2a456f5c7b [naga] Move methods on TypeInner and friends into their own module. (#7018) 2025-01-28 19:47:40 -05:00
Erich Gubler 65d499f302 Clean up naga's xtask a bit (#7014) 2025-01-28 16:26:38 +00: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
Jamie Nicol 34cfee6ebc [naga wgsl-in] Return error if wgsl parser recurses too deeply.
It's currently trivial to write a shader that causes the wgsl parser
to recurse too deeply and overflow the stack. This patch makes the
parser return an error when recursing too deeply, before the stack
overflows.

It makes use of a new function Parser::track_recursion(). This
increments a counter returning an error if the value is too high,
before calling the user-provided function and returning its return
value after decrementing the counter again.

Any recursively-called functions can simply be modified to call
track_recursion(), providing their previous contents in a closure as
the argument. All instances of recursion during parsing call through
either Parser::statement(), Parser::unary_expression(), or
Parser::type_decl(), so only these functions have been updated as
described in order to keep the patch as unobtrusive as possible.

A value of 256 has been chosen as the recursion limit, but can be
later tweaked if required. This avoids the stack overflow in the
testcase attached to issue #5757.
2025-01-28 15:00:26 +00:00
@brody4hire - C. Jonathan BrodyandConnor Fitzgerald df54acc05d use hashbrown in more crates (etc.) (#6938)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-27 11:50:33 -05:00
Reina_Sakiria 5386d38113 [naga spv-in] OpImageWrite allows input other than Vector4. (#6630)
* fix(naga-spv-in): Image write value type is invalid.

* fix(naga-spv-in): input vector 4 may case error

* fix(naga-spv-in): Incorrect swizzle pattern for vector size 3.
2025-01-24 16:59:58 +01: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
Teodor Tanasoaia a8bd1fe1ac [d3d12] bound check dynamic buffers (#6931)
To achieve this for dynamic storage buffers we changed the way we bind them. They now go in root tables and we pass the offset via a root constant.
2025-01-23 17:18:36 +00:00
Kent Slaney 3cd2e7caf0 [naga] Remove unused types and global expressions in a single pass.
In compaction, correctly identify unused types and global expressions,
rather than treating all global expressions referred to by
`PendingArraySize::Expression` array lengths as used even if the array
type itself is not.

This is tested by checking that going from expression to type and
back, along with the opposite, is correctly marked as used. It also
checks that adding an unused type using an expression gets compacted
out.

See the comments on `ModuleTracer::type_expression_tandem` for
details.

Fixes #6788.
2025-01-23 08:11:18 -08:00
Jamie Nicol 0282d61f91 [naga hlsl-out] Handle array types for function return values and calls (#6971) 2025-01-23 16:56:18 +01:00
Jim Blandy e86ed8b6c8 [naga] Document arena ordering requirements. 2025-01-22 19:33:05 -08:00
Connor Fitzgerald 436f716715 Unconditionally Generate Bindless Samplers in DX12 (#6766) 2025-01-21 14:24:03 -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
Samson 6e7d3c4b3e [naga] Explicitly use global const ctx in offset (#6945)
* Fix as_const on expr ctx

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

* fixup

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

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-01-20 18:59:11 +01:00
Jamie Nicol 1f939e1c44 [naga msl-out] Avoid undefined behaviour due to signed integer overflow (#6959)
Signed integer overflow is undefined behaviour in MSL. However, signed
integers are defined to be two's complement. This allows us to cast
signed values to their corresponding unsigned type, perform the
arithmetic on these unsigned values (which has defined overflow
behaviour) then cast the result back to signed.

Care must be taken when emitting the isign polyfill, which uses
metal::select(). We must ensure the -1, 0, and 1 literals used as
inputs to select() have the correct width, else bitcasting the output
of select() will fail due to mismatched widths.
2025-01-20 18:11:27 +01:00
the letter Landturbocrime 0b0cb8fec9 remove unused CallError::ResultValue (#6944)
Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
2025-01-20 16:29:12 +01:00
VecvecandConnor Fitzgerald bdef8c0407 [spirv] Stop naga causing undefined behavior in rayQueryGet*Intersection (#6752)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-17 00:04:33 +00:00
Connor Fitzgerald 779261e64d Release v24 (#6923) 2025-01-15 16:29:22 -05:00
Kent SlaneyandConnor Fitzgerald a32467041d fix >= in template list matching for a<b>=c (#6898)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-15 17:25:04 +00:00
atlv be95178709 64 bit image atomics (#5537) 2025-01-15 08:05:13 -05:00
sagudev ea5d3b953f Add test
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-01-15 11:14:17 +01:00
sagudev a65216cabe [naga] wgsl automatic conversion for override initializers
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-01-15 11:14:17 +01:00
sagudev 4576e4d0d2 Refactor init and type handling into separate function from var
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-01-15 11:14:17 +01:00
VecvecandConnor Fitzgerald 21de7f7773 Support DXR in wgpu-hal & naga. (#6777)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-14 21:28:37 -05:00
Jim Blandy bd3e7b676e [naga] Consolidate entry point tracing code. (#6917) 2025-01-14 21:12:52 +00:00
Jim Blandy aa7bec65b9 [naga] Remove vestigial false. (#6909) 2025-01-13 23:02:47 +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
Teodor Tanasoaia 214396a807 [spv] output the right capability for subgroupBroadcast (#6904) 2025-01-13 14:29:04 -05:00
18471d8e78 Image atomics support (#6706)
* Image atomics support

* Address feedback

* fix merge

* Fixes

* Add a couple tests

* Update wgpu-types/src/lib.rs

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>

* feedback

* feedback

* glsl

* glsl fix

* fix glsl

* fix fix

* fix fix fic

* fix?

* fix

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2025-01-13 15:37:12 +00:00
dependabot[bot]andConnor Fitzgerald a5704d9a1c chore(deps): bump the patch-updates group with 14 updates (#6899)
* chore(deps): bump the patch-updates group with 14 updates

Bumps the patch-updates group with 14 updates:

| Package | From | To |
| --- | --- | --- |
| [bitflags](https://github.com/bitflags/bitflags) | `2.6.0` | `2.7.0` |
| [futures-lite](https://github.com/smol-rs/futures-lite) | `2.5.0` | `2.6.0` |
| [thiserror](https://github.com/dtolnay/thiserror) | `2.0.10` | `2.0.11` |
| [glutin_wgl_sys](https://github.com/rust-windowing/glutin) | `0.6.0` | `0.6.1` |
| [petgraph](https://github.com/petgraph/petgraph) | `0.6.5` | `0.7.1` |
| [syn](https://github.com/dtolnay/syn) | `2.0.95` | `2.0.96` |
| [cc](https://github.com/rust-lang/cc-rs) | `1.2.7` | `1.2.9` |
| [clap](https://github.com/clap-rs/clap) | `4.5.24` | `4.5.26` |
| [clap_builder](https://github.com/clap-rs/clap) | `4.5.24` | `4.5.26` |
| [const_panic](https://github.com/rodrimati1992/const_panic) | `0.2.11` | `0.2.12` |
| [prettyplease](https://github.com/dtolnay/prettyplease) | `0.2.27` | `0.2.29` |
| [proc-macro2](https://github.com/dtolnay/proc-macro2) | `1.0.92` | `1.0.93` |
| [uuid](https://github.com/uuid-rs/uuid) | `1.11.0` | `1.11.1` |
| [winnow](https://github.com/winnow-rs/winnow) | `0.6.22` | `0.6.24` |


Updates `bitflags` from 2.6.0 to 2.7.0
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.6.0...2.7.0)

Updates `futures-lite` from 2.5.0 to 2.6.0
- [Release notes](https://github.com/smol-rs/futures-lite/releases)
- [Changelog](https://github.com/smol-rs/futures-lite/blob/master/CHANGELOG.md)
- [Commits](https://github.com/smol-rs/futures-lite/compare/v2.5.0...v2.6.0)

Updates `thiserror` from 2.0.10 to 2.0.11
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/2.0.10...2.0.11)

Updates `glutin_wgl_sys` from 0.6.0 to 0.6.1
- [Release notes](https://github.com/rust-windowing/glutin/releases)
- [Changelog](https://github.com/rust-windowing/glutin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-windowing/glutin/commits)

Updates `petgraph` from 0.6.5 to 0.7.1
- [Changelog](https://github.com/petgraph/petgraph/blob/master/RELEASES.rst)
- [Commits](https://github.com/petgraph/petgraph/compare/petgraph@v0.6.5...petgraph@v0.7.1)

Updates `syn` from 2.0.95 to 2.0.96
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.95...2.0.96)

Updates `cc` from 1.2.7 to 1.2.9
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.7...cc-v1.2.9)

Updates `clap` from 4.5.24 to 4.5.26
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.24...clap_complete-v4.5.26)

Updates `clap_builder` from 4.5.24 to 4.5.26
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.5.24...v4.5.26)

Updates `const_panic` from 0.2.11 to 0.2.12
- [Release notes](https://github.com/rodrimati1992/const_panic/releases)
- [Changelog](https://github.com/rodrimati1992/const_panic/blob/main/Changelog.md)
- [Commits](https://github.com/rodrimati1992/const_panic/commits/0.2.12)

Updates `prettyplease` from 0.2.27 to 0.2.29
- [Release notes](https://github.com/dtolnay/prettyplease/releases)
- [Commits](https://github.com/dtolnay/prettyplease/compare/0.2.27...0.2.29)

Updates `proc-macro2` from 1.0.92 to 1.0.93
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.92...1.0.93)

Updates `uuid` from 1.11.0 to 1.11.1
- [Release notes](https://github.com/uuid-rs/uuid/releases)
- [Commits](https://github.com/uuid-rs/uuid/compare/1.11.0...1.11.1)

Updates `winnow` from 0.6.22 to 0.6.24
- [Changelog](https://github.com/winnow-rs/winnow/blob/main/CHANGELOG.md)
- [Commits](https://github.com/winnow-rs/winnow/compare/v0.6.22...v0.6.24)

---
updated-dependencies:
- dependency-name: bitflags
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: futures-lite
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: glutin_wgl_sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: petgraph
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: cc
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: clap
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: clap_builder
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: const_panic
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: prettyplease
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: proc-macro2
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: uuid
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: winnow
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update naga/Cargo.toml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-13 03:15:57 +00:00
Zachary HarroldandConnor Fitzgerald 05e62f96f9 Add no_std support to wgpu-types (#6892)
* Initial Commit

* Remove now-redundant `format` import

* Update CHANGELOG.md

* Appropriately feature-gate `texture_format_serialize` test

* Remove `alloc` feature

Also fixed some documentation links and a Wasm `std` import

* Revert change to `Serialize` for `TextureFormat`

* Combine use statements

* Switch from `PathBuf` to `String`

* Consider environmental flags as unset on `no_std`

* Fix missing `format!`

* Add new CI tasks for `no_std` testing

* Comment out known failing CI matrix option

* Update all usage of `Dx12Compiler::DynamicDxc`

* Added comments to CI

* Update .github/workflows/ci.yml

* Update .github/workflows/ci.yml

* Update .github/workflows/ci.yml

* CI Touchups

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-12 05:03:47 +00:00