Commit Graph

200 Commits

Author SHA1 Message Date
teoxoy
ee81f569df add constructors test file 2023-07-17 16:26:08 -07: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
Igor Shaposhnik
f31093fb3b Add array-in-function-return-type test 2023-06-15 14:53:19 +02: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
Daniel McNab
907b7c7cda
Workgroup uniform load (#2201)
Implement the WGSL `workgroupUniformLoad` function.
2023-05-26 13:32:22 -07:00
Eduard-Mihai Burtescu
423a069dcd [spv-in] Convert conditional backedges to break if. 2023-05-12 13:59:08 -07: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
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
Dzmitry Malyshau
532d1ad510 msl: ray query support 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
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
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
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
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
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
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
Patryk Wychowaniec
954cbaaff3
[spv-in] Support binding arrays (#2199) 2023-01-25 17:49:52 +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
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
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
Erich Gubler
21c7092762
Satisfy latest clippy lints (up to Rust 1.64) (#2081)
* 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`
2022-11-03 09:32:15 -07:00
Connor Fitzgerald
d974f2f832 [hlsl-out] Properly implement bitcast 2022-10-20 11:00:21 -04:00
João Capucho
d64d78ff0b wgsl-in: Implement lexical scopes
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.
2022-09-01 17:31:50 -07:00
João Capucho
9df243c42c
hlsl-out: Add support for push constants (#2005)
Push constants need to be configured by the consumer which must pass the
bind target of the constant buffer used for the push constants.
2022-08-29 11:58:02 +01:00
João Capucho
c6f34fa4d8 dot-out: Improvements
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
2022-08-03 15:01:26 -07:00
Ashley
e2d688088a
Support for the OVR_multiview2 WebGL extension (#1933)
* 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
2022-06-30 17:58:47 +01:00
João Capucho
67ef37ae99 Add support for 'break if' to IR, wgsl-in, and all backends. 2022-06-24 17:47:07 -07:00
Ashley
ea832a9eec
[glsl-out] Handle vector bitcasts (#1966)
* [spv-in] Fix bitcasts on non-scalars

* Fix ::As handling in glsl

* Cargo fmt

* Make cargo clippy happy

* Add snapshot tests

* Use write_type_value

* target_vector_kind -> target_vector_type
2022-06-20 22:25:13 -07:00
João Capucho
0aa7681165
glsl-out: Implement bounds checks for ImageLoad (#1889)
* 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>
2022-05-30 12:13:58 -07:00
Connor Fitzgerald
1aa9154964
Binding arrays play nice with bounds checks (#1855) 2022-04-25 04:17:51 +00:00
Connor Fitzgerald
ad28396851
Implement Binding Arrays (#1845) 2022-04-19 14:23:07 -04:00
Teodor Tanasoaia
bd62887a13
[hlsl-out] Add more padding when necessary (#1814)
* [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
2022-04-11 20:34:06 -07:00
Jim Blandy
679087bd9c
[msl-out] Bounds checks for ImageLoad and ImageStore. (#1730) 2022-02-21 15:08:14 -08:00
João Capucho
1ccfc8991e glsl-in: Add test for conditional builtin inject 2022-02-19 10:42:44 -05:00
glalonde
bb604fd6a3
Mitigation for MSL atomic bounds check. (#1703)
[msl-out] Correct output for bounds-checked atomic accesses.
2022-02-01 16:37:09 -08:00
Dzmitry Malyshau
76814a83a2 msl: inject point size if needed 2022-01-19 11:33:14 -05:00
João Capucho
a1840beb1a glsl-out: Add test for push constants 2022-01-16 19:32:51 -05:00
Dzmitry Malyshau
b1ab59925d
msl: fix packed float support (#1630) 2021-12-27 02:57:47 +00:00
Luke Street
0d1fc2131f
[wgsl-in] Support radians/degrees builtin functions (#1627) 2021-12-27 00:29:33 +00:00
Jay Oster
924ab17b62
Fixes for fma function (#1580)
* [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
2021-12-22 09:41:07 -05:00
Jim Blandy
db98743a5a [glsl-out] Don't return early from snapshot tests. 2021-12-17 20:27:27 -05:00