Change `naga::front::wgsl::lower` to `use` `ir` and `proc`,
and then qualify identifiers with that instead of `crate`.
This is strictly fiddling with `use` directives and name
qualification, with the concomitant formatting changes; there should
be no change to the module's behavior or meaning.
Closes#7481.
This implementation roughly follows approach 2 outlined in #7481, i.e.,
it adds a polyfill for the signed and unsigned dot product of packed
vectors for each platform. It doesn't use the specialized instructions
that are available for this operation on SPIR-V (with capability
DotProductInput4x8BitPacked).
Have constant evaluator use `wrapping_abs` instead of `abs` when
applying `MathFunction::Abs` to AbstractInt values. WGSL says that
applying `abs` to the most negative AbstractInt value must return it
unchanged, which is what Rust's `i64::wrapping_abs` does.
Change `resolve_type` and `resolve_type_impl` to return
`TypeResolution`s. Add a new method `resolve_type_inner` that returns a
`TypeInner` (i.e. what `resolve_type` used to do).
As we know that minimum value integer literals can cause problems for
some compilers. (See #7437)
Make the code which generates these functions call
msl::Writer::put_literal() and hlsl::Writer::write_literal()
respectively to output the minimum value integer literals instead of
just writing them directly, ensuring we only have to handle this
workaround in a single location (per backend).
As we did for MSL in #7437. eg `-2147483648` becomes `-2147483647 - 1`.
Neither FXC nor DXC currently have any issues parsing the most negative
value literals. However, we have been informed this is not guaranteed to
always be the case, so are making this change as a precaution.
When asked to generate WGSL for `TypeInner::Struct`, rather than
unconditionally calling `unreachable!`, defer to a new `TypeContext`
method, `write_unnamed_struct`.
Provide appropriate `write_unnamed_struct` implementations:
- In the WGSL backend, implement this as `unreachable!`, since the WGSL
backend should always know the proper name to use for a struct.
- For diagnostic messages, generate something human-readable that
indicates that some struct type was encountered.
- For logging and debugging, defer to `TypeInner`'s `Debug`
implementation.
Delete the implementation of `core::fmt::Display` for
`naga::common::DiagnosticDisplay`, as it is a footgun wherever
`Struct` types can arise.
Document that it should not be implemented for `TypeInner`.
Although it is possible to put a dummy implementation in the way of
people adding real implementations, that would also turn attempts to
use it into dynamic errors rather than compile-time errors. Make do
with a comment for now.
Simplify the implementation of `Display` for
`DiagnosticDisplay<(TypeResolution, GlobalCtx)>` by calling
`GlobalCtx`'s implementation of `write_type_resolution` directly,
rather than duplicating its code. Provide a fallback for non-wgsl
builds.
In `naga:🔙:wgsl`, prefer `TypeContext::write_type_resolution`
over `write_type_inner`, since the former is actually what we need,
and the latter can be troublesome if asked to write a `struct` type.
In `naga::common::wgsl`, delete the method
`TypeContext::type_inner_to_string`, since it's a footgun: anyone
trying to convert a `TypeInner::Struct` to a string will hit
"unreachable" code.