Commit Graph

8278 Commits

Author SHA1 Message Date
Jim Blandy
0f17ad6455 [naga] Add new function, GuardedIndex::from_expression.
Pull out the code to build a `naga::proc::index::GuardedIndex` from a
`Handle<Expression>` into its own function,
`GuardedIndex::from_expression`. Use that function in
`GuardedIndex::try_resolve_to_constant`.
2024-10-11 08:27:15 -07:00
Jim Blandy
0392613b5a [naga spv-out] Abstract out NumericType::from_inner.
Pull out the code for building a `naga:🔙:spv::NumericType` from a
`TypeInner` into its own function, `NumericType::from_inner`. Use that
in `LocalType::from_inner`.
2024-10-11 08:27:15 -07:00
Jim Blandy
4427ff9622 [naga spv-out] Use crate::proc::index::GuardedIndex.
Replace qualified paths with a `use` directive.
2024-10-11 08:27:15 -07:00
Jim Blandy
57b8858f96 [naga spv-out] Gather array, matrix, and vector cases.
This commit is just code motion.
2024-10-11 08:27:15 -07:00
Jim Blandy
f9075fc4b8 [naga] Test access to a member/element through a pointer. 2024-10-11 08:27:15 -07:00
Jim Blandy
b9f1e4a266 [naga spv-out] Clean up write_expression_pointer type adjustment.
Replace the `return_type_override` argument of
`BlockContext::write_expression_pointer` with an enum that says how to
derive the return type from `expr_handle`'s type.

Introduce a new type, `AccessTypeAdjustment`, that covers possible
derivation rules.

This simplifies callers and the callee, in part by making the possible
alternatives less general, and by giving them explicit names (the
variants of the `AccessTypeAdjustment` enum).
2024-10-11 08:27:15 -07:00
Jim Blandy
d034c4b428 [naga spv-out] Move code to load a pointer into its own function.
Introduce a new function,
`naga:🔙:spv::BlockContext::write_checked_load`, that does the
work of `Expression::Load`.

This change is just code motion, and should have no effect on
behavior. The new function will be used in later commits.
2024-10-11 08:27:15 -07:00
Ronny Chan
73764fdc6a
[naga/wgsl-out]: polyfill inverse function (#6385) 2024-10-11 15:56:12 +02:00
Jim Blandy
d70ef62e9e
[wgpu] Revert changes to vendored copy of web-sys from #6377. (#6380)
Revert the changes to the vendored copy of web-sys's WebGPU bindings
made in #6377. The only purpose of vendoring is to pin down our WebGPU
JS bindings, not to allow local changes. And as it turns out, removing
the `max_inter_stage_shader_components` accessor isn't necessary in
order to fix #6290.
2024-10-10 11:24:49 -04:00
Jim Blandy
ae52e5dc96 [naga spv-out] Delete BlockContext::is_intermediate; use types.
Delete the function `BlockContext::is_intermediate`. Instead, have
`Access` and `AccessIndex` instructions decide whether to defer code
generation based on the type of the base expression: indexing
operations on pointers are deferred; anything else is not.
2024-10-10 07:42:02 -07:00
Jim Blandy
5c6b00886e [naga spv-out] Simplify Writer::get_pointer_id.
Simplify the definition of `naga:🔙:spv::Writer::get_pointer_id`
by using `get_type_id`'s ability to handle `LocalType::Pointer`.

This means that `get_pointer_id` is no longer fallible, and no longer
needs a type arena. Simplify callers, as well as the
`BlockContext::get_pointer_id` convenience function.
2024-10-10 07:41:35 -07:00
Jim Blandy
908e8353a8 [naga spv-out] Expand LocalType to permit pointers to matrices.
In `back::spv`:

- Factor out the numeric variants of `LocalType` into a
  new enum, `NumericType`.

- Split the `Value` variant into `Numeric` and `LocalPointer`
  variants, and let `LocalPointer` point to any numeric type,
  including matrices.

In subsequent commits, we'll need to spill matrices out into temporary
local variables. This means we'll need to generate SPIR-V
pointer-to-matrix types, so `LocalType` needs to be able to represent
that.
2024-10-10 07:41:15 -07:00
Jim Blandy
0392cb783d [naga spv-out] Rename make_local to LocalType::from_inner.
Change the free function `back::spv::make_local` into an associated
function `LocalType::from_inner`.
2024-10-10 07:41:15 -07:00
Asher Jingkong Chen
bf33e481f3
[naga msl-out] Implement atomicCompareExchangeWeak for MSL backend (#6265) 2024-10-10 12:45:24 +02:00
Teodor Tanasoaia
d9178a1876 add more changelog items 2024-10-09 16:39:51 -07:00
Jim Blandy
3693da27f9 [naga spv-out] Bounds-check runtime-sized array access correctly.
Do not neglect to apply bounds checks to indexing operations on
runtime-sized arrays, even when they are accessed via an `AccessIndex`
instruction.

Before this commit, `BlockContext::write_expression_pointer` would not
apply bounds checks to `OpAccessChain` indices provided by an
`AccessIndex` instruction, apparently with the rationale that any
out-of-bounds accesses should have been reported by constant
evaluation.

While it is true that the `index` operand of an `AccessIndex`
expression is known at compile time, and that the WGSL constant
evaluation rules require accesses that can be statically determined to
be out-of-bounds to be shader creation or pipeline creation time
errors, accesses to runtime-sized arrays don't follow this pattern:
even if the index is known, the length with which it must be compared
is not.

Fixes #4441.
2024-10-08 11:53:15 -07:00
Jim Blandy
7283185305 [naga] Extend snapshot tests for bounds checks.
Extend the snapshot tests for bounds checking to cover the case where
a runtime-sized array is indexed by a constant.
2024-10-08 11:53:15 -07:00
Jim Blandy
5a6b749335 [naga spv-out] Let BoundsCheckResult supply the index value.
Let `BoundsCheckResult::Conditional` provide both the condition to
check before carrying out the access, and the index to use for that
access. The `Conditional` variant indicates that we generated a
runtime bounds check, which implies we must have had a SPIR-V id for
the index to pass to that check, so there's no reason not to provide
that to the callers - especially if the bounds check code was able to
reduce it to a known constant.

At the moment, this is not much of a refactor, but later commits will
use `GuardedIndex` in more places, at which point this will avoid a
re-matching and assertion.
2024-10-08 11:53:15 -07:00
Jim Blandy
69ab63ca34 [naga spv-out] Abstract out OpAccessChain index production.
Abstract the code from `write_expression_pointer` to handle one
indexing operation out into its own function,
`BlockContext::write_access_chain_index`.
2024-10-08 11:53:15 -07:00
Jim Blandy
3d85781f05 [naga spv-out] Consolidate code to find index values.
Let the SPIR-V backend use `GuardedIndex::try_resolve_to_constant`,
rather than writing out its definition in `write_restricted_index` and
`write_index_comparison`.

Call `try_resolve_to_constant` in one place, in `write_bounds_check`,
and simply pass the `GuardedIndex` into subroutines.

Reduce `write_restricted_index` and `write_index_comparison` to case
analysis and code generation.

Note that this commit does have a benign effect on SPIR-V snapshot
output for programs like this:

    let one_i = 1i;
    var vec0 = vec3<i32>();
    vec0[one_i] = 1;

The value indexing `vec0` here is an `i32`, but after this commit, the
operand to `OpAccessChain` becomes a `u32` constant (with the same
value).

This is because `write_bounds_check` now calls
`try_resolve_to_constant` itself, rather than deferring this work to
its callees, so it may return `BoundsCheckResult::KnownInBounds` even
when the `Unchecked` policy is in force. This directs the caller,
`write_expression_pointer`, to treat the `OpAccessChain` operand as a
fresh `u32` constant, rather than simply passing through the original
`i32` expression.
2024-10-08 11:53:15 -07:00
Jim Blandy
287ca16b52 [naga spv-out] Abstract extending a bounds check condition chain.
Introduce a new function,
`BlockContext::extend_bounds_check_condition_chain`, which adds a new
boolean condition to the chain of bounds checks guarding an
`OpAccessChain` instruction.
2024-10-08 11:53:15 -07:00
Jim Blandy
21c527a458 [naga spv-out] Doc fix: typo 2024-10-08 11:53:15 -07:00
Jim Blandy
634a97fcb8 [naga spv-out] Abstract out non-uniform binding array access test.
Introduce a new function,
`BlockContext::is_nonuniform_binding_array_access`, which determines
whether a given array access expression means that the `OpAccessChain`
instruction must have a `NonUniform` decoration.
2024-10-08 11:53:15 -07:00
Jim Blandy
58e1946bd6 Document rationale for vendoring WebGPU bindings.
This commit is almost entirely autogenerated changes.
2024-10-08 09:55:03 -07:00
ChosenName
43cb730d58
[naga] added DrawID (#6325) 2024-10-08 13:00:00 +00:00
Erich Gubler
c0fa1bcce5 fix(web)!: remove maxInterStageShaderComponents from vendored web-sys 2024-10-07 07:20:52 -07:00
Erich Gubler
d5082b75ce
refactor(ci): use more descriptive name for Rust formatting (#6369) 2024-10-07 15:05:33 +02:00
Erich Gubler
0a5ed0a1dc
test(ci): include naga/xtask in cargo fmt check (#6367) 2024-10-07 08:49:10 +02:00
dependabot[bot]
f658875e9f
build(deps): bump the patch-updates group with 24 updates (#6374)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-06 23:41:57 -04:00
Jim Blandy
ee0d1703e5 Roll back once_cell to 1.19.0.
Roll back `wgpu`'s dependencies on `once_cell` from 1.20.1 to 1.19.0.

Version 1.20.1 of `once_cell` added a more complex conditional
dependency on `portable-atomic`, which causes `cargo metadata` to
incorrectly list `portable-atomic` as a dependency even though the
given `once_cell` features are not enabled.

The Firefox source tree uses `cargo vet` to enforce supply-chain
auditing. Since `cargo vet` depends on `cargo metadata` to tell it
what crates are going to be included in the tree, the extraneous
dependency above adds `portable-atomic` to the set of sources we must
audit. Since `portable-atomic` is roughly 50kloc, we would like to
avoid this.

Nothing in `wgpu` actually needs `once_cell` 1.20; it was upgraded by
Dependabot. So the simplest workaround for the moment is to roll back
the version.
2024-10-04 13:21:59 -04:00
Jim Blandy
e432980a73 [naga spv-out] Don't emit unreachable blocks that jump into loops.
When generating SPIR-V, avoid generating unreachable blocks following
statements like `break`, `return`, and so on that cause non-local
exits. These unreachable blocks can cause SPIR-V validation to fail.

Fixes #6220.
2024-10-03 21:07:18 -07:00
Jim Blandy
04182c24ec [naga spv-out] Make write_block and its types private.
Make `naga:🔙:spv::BlockContext::write_block` private to
`naga:🔙:spv::block`. Introduce a new `pub(super)` function,
`write_function_body`, for `Writer::write_function` to call.

Make `BlockExit` private to `naga:🔙:spv::block`.

Move `LoopContext` from `naga:🔙:spv` into
`naga:🔙:spv::block`, and make it private.
2024-10-03 21:07:18 -07:00
Imbris
c5a4b4ecc3
Fix unaligned slice::from_raw_parts in gles push contant handling. (#6341) 2024-10-03 20:40:43 +00:00
Jim Blandy
d3e09dd63a [naga spv-out] Consolidate explanation of global wrapping.
Consolidate the explanation of why and how we wrap Naga global
variables in structs to satisfy Vulkan's requirements, and include it
in the documentation for `back::spv::GlobalVariable`.

Clarify `GlobalVariable`'s members documentation.
2024-10-03 10:13:08 -07:00
Erich Gubler
6e528aaf24 style: split (most) string literals over 100-column line width limit 2024-10-03 10:57:28 -04:00
Erich Gubler
9f275f7655 style: remove comments from MathFunction type res. that stop rustfmt 2024-10-03 10:57:28 -04:00
Erich Gubler
25b2b6afa1 style: newline b/w Span::{UNDEFINED, new} 2024-10-03 10:57:28 -04:00
Erich Gubler
78928654a2 style(wgsl-in): unblock rustfmt in Error::as_parse_error 2024-10-03 10:57:28 -04:00
Erich Gubler
3d584f99ed refactor(spv-out): linkify docs. ref. to write_bounds_check 2024-10-02 22:35:09 -04:00
Jim Blandy
215f0fc887 [naga spv-out] Internal doc fixes for back::spv::index.
In `naga:🔙:spv::index`, clarify documentation for:
- `BoundsCheckResult`
- `write_index_comparison`
- `write_bounds_check`
2024-10-02 22:35:09 -04:00
sagudev
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
teoxoy
71b4f361e2 chore(core): more detail on TODO for push constants 2024-10-02 04:41:34 -04:00
teoxoy
38a13b94f0 refactor: make Snatchable::snatch take _guard by &mut _ 2024-10-02 04:41:34 -04:00
teoxoy
7ac533a312 add missing indirect buffer offset validation 2024-10-02 04:41:34 -04:00
Erich Gubler
0903ba6d47 refactor(core): delete unused CreateDeviceError 2024-10-02 04:41:34 -04:00
teoxoy
76af20348d remove old comment 2024-10-02 04:41:34 -04:00
teoxoy
025787bbad remove duplicate validation 2024-10-02 04:41:34 -04:00
Elie Michel
c9202ee54a
Remove redundant let binding (#6356) 2024-10-02 10:21:30 +02:00
dependabot[bot]
6db097694c
build(deps): bump JamesIves/github-pages-deploy-action from 4.6.4 to 4.6.8 (#6342)
Bumps [JamesIves/github-pages-deploy-action](https://github.com/jamesives/github-pages-deploy-action) from 4.6.4 to 4.6.8.
- [Release notes](https://github.com/jamesives/github-pages-deploy-action/releases)
- [Commits](https://github.com/jamesives/github-pages-deploy-action/compare/v4.6.4...v4.6.8)

---
updated-dependencies:
- dependency-name: JamesIves/github-pages-deploy-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-30 08:28:48 +02:00
dependabot[bot]
65cb4e752f
build(deps): bump the patch-updates group with 16 updates (#6343)
Bumps the patch-updates group with 16 updates:

| Package | From | To |
| --- | --- | --- |
| [libc](https://github.com/rust-lang/libc) | `0.2.158` | `0.2.159` |
| [once_cell](https://github.com/matklad/once_cell) | `1.19.0` | `1.20.1` |
| [png](https://github.com/image-rs/image-png) | `0.17.13` | `0.17.14` |
| [tracy-client](https://github.com/nagisa/rust_tracy_client) | `0.17.3` | `0.17.4` |
| [syn](https://github.com/dtolnay/syn) | `2.0.77` | `2.0.79` |
| [async-trait](https://github.com/dtolnay/async-trait) | `0.1.82` | `0.1.83` |
| [autocfg](https://github.com/cuviper/autocfg) | `1.3.0` | `1.4.0` |
| [cc](https://github.com/rust-lang/cc-rs) | `1.1.21` | `1.1.22` |
| [const_panic](https://github.com/rodrimati1992/const_panic) | `0.2.9` | `0.2.10` |
| [fdeflate](https://github.com/image-rs/fdeflate) | `0.3.4` | `0.3.5` |
| [flate2](https://github.com/rust-lang/flate2-rs) | `1.0.33` | `1.0.34` |
| [pkg-config](https://github.com/rust-lang/pkg-config-rs) | `0.3.30` | `0.3.31` |
| [regex](https://github.com/rust-lang/regex) | `1.10.6` | `1.11.0` |
| [toml_edit](https://github.com/toml-rs/toml) | `0.22.21` | `0.22.22` |
| [tracy-client-sys](https://github.com/nagisa/rust_tracy_client) | `0.24.0` | `0.24.1` |
| [winnow](https://github.com/winnow-rs/winnow) | `0.6.18` | `0.6.20` |


Updates `libc` from 0.2.158 to 0.2.159
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.159/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.158...0.2.159)

Updates `once_cell` from 1.19.0 to 1.20.1
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.19.0...v1.20.1)

Updates `png` from 0.17.13 to 0.17.14
- [Changelog](https://github.com/image-rs/image-png/blob/master/CHANGES.md)
- [Commits](https://github.com/image-rs/image-png/compare/v0.17.13...v0.17.14)

Updates `tracy-client` from 0.17.3 to 0.17.4
- [Commits](https://github.com/nagisa/rust_tracy_client/compare/tracy-client-v0.17.3...tracy-client-v0.17.4)

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

Updates `async-trait` from 0.1.82 to 0.1.83
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](https://github.com/dtolnay/async-trait/compare/0.1.82...0.1.83)

Updates `autocfg` from 1.3.0 to 1.4.0
- [Commits](https://github.com/cuviper/autocfg/compare/1.3.0...1.4.0)

Updates `cc` from 1.1.21 to 1.1.22
- [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.1.21...cc-v1.1.22)

Updates `const_panic` from 0.2.9 to 0.2.10
- [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.10)

Updates `fdeflate` from 0.3.4 to 0.3.5
- [Changelog](https://github.com/image-rs/fdeflate/blob/main/CHANGES.md)
- [Commits](https://github.com/image-rs/fdeflate/commits)

Updates `flate2` from 1.0.33 to 1.0.34
- [Release notes](https://github.com/rust-lang/flate2-rs/releases)
- [Changelog](https://github.com/rust-lang/flate2-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/flate2-rs/compare/1.0.33...1.0.34)

Updates `pkg-config` from 0.3.30 to 0.3.31
- [Changelog](https://github.com/rust-lang/pkg-config-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/pkg-config-rs/compare/0.3.30...0.3.31)

Updates `regex` from 1.10.6 to 1.11.0
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.10.6...1.11.0)

Updates `toml_edit` from 0.22.21 to 0.22.22
- [Commits](https://github.com/toml-rs/toml/compare/v0.22.21...v0.22.22)

Updates `tracy-client-sys` from 0.24.0 to 0.24.1
- [Commits](https://github.com/nagisa/rust_tracy_client/compare/tracy-client-sys-v0.24.0...tracy-client-sys-v0.24.1)

Updates `winnow` from 0.6.18 to 0.6.20
- [Changelog](https://github.com/winnow-rs/winnow/blob/main/CHANGELOG.md)
- [Commits](https://github.com/winnow-rs/winnow/compare/v0.6.18...v0.6.20)

---
updated-dependencies:
- dependency-name: libc
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: png
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: tracy-client
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: async-trait
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: autocfg
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: cc
  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: fdeflate
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: flate2
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: pkg-config
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: regex
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: patch-updates
- dependency-name: toml_edit
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: patch-updates
- dependency-name: tracy-client-sys
  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>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-09-30 08:28:08 +02:00