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
* [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.
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.
* refactor: satisfy `clippy::borrow_deref_ref`
* chore: satisfy `clippy::ptr_arg`
* refactor: satisfy `clippy::needless_update`
* chore: `allow(clippy::too_many_arguments)` on `write_output_glsl` test
Since this is test code, I don't think there's a strong impetus to refactor types to consolidate
or otherwise alter arguments here. Let's just `allow` this.
* refactor: satisfy `clippy::single_match`
I think it's sixes whether to keep this code as-is or to `allow(...)` as-is. 🤷🏻♂️
* refactor: satisfy `clippy::single_char_pattern`
* refactor: satisfy `clippy::reversed_empty_ranges`
The lint fires because it generally doesn't make sense to use a `Range` built this way; [upstream
`Range` docs]) states:
> It is empty if `start >= end`.
`clippy` wants to help us from naively iterating over a `Range` like this! Thanks, `clippy`!
However, we're not actually using the offending `addresses` variables for iteration. We're using
them as a flat data structure with fields that happen to conceptually match. We can, therefore,
sidestep this lint by "just" inlining into separate variables for start and end instead.
[upstream `Range` docs]: https://doc.rust-lang.org/stable/std/ops/struct.Range.html
* refactor: satisfy `clippy::pattern_type_mismatch`
* chore: `allow(clippy::panic)` for `test`
We definitely should let `panic!(...)` calls exist in `cfg(test)`! It's a very standard way to fail
`#[test]` functions. It seems that previous test authors agree! 😅
* fixup! refactor: satisfy `clippy::pattern_type_mismatch`
* fixup! refactor: satisfy `clippy::single_match`
Previously the wgsl frontend wasn't aware of lexical scopes causing all
variables and named expressions to share a single function scope, this
meant that if a variable was defined in a block with the same name as a
variable in the function body, the variable in the function body would
be lost and exiting the block all references to the variable in the
function body would be replaced with the variable of the block.
This commit fixes that by using the previously introduced `SymbolTable`
to track the lexical and perform the variable lookups, scopes are pushed
and popped as defined in the wgsl specification.
Improves the dot backend output by:
- Linking new nodes to the end of other blocks, instead of the beginning
- Generating merge nodes for conditional statements
- Generating connections from break/continue nodes to their target
- Introducing a "cfg only" mode that only generates statements
* Make some (currently hacky) changes to enable multiview in webgl
* Fix ViewIndex built in for this extension
* Run cargo fmt, fix tests
* Allow specifying if we're targetting webgl in the glsl version
* Document multiview2 extension
* fn embedded -> const fn embedded
* Fix tests
* Fix benches
* Add snapshot tests
* Revamp so that the glsl options have some multiview options. Also add tests
* Make clippy happier
* Go back to having is_webgl be part of Version
* Use wgsl as input for tests
* Rename Version::new_embedded to Version::new_gles, fix glsl validation
* Run cargo fmt
* Fix brand new clippy warnings
* glsl-out: Implement bounds checks for `ImageLoad`
* Enable image bounds check snapshot tests for GLSL.
In addition to the snapshot.rs changes, this entails adding an entry
point function to `bounds-check-image-restrict.wgsl` and
`bounds-check-image-rzsw.wgsl`, including appropriate data in the
param.ron files.
* Apply comments
Snapshot test changes:
Co-authored-by: Jim Blandy <jimb@red-bean.com>
* [hlsl-out] add padding at the end of structs and after struct members of type matrix and array (when necessary)
* use wrapped constructor fn for constants
* add array as fn arg test
* fix glsl array fn arg
* add wrapped constructor for arrays
* [glsl-out] support multidimensional arrays
* address comments
* [hlsl-out] Write `mad` intrinsic for `fma` function
- This should be enough because we only support f32 for now.
- Adds a new test for WGSL functions, in the spirit of operators.wgsl.
- Closes#1579
* Add FMA feature to glsl backend
- I think this is right. Just iterate all known expressions in all
functions and entry points to locate any `fma` function call.
Should not need to walk the statement DAG.
* Transform GLSL fma function into an airthmetic expression when necessary
* Add tests for GLSL fma function tranformation
* Remove the hazard comment from the webgl test input
* Add helper method for fma function support checks
* Address review comment