Commit Graph

232 Commits

Author SHA1 Message Date
Teodor Tanasoaia
a8bd1fe1ac [d3d12] bound check dynamic buffers (#6931)
To achieve this for dynamic storage buffers we changed the way we bind them. They now go in root tables and we pass the offset via a root constant.
2025-01-23 17:18:36 +00:00
Jamie Nicol
0282d61f91 [naga hlsl-out] Handle array types for function return values and calls (#6971) 2025-01-23 16:56:18 +01:00
Connor Fitzgerald
436f716715 Unconditionally Generate Bindless Samplers in DX12 (#6766) 2025-01-21 14:24:03 -05:00
the letter L
b626020769 [naga] parse and validate @must_use attribute (#6801)
* feat: parse and enforce `@must_use` attribute

* feat: refuse `@must_use` of void function

* generated naga/tests/out/ir

* revert extraneous changes

* fix clippy

* update repeated attribute error to trunk format

* struct members can't have `@must_use`

* review fixes

* Remove must_use from FunctionResult and revert the related changes

---------

Co-authored-by: turbocrime <turbocrime@users.noreply.github.com>
Co-authored-by: Jamie Nicol <jnicol@mozilla.com>
2025-01-20 18:09:36 +00:00
Jamie Nicol
1f939e1c44 [naga msl-out] Avoid undefined behaviour due to signed integer overflow (#6959)
Signed integer overflow is undefined behaviour in MSL. However, signed
integers are defined to be two's complement. This allows us to cast
signed values to their corresponding unsigned type, perform the
arithmetic on these unsigned values (which has defined overflow
behaviour) then cast the result back to signed.

Care must be taken when emitting the isign polyfill, which uses
metal::select(). We must ensure the -1, 0, and 1 literals used as
inputs to select() have the correct width, else bitcasting the output
of select() will fail due to mismatched widths.
2025-01-20 18:11:27 +01:00
Vecvec
bdef8c0407 [spirv] Stop naga causing undefined behavior in rayQueryGet*Intersection (#6752)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-17 00:04:33 +00:00
Kent Slaney
a32467041d fix >= in template list matching for a<b>=c (#6898)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-15 17:25:04 +00:00
atlv
be95178709 64 bit image atomics (#5537) 2025-01-15 08:05:13 -05:00
sagudev
ea5d3b953f Add test
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-01-15 11:14:17 +01:00
Vecvec
21de7f7773 Support DXR in wgpu-hal & naga. (#6777)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
2025-01-14 21:28:37 -05:00
Erich Gubler
1963eb7c3f diag(wgsl-in): use backticks for code-like text in WGSL FE errors (#6908) 2025-01-13 22:13:40 +00:00
Erich Gubler
cc741735df fix(wgsl-in): print debug repr. of unexpected tokens (#6907) 2025-01-13 16:43:41 -05:00
atlv
18471d8e78 Image atomics support (#6706)
* Image atomics support

* Address feedback

* fix merge

* Fixes

* Add a couple tests

* Update wgpu-types/src/lib.rs

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>

* feedback

* feedback

* glsl

* glsl fix

* fix glsl

* fix fix

* fix fix fic

* fix?

* fix

---------

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2025-01-13 15:37:12 +00:00
Asher Jingkong Chen
198762e5cc feat: Add 32-bit floating-point atomics (SHADER_FLOAT32_ATOMIC) (#6234)
* feat: Add 32-bit floating-point atomics

* Current supported platforms: Metal
* Platforms to support in the future: Vulkan

Related issues or PRs:

* gfx-rs/wgpu#1020

* Add changelog

* Edit changelog

* feat: Add 32-bit float atomics support for Vulkan (SPIR-V shaders)

* atomicSub for f32 in the previous commits is removed.

* Update test

* chore: doc type link

* refactor: Revise float atomics on msl and spv

* Make branches tidy
* Also revise old codes
* Ensure the implementations are supported by Metal and Vulkan backends

* refactor: Renaming flt32 atomics to float32 atomics

* chore: Add link to Vulkan feature

* fix: cargo fmt

* chore: hack comment

* Revert changelog

* Fix: Cargo advisory

* Update wgpu-hal/src/metal/adapter.rs

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>

* Update naga/src/lib.rs

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>

* Adjust feature flag position

---------

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2025-01-09 16:03:47 +00:00
Connor Fitzgerald
a8a91737b2 Switch Binding Arrays on Metal to Argument Buffers (#6751) 2025-01-07 16:00:56 -05:00
Jamie Nicol
78e35c4a7e [naga wgsl-in] Disallow named component expression for matrix types
The WGSL spec only allows named component expressions when the base
type is a vector or a structure, so this patch removes support for it
for matrices. Additionally tests which used this for matrices have
been updated to use indexing expressions instead, and a test has been
added to ensure a named component expression on a matrix results in an
error.
2025-01-07 13:46:41 +01:00
Jamie Nicol
15095122a2 [naga] Handle bitshifts for abstract lhs operands during const evaluation (#6865) 2025-01-06 17:33:25 -05:00
Jim Blandy
a84b6ca579 [naga] Add tests for automatic conversions in assignments.
Add tests for automatic conversions of the right-hand sides of
assignment expressions.
2025-01-06 17:29:58 -05:00
Jim Blandy
4f22f8d7b6 [naga wgsl-in] Apply automatic conversions to values being assigned.
Apply automatic conversions to the right-hand sides of assignment and
compound assignment statements.

Fix `try_automatic_conversion_for_leaf_scalar` to handle arrays,
not just scalars, vectors, and matrices. Previously this was only used
for converting the right-hand sides of bit shift operators to `u32`,
and bit shift operators don't support arrays. But now we're using
`try_automatic_conversion_for_leaf_scalar` for ordinary assignments,
and you can assign arrays.

Update a test of propagating source code spans through compaction.
This test needs validation to report an error, but this commit's fix
causes the error in the test to be detected in the front end, which is
too early to exercise compaction. Use a new error that the front end
still won't notice.
2025-01-06 17:29:58 -05:00
Jim Blandy
04f0de6d64 [naga] Add some tests to in/abstract-types-var.wgsl.
Fill out a few more cases for variable type inference and automatic
conversions of initializers.
2025-01-06 17:29:58 -05:00
Erich Gubler
9d9b99adb6 fix: make unpack4x{I,U}8 output exprs. composable in {hlsl,msl}-out (#6773) 2024-12-23 09:10:18 -08:00
Erich Gubler
6c9f93b7de diag(naga): clarify select built-in type mismatch messages 2024-12-20 10:34:20 -05:00
Erich Gubler
9ea464b85b test(valid): cover select arg. mismatches 2024-12-20 10:34:20 -05:00
Schell Carl Scivally
ea7556853d [naga spv-in] Support atomics in fields of global structs
Handle SPIR-V input that performs atomic operations on structs that
have more than one field. Track which fields of which struct types are
used by atomic operations on which global variables, and then give
those global variables new types in which exactly those fields have
had their `Scalar` leaf types changed to `Atomic`.

Add snapshot tests.

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-12-17 07:45:41 -08:00
Connor Fitzgerald
411ffa7a5a Make Force Loop Bounding Optional (#6662)
* Make Force Loop Bounding Optional

Co-authored-by: rudderbucky <anandkwork7@gmail.com>

* Deprecate and Rename

---------

Co-authored-by: rudderbucky <anandkwork7@gmail.com>
2024-12-16 04:23:22 -05:00
Kent Slaney
5bec461fb5 Override-expressions for Fixed Size Arrays (#6654) 2024-12-10 15:43:22 +01:00
Schell Carl Scivally
8b93a71129 chore: [spv-in] atomics snapshot tests (#6692)
* chore: [spv-in] clean up atomic upgrade tests

* add output test files

* update changelog

* remove extraneous snapshot out files
2024-12-09 19:54:02 -08:00
Jamie Nicol
90859b4ea1 [naga wgsl-in] Attempt automatic conversion for arguments to user defined function calls (#6577)
When lowering arguments for a user-defined function call, avoid
concretizing the argument types. Instead make use of the existing
`try_automatic_conversions()` machinery to attempt to convert each
argument to the type expected by the function. This is straightforward
as user-defined functions only have a single overload.

This additionally changes an argument type in the test
parse_pointers() from `ptr<private>` to `ptr<function>`. The former is
invalid code which is indeed caught by the validator, but the test
only asserts that parsing succeeds, not validation. With this patch,
this error is now caught during parsing which caused the test to fail.
2024-12-09 16:36:17 +00:00
Schell Carl Scivally
234b6dd613 feature: [spv-front] Support for OpAtomicCompareExchange (#6590)
Add support for parsing and executing OpAtomicCompareExchange in the SPIR-V frontend.
This concludes the work to support atomics in the SPIR-V frontend,
excluding test clean-up.

Fixes #6296.
Fixes #6590.

Connections:

- [naga spv-in] Support for OpAtomicCompareExchange #6296
- [spv-in] Atomics support #4489

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-12-09 14:56:51 +00:00
Kent Slaney
b56960b8e8 Add Pipeline Overrides for workgroup_size (#6635) 2024-12-06 11:44:05 +01:00
Connor Fitzgerald
c933487697 Improve Snapshot Test Configuration Deserialization (#6661) 2024-12-05 10:32:23 -06:00
Dzmitry Malyshau
314e196c90 Implement candidate intersections 2024-11-27 11:49:32 +01:00
Dzmitry Malyshau
cdcba54d06 Declare ray flags in IR, parse all of them in WGSL 2024-11-27 11:49:32 +01:00
Jasper St. Pierre
7fff667c5a [glsl-in] Don't reinterpret function arguments twice in the normal case
We already lowered the function expression if it's a normal in argument; no need to do it again. This eliminates an unused variable and expression. With chained function calls, this could lead to a lot of waste.

There's still an extra unused expression in the case of an out/inout argument; ideally we'd remove these expressions, but it might be tricky.

Fixes #6602
2024-11-26 11:32:15 -08:00
Sludge
a9f14c7a90 Allow 64-bit hex literals and const-evaluate unary ops (#6616)
* Allow 64-bit hex literals

* Implement const evaluation for unary 64-bit ops

* Test 64-bit hex literals

* Add changelog entry
2024-11-25 18:54:12 -08:00
Jamie Nicol
00a6032eb7 [naga spv-out] Handle nested arrays when adding matrix decorations
Previously we only checked whether the outermost array's subtype was a
Matrix when determining whether to add ColMajor and MatrixStride
decorations, meaning arrays of arrays of matrices would not be
decorated.
2024-11-20 06:38:39 -08:00
Jim Blandy
0b82776947 [naga msl-out] Avoid UB by making all loops bounded.
In MSL output, avoid undefined behavior due to unbounded loops by
adding an unpredictable, never-actually-taken `break` to the bottom of
each loop body, rather than adding an unpredictable,
never-actually-taken branch over each loop.

This will probably have more of a performance impact, because it
affects each iteration of the loop, but unlike branching over the
loop, which leaves infinite loops (and thus undefined behavior) in the
output, this actually ensures that no loop presented to Metal is
unbounded, so that there is no undefined behavior present that the
optimizer could use to make unwelcome inferences.

Fixes #6528.
2024-11-18 14:10:50 -08:00
Erich Gubler
e59f00399e fix(wgsl-in): include user and unknown rules in diagnostic(…) tracking 2024-11-18 17:10:07 -05:00
Jamie Nicol
6f528e2ebc [wgsl-in] Reject invalid texture types for textureSampleBias (#6566)
Non-sampled textures are not allowed, and neither are 1 dimensional
textures.
2024-11-18 17:37:52 +01:00
Jamie Nicol
baecb5fbf1 [wgsl-in] Ensure textureSampleLevel's level argument is an integer for depth textures (#6529)
Until now we accepted a float, as is the case for non-depth textures.
This makes us compliant with the spec.

The validator is updated to expect an Sint or Uint when the ImageClass
is ImageClass::Depth. The SPIR-V frontend converts the LOD argument
from float to Sint (assuming that it is representable), likewise The
SPIR-V backend now converts the LOD from either Sint or Uint to
Float. HLSL and MSL backends require no changes as they implicitly do
that conversion. GLSL does not support non-compare LOD samples,
therefore no changes are required.
2024-11-18 12:05:04 +00:00
Erich Gubler
92ca5a3850 feat(wgsl-in): parse diagnostic attrs. on fns 2024-11-15 07:44:14 -05:00
David Peicho
3018912897 naga: Add support for GLSL signed/unsigned samplers (#6513) 2024-11-15 11:49:56 +01:00
Erich Gubler
b81fcb4134 refactor(wgsl-in): track diagnostic directives in func. analysis 2024-11-12 08:49:02 -05:00
Jamie Nicol
cffc7933fd [naga] Implement quantizeToF16 (#6519)
Implement WGSL frontend and WGSL, SPIR-V, HLSL, MSL, and GLSL
backends. WGSL and SPIR-V backends natively support the instruction.
MSL and HLSL emulate it by casting to f16 and back to f32. GLSL does
similar but must (mis)use (un)pack2x16 to do so.
2024-11-12 12:05:19 +01:00
Gábor Gyebnár
47d20d913d Fixes crash when there's a missing texture argument (#6486) 2024-11-07 16:35:36 +01:00
Jasper St. Pierre
9ccea8179d naga: Fix textureNumLevels in the GLSL backend
... and reactivate the GLSL test for it.

Fixes issue #6435.
2024-11-04 08:07:23 -08:00
teoxoy
207747cab5 [hlsl-out] add support for restricting indexing to avoid OOB accesses 2024-10-23 16:51:44 +02:00
Erich Gubler
36fab5ce3d fix(msl-out): use namer for <fun>{Input,Output} structs 2024-10-22 10:14:26 -04:00
Erich Gubler
2302b5fac6 test: add regr. cvg. for conflicting idents. in shader I/O and locals 2024-10-22 10:14:26 -04:00
Jasper St. Pierre
1b2ef8612d naga: Add support for textureQueryLevels to GLSL parser (#6415) 2024-10-18 10:07:58 +02:00