Commit Graph

24 Commits

Author SHA1 Message Date
Jim Blandy
ea50486b2d
Forbid unsized structs as final members of structs. (#1443)
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.
2021-10-01 09:40:18 -04:00
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
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
João Capucho
98944bb7a6 Track finished across compound statements 2021-09-20 12:00:22 -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
Hans Christian Schmitz
58a5b7d2b9
Implement lexing and parsing for all WGSL number literal types (#1184)
* Implement lexing for all WGSL number literal types

* Move number literal test cases

* Adjust tests to match WGSL spec on number literals

Suffixes are not type names and currently only a plain `u` is supported
for uints. More specifically, `i` and `f` suffixes or suffixes with
widths in bits like `u32` are not supported at the moment.

* Add more tests for invalid number literal suffixes

* Replace code too new for Rust 1.43

* Implement parsing for hexadecimal integers

* Switch to enum number types, and Bytes for width

* Check for negative and leading zeros in int literals

* Implement parsing of hex floats with hexf-parse

* Update error message tests

* Update snapshot test output files

* Clean up lexer state machine code

* Clean up unexpected token error code

* Move number literal parsing to own submodule
2021-08-24 01:50:53 -04:00
Jim Blandy
93db57c12b [wgsl-in] Test validation of arrays with zero and negative lengths. 2021-08-23 15:57:23 -04:00
Dzmitry Malyshau
67dd604b0c [wgsl-out] atomic load/stores, [glsl-out] revert the prefix 2021-08-10 21:48:02 -04:00
pyrotechnick
2f516c0932
[wgsl] Storage buffer/texture access (#1142)
* Resurrect texture_storage_* tests
* Test parsing of `var<storage,write>`
* Default storage textures to READ
* Restore default features
* Fix glsl/hlsl/msl/spv front and back ends
* Add missing test outputs
* All-around fixes for the storage access

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
2021-07-28 01:47:18 -04:00
Dzmitry Malyshau
c69736210a Snapshot test local variable inference 2021-07-06 01:26:03 -04:00
Dzmitry Malyshau
beabd62d96 wgsl: type inference for local variables 2021-07-06 01:26:03 -04:00
Joshua Groves
9192f7b882 wgsl-in: add more error tests 2021-07-05 02:24:18 -04:00
Joshua Groves
c5805a9e10 wgsl-in: add more error tests 2021-07-04 01:00:21 -04:00
Jim Blandy
c16f2097ad [spv-out]: Ensure array subscripts are in bounds. 2021-06-18 20:44:07 -04:00
Jim Blandy
1d0b3f3a75 Functions can take pointers to unsized structs, but no other unsized types. 2021-06-18 20:44:07 -04:00
Jim Blandy
a2a35f2eb3
Permit dynamic indexing of arrays and matrices only behind a pointer. (#949)
This makes Naga IR validation impose the restrictions added to WGSL in
gpuweb/gpuweb#1801.

Remove code in the SPIR-V writer to spill arrays to temporary variables in order
to index them dynamically. If such IR is encountered, treat it as a failure of
validation.
2021-06-04 12:57:20 -04:00
Aron Granberg
37724102a3 Improve wgsl lexer error messages.
Better errors for Unexpected, BadInteger, BadFloat, BadTexture, BadTypeCast, UnknownScalarType, UnknownStorageClass, UnknownAttribute, UnknownBuiltin, UnknownShaderStage, UnknownStorageFormat and UnknownConservativeDepth, ZeroStride, ZeroSizeOrAlign and UnknownType.

Also adds lexer::capture_span.

Also fixes some validation for texture sample types and and issue that cauld cause e.g. the type `f33` to be parsed as `f32`.
2021-05-30 11:01:00 -04:00
Jim Blandy
48363fcef1 Don't accept unsized types as function arguments. 2021-05-26 12:27:29 -04:00
Jim Blandy
50de6ae9ac Improve error messages for missing I/O bindings.
The `apply_common_default_interpolation` helper function would panic if bindings
were missing, but missing bindings should be something that front ends can count
on validation to detect, so the helper should just return silently.

The validator returned `InvalidType` errors for missing bindings, apparently
because variables without bindings must be structs that do have bindings. But
this is unhelpful when you've just forgotten to label an argument. So this patch
adds a new, more specific, `VaryingError` variant.
2021-05-21 23:04:27 -04:00
Jim Blandy
5753f6e107 [wgsl-in] Improve error message for UnknownIdent. 2021-05-19 00:07:39 -04:00
Jim Blandy
0985727710 [wgsl-in] Include span information in 'unknown identifier' errors. 2021-05-17 19:46:37 -04:00
Dzmitry Malyshau
b191c982ec Remove alignment from struct IR 2021-05-17 09:32:52 -04:00
Jim Blandy
057d03ad86 [wgsl-in]: Add tests for array and struct validation. 2021-05-13 22:09:22 -04:00
Jim Blandy
f45d812266 [wgsl-in]: Move WGSL front end integration tests into a WGSL-specific file.
This lets us reduce noise by removing a bunch of `#[cfg]` attributes. In the
future, if we have tests for other front ends, we can create an `errors`
subdirectory, but for now, we only have the WGSL tests, so we should keep things
flat.
2021-05-13 22:09:22 -04:00