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
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.
* 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
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
* 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
* [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
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.
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.
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
- 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.
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.
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>
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`.
[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
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>
* 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`.
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.
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.
* 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>