Commit Graph
55 Commits
Author SHA1 Message Date
teoxoy a730236b68 [wgsl-in] eagerly evaluate const-expressions
[wgsl-in] support const-expressions in attributes

allow `Splat` as an evaluated const-expression type
2023-10-12 13:13:26 +02:00
Fredrik Fornwall 5329aa2bd5 [wgsl-in] Handle modf and frexp (#2454) 2023-09-02 08:55:35 +02:00
Fredrik Fornwall b001313947 [wgsl-in] Only splat 'scalar op vec', not '_ op vec' (#2444)
Change binary_op_splat() from splatting:

        vec op scalar
        _ op vec

to only splat:

        vec op scalar
        scalar op vec
2023-08-18 15:16:44 +02:00
Fredrik Fornwall 3da9355125 [wgsl-in] Avoid splatting all binary operator expressions (#2440)
* [wgsl-in] Avoid splatting all binary operator expressions

Fixes #2439.

* [wgsl-in] Expand binary_op_splat function comment
2023-08-18 13:07:24 +02:00
Fredrik Fornwall f6e99a4603 [wgsl-in] Handle repeated or missing @workgroup_size (#2435) 2023-08-17 13:20:10 +02:00
Fredrik Fornwall 7a19f3af90 [wgsl-in] Fail on repeated attributes (#2428)
* [wgsl-in] Fail on repeated attributes

Fixes #2425.

* [wgsl-in] Use ParsedAttribute to keep track of parsed attributes
2023-08-13 17:52:10 +02:00
Fredrik Fornwall 30afa5bd1f [wgsl-in] Fix error message for invalid texture{Load,Store}() on 2d_array (#2432)
Fixes https://github.com/gfx-rs/naga/issues/2431
2023-08-11 16:35:41 +02:00
Christopher Fleetwood 7c00548075 [wgsl] Use alias instead of type for type aliases (#2299) 2023-04-04 12:35:32 +02:00
Evan Mark Hopkins 1ad47f732d Fix texture built-ins where u32 was expected (#2245)
- The Typifier was updated to expect `uint`
- Both `glsl` and `spv` frontends where updated to cast the result to `sint`.
- Both `glsl` and `spv` backends where updated to cast the result to `uint`.
- Remove cast in `msl` backend.
2023-02-13 14:13:58 +01:00
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
teoxoy e05706bc48 [wgsl] remove fallthrough statement
also add support for default to be used with other case selectors
2022-12-09 10:21:58 -08:00
teoxoy 531d563f0e [wgsl-in] implement complete validation for size and align attributes 2022-06-16 12:13:08 -07:00
teoxoy 53aa3e2df5 [wgsl-in] overhaul number lexing / parsing
Bring the lexer's parsing of numeric literals in line with the WGSL
specification as of 86a23b83 (2022-05-10).
2022-06-10 10:36:07 -07:00
Igor Shaposhnik fbb77aa0dc [wgsl-in] Update entry point stage attributes 2022-04-15 18:02:48 +01:00
Igor Shaposhnik 43cd0ecedd [wgsl] Make colon in case optional (#1801) 2022-03-30 14:32:01 -04:00
Pu Xingyu 3c313564ac wgsl-in: Make semicolon after struct decl optional 2022-03-27 00:22:58 -07:00
teoxoy cf992a9a95 [wgsl-in] implement while loop 2022-03-22 22:47:47 -07:00
Igor Shaposhnik 816fa347ad [wgsl-in] Uses commas to separate struct members instead of semicolons 2022-03-12 22:07:06 -08:00
Igor Shaposhnik c356b93962 [wgsl-in] Optional parentheses for if and switch 2022-02-15 09:57:07 -05:00
Dzmitry Malyshau 4c91abe5b3 wgsl: remove stride 2022-01-24 16:44:12 -05:00
Dzmitry Malyshau 4bd1efc34d wgsl: declare attribtues with @ 2022-01-20 19:44:05 -05:00
Christofer Nolander d13e9e3b83 wgsl-in: correctly parse else if (#1611)
* wgsl-in: correctly parse `else if`

* wgsl-in: use early exit in `else if` parsing
2021-12-17 16:19:38 +00:00
Dzmitry Malyshau 8ffd6ba929 Remove top_level property of structs 2021-12-15 09:33:33 -05:00
Igor Shaposhnik dba6beb941 [wgsl-in] Don't allow redefinition of module scope identifiers 2021-11-28 21:23:22 -05: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
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
Hans Christian Schmitz 01250b85fe Fix WGSL vector splat constructor's type handling
Previously the constructor just used the type of the scalar argument
regardless of whether or not it actually matched the vector splat
constructors target type. This resulted in e.g. `vec2<f32>(0)`
erroneously getting the type of a bi-vector of Sints with width 4.

Now the splat constructor checks that the kind and width of the scalar
argument is the same as that of the target specified in the
constructor's type parameter.
2021-08-18 10:41:00 -04:00
pyrotechnickandDzmitry Malyshau 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 beabd62d96 wgsl: type inference for local variables 2021-07-06 01:26:03 -04:00
Lachlan Sneff 960551f952 Add support for arrayLength to the wgsl frontend (#805)
* Add support for arrayLength to the wgsl frontend

* Fix clippy warning
2021-04-30 00:20:09 -04:00
Lachlan SneffandDzmitry Malyshau 4cbef59dd6 Add struct instantiation support to wgsl-in (#507)
* Add struct instantiation support to wgsl-in

* Readd type matching and move struct test

* rebase onto master and update tests

* Update tests to upstream

* Fix merge errors

* Rebase onto master

* [wgsl-in] delay composite type creation

* Use the new WGSL construction syntax in the tests

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
2021-04-17 01:14:07 -04:00
Mehmet Oguz Derin 142038c85b WGSL: const to let 2021-04-11 01:24:19 -04:00
Dzmitry Malyshau c41f050312 [wgsl-in] ability to take a pointer to something 2021-03-30 01:01:28 -04:00
Dzmitry Malyshau ca6876b7a0 Validate math functions 2021-03-29 11:06:41 -04:00
Dzmitry Malyshau 08eaad89db Implement default layout in the IR and WGSL 2021-03-15 22:27:35 -04:00
Dzmitry Malyshau 20979b4800 [wgsl] type inference for constants 2021-03-15 01:31:57 -04:00
Systemcluster e49910bb0a [wgsl] allow empty for statement headers 2021-02-18 10:55:16 -05:00
Systemcluster 539db1a317 [wgsl] support for statement 2021-02-15 23:51:19 -05:00
Dzmitry Malyshau e6251a23fe [wgsl] fix boolean types and bang parsing 2021-02-15 22:59:04 -05:00
Dzmitry Malyshau 9b358efea1 [wgsl] support 'elseif' construct 2021-02-11 20:50:27 -05:00
Dzmitry Malyshau 86bb611905 [wgsl] support select() 2021-02-11 15:32:28 -05:00
Dzmitry Malyshau 11a3ed9837 WGSL support for void function calls 2021-02-06 10:42:54 -05:00
Dzmitry Malyshau b1fa7471d2 Basic image query support in SPV and WGSL frontends 2021-02-05 15:26:45 -05:00
Dzmitry Malyshau 3e4cb21b90 [wgsl] support simple block statements 2021-01-27 21:31:04 +01:00
Dzmitry Malyshau ab2cf8b842 [wgsl] support vector type casts 2021-01-26 23:33:08 -05:00
Dzmitry Malyshau 9c74468f81 [wgsl] enable access via rgba 2021-01-26 17:04:11 -05:00
Dzmitry Malyshau 292304b66f [wgsl] fix postfix expression parsing 2021-01-26 16:44:19 -05:00
Dzmitry Malyshau 986550aff8 [wgsl] fix and update storage load 2021-01-26 15:57:48 -05:00
Jay Oster 3bf7f41068 WGSL // comments
- Update parser to match the latest spec: https://github.com/gpuweb/gpuweb/pull/1326
2021-01-06 09:19:46 -05:00
Dzmitry Malyshau b95346877a Remove MemberOrigin in favor of spans 2020-12-18 16:11:12 -05:00