Commit Graph

9179 Commits

Author SHA1 Message Date
Jamie Nicol
08d3bb5196 [naga msl-out hlsl-out] Ensure wrapper functions for integer division and modulo avoid using minimum value literals
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).
2025-04-10 10:36:27 -04:00
Jamie Nicol
6dc3b7186c [naga hlsl-out] Emit most-negative integer value literals as 2nd-most-negative value minus one
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.
2025-04-10 10:36:27 -04:00
Vecvec
8010203281 Rework acceleration structure build tracking. 2025-04-09 22:27:04 -04:00
Vecvec
382a1e3c9b Make submission index lockable. 2025-04-09 22:27:04 -04:00
Christian Legnitto
09a641bdf4
Fix include_spirv_raw macro (#7503) 2025-04-09 20:56:22 -04:00
Andy Leiserson
a0dbe5ebc6 refactor(msl-out): create a type for bounds check iter items
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Andy Leiserson
a7afb56276 [msl-out] Fix ReadZeroSkipWrite bounds check mode for pointer arguments
Fixes #4541

--
Co-authored-by: Liam Murphy <liampm32@gmail.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Andy Leiserson
7cf3e2f3cc refactor(msl-out): extract puts_local helper
--
Co-authored-by: Liam Murphy <liampm32@gmail.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Andy Leiserson
dbb36cc556 chore(msl-out): remove TRACE-level logging of expressions 2025-04-09 18:45:27 -04:00
Andy Leiserson
e03c55b236 docs(msl-out): add missing docs. for msl::Writer::access_needs_check
--
Co-authored-by: Liam Murphy <liampm32@gmail.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Andy Leiserson
fc9c8bfba7 refactor(msl-out): add NamedKeyExt trait with local helper method
--
Co-authored-by: Liam Murphy <liampm32@gmail.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Andy Leiserson
587aea2da6 refactor(msl-out): extract bounds_check_iter helper
--
Co-authored-by: Liam Murphy <liampm32@gmail.com>
Co-Authored-By: Erich Gubler <erichdongubler@gmail.com>
2025-04-09 18:45:27 -04:00
Jim Blandy
aad187f52f [naga wgsl] New TypeContext method write_unnamed_struct.
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.
2025-04-09 16:48:49 -04:00
Jim Blandy
25f03960e1 [naga] Delete DiagnosticDisplay impl for for TypeInner.
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.
2025-04-09 16:48:49 -04:00
Jim Blandy
6150576a77 [naga] Use TypeContext::write_type_resolution where appropriate.
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.
2025-04-09 16:48:49 -04:00
Jim Blandy
7f08498069 [naga wgsl-out] Stop using TypeContext::write_type_inner.
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.
2025-04-09 16:48:49 -04:00
Jim Blandy
dd60ce30e4 [naga] Remove TypeContext::type_inner_to_string.
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.
2025-04-09 16:48:49 -04:00
Jim Blandy
e3b005ea82 [naga wgsl-in] Avoid crashes when logging types.
In `naga::front::wgsl::lower`, change logging in
`ExpressionContext::automatic_conversion_consensus` to use
`TypeResolution`s instead of `TypeInner`s, so that structs don't cause
a crash.
2025-04-09 16:48:49 -04:00
Jim Blandy
59db4a6d62 [naga wgsl-in] Don't panic printing struct types for initializers.
When an initializer has the wrong type and it's a struct, don't panic
trying to format its type for the error message.
2025-04-09 16:48:49 -04:00
Jim Blandy
2f7698d390 [naga wgsl-in] Don't panic printing struct types for conversions.
When a type conversion expression is ill-formed and the operand is a
struct type, don't panic trying to format the operand's type for the
error message.
2025-04-09 16:48:49 -04:00
Jim Blandy
b837db37ad [naga wgsl-in] Handle struct types in error messages properly.
Don't try to use `&TypeInner` values to generate error messages, since
`&TypeInner` cannot represent struct types in WGSL - they must be
referred to by name, and only `Type` knows the type's name. Using
`Handle<Type>` or `TypeResolution` works fine, so use that instead.

Add a new `Display` impl for `DiagnosticDisplay` for `TypeResolution`.

Fixes #7495.
2025-04-09 16:48:49 -04:00
Vecvec
1c4b73c098
Implement as_hal for BLASes and TLASes (#7303) 2025-04-09 14:50:43 -04:00
Christian Legnitto
6ef9b8256a [naga msl-out] invalid code emitted for minimum i32/i64 value literal.
The literal `-2147483648` is parsed by Metal as negation of positive
2147483648. As 2147483648 is too large for a int, the expression is
silently promoted to a long. Sometimes this does not matter as it will
often be implicitly converted back to an int after the negation.
However, if the expression is used in a bitcast then we hit a compiler
error due to mismatched bitwidths.

Similarily for `-9223372036854775808`, as 9223372036854775808 is too
large for a long, metal emits a `-Wconstant-conversion` warning and
changes the value to -9223372036854775808. This would then be negated
again, possibly causing undefined behaviour.

In both cases we can avoid the issue by expressing the literals as the
second most negative value expressible by the type, minus one.

eg `-2147483647 - 1` and `-9223372036854775807L - 1L`.

We have added a test which uses the most negative i32 literal in an
addition. Because we bitcast addition operands to unsigned in metal,
this would cause a validation error without this fix. For the i64 case
existing tests already make use of the minimum literal value. Passing
the flag `-Werror=constant-conversion` to Metal during validation will
therefore catch this issue.
2025-04-09 14:13:03 -04:00
Jamie Nicol
e3828fcc18 [naga wgsl-out] Improve representation of minimum int64 literal
In #7424 we fixed a bug where the representation of the minimum int64
literal generated by naga was invalid WGSL. It changed us from
expressing it as `-9223372036854775808` which was invalid, to
`-9223372036854775807li - 1li`.

This is valid WGSL. However, as the values are concrete i64 types if the
shader is parsed again by naga the expression does not get const
evaluated away, leading to suboptimal code generated by the
backends. This patch makes us perform the subtraction using abstract
integers before casting to i64, solving this problem.

Additionally the input WGSL test is updated to use the same construct.
2025-04-09 14:13:03 -04:00
Zachary Harrold
4761e27da5
[naga] Fix improper feature gates (#7484) 2025-04-09 12:10:40 -04:00
Andy Leiserson
be16f8ce18 Use ty.for_debug 2025-04-09 08:15:47 -07:00
Andy Leiserson
d223bb582f [naga] Disallow logical operators && and || on vectors
Fixes #6856
2025-04-09 08:15:47 -07:00
Sylvain Benner
14690470bb
[metal] Metal compute shader passthrough (#7326)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-04-09 14:25:41 +00:00
Connor Fitzgerald
3ba97bc3b7
Fix CI flakes (#7491) 2025-04-08 11:15:31 -04:00
Connor Fitzgerald
a6d7e0d56b [d3d12] Move naming inside suballocation functions 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
a1e96cc179 [d3d12] Simplify set_name calls with a helper 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
6262462979 [d3d12] Make placed/committed resource paths the same 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
1831267551 [d3d12] Separate placed resource construction into separate functions 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
460eff4866 [d3d12] Always associate a size with an allocation 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
014b5b52f2 [d3d12] Internalize raw buffer desc mapping 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
4fce269b1d [d3d12] Isolate buffer descriptor mapping 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
b57ec2c9e0 [d3d12] Remove unused visibility and arguments 2025-04-07 21:03:43 -04:00
Connor Fitzgerald
004961874f [d3d12] Turn suballocation free functions into member functions 2025-04-07 21:03:43 -04:00
Jim Blandy
b5f6547934
[naga] Exhaustively match MathFunction in the constant evaluator. (#7487) 2025-04-07 16:54:15 -04:00
Jim Blandy
a611f72e56 [naga wgsl-in] Move Expression::Math construction into a helper.
In `naga::front::wgsl`, add a new helper method,
`Lowerer::math_function_helper`, that constructs `Expression::Math`
expressions for calls to `MathFunction` builtins. Use this helper in
`Lowerer::call`.
2025-04-07 16:53:50 -04:00
Jim Blandy
b9ac282518 [naga wgsl-in] In Lowerer, rename some argument types.
Since we have moved some code out into separate functions, we have
less context to compete with, so we can use simpler names for the
arguments.

This commit is just renaming.
2025-04-07 16:53:50 -04:00
Jim Blandy
10145efed4 [naga wgsl-in] In Lowerer, abstract out overload resolution.
In `naga::front::wgsl::lower::Lowerer`, add a new helper method,
`resolve_overloads`, that selects the appropriate rule for a given
list of of arguments from an overload set.

Use this helper in the `call` method when building `Math`
expressions.

This is just code motion, and should have no effect on behavior.
2025-04-07 16:53:50 -04:00
Jim Blandy
f7dde7e9a0 [naga wgsl-in] In Lowerer, add helper for automatic conversions.
In `naga::front::wgsl::lower::Lowerer`, add a new helper method,
`apply_automatic_conversions_for_call`, that applies the conversions
necessary to pass a given set of arguments to a given overload.

Use this helper in the `call` method when building `Math`
expressions.

This is just code motion, and should have no effect on behavior.
2025-04-07 16:53:50 -04:00
Jim Blandy
62e0272537 [naga wgsl-in] In Lowerer, expand role of lowered arguments vector.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, use `lowered_arguments` for both the original Naga IR
argument expressions and their counterparts after applying automatic
conversions.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy
fc1ebc481d [naga wgsl-in] In Lowerer, rename unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, rename `unconverted_arguments` to `lowered_arguments`.

No change to behavior. This is a minor refactor that prepares for
later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy
c50f8c32ea [naga wgsl-in] In Lowerer, check arity with unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, use `unconverted_arguments` to check the number of
arguments to the call. This means that `arguments` is never used in
this branch once we have built `unconverted_arguments`.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy
f06ba9a528 [naga wgsl-in] In Lowerer::call, prefer unconverted_arguments.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, replace some uses of the `arguments` vector with
uses of `unconverted_arguments`.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy
20c2f8d8c1 [naga wgsl-in] In Lowerer::call, precompute unconverted arg list.
In `naga::front::wgsl::lower::Lowerer::call`, when building `Math`
expressions, build the vector of lowered but not yet converted
argument expressions completely before starting overload resolution.
Then iterate over those lowered arguments, not the ast arguments.

This is a minor refactor that prepares for later cleanups.
2025-04-07 16:53:50 -04:00
Jim Blandy
dec819899a [naga wgsl-in] Minor cleanup to math function lowering.
In `naga::front::wgsl::lower::Lowerer::call`, use only the
`unconverted_arguments` vector, rather that using both `arguments` and
`unconverted_arguments`.
2025-04-07 16:53:50 -04:00
Erich Gubler
1b51f0aa40 feat(naga): add UnimplementedEnableExtension::Subgroups 2025-04-07 11:48:41 -07:00