Commit Graph
656 Commits
Author SHA1 Message Date
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 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 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 63a8463edd [glsl-in] Support function declarations with void as arguments 2021-09-21 15:07:14 -04:00
João Capucho af44603e47 [glsl-in] Use Span instead of SourceMetadata 2021-09-21 11:00:33 -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 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 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 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
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 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
Dzmitry Malyshau db80ed4fa9 Fix warnings in snapshots and spv-in 2021-09-14 09:46:25 -04:00
Dzmitry Malyshau 807accd7de wgsl-in: require storage class to be given 2021-09-13 15:44:05 -04:00
Jasper St. Pierre 0e66930aff [glsl-in] Fix sampling texture array types
Fixes #1349.
2021-09-12 09:44:14 -04:00
João Capucho 130f802c89 Make span copyable (#1314)
* Make span copyable

* Use fixed size integers for span
2021-09-10 19:52:45 +00:00
João Capucho 439148b1a7 [spv-in] Move essential code out of debug_assert 2021-09-10 17:28:16 +01:00
João CapuchoandJim Blandy 3049f63cad [spv-in] new block parser (#1294)
* [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>
2021-09-10 08:51:05 -07:00
Dzmitry Malyshau c1eed779fe Infer types of module-scope let declarations 2021-09-08 09:42:36 -04:00
João Capucho 843c6d5758 [spv-in] Divide the depth ref in projection sample 2021-09-04 22:27:10 -04:00
João Capucho 803093e710 [spv-in] Handle structs with no offset decorations 2021-09-04 13:10:12 -04:00
João Capucho bd411c28c2 [glsl-in] Allow code after terminator statements (#1308)
* [glsl-in] Allow code after terminator statements

* [glsl-in] Track finished state in the context

* [glsl-in] Cull statements after terminators
2021-08-31 12:15:30 -04:00
Dzmitry Malyshau 1e9f2b9287 Add atomicSubtract support 2021-08-26 11:50:21 -04:00
fsh f11afd4fcf [glsl-in] Avoid infinite loop when parsing invalid statements (#1280) 2021-08-24 19:46:54 +00: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
Dzmitry Malyshau ea883d98e2 [spv-in] track function parameter sampling flags across handle permutation 2021-08-23 01:48:45 -04:00
João Capucho b0569d9593 [glsl-in] Add support for derivative functions 2021-08-22 22:21:30 -04:00
Dzmitry Malyshau 70be72d9b9 [spv-in] fix expression emit in image store 2021-08-20 21:35:48 -04:00
João Capucho c09354c78e [glsl-in] Add support for float encoding/decoding builtins
Fixes #1246
2021-08-20 20:41:13 -04:00
João Capucho fd3f9543b5 Fix round in backends and add support for roundEven in frontends 2021-08-20 19:04:03 -04:00
Zicklag 897afbd710 [wgsl-in] [wgsl-out] Implement bitcast() 2021-08-20 17:19:23 -04:00
João Capucho bbf3e465f3 Add support for inverse hyperbolic trignometric functions
Hlsl and wgsl don't support them directly so a polyfill is used taken
from the msl spec.

`asinh` = `log(x + sqrt(x * x + 1.0))`
`acosh` = `log(x + sqrt(x * x - 1.0))`
`atanh` = `0.5 * log((1.0 + x) / (1.0 – x))`
2021-08-20 16:57:18 -04:00
João Capucho 8d6647d369 [glsl-in] Add support for radians and degrees builtins 2021-08-20 11:59:16 -04:00
João Capucho 846ea0ec09 [glsl-in] Align child structs 2021-08-20 10:59:28 -04:00
João Capucho 0b0d2ab0f3 [glsl-in] Use power of two alignment for bad type in struct
Fixes #1243
2021-08-19 20:38:10 -04:00
João Capucho 448ea65940 [glsl-in] Add support for more builtins
Fixes #1245
2021-08-19 19:58:51 -04:00
João Capucho 0dd32219c5 [glsl-in] Cast grad sampling on shadow image into zero sampling 2021-08-19 19:24:38 -04:00