Without the suffix, `Expression::Literal(Literal::F32)` expressions
get written without any suffix on the number, meaning that they get
re-parsed as `AbstractFloat` values. In theory, this should always be
fine, but since we don't actually support abstract types yet in all
the places we should, having them appear in the output causes
validation problems.
See also: #4863, which did the same for `i32` literals.
Without the suffix, `Expression::Literal(Literal::I32)` expressions
get written without any suffix on the decimal number, meaning that
they get re-parsed as AbstractInt values. In theory, this should
always be fine, but since we don't actually support abstract types yet
in all the places we should, having them appear in the output causes
validation problems.
Apply the `NonUniform` decoration to the results of all access chains rooted in binding arrays that use non-uniform values as indices, regardless of the binding array's element type and address space. Previously, Naga only decorated non-uniform access chains for binding arrays of buffers.
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.
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.
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.
Delete the `first_component_ty_inner` field from
`front::wgsl::lower:🚧:Components::Many`. With the
introduction of abstract types, it will no longer be possible to infer
the type of the vector being constructed by looking at the type of its
first constructor argument alone: automatic conversion rules might
need to be applied to that argument.
The large `match` statement in `Lowerer::construct` seems to flop back
and forth between two indentation levels as it's edited, making the
diffs hard to read. Rewrite it to use deferred initialization of
`expr`, so that `cargo fmt` doesn't have to decide whether or not to
put the `match` on the same line as `let expr`. This makes subsequent
diffs easier to read.
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.
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).
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.
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.
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.
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.
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.
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.
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>`