Commit Graph

74 Commits

Author SHA1 Message Date
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
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
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
Schell Carl Scivally
76b1605090
[spv-in] sampling from depth textures returns a scalar and is splatted (#6384) 2024-10-11 20:24:16 +02:00
Jim Blandy
1047fa57f0 [naga] Move array-by-value snapshot tests to index-by-value.wgsl. 2024-10-11 08:27:15 -07:00
Jim Blandy
ed3006ccc6 [naga spv-out] Spill arrays and matrices for runtime indexing.
Improve handling of `Access` expressions whose base is an array or
matrix (not a pointer to such), and whose index is not known at
compile time. SPIR-V does not have instructions that can do this
directly, so spill such values to temporary variables, and perform the
accesses using `OpAccessChain` instructions applied to the
temporaries.

When performing chains of accesses like `a[i].x[j]`, do not reify
intermediate values; generate a single `OpAccessChain` for the entire
thing.

Remove special cases for arrays; the same code now handles arrays and
matrices.

Update validation to permit dynamic indexing of matrices.

For details, see the comments on the new tracking structures in
`naga:🔙:spv::Function`.

Add snapshot test `index-by-value.wgsl`.

Fixes #6358.
Fixes #4337.
Alternative to #6362.
2024-10-11 08:27:15 -07:00
Jim Blandy
f9075fc4b8 [naga] Test access to a member/element through a pointer. 2024-10-11 08:27:15 -07:00
Ronny Chan
73764fdc6a
[naga/wgsl-out]: polyfill inverse function (#6385) 2024-10-11 15:56:12 +02:00
Jim Blandy
7283185305 [naga] Extend snapshot tests for bounds checks.
Extend the snapshot tests for bounds checking to cover the case where
a runtime-sized array is indexed by a constant.
2024-10-08 11:53:15 -07: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
sagudev
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
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
Schell Carl Scivally
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
Erich Gubler
2aa69e1bb2 test(wgsl): note link b/w cross and bad_cross_builtin_args tests 2024-09-04 15:08:56 -04:00
Erich Gubler
fcbec57d84 test(wgsl): test explicit center with {perspective,linear} interpolation 2024-09-04 15:08:56 -04: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
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
327b92e92b test(wgsl): check that vec3 args. are accepted in cross built-in 2024-08-28 13:26:54 -04:00
teoxoy
ccd6d2ca48 remove BoundsCheckPolicies.image_store 2024-07-26 10:44:22 -07:00
Imbris
6d7975eb3b [naga hlsl-out glsl-out] Work around backend loop/switch bugs.
Introduce a new module, `naga:🔙:continue_forward`, containing
shared code for rendering Naga `Continue` statements as backend
`break` statements and assignments to introduced `bool` locals.
See the module's documentation for details.

- [hlsl-out] Transform degenerate single body switches into `do-while`
  loops. Properly render `Continue` statements enclosed by
  `Switch` statements enclosed by `Loop` statements.

- [glsl-out] Transform degenerate single body switches into `do-while`
  loops.

Improve `naga xtask validate spv` error message.

Fixes #4485.
Fixes #4514.
2024-07-23 18:12:19 -07:00
Dzmitry Malyshau
1b4e8ada63 spv-out: fix acceleration structure in a function argument 2024-07-15 10:05:51 +02:00
JMS55
17fcb19425
[naga, hal] miscellaneous fixes for Atomic64 support (#5952)
In `naga:🔙hlsl`:

- Generate calls to `Interlocked{op}64` when necessary. not
  `Interlocked{op}`.

- Make atomic operations that do not produce a value emit their
  operands properly.
  
In the Naga snapshot tests:

- Adapt `atomicOps-int64-min-max.wgsl` to include cases that
  cover non-trivial atomic operation operand emitting.

In `wgpu_hal::vulkan::adapter`:

- When retrieving physical device features, be sure to include
  the `PhysicalDeviceShaderAtomicInt64Features` extending struct
  in the chain whenever the `VK_KHR_shader_atomic_int64` extension
  is available.

- Request both `shader_{buffer,shared}_int64_atomics` in the
  `PhysicalDeviceShaderAtomicInt64Features` extending struct when either of
  `wgpu_types::Features::SHADER_INT64_ATOMIC_{ALL_OPS,MIN_MAX}` is requested.

---------

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-07-13 19:17:59 -07:00
Imbris
3a6814770a
Allow unconsumed inputs in fragment shaders (#5531)
* Allow unconsumed inputs in fragment shaders by removing them from vertex
outputs when generating HLSL.

Fixes https://github.com/gfx-rs/wgpu/issues/3748

* Add naga:🔙:hlsl::FragmentEntryPoint for providing information
  about the fragment entry point when generating vertex entry points via
  naga:🔙:hlsl::Writer::write. Vertex outputs not consumed by the
  fragment entry point are omitted in the final output struct.
* Add naga snapshot test for this new feature,
* Remove Features::SHADER_UNUSED_VERTEX_OUTPUT,
  StageError::InputNotConsumed, and associated validation logic.
* Make wgpu dx12 backend pass fragment shader info when generating
  vertex HLSL.
* Add wgpu regression test for allowing unconsumed inputs.

* Address review

* Add note that nesting structs for the inter-stage interface can't
  happen.
* Remove new TODO notes (some addressed and some transferred to an issue
  https://github.com/gfx-rs/wgpu/issues/5577)
* Changed issue that regression test refers to 3748 -> 5553
* Add debug_assert that binding.is_some() in hlsl writer
* Fix typos caught in CI

Also, fix compiling snapshot test when hlsl-out feature is not enabled.
2024-07-04 09:08:46 +02:00
Schell Carl Scivally
6405dcf611 [naga spv-in] Adjust types of globals used by atomic instructions.
To support atomic instructions in the SPIR-V front end, observe which
global variables the input accesses using atomic instructions, and
adjust their types from ordinary scalars to atomic values.

See comments in `naga::front::atomic_upgrade`.
2024-06-21 21:51:25 -07:00
Atlas Dostal
abba12ae4e Add support for 64 bit integer atomic operations in shaders.
Add the following flags to `wgpu_types::Features`:

- `SHADER_INT64_ATOMIC_ALL_OPS` enables all atomic operations on `atomic<i64>` and
  `atomic<u64>` values.

- `SHADER_INT64_ATOMIC_MIN_MAX` is a subset of the above, enabling only
  `AtomicFunction::Min` and `AtomicFunction::Max` operations on `atomic<i64>` and
  `atomic<u64>` values in the `Storage` address space. These are the only 64-bit
  atomic operations available on Metal as of 3.1.

Add corresponding flags to `naga::valid::Capabilities`. These are supported by the
WGSL front end, and all Naga backends.

Platform support:

- On Direct3d 12, in `D3D12_FEATURE_DATA_D3D12_OPTIONS9`, if
  `AtomicInt64OnTypedResourceSupported` and `AtomicInt64OnGroupSharedSupported` are
  both available, then both wgpu features described above are available.

- On Metal, `SHADER_INT64_ATOMIC_MIN_MAX` is available on Apple9 hardware, and on
  hardware that advertises both Apple8 and Mac2 support. This also requires Metal
  Shading Language 2.4 or later. Metal does not yet support the more general
  `SHADER_INT64_ATOMIC_ALL_OPS`.

- On Vulkan, if the `VK_KHR_shader_atomic_int64` extension is available with both the
  `shader_buffer_int64_atomics` and `shader_shared_int64_atomics` features, then both
  wgpu features described above are available.
2024-06-08 18:36:26 -07:00
Brad Werth
9b7a965667 Add an experimental vertex pulling flag to Metal pipelines.
This proves a flag in msl::PipelineOptions that attempts to write all
Metal vertex entry points to use a vertex pulling technique. It does
this by:

1) Forcing the _buffer_sizes structure to be generated for all vertex
entry points. The structure has additional buffer_size members that
contain the byte sizes of the vertex buffers.
2) Adding new args to vertex entry points for the vertex id and/or
the instance id and for the bound buffers. If there is an existing
@builtin(vertex_index) or @builtin(instance_index) param, then no
duplicate arg is created.
3) Adding code at the beginning of the function for vertex entry points
to compare the vertex id or instance id against the lengths of all the
bound buffers, and force an early-exit if the bounds are violated.
4) Extracting the raw bytes from the vertex buffer(s) and unpacking
those bytes into the bound attributes with the expected types.
5) Replacing the varyings input and instead using the unpacked
attributes to fill any structs-as-args that are rebuilt in the entry
point.

A new naga test is added which exercises this flag and demonstrates the
effect of the transform. The msl generated by this test passes
validation.

Eventually this transformation will be the default, always-on behavior
for Metal pipelines, though the flag may remain so that naga
translation tests can be run with and without the tranformation.
2024-05-30 13:08:59 +02:00
Schell Carl Scivally
480d4dbd73
spv-in parsing Op::AtomicIIncrement (#5702)
Parse spirv::Op::AtomicIIncrement, add atomic_i_increment test.
2024-05-30 04:39:32 +00:00
Vladislav
00456cfb37 Add parsing support for un/pack4xI/U8 2024-05-14 17:57:04 +02:00
teoxoy
55c9d69ba0 [naga] fix the way we adjust constant initializers when processing overrides
This fixes 2 issues:
- we used to index `adjusted_global_expressions` with the handle index of the constant instead of its initializer
- we used to adjust the initializer multiple times if the arena contained multiple `Expression::Constant`s pointing to the same constant
2024-04-25 11:04:09 -07:00
teoxoy
c2e520c52c [naga] add Expression::Override to needs_pre_emit 2024-04-22 08:38:31 -07:00
Alexander Meißner
ea77d5674d
Subgroup Operations (#5301)
Co-authored-by: Jacob Hughes <j@distanthills.org>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Co-authored-by: atlas dostal <rodol@rivalrebels.com>
2024-04-17 15:25:52 -04:00
teoxoy
9df68197a4 [spv-in] add support for specialization constants 2024-04-11 09:46:55 -07:00
wicast
17ef6cac90 fix(spv-out): OpSourceContinued for large source (gfx-rs#5390) 2024-04-08 11:27:18 +02:00
teoxoy
7df0aa6364 move the burden of evaluating override-expressions to users of naga's API 2024-04-05 18:07:41 +02:00
Jim Blandy
ba19d8df34 [naga] Adjust RayQuery statements in override processing. 2024-04-05 18:07:41 +02:00
Jim Blandy
8a2bc07f11 [naga] Handle comparison operands in pipeline constant evaluation.
Properly adjust `AtomicFunction::Exchange::compare` after pipeline
constant evaluation.
2024-04-05 18:07:41 +02:00
Jim Blandy
a7d8ee999d [naga] Add missing newline to test input file. 2024-04-05 18:07:41 +02:00
teoxoy
ca252b9e74 allow private variables to have an override-expression initializer 2024-04-05 18:07:41 +02:00
teoxoy
3abdfde0ba evaluate override-expressions in functions 2024-04-05 18:07:41 +02:00
teoxoy
d6ebd88f42 implement override-expression evaluation for initializers of override declarations 2024-04-05 18:07:41 +02:00
teoxoy
2929ec333c [spv/msl/hlsl-out] support pipeline constant value replacements 2024-04-05 18:07:41 +02:00
Teodor Tanasoaia
f949ea69c4 [wgsl-in] add support for override declarations (#4793)
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2024-04-05 18:07:41 +02:00
teoxoy
3bda381812 add pipeline constants plumbing 2024-04-05 18:07:41 +02:00
Dzmitry Malyshau
3a467ad93d spv-out: Support arrayLength of a dynamically indexed bindings array 2024-04-02 19:22:34 +02:00