The original pointer access test used SPIR-V for its input because WGSL didn't
have a working pointer indirection operator at the time. Now that it does, we
can just write this test in WGSL directly.
Fixes#1432.
WGSL says:
> - The last member of the structure type defining the store type for a variable
> ... may be a runtime-sized array.
>
> - A runtime-sized array must not be used as the store type or contained within
> a store type in any other cases.
Thus, a struct whose final member is a struct whose final member is a
runtime-sized array is verboten.
Replace uses of `call_unique` with uses of `call` and `call_or`, which becomes
public. It's not clear when `call_unique` is correct to use, and avoiding a few
numeric suffixes here and there isn't worth it.
* 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.
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.
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.
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.
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.
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.
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.
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
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.
`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.
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.
Regression from ce676cf130.
We need to output (*d).mx rather than *d.mx, at least according to Tint.
wgsl-in seems to handle *d.mx just fine, which is likely a separate bug.
* [spv-in] New two pass parser based
* [spv-in] Allow expressions defined in dominant block in different scopes
* Make the patch non breaking
* [spv-in] Allow scope transfers in phi instructions
* [spv-in] Remove unused stuff
* [spv-in] Handle switch merges as breaks
* Remove no longer needed stuff
* Revert some changes to prepare to merge
* Remove dead code
* Don't spill into local if in scope
* [spv-in] Documentation, comments, some renaming for clarity.
* Address comments
Co-authored-by: Jim Blandy <jimb@red-bean.com>