Commit Graph

1385 Commits

Author SHA1 Message Date
Dzmitry Malyshau
21324b8fea Update WGSL grammar for pointer access. (#1312)
* Update WGSL grammar for pointer access.

Comes with a small test, which revealed a number of issues in the backends.

* Validate pointer arguments to functions to only have function/private/workgroup classes.

Comes with a small test. Also, "pointer-access.spv" test is temporarily disabled.
2021-09-27 18:49:28 -04:00
João Capucho
38d74a7f0a [glsl-in] Use intermediate local if storage class isn't function
Automatically spills to a local variable function call arguments to
parameters expecting a pointer where the argument storage class isn't
function since the storage classes wouldn't match.
2021-09-27 21:09:08 +01:00
João Capucho
aa08cf94a4 [spv-in] preserve case order when reusing blocks 2021-09-27 16:01:43 -04:00
Jim Blandy
8122598fe7 [wgsl-out] Correct handling of named pointer expressions.
Treat expressions in `Function::named_expressions` like WGSL `let` declarations,
assuming that the Load Rule was applied to the rhs of the declaration, meaning
that their values are always `Indirection::Ordinary`.

Split `write_expr_plain_form` out from `write_expr_with_indirection`, to clean
up the parenthesis generation: no more `opened_paren` variable, just function
calls. This makes the early return for named expressions neater.

Fixes #1382.
2021-09-27 16:01:43 -04:00
Jim Blandy
7b023ce396 [wgsl-out] Make plain_form_indirection an associated fn of Writer. 2021-09-27 16:01:43 -04:00
Jim Blandy
f3ea2130a4 [wgsl-in]: Correctly compare pointer types.
Treat `TypeInner::ValuePointer` and `TypeInner::Pointer` as equivalent by
converting them to a canonical form before comparison.

Support `ValuePointer` in WGSL type output.

Fixes #1318.
2021-09-27 16:01:43 -04:00
Jim Blandy
6e4401ae96 Rename UniqueArena methods to more closely resemble HashSet.
`UniqueArena::fetch_or_append` becomes `insert`.

`UniqueArena::try_get` becomes `get_handle`, by analogy with `get`, that takes a
type as a key.
2021-09-27 15:17:41 -04:00
Jim Blandy
944a693ae5 Use UniqueArena for types.
Ensure that each distinct type occurs only once in `Module::types`, so that we
can use `Eq` on `Type` or `TypeInner` for type equivalence, without being
confused by differing `Handle<Type>` values that point to identical types.

This removes a number of duplicate types from the ir snapshots.

Fixes #1385.
2021-09-27 15:17:41 -04:00
Jim Blandy
d026577a91 Consolidate Handle construction code. 2021-09-27 15:17:41 -04:00
Jim Blandy
f91e95b22e [glsl-in]: Register new types as necessary during constant solving. 2021-09-27 15:17:41 -04:00
Jim Blandy
d44e2ad207 Simplify interpolation defaulting.
Replace `Module::apply_common_default_interpolation` with a simpler function
that handles a single `Binding` at a time. In exchange for the simplicity, the
function must be called at each point function arguments, function results, and
struct members are prepared. (Any missed spots will be caught by the verifier.)

This approach no longer requires mutating types in the arena, a prerequisite for
properly handling type identity.

Applying defaults to struct members when the struct declaration is parsed does
have a disadvantage, compared to the old whole-module pass: at struct parse
time, we don't yet know which pipeline stages the struct will be used in. The
best we can do is apply defaults to anything with a `Location` binding. This
causes needless qualifiers to appear in some output. However, it seems that our
back end languages all tolerate such qualifiers.
2021-09-27 15:17:41 -04:00
João Capucho
73f9d07207 [Typifier] Some relational functions output vectors
Previously the typifier flagged all relational functions as producing a
scalar boolean but with the exception of `all` and `any`, according to
the wgsl spec, all other relational functions output a type the same
size as the input.
2021-09-26 21:19:08 -04:00
João Capucho
04b176ec6b [glsl-in] Refractor overload selector and add comments 2021-09-23 15:04:07 -04:00
João Capucho
160ab82fee [glsl-in] Allow array constructors 2021-09-21 18:25:43 -04:00
João Capucho
70db5f681d [glsl-in] Allow use of constructors for user types 2021-09-21 18:25:43 -04:00
João Capucho
d5fc05e8a4 Allow unsigned integers in switch 2021-09-21 17:16:51 -04:00
João Capucho
6a57559070 [glsl-out] Improve handling of samplerCubeArrayShadow
Adds checks that it isn't used in an unsupported function and emits the
depth_ref as a separate argument.
2021-09-21 16:54:05 -04:00
João Capucho
63a8463edd [glsl-in] Support function declarations with void as arguments 2021-09-21 15:07:14 -04:00
Dzmitry Malyshau
115d170584 wgsl-out: update reserved words 2021-09-21 13:51:12 -04:00
João Capucho
af44603e47 [glsl-in] Use Span instead of SourceMetadata 2021-09-21 11:00:33 -04:00
Aleksi Sapon
42db64628e wgsl-out: vector bitcast 2021-09-21 15:50:10 +01:00
João Capucho
98944bb7a6 Track finished across compound statements 2021-09-20 12:00:22 -04:00
Aleksi Sapon
dc8a41de04 spv-in: no case fallthrough when last statement allows it 2021-09-20 15:11:46 +01:00
João Capucho
60d0bf850b Add support for multi view extensions 2021-09-19 17:38:27 -04:00
João Capucho
cd65484a22 [wgsl-in] Disallow identifiers starting with _ 2021-09-19 20:41:53 +01:00
João Capucho
7895e7f036 Don't output identifiers starting with _ 2021-09-19 15:18:17 -04:00
João Capucho
aea755fd32 [spv-in] Allow OpLine anywhere in the function 2021-09-19 14:06:08 -04:00
João Capucho
9b34d503da Add formating checks to CI 2021-09-19 11:55:49 -04:00
João Capucho
d7ca7d43b9 [glsl-in] Improve infix handling
Add support for float, vector and matrices targets.

Fix prefix and postfix being inverted (one was returning the value
of the other).

Remove an unneeded local indirection for prefix handling.

Add tests.
2021-09-17 13:56:42 -04:00
João Capucho
1cb4447ec3 [glsl-in] Add test array constant dynamic indexing 2021-09-17 13:47:38 -04:00
João Capucho
e824519378 [glsl-in] Cast switch selector to int if it's uint 2021-09-17 12:30:43 -04:00
João Capucho
796f5f14b0 [glsl-in] Fix bad bit pattern in texelFetch
This caused arrayed textures to not be accepted
2021-09-17 10:19:59 -04:00
Jasper St. Pierre
27d6e442d2 [glsl-in] Also apply vector splatting to bitwise ops 2021-09-17 10:19:28 -04:00
João Capucho
2610082bbf [glsl-in] Use local for constant indexing
Constants that are to be dynamically indexed now are first transformed
into locals with them as the initializer.
2021-09-17 09:53:30 -04:00
Jasper St. Pierre
a9d20d8ef4 [glsl-in] Add support for a large number of texture sample overrides 2021-09-16 23:00:19 +01:00
João Capucho
60bd9ec884 [glsl-in] Compile tests without codespan 2021-09-16 16:10:01 -04:00
Jim Blandy
8aae069f22 Document some Expression, EntryPoint, and Module rules. 2021-09-16 11:01:45 -04:00
Jim Blandy
636b8ed606 Document AtomicResult expressions. 2021-09-16 11:01:24 -04:00
Dzmitry Malyshau
52d74e91a4 spv-out: option to emit PointSize 2021-09-15 18:48:18 -04:00
Jim Blandy
5d3c93e8c7 [wgsl-out] Properly parenthesize address-of expressions.
Fixes #1352.
2021-09-15 18:46:55 -04:00
Jim Blandy
045ec6db32 [spv-out] Various doc fixes. 2021-09-15 18:41:07 -04:00
Jim Blandy
95d3a4e699 Enable span tracking by default in the Naga CLI. (#1364) 2021-09-15 15:32:19 -07:00
Jim Blandy
e5ba11332f Correctly recognize defined spans.
Without this change, the `to_range` method method returns `None` even when spans
are enabled.
2021-09-15 10:53:46 -04:00
Jim Blandy
d31121df77 [wgsl-in] Refuse to apply postfix expressions to WGSL pointers.
Fixes #1356.

Output for the test case in that issue is now:

    error: the value indexed by a `[]` subscripting expression must not be a pointer
      ┌─ wgsl:5:14
      │
    5 │     let a = *pv[3]; // Problematic line
      │              ^^ expression is a pointer

    Could not parse WGSL
2021-09-15 10:51:35 -04:00
Jim Blandy
08c1a1e9a3 [wgsl-in] Record identifier definitions as TypedExpression values.
Both a `var` binding and a `let` binding of a pointer to a variable create
entries in the `lookup_ident` tables whose expression is a `LocalVariable`.
However, the `let` should be a pointer, whereas the `var` should be a reference.
This patch changes the tables to hold `TypedExpression` values, thus preserving
the distinction.
2021-09-15 10:51:35 -04:00
Jim Blandy
4abf22c4d1 snapshot tests: Always write IR when requested, even if validation fails. 2021-09-15 10:37:12 -04:00
João Capucho
36114d95b6 [spv-in] Move function data into BlockContext
This allows removing many arguments from functions dealing with
instruction parsing
2021-09-15 10:24:01 -04:00
Jim Blandy
933ecc4a44 [spv-out] Rename test snapshot files.
The old filenames were probably based on the shader stage, not the shader
function name, which the PR changed to do in response to a review suggestion.
2021-09-14 18:41:23 -04:00
Jim Blandy
0d3dbfe781 Clean up some old snapshot files.
`tests/out/glsl/operators.main.Fragment.glsl` is no longer generated because the
function in question changed to a Compute entry point.

`tests/out/wgsl/multiple_entry_points-glsl.wgsl` is no longer generated because
the input test was removed in 057dc310.
2021-09-14 18:38:49 -04:00
Jim Blandy
3fdd8592fc [wgsl-in] Rework Load Rule handling and indirection.
Make the parser code more closely follow the spec's grammar around
`unary_expression`, `postfix_expression`, and `singular_expression`.

Change the handling of postfix expressions (indexing, member/component access,
and swizzling) to apply the indirection at the appropriate time, resulting in
code improvements on all output formats. For example, where we used to generate
the following MSL:

    metal::float4 _e13 = bar.matrix[3];
    float b = _e13.x;

we now generate, simply:

    float b = bar.matrix[3].x;

Propagate WGSL reference types correctly, so that parenthesizing expressions no
longer causes the Load Rule to be applied.

Together with #1332 (already landed), this is a replacement for #1312, and
unblocks #1352.

Fixes #1351.
2021-09-14 16:17:57 -04:00