Commit Graph

42 Commits

Author SHA1 Message Date
Jim Blandy
4f9cc288e3 [naga] Make compaction preserve named types, even if unused.
Have `compact::compact` preserve entries in the `Module::types` arena
if they have names.

Future abstract type support will require the WGSL front end to
compact the module before validation. Without this change, that will
drop `alias` declarations, making it harder to test type validation.
2023-11-22 18:33:59 +01:00
Jim Blandy
3f0465be59 [naga wgsl-in] Preserve type names in alias declarations.
Given a WGSL `alias` declaration, create a Naga `Type` with the
alias's name, rather than dropping the type name on the floor.
2023-11-22 18:17:02 +01:00
Erich Gubler
1cf0fe841a test(naga): add struct-layout test 2023-11-22 03:54:16 -07:00
Erich Gubler
06b0a67551 chore(msl-out): remove outdated "quick and dirty" comment 2023-11-22 03:54:16 -07:00
Erich Gubler
a8da664773 chore(msl-out): should_pack_struct_member: remove unnecessary alignment check for vec3s 2023-11-22 03:54:16 -07:00
Erich Gubler
611da6da2d fix(msl-out): emit and init struct member padding always
Previously, implicit padding members of `struct`s were suppressed from
structure definitions in Metal output if they had a binding specified
for them (i.e., `@location(0)`). This padding is, however, is necessary
for correct access of member fields passed into shaders by uniform and
storage buffers. Unconditionally emit padding members for `struct`s.

Resolves
[`gfx-rs/wgpu`#4701](https://github.com/gfx-rs/wgpu/pull/4701).
2023-11-22 03:54:16 -07:00
Jim Blandy
dec907a771 [naga wgsl-in] Test hex float suffix handling corner case.
Test Naga's WGSL front end's handling of `h` and `f` suffixes on
hexadecimal float literals. WGSL permits these suffixes only if an
exponent is present, because otherwise `f` suffixes can be confused
with a hexadecimal digit.
2023-11-22 11:10:38 +01:00
Connor Fitzgerald
1df98d9888
Test And Normalize Vertex Behavior on All Backends (#4723)
Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2023-11-21 22:11:24 +00:00
Jim Blandy
a820a3ffba [naga]: Make snapshot tests include paths in errors.
Following Rust convention, let `naga::front::wgsl::ParseError`'s
methods `emit_to_stderr_with_path` and `emit_to_string_with_path`
accept any `AsRef<Path>` argument as the path.

Pass input paths in snapshot tests, so that failures processing
shaders name the input file being processed.
2023-11-21 21:47:03 +01:00
Jim Blandy
104119a402 [naga] Fix type error in test.
Change the WGSL code in the `function_returns_void` test in
`tests/wgsl-errors.rs` so that the construction expression types
correctly. Subsequent iterations of the WGSL front end will be doing
some type checking earlier, to support WGSL's automatic conversions,
and without this fix, this test will stop checking what it is intended
to check.
2023-11-21 21:41:39 +01:00
Jim Blandy
72462267e8 [naga]: Let TypeInner::Matrix hold a Scalar, not just a width.
Let `naga::TypeInner::Matrix` hold a full `Scalar`, with a kind and
byte width, not merely a byte width, to make it possible to represent
matrices of AbstractFloats for WGSL.
2023-11-21 12:02:50 +01:00
dependabot[bot]
4b10ce7e5b
Bump serde from 1.0.192 to 1.0.193 (#4736)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.192 to 1.0.193.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.192...v1.0.193)

---
updated-dependencies:
- dependency-name: serde
  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>
2023-11-20 23:53:53 -05:00
Jim Blandy
42058cf24f [naga] Add Literal::I64, for signed 64-bit integer literals.
Add an `I64` variant to `crate::Literal`, making `crate::Expression`
suitable for representing `AbstractFloat` and `AbstractInt` values in
the WGSL front end.

Make validation reject uses of `Literal::I64` in constant and function
expression arenas unconditionally. Add tests for this.

Let the frontends and backends for languages that have 64-bit integers
read/write them.
2023-11-20 16:11:30 -08:00
Jim Blandy
fd53ea90e6 [naga] Let constant evaluation of As preserve Splat expressions.
When asked to evaluate an `Expression::As` cast applied to a `Splat`
expression, change `ConstantEvaluator::cast` to preserve the `Splat`,
rather than expanding it out to a `Compose` expression.
2023-11-17 16:20:11 -08:00
Jim Blandy
c9ae35edbb [naga wgsl-in] Include base when printing pointer and array types.
When formatting `TypeInner::Pointer` and `TypeInner::Array` as WGSL
source code, bother to actually generate text for the target/element
type. This avoids producing ridiculous messages like:

> the type of `foo` is expected to be `array<unknown, 2>`, but got `array<unknown, 2>`
2023-11-17 23:36:15 +01:00
Teodor Tanasoaia
a26e4a009a
[naga] remove span and validate features (#4706) 2023-11-17 13:37:25 -05:00
Fredrik Fornwall
a5c93caa56
Add more metal keywords (#4707) 2023-11-17 17:02:36 +01:00
Jim Blandy
3ec547cdca [naga] Preserve spans when compacting Arenas.
When compacting a module, properly adjust spans along with `Arena`
contents.
2023-11-16 22:50:54 +01:00
Jim Blandy
b7dd59e1dc [naga] Let constant evaluation handle Compose of Splat.
When consuming a `Compose` expression that constructs a vector,
flatten `Splat` subexpressions out into their components.

Fixes #4581.
2023-11-16 13:34:27 +01:00
dependabot[bot]
8870a085a8
Bump termcolor from 1.3.0 to 1.4.0 (#4688)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-15 12:27:05 -05:00
Jim Blandy
ecb522e4e3 [naga] New tests for GLSL double-precision builtin functions. 2023-11-14 20:12:31 -08:00
Jim Blandy
16965f64e5 [naga wgsl-out] Correctly include width in matrix constructions.
When generating WGSL for an `Expression::Compose` constructing a
matrix, consult `TypeInner::Matrix::width` when writing the
type name in the construction expression, rather than just always
writing `matNxM<f32>`.

Fixes #4681.
2023-11-14 20:12:31 -08:00
Jim Blandy
721e611b79 [naga glsl-in] Fix type of double ldexp's second arg.
The second argument of the GLSL `ldexp` builtin is always a 32-bit
integer or a vector of such, never a 64-bit integer. In
`inject_common_builtin`, that argument's type should not be influenced
by `float_width`.

Fixes #4680.
2023-11-14 20:12:31 -08:00
Jim Blandy
324ec4a5ec [naga glsl-in] Fix double overload for dot/reflect/distance/ldexp.
The first argument of the `dot`, `reflect`, `distance`, and `ldexp`
GLSL builtin functions may be either a float or a double, and thus the
argument type registered by `inject_common_builtin` must depend on the
`float_width` argument; it cannot simply be `Scalar::F32`.

Introduced by #4673.
2023-11-14 20:12:31 -08:00
Jim Blandy
cf2405ca39 [naga wgsl-in] Use to_wgsl functions everywhere appropriate.
Replace `ExpressionContext`'s methods `format_typeinner`,
`format_type`, and `format_type_resolution` with more `to_wgsl`
methods in the `naga::front::wgsl::to_wgsl` module.
2023-11-14 19:58:49 -08:00
Jim Blandy
941cd2e25c [naga wgsl-in] Let TypeInner::to_wgsl take the context by reference. 2023-11-14 19:58:49 -08:00
Jim Blandy
cbb59c7bf3 [naga wgsl-in] Move all to_wgsl functions into their own module.
This is code motion only, with minor doc fixes. There should be no
changes to the code.
2023-11-14 19:58:49 -08:00
Jim Blandy
a6aa3cd30d [naga] Follow-ups to #4763, Introduce Scalar type to IR.
Clean up some things that should have been taken care of in the
original PR:
- Use `Scalar::float` helper.
- Use `Scalar` associated constants in match patterns.
- Use `Scalar`'s `PartialEq` implementation.
- Clean up identifier paths.
2023-11-14 21:42:38 +01:00
Jim Blandy
734e246e87 [naga] Improve algorithm for Module compaction.
Identify reachable function expressions, constant expressions, and
types using a single pass over each arena, taking advantage of the
fact that expressions and types may only refer to other entries that
precede them within their arena. Only walking the statement tree still
requires a worklist/recursion.

In addition to presumably being faster, this change slightly reduces
the number of non-comment lines of code in `src/compact`.
2023-11-14 11:18:43 -08:00
Jim Blandy
9f91c95c24 [naga] Introduce Scalar type to IR.
Introduce a new struct type, `Scalar`, combining a `ScalarKind` and a
`Bytes` width, and use this whenever such pairs of values are passed
around.

In particular, use `Scalar` in `TypeInner` variants `Scalar`, `Vector`,
`Atomic`, and `ValuePointer`.

Introduce associated `Scalar` constants `I32`, `U32`, `F32`, `BOOL`
and `F64`, for common cases.

Introduce a helper function `Scalar::float` for constructing `Float`
scalars of a given width, for dealing with `TypeInner::Matrix`, which
only supplies the scalar width of its elements, not a kind.

Introduce helper functions on `Literal` and `TypeInner`, to produce
the `Scalar` describing elements' values.

Use `Scalar` in `wgpu_core::validation::NumericType` as well.
2023-11-14 14:21:27 +01:00
dependabot[bot]
01cb63c758
Bump serde from 1.0.191 to 1.0.192 (#4652)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.191 to 1.0.192.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.191...v1.0.192)

---
updated-dependencies:
- dependency-name: serde
  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>
2023-11-08 09:46:47 +01:00
dependabot[bot]
ba3d6898f1
Bump serde from 1.0.190 to 1.0.191 (#4646)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.190 to 1.0.191.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.190...v1.0.191)

---
updated-dependencies:
- dependency-name: serde
  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>
2023-11-07 12:12:05 +01:00
Connor Fitzgerald
7f72c9fc3b
Fix GL Push Constant Layout (#4607)
* It verks!

* More tests

* Fixes

* Working multi-stage push constants

* Comments

* Add push constant partial update teste

* Docs

* Update Cargo.toml

* Comments
2023-11-06 07:58:26 -05:00
Jim Blandy
267bd488d3 [naga wgsl-in] Introduce Scalar type.
Introduce a new struct `Scalar`, holding a scalar kind and width, and
use it as appropriate in the WGSL front end. This consolidates
many (kind, width) pairs, and lets us name the two components.

Ideally, `Scalar` would be used throughout Naga, but this would be a large
change, touching hundreds of use sites. This patch begins by
introducing `Scalar` to the WGSL front end only.
2023-11-06 13:27:49 +01:00
Daniel McNab
7709010a79
Naga(msl): Clear named expressions after writing each function (#4594)
This appears to match other backends, and fixes
fix the case where expressions which were named in earlier
functions are used in local variable declarations
2023-11-02 18:46:36 +00:00
Jim Blandy
ea8b619ba4 Add some doc comments to naga::proc::constant_evaluator. 2023-11-02 19:22:35 +01:00
Jim Blandy
e6063c5255 [wgsl-in] Replace TypedExpression with a generic enum, Typed.
Replace the `TypedExpression` struct, used to distinguish between WGSL
pointers and references since Naga has only `Pointer`, with an enum,
`Typed`, with variants for references and plain types. This cleans up
a bunch of code, since the struct's `is_reference` field basically
served as a detached enum discriminant. This also prepares the code
for adding abstract types.
2023-11-02 19:21:31 +01:00
dependabot[bot]
5661de7a3c
Bump arbitrary from 1.3.1 to 1.3.2 (#4616)
Bumps [arbitrary](https://github.com/rust-fuzz/arbitrary) from 1.3.1 to 1.3.2.
- [Changelog](https://github.com/rust-fuzz/arbitrary/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-fuzz/arbitrary/compare/derive_arbitrary@1.3.1...v1.3.2)

---
updated-dependencies:
- dependency-name: arbitrary
  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>
2023-10-31 01:50:52 -04:00
Connor Fitzgerald
2a9fdf9aa1
Misc Repo Cleanup Tasks (#4579)
* Misc Repo Cleanup Tasks

* Dependency Trimming

* Dep cleanup

* Restrict libfuzzer

* Flip cfg

* mod fuzz
2023-10-27 00:15:51 -04:00
Jim Blandy
61bca7e0aa
wgsl-errors: Reverse "old" and "new" sides of diff output. (#4577)
When an error snapshot test fails and we generate a diff comparing the
expected output with the actual output, treat the expected output as
the diff "from", and the actual output as the diff "to" - not the
reverse.
2023-10-26 20:12:39 -04:00
Connor Fitzgerald
34e947de4b
Integration of Naga into Repo (#4296) 2023-10-25 16:51:36 -04:00
Connor Fitzgerald
5369eec3b2
Move naga to subfolder 2023-10-25 14:25:04 -04:00