Commit Graph

805 Commits

Author SHA1 Message Date
Evan Mark Hopkins
5f8e4f6dea
[spv] Fix OpImageQueries to allow Uints (#2404) 2023-07-24 21:25:45 +02:00
teoxoy
ee81f569df add constructors test file 2023-07-17 16:26:08 -07:00
teoxoy
d348d843e1 implement const-expressions (phase 1) 2023-07-17 16:26:08 -07:00
Fredrik Fornwall
dfd88ee485
[glsl-in] Support commas in structure definitions (#2400) 2023-07-17 16:22:25 +01:00
Teodor Tanasoaia
a550b0b499
Split image bounds check policy (#2265) 2023-06-29 14:59:37 +00:00
wicast
25e4f17a69
add debug info for spv-out (#2379) 2023-06-28 14:30:25 +02:00
Elabajaba
adf1cca68d
Implement Pack/Unpack for HLSL (#2353) 2023-06-23 15:52:22 +02:00
Teodor Tanasoaia
ffe2308a60
rename allow_point_size to allow_and_force_point_size (#2280) 2023-06-22 06:36:54 -07:00
Eduard-Mihai Burtescu
f915d39a87 [spv-out] Use IndexSet instead of HashSet for iterated sets (capabilities/extensions). 2023-06-21 13:30:01 -07:00
Igor Shaposhnik
f31093fb3b Add array-in-function-return-type test 2023-06-15 14:53:19 +02:00
teoxoy
08105461ce omit non referenced expressions 2023-06-12 17:49:06 -07:00
Erich Gubler
91d48b2923 build: move from make to cargo xtask workflows
Re-implement `naga` development workflows using [`cargo xtask`]. Convert
`make` logic and shader test configuration as file with Bash variables
into an `xtask` crate and YAML files, respectively.

Pros:

* We now have a _portable_ workflow everywhere, which means Windows
  folks and people who don't install `make` don't have to suffer.
  😮‍💨
* Workflow logic is now relatively easy to inspect and change. Whew!
  💁🏻‍♂️💦
* Contributors can use their existing Rust knowledge to contribute to
  developer experience. 🎉
* `cargo xtask` is a relatively well-known convention for workflows in
  the ecosystem.
* We can do fancy things like allow folks to run at different log levels
  for workflows, depending on their tastes.

Cons:

* There's now a non-trivial compile step to project workflow.
  Incremental rebuilds seem to be pretty short, though!
* Code is much more verbose than the (very) terse `make` implementation.

[`cargo xtask`]: https://github.com/matklad/cargo-xtask
2023-06-08 16:56:57 +02:00
daxpedda
b7f4006e46
Bump bitflags to v2 (#2358) 2023-06-01 15:40:47 +02:00
Pieter-Jan Briers
544ccf88da
Handle case insensitive FXC HLSL keywords. (#2347)
There are a few keywords like "pass" in HLSL that are actually case-insensitive for FXC. This can be disabled with strict mode, but even if you do that FXC will continue to give an error if you try to use them in identifiers (at all, with any casing).

This changes the namer code to escape these keywords even if the casing is different.

If you're wondering where I got the list from: I looked at the list of strings in D3DCompiler_47.dll.
2023-05-31 15:00:23 +02:00
Teodor Tanasoaia
5206c59509
update snapshots (#2363) 2023-05-30 14:03:10 +02:00
Daniel McNab
907b7c7cda
Workgroup uniform load (#2201)
Implement the WGSL `workgroupUniformLoad` function.
2023-05-26 13:32:22 -07:00
Shaye Garg
1c17fa82d4
[wgsl-in] Error on param redefinition (#2342)
* error on param redefinition

* also fix #2312
2023-05-25 13:13:27 +02:00
Ashley
ce48588d74
[front/spir-v] Obey the is_depth field of OpTypeImage (#2341)
* [front/spir-v] Obey the is_depth field of OpTypeImage

* Add changed tests
2023-05-22 09:35:58 -07:00
Eduard-Mihai Burtescu
423a069dcd [spv-in] Convert conditional backedges to break if. 2023-05-12 13:59:08 -07:00
Teodor Tanasoaia
62b287e761
Change type of constant sized arrays to NonZeroU32 (#2337) 2023-05-12 14:38:50 +02:00
Jim Blandy
959c84f039 [glsl-in] Generate Expression::Literal. 2023-05-11 07:09:53 -07:00
Jim Blandy
412d5aa62e [wgsl-in] Generate Expression::Literal. 2023-05-11 07:09:53 -07:00
Teodor Tanasoaia
4d87401fac Use Expression::ZeroValue in SPIR-V and WGSL front ends. 2023-05-10 19:30:03 -07:00
Jim Blandy
59a2441a43
[msl-out] Revert af4d989 since #764 removes the need for it (#2331)
Assigning arrays by value works fine since all arrays are now wrapped by a struct.

Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2023-05-09 16:20:15 -07:00
Ashley
da3f43394f
[wgsl-out] Simplify map_binding_to_attribute to always return an interpolate attribute (#2318) 2023-05-02 13:50:59 +02:00
Evan Mark Hopkins
9befaed7e9
[hlsl-out] Fix return type for firstbitlow/high (#2315) 2023-04-25 14:49:26 +02:00
Dzmitry Malyshau
37b3c36a8f
Support array bindings of buffers (#2282)
* Support buffer resource arrays in IR, wgsl-in, and spv-out

* spv-out: refactor non-uniform indexing semantics to support buffers

* Update the doc comment on BindingArray type

* Improve TypeInfo restrictions on binding arrays

* Strip DATA out of binding arrays

* Include suggested documentation, more binding array tests, enforce structs
2023-04-24 21:30:49 -07:00
teoxoy
b9c5cb5a78 validate vertex stage returns the position built-in 2023-04-12 10:48:18 -07:00
daxpedda
f59668ccfa
Allow array_index to be unsigned (#2298) 2023-04-07 16:01:55 +02:00
Erich Gubler
99a7773e65
fix(hlsl-out): use Interlocked<op> intrinsic for atomic integers (#2294)
We currently assume that we are using raw `RWByteAddressBuffer` methods for all atomic operations (`<pointer>.Interlocked<op>(<raw_byte_offset>, …)`), which is only true when we use `var<storage, read_write>` globals. For `var<workgroup>` globals, we need `Interlocked<op>(<pointer>, …)`, using the original expression as the first argument.

Fix this by branching on the `pointer`'s address space in `Atomic` statements, and implementing the workgroup address space case with intrinsics.

Remove atomic ops from `access`, add new `atomicOps` test.

Fixes #2284
2023-04-05 19:37:22 -07:00
Christopher Fleetwood
7c00548075
[wgsl] Use alias instead of type for type aliases (#2299) 2023-04-04 12:35:32 +02:00
PyryM
52043be004
[spv-out] Fix invalid spirv being generated from integer dot products (#2291)
* Fix invalid spirv generation in int dotprod

constants cannot be declared inside of a function block, so instead use `write_constant_null` to produce a correctly-declared constant 0.

* autogenerated test snapshots
2023-03-30 16:02:54 +02:00
Jim Blandy
53d62b9ede Clean up handling of RayDesc builtin type, somewhat. 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
c34eed5e47 Address Jim's review notes, use typegen module for atomic struct 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
024c197cc8 ray query: validation, better test 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
532d1ad510 msl: ray query support 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
22e341b039 wgsl: handle RayDesc/RayIntersection at the type decl level instead of an AST constructor 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
ab9c36441f fill up the ray query intersection struct 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
67d31b8e8c spv-out: basic ray query support 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
b856625821 Ray query expressions and special types 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
e46c53d212 Add ray query statements to the IR 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau
432b4990a7 Add ray query types to the IR 2023-03-22 17:23:07 -07:00
Erich Gubler
0b87d1918a
fix(hlsl): emit constructor functions for arrays (#2281)
* test(hlsl-out): add failing case for array as ctor arg

See issue #2184.

* fix(hlsl): emit constructor functions for arrays
2023-03-20 17:21:52 +01:00
Andreas Reich
67c081bebe
[spirv-out] Fix adding illegal decorators on fragment outputs. (#2286)
* [spirv-out] Fix adding illegal decorators on fragment outputs.

Furthermore, fix allowing to add `Centroid` and `Sample` decorator to vertex inputs.
Fixes #2270

* Add test for fragment outputs

* Fix fragment-output.wgsl test using more than 8 outputs in a single shader
Breaks HLSL & MSL validation

* formatting
2023-03-20 13:43:13 +01:00
Evan Mark Hopkins
6db8da72ca
Add partial derivative builtins (#2277)
* Add partial derivative builtins

* [dot] emit derivative control

* Fix fmt

---------

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2023-03-17 00:15:44 +01:00
Teodor Tanasoaia
63e91faecb
Skip gl_PerVertex unused builtins in the SPIR-V frontend (#2272)
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2023-03-15 18:46:25 +01:00
Evan Mark Hopkins
7f829c6ac6
[glsl-in] Switch implicit type conversion (#2273) 2023-03-14 10:11:03 +01:00
Pâris DOUADY
a7b52b8663
enforce discard only in fragment (#2262) 2023-02-27 10:47:10 +01:00
Arman Uguray
00be08e9f8
[msl-out] Replace per_stage_map with per_entry_point_map (#2237)
The existing `per_stage_map` field of MSL backend options specifies
resource binding maps that apply to all entry points of each stage type.
It is useful to have the ability to provide a separate binding index map
for each entry point, especially when the same shader module defines
multiple entry points of the same stage kind.

This patch replaces `per_stage_map` with a new `per_entry_point_map`
option where resources are keyed by the entry-point function name.
2023-02-22 18:15:39 +01:00
Teodor Tanasoaia
9742f1616c
fix zero initialization of workgroup memory (#2259)
Use the local (not global) invocation id to decide which invocation should do the initialization, so that every workgroup gets initialized, not just the first.
2023-02-20 19:56:24 -08:00
Teodor Tanasoaia
cde457cedd
[spv-out] fix countLeadingZeros impl (#2258) 2023-02-20 20:40:26 +00:00
Mauro Gentile
810e9d26fc
Add countTrailingZeros (#2243)
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2023-02-20 20:40:59 +01:00
Evan Mark Hopkins
60c0fc0284
[spv-out] Cache constant composites (#2257) 2023-02-20 15:24:20 +01:00
Leah
58105a06e2
[glsl/hlsl-out] Write sizes of arrays behind pointers in function arguments (#2250)
arrays can be put behind pointers in inout and out parameters in GLSL and HLSL,
whose dimensions must be specified to let array access
compile. so, we specify their dimensions.

fixes #2248
2023-02-17 00:40:21 +00:00
Evan Mark Hopkins
7422ace934
[wgsl-in] Add predeclared vector and matrix type aliases (#2251) 2023-02-16 15:49:54 -08:00
Josh Groves
f48b6bf2a7
Skip invariant for gl_FragCoord on WebGL2 (#2254) 2023-02-16 15:33:24 -08:00
teoxoy
cc3a8ac737 add Capabilities::MULTISAMPLED_SHADING 2023-02-16 18:16:49 -05:00
teoxoy
df567a94eb add Capabilities::MULTIVIEW 2023-02-16 18:16:49 -05:00
Evan Mark Hopkins
1ad47f732d
Fix texture built-ins where u32 was expected (#2245)
- The Typifier was updated to expect `uint`
- Both `glsl` and `spv` frontends where updated to cast the result to `sint`.
- Both `glsl` and `spv` backends where updated to cast the result to `uint`.
- Remove cast in `msl` backend.
2023-02-13 14:13:58 +01:00
João Capucho
f038537e61 glsl-in: Add tests for output parameters casts 2023-02-08 11:39:09 +00:00
João Capucho
fc81a20f53
spv-in: Don't apply interpolation to fragment shaders outputs (#2239)
SPIR-V doesn't allow the `Flat`, `NoPerspective`, `Sample` or
`Centroid` decorations on fragment shaders outputs, but the spirv
frontend was applying default interpolation to all outputs
unconditionally.

This wasn't an issue for most shaders since they output floats and the
default values for them don't interfere with SPIR-V semantics, but if
the shader returned a uint or int the interpolation would be set to
`Flat` which as stated above is disallowed.

This commit fixes the issue by only running the default interpolation
code when constructing the entry point and if the stage/IO allow it.
2023-02-03 11:48:23 +01:00
Evan Mark Hopkins
4b796b157c
[glsl-out] Version check countLeadingZeros (#2238) 2023-02-02 22:11:09 +01:00
Evan Mark Hopkins
fb2d438dbd
[msl-out] Update firstLeadingBit for signed integers (#2235)
The prior code only supported unsigned integers.

Also fixes #2236.

Co-authored-by: Jim Blandy <jimb@red-bean.com>
2023-02-02 09:47:17 -08:00
Artavazd Balaian
fe851fb008
[glsl] Inject default gl_PointSize = 1.0 in vertex shaders if FORCE_POINT_SIZE option was set (#2223)
According to https://registry.khronos.org/OpenGL/specs/es/3.2/GLSL_ES_Specification_3.20.html#built-in-language-variables

> The variable gl_PointSize is intended for a shader to write the size of the point to be rasterized. It is measured in pixels. If gl_PointSize is not written to, its value is undefined in subsequent pipe stages.

- Write warn message if `ClipDistance` and `CullDistance` are used on unsupported version

---------

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2023-02-02 13:08:18 +01:00
SparkyPotato
a5c2cf94b8 update tests 2023-02-01 12:28:31 +01:00
Dzmitry Malyshau
16be1a9237
spv-out: support version 1.4 (#2230)
* spv-out: support version 1.4

* Extract SPV version numner from the comment
2023-02-01 12:24:05 +01:00
Evan Mark Hopkins
6be394dac3
Add countLeadingZeros (#2226)
* Add countLeadingZeros

* [glsl-out] Bake countLeadingZeros

* [hlsl-out] Bake countLeadingZeros

* [hlsl-out] Update Baked expressions

* Remove unnecessary bake for sints

* [glsl-out] CountLeadingZeros without findMSB

* Don't check negatives when uint

* Perform the type conv after mix

* use log2

* fix clippy lints

---------

Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2023-01-31 21:31:05 +01:00
teoxoy
a2b39e45bf [hlsl-out] clear named_expressions inserted by duplicated blocks
changed the type of `named_expressions` from `HashMap` to `IndexMap` so that insertion order is preserved
2023-01-31 10:43:02 -08:00
Shaye Garg
67ea8f0c06
[wgsl-in] Split into multiple files (#2207)
Make changes suggested in #2075, but put off to a separate PR because they would interfere with reviewing the change:

- Split the new WGSL front end into modules in a logical way.
- Rename `Parser` to `Frontend`.
2023-01-31 07:17:58 -08:00
João Capucho
ae049edc49 glsl-in: Add not vector relational builtin 2023-01-31 13:29:37 +00:00
João Capucho
191d71c107 glsl-in: Add test for relational vector builtins 2023-01-31 13:29:37 +00:00
Jim Blandy
ca99d8bcbc Inline identifiers into format strings.
[Since Rust 1.58], Rust format strings have been able to "capture
arguments simply by writing {ident} in the string." Clippy 1.67 made
the corresponding warning, `uninlined_format_args`, warn-by-default.
Inlined arguments seem more readable, so Naga should adopt them.

[Since Rust 1.58]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1580-2022-01-13
2023-01-31 11:27:51 +01:00
teoxoy
c7d02151f0 add support for zero-initializing workgroup memory 2023-01-25 18:07:48 +01:00
teoxoy
3ace8b81cb fix array being flagged as constructible when its base isn't 2023-01-25 18:07:48 +01:00
teoxoy
85e3b0844f add type_flags to ModuleInfo 2023-01-25 18:07:48 +01:00
teoxoy
a42857d291 [hlsl-out] simplify write_default_init 2023-01-25 18:07:48 +01:00
Patryk Wychowaniec
954cbaaff3
[spv-in] Support binding arrays (#2199) 2023-01-25 17:49:52 +01:00
Teodor Tanasoaia
f70d8ec51f
update test snapshots (#2219) 2023-01-23 11:09:15 +00:00
robtfm
4142971cb1
glsl: include unused items (#2205)
* include_unused_items

* clippy

* tests

* rename original const if possible
2023-01-23 11:58:05 +01:00
Evan Mark Hopkins
74e5b4a07e [wgsl] Update inverse hyperbolic built-ins 2023-01-23 11:50:50 +01:00
Evan Mark Hopkins
9f182ade30 [wgsl] Add refract built-in 2023-01-23 11:50:50 +01:00
SparkyPotato
6035b07b78 [wgsl-in] Implement module-level scoping.
Fixes #1745: Support out-of-order module scope declarations in WGSL
Fixes #1044: Forbid local variable shadowing in WGSL
Fixes #2076: [wgsl-in] no error for duplicated type definition
Fixes #2071: Global item does not support 'const'
Fixes #2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument
Fixes #1775: Referencing a function without a return type yields an unknown identifier error.
Fixes #2089: Error span reported on the declaration of a variable instead of its use
Fixes #1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'"

Separate parsing from lowering by generating an AST, which desugars as
much as possible down to something like Naga IR. The AST is then used
to resolve identifiers while lowering to Naga IR.

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2023-01-12 09:37:08 -08:00
teoxoy
5b4e94630b [glsl-out] use fma polyfill for versions below gles 320 2023-01-06 17:20:27 -08:00
PENGUINLIONG
24316fd4bc
Allow u32 coordinates for textureStore/textureLoad (#2172) 2022-12-22 18:59:22 +01:00
Dzmitry Malyshau
76d30e5055 Add ValidationFlags::BINDINGS 2022-12-13 12:59:28 -05:00
Avi Weinstock
5d8fc3fdcf
[wgsl-in/spv-out] Add support for WGSL's atomicCompareExchangeWeak (#2165)
* Add support for WGSL's `atomicCompareExchangeWeak` with the `__atomic_compare_exchange_result` struct, and add SPIR-V codegen for it.

Partially addresses https://github.com/gpuweb/gpuweb/pull/2113, #1755.

* Add tests for `atomicCompareExchangeWeak`, and support both u32 and i32 atomics with it.

* More thorough typechecking of the struct returned by `atomicCompareExchangeWeak`.
2022-12-13 10:47:28 +01:00
teoxoy
8f1d82f0d2 [wgsl] update reserved keywords 2022-12-12 16:54:21 -08:00
Teodor Tanasoaia
ee5c343038 fix tests 2022-12-12 09:46:38 -08:00
Teodor Tanasoaia
4748721857 remove comment 2022-12-12 09:33:24 -08:00
Jim Blandy
0197246365 Ignore unused_imports in tests/snapshots.rs.
This is for the same reason that we ignore `dead_code`:

    // A lot of the code can be unused based on configuration flags,
    // the corresponding warnings aren't helpful.
2022-12-12 11:14:17 +01:00
Jonathan Behrens
4f77cbafb7
[wgsl-out] Write correct scalar kind when width != 4 (#1514)
* [wgsl-out] Write correct scalar kind when width != 4

* slight refactoring

* Also handle matrix scalar widths

* Fix formatting
2022-12-12 10:56:28 +01:00
teoxoy
f36adeefaa [glsl-out] introduce a new block for switch cases 2022-12-09 10:21:58 -08:00
teoxoy
eccdc0aeb1 [spv-out] omit extra switch case blocks where possible 2022-12-09 10:21:58 -08:00
teoxoy
be70a2ec03 [spv-out] fix switch cases after default not being output 2022-12-09 10:21:58 -08:00
teoxoy
3455147496 [hlsl-out] omit extra switch case blocks where possible 2022-12-09 10:21:58 -08:00
teoxoy
db63877c8c [msl-out] omit extra switch case blocks where possible 2022-12-09 10:21:58 -08:00
teoxoy
e05706bc48 [wgsl] remove fallthrough statement
also add support for default to be used with other case selectors
2022-12-09 10:21:58 -08:00
JMS55
bf4e62b1ac
Fix textureGather on texture_2d<u32/i32> (#2138)
* Fix textureGather on texture_2d<u32/i32>

* Add textureGather u32/i32 tests

* Update src/valid/expression.rs

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

* Fix formatting

* undo analyzer change

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2022-12-05 10:03:11 +00:00
João Capucho
d1c29534c8
glsl-in: Fix position propagation in lowering (#2079)
When lowering `Select` expressions the position could be wrongfully
updated from `AccessBase { constant_index: false }` to
`AccessBase { constant_index: true }` this caused dynamic indexing
in an array behind a structure to fail if it was stored in a constant.

Furthermore the position could also be updated from `Rhs` to
`AccessBase`, this could cause issues because `AccessBase` doesn't
load variables (which `Rhs` does), so accessing a member from a
structure behind a pointer would return the wrong result.
2022-12-02 10:48:20 +01:00
Erich Gubler
aa22301b4b
Parenthesize unary negations to avoid -- (#2087)
* fix(glsl-out,hlsl-out,msl-out): parenthesize unary negations a la `wgsl` everywhere

Unify parenthesization of unary negations across all backends with what the `wgsl` backend does,
which is `<op>(<expr>)`. This avoids ambiguity with output languages for which `--` is a different
operation; in this case, we've been accidentally emitting prefix decrements.

* build: update `rspirv` 0.11 -> 0.12 (FIXME: use upstream release)

* test: add `operators::negation_avoids_prefix_decrement` test

Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com>
2022-11-17 11:43:56 +01:00