Commit Graph
545 Commits
Author SHA1 Message Date
Jim Blandy 21c527a458 [naga spv-out] Doc fix: typo 2024-10-08 11:53:15 -07:00
Jim Blandy 634a97fcb8 [naga spv-out] Abstract out non-uniform binding array access test.
Introduce a new function,
`BlockContext::is_nonuniform_binding_array_access`, which determines
whether a given array access expression means that the `OpAccessChain`
instruction must have a `NonUniform` decoration.
2024-10-08 11:53:15 -07:00
ChosenName 43cb730d58 [naga] added DrawID (#6325) 2024-10-08 13:00:00 +00:00
Jim Blandy e432980a73 [naga spv-out] Don't emit unreachable blocks that jump into loops.
When generating SPIR-V, avoid generating unreachable blocks following
statements like `break`, `return`, and so on that cause non-local
exits. These unreachable blocks can cause SPIR-V validation to fail.

Fixes #6220.
2024-10-03 21:07:18 -07:00
Jim Blandy 04182c24ec [naga spv-out] Make write_block and its types private.
Make `naga::back::spv::BlockContext::write_block` private to
`naga::back::spv::block`. Introduce a new `pub(super)` function,
`write_function_body`, for `Writer::write_function` to call.

Make `BlockExit` private to `naga::back::spv::block`.

Move `LoopContext` from `naga::back::spv` into
`naga::back::spv::block`, and make it private.
2024-10-03 21:07:18 -07:00
Jim Blandy d3e09dd63a [naga spv-out] Consolidate explanation of global wrapping.
Consolidate the explanation of why and how we wrap Naga global
variables in structs to satisfy Vulkan's requirements, and include it
in the documentation for `back::spv::GlobalVariable`.

Clarify `GlobalVariable`'s members documentation.
2024-10-03 10:13:08 -07:00
Erich Gubler 6e528aaf24 style: split (most) string literals over 100-column line width limit 2024-10-03 10:57:28 -04:00
Erich Gubler 9f275f7655 style: remove comments from MathFunction type res. that stop rustfmt 2024-10-03 10:57:28 -04:00
Erich Gubler 25b2b6afa1 style: newline b/w Span::{UNDEFINED, new} 2024-10-03 10:57:28 -04:00
Erich Gubler 78928654a2 style(wgsl-in): unblock rustfmt in Error::as_parse_error 2024-10-03 10:57:28 -04:00
Erich Gubler 3d584f99ed refactor(spv-out): linkify docs. ref. to write_bounds_check 2024-10-02 22:35:09 -04:00
Jim Blandy 215f0fc887 [naga spv-out] Internal doc fixes for back::spv::index.
In `naga::back::spv::index`, clarify documentation for:
- `BoundsCheckResult`
- `write_index_comparison`
- `write_bounds_check`
2024-10-02 22:35:09 -04:00
2d82054ae4 [wgsl-in, spv-out] Allow dynamic indexing of arrays by value.
Bring https://github.com/gfx-rs/naga/pull/723 back from the dead.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-10-02 18:07:02 -07:00
Jim Blandy 2021e7f29f [naga spv-out] Document and refactor write_runtime_array_length.
Document and refactor
`naga::back::spv::BlockContext::write_runtime_array_length`.

Don't try to handle finding the length of a particular element of a
`binding_array<array<T>>`. The SPIR-V backend doesn't wrap that type
correctly anyway; #6333 changes the validator to forbid such types.
Instead, assume that the elements of a `binding_array<T>` are always
structs whose final members may be a runtime-sized array.

Pull out consistency checks after the analysis of the array
expression, so that we always carry out all the checks regardless of
what path we took to produce the information.
2024-09-27 17:02:34 -07:00
Jim Blandy 259592b926 [naga spv-out] Update Vulkan spec section number, and provide link. 2024-09-27 17:02:34 -07:00
Jim Blandy 04032905ef [naga spv-out] Replace match with equivalent !=. 2024-09-27 17:02:34 -07:00
Jim Blandy 98c4d6f42e [naga] Permit only structs as binding array elements. (#6333)
Require `T` to be a struct in `binding_array<T, ...>`; do not permit
arrays.

In #5428, the validator was changed to accept binding array types that
the SPIR-V backend couldn't properly emit. Specifically, the validator
was changed to accept `binding_array<array<T>>`, but the SPIR-V
backend wasn't changed to wrap the binding array elements in a SPIR-V
struct type, as Vulkan requires. So the type would be accepted by the
validator, and then rejected by the backend.
2024-09-27 17:00:21 -07:00
Samson 866be693d6 [naga] Handle phony statements properly by treating them as named expressions (#6328)
* [naga wgsl-in] phony assignments add named expressions

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* [naga wgsl-out] write out _naga_phony as phony

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Add test

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* use statement span

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* every phony has same name

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-27 14:52:53 -07:00
Jim Blandy e7f891bf2b [naga] Remove redundant handle ordering check from validator. (#6321)
`Validator::validate_module_handles` already ensures that types refer
only to other types appearing earlier in the arena than themselves, so
this check in `Validator::validate_type` is redundant.
2024-09-25 17:10:27 -04:00
Hamir Mahal 8e787eb70a style: simplify string formatting for readability (#6316) 2024-09-24 23:40:53 -04:00
Jasper St. Pierre 390a4169fb naga: Don't consider per-polygon inputs to be subgroup uniform
Implementations can absolutely pack multiple triangles per subgroup.

Fixes #6270.
2024-09-22 03:57:41 -04:00
Erich Gubler b54fb72d4a chore: un-regress unused_qualifications lint in naga::front::spv (#6297)
Regressed in #5824.
2024-09-20 09:29:05 +02:00
Erich Gubler f942ceef9b docs(msl-out): note that Dawn also avoids loop UB like we do 2024-09-18 09:12:58 -07:00
Jim Blandy 3fda684eb9 [naga msl-out] Defeat the MSL compiler's infinite loop analysis.
See the comments in the code for details.

This patch emits the definition of the macro only when the first loop
is encountered. This does make that first loop's code look a bit odd:
it would be more natural to define the macro at the top of the
file. (See the modified files in `naga/tests/out/msl`.)

Rejected alternatives:

- We could emit the macro definition unconditionally at the top of the
  file. But this changes every MSL snapshot output file, whereas only
  eight of them actually contain loops.

- We could have the validator flag modules that contain loops. But the
  changes end up being not small, and spread across the validator, so
  this seems disproportionate. If we had other consumers of this
  information, it might make sense.

- We could change the MSL backend to allow text to be generated out of
  order, so that we can decide whether to define the macro after we've
  generated all the function bodies. But at the moment this seems like
  unnecessary complexity, although it might be worth doing in the
  future if we had additional uses for it - say, to conditionally emit
  helper function definitions.

Fixes #4972.
2024-09-18 11:01:51 -04:00
Schell Carl ScivallyandJim Blandy fc85e4f970 spv-in parse more atomic ops (#5824)
* add parsing for spirv::Op::AtomicLoad and spirv::Op::AtomicStore

* spv-in parse AtomicExchange and AtomicCompareExchange

* add atomic i decrement

* bookend atomic store statement with emmitter.finish/emitter.start to suppress a double load expression

bookend atomic result expressions with emitter.finish/start to prevent double defs

* add atomic iadd, isub, smin, umin, smax, umax, and, or, xor

* parse atomic flag test and set, parse atomic flag clear

* remove atomic compare exchange work

* changelog

* moved spirv tests into front/spv/mod.rs

* feature gate atomic spv tests because they require wgsl-[in,out]

* BlockContext::get_contained_global_variable returns Result

* Generate spans covering the entire instruction.

Granted, there is pre-existing code in the SPIR-V front end that gets
this wrong, but:

It doesn't make sense to read `self.data_offset`, and then immediately
pass that to `self.span_from_with_op`. The point of that function is
to make the span cover the entire instruction, operands included.

* Move `From` implementation into spv front end

* doc comments, minor cleanups

* remove parsing of OpAtomicFlagClear and OpAtomicFlagTestAndSet

* sync atomic spvasm files

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-09-18 05:39:36 +00:00
Dzmitry Malyshau eb18854b46 spv-out: configure source language in debug info 2024-09-13 11:37:23 -07:00
Valaphee The Meerkat 07684d3623 Rename Rg11b10UFloat to Rg11b10Ufloat (#6226) 2024-09-06 11:46:49 +02:00
Jim Blandy 64ea7efc04 [naga] Update docs for private items. (#6218)
Make `cargo doc --document-private-items` work again in Naga.

Update some documentation missed by the local const work in #6156.
2024-09-05 10:15:02 +02:00
Samson 4e9a2a5003 [naga wgsl] Impl const_assert (#6198)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-02 17:37:04 +00:00
Samson ace2e201cf [naga wgsl-in] allow global vars without explicit type (#6199)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-02 18:27:52 +02:00
Samson 105cb9db31 [naga wgsl-in] Proper singular generic in vec and matrix (#6189)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-09-02 14:04:51 +02:00
Samson 26398ea0db Use checked_mul or leading_zeros for shl overflows (#6186)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-08-31 11:31:50 +02:00
Samson 585f4a1036 [naga wgsl] all swizzle components must be either color or dimension (#6187) 2024-08-31 11:08:34 +02:00
Erich Gubler 04618b36a8 feat(wgsl): add first and either sampling for @interpolate(flat, …) (#6181) 2024-08-30 15:08:00 +00:00
Samson 34bb9e4ceb [naga wgsl] Implement local const declarations (#6156) 2024-08-30 11:55:03 +02:00
Erich Gubler 0ce5996891 refactor(naga): split out cross handling to separate match arm 2024-08-28 13:26:54 -04:00
Erich Gubler 7164f3eb4e fix(wgsl): narrow accepted args. of cross to vec3<$float> 2024-08-28 13:26:54 -04:00
Kornel c7e5d07dee Reduce size of parse error 2024-08-27 10:52:02 +02:00
Kornel 222f1ea733 Reduce code size of error handling 2024-08-19 14:38:20 +01:00
vero 3178ffb0d7 Fix hlsl image type conversion (#6123) 2024-08-19 10:24:40 +02:00
Erich Gubler 23e7846400 refactor(hal): satisfy trivial_casts 2024-08-15 14:14:13 +01:00
Samson c6a3d92734 Rg11b10Float -> Rg11b10UFloat and deduplicate entries in TEXTURE_FORMAT_LIST (#6108)
* Resync `TEXTURE_FORMAT_LIST` to match `TextureFormat`

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* `Rg11b10Float` -> `Rg11b10UFloat`

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Add changelog entry

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2024-08-13 08:28:55 +00:00
Erich Gubler 5533c37786 chore: satisfy clippy::collapsible_match 2024-08-13 08:42:41 +01:00
Erich Gubler 22b8f50987 chore: satisfy unused_qualifications lint 2024-08-13 08:42:41 +01:00
Erich Gubler 7f881bd35f chore(naga): remove broken Unsupported64Bit tests
Seemingly missed in 4e6f873da5.
2024-08-13 08:42:41 +01:00
Erich Gubler ce23c02feb chore(naga): remove dead "validation" feat. refs.
Missed in a26e4a00, but we're fixing it now!
2024-08-13 08:42:41 +01:00
Jim Blandy 7ff80d65fc [naga] Use cfg aliases to enable naga::back::continue_forward.
Rather than `feature = "blah"`, use the new `cfg` identifiers
introduced by the `cfg_aliases` invocation in `naga/build.rs` to
decide whether to compile the `naga::back::continue_forward` module,
which is only used by the GLSL and HLSL backends.

The `hlsl_out` `cfg` identifer has a more complex condition than just
`feature = "hlsl-out"`, introduced by #5919.

Fixes #6063.
2024-07-31 06:08:07 -04:00
teoxoy ccd6d2ca48 remove BoundsCheckPolicies.image_store 2024-07-26 10:44:22 -07:00
teoxoy 1f4f675b1b [naga] add back PartialEq derives for some types 2024-07-26 09:37:52 -07:00
Erich Gubler 591e1d2a08 refactor(naga)!: remove FunctionTracer::overrides 2024-07-24 13:42:04 -04:00