Commit Graph

717 Commits

Author SHA1 Message Date
Dzmitry Malyshau
75692d3795 Allow non-structure buffer types 2022-02-02 10:08:20 -05:00
glalonde
bb604fd6a3
Mitigation for MSL atomic bounds check. (#1703)
[msl-out] Correct output for bounds-checked atomic accesses.
2022-02-01 16:37:09 -08:00
Dzmitry Malyshau
2ddc8d1929 Rename StorageClass to AddressSpace 2022-01-31 16:25:06 -05:00
Connor Fitzgerald
f5d97cae84 Adjust MSL version invariant needs 2022-01-25 13:25:48 -05:00
Dzmitry Malyshau
4c91abe5b3 wgsl: remove stride 2022-01-24 16:44:12 -05:00
Dzmitry Malyshau
aea427fa92 msl: add invariance if supported 2022-01-24 09:59:45 -05:00
João Capucho
81dc67402a glsl-out: push constants use anonymous uniforms
Previously this was done with UBOs but this posed some problems when
integrating with wgpu (see https://github.com/gfx-rs/wgpu/pull/2400)
2022-01-21 21:13:12 -05:00
francesco-cattoglio
8647e06b72
glsl-out: Call proper memory barrier functions (#1680)
* glsl-out: Call proper memory barrier functions

* glsl-out: Change test for control flow

* Removed two unnecessary calls
2022-01-21 15:34:44 +00:00
Dzmitry Malyshau
4bd1efc34d wgsl: declare attribtues with @ 2022-01-20 19:44:05 -05:00
Dzmitry Malyshau
76814a83a2 msl: inject point size if needed 2022-01-19 11:33:14 -05:00
João Capucho
a1840beb1a glsl-out: Add test for push constants 2022-01-16 19:32:51 -05:00
João Capucho
91ca923553 glsl-out: Add support for push constant emulation 2022-01-16 19:32:51 -05:00
Dzmitry Malyshau
c0b7ac7f54 WGSL: assignment binary operators 2022-01-11 11:01:24 -05:00
Igor Shaposhnik
298a8c30bd [wgsl-in] Write a real type in type mismatch error 2022-01-10 10:02:05 -05:00
João Capucho
70b5ddaaad spv-out: use OpFRem instead of OpFMod 2022-01-07 20:19:15 -05:00
Dzmitry Malyshau
09d35f3631 gl-out: skip unsized types if unused 2022-01-05 23:11:43 -05:00
Jim Blandy
53eeb654aa [msl-out] Don't give level in texture1d accesses.
Fixes #1642.

Since 1d textures cannot have mipmaps, MSL requires that the `level` argument to
texel accesses and dimension queries be a constexpr 0. For our purposes, just
omit the level argument altogether.
2022-01-04 15:33:23 -08:00
João Capucho
743d058b49 glsl-out: Use constructors shorthand for zero init 2022-01-04 13:52:00 +00:00
João Capucho
b9c4893112 glsl-out: Write struct initializers 2022-01-04 13:52:00 +00:00
João Capucho
32205e3097 glsl-out: write array initializers 2022-01-04 13:52:00 +00:00
Vinh Truong
6aca3e0b36
Fix data packing functions on MSL (#1637)
* Fix data packing functions on MSL

`snorm` and `unorm` got mixed up.

* Fix bits.msl
2021-12-31 16:44:54 +00:00
João Capucho
1d0f484b37
glsl-in: fix composite constructors (#1631)
* glsl-in: Remove unneeded mutability from reference

* glsl-in: Fix composite constructors

In the recent rework of the constructors it seems that the logic for
composite types (arrays and structs) was accidentally removed by me.
2021-12-28 20:16:56 -05:00
Dzmitry Malyshau
2738ad80b9
msl: fix packed vec access (#1634) 2021-12-28 05:13:13 +00:00
João Capucho
5a26606a09
glsl-in: Fix using swizzle as out arguments (#1632)
This worked at one point but because of some changes to the IR it was
temporarily broken.
2021-12-27 19:09:33 -05:00
Dzmitry Malyshau
b1ab59925d
msl: fix packed float support (#1630) 2021-12-27 02:57:47 +00:00
Dzmitry Malyshau
f2832b8999
hlsl: support arrays of matrices (#1629) 2021-12-27 00:30:57 +00:00
Luke Street
0d1fc2131f
[wgsl-in] Support radians/degrees builtin functions (#1627) 2021-12-27 00:29:33 +00:00
Igor Shaposhnik
8df5421e2e
[glsl-out] Add stage postfix to generated global name (#1616) 2021-12-23 22:19:07 -05:00
Jay Oster
924ab17b62
Fixes for fma function (#1580)
* [hlsl-out] Write `mad` intrinsic for `fma` function

- This should be enough because we only support f32 for now.
- Adds a new test for WGSL functions, in the spirit of operators.wgsl.
- Closes #1579

* Add FMA feature to glsl backend

- I think this is right. Just iterate all known expressions in all
  functions and entry points to locate any `fma` function call.
  Should not need to walk the statement DAG.

* Transform GLSL fma function into an airthmetic expression when necessary

* Add tests for GLSL fma function tranformation

* Remove the hazard comment from the webgl test input

* Add helper method for fma function support checks

* Address review comment
2021-12-22 09:41:07 -05:00
Jonathan Behrens
f9b348557a
Add FindLsb / FindMsb (#1473)
* Add FindLsb / FindMsb

* Fixes and tests for FindLsb/FindMsb

* Add findLsb / findMsb as WGSL builtins

* Fix tests

* Fix incompatible type issue with MSL output

* Requested changes

* Test fewer cases of findLsb/findMsb
2021-12-20 14:48:54 -05:00
Dzmitry Malyshau
c2328fea75 Release v0.8 2021-12-18 12:05:12 -05:00
Dzmitry Malyshau
8caa2bd87e Gather operations 2021-12-18 11:46:49 -05:00
Jim Blandy
db98743a5a [glsl-out] Don't return early from snapshot tests. 2021-12-17 20:27:27 -05:00
Ashley
75ce45d4f3 spv-in: fix support for degrees and radians conversion 2021-12-17 11:56:47 -05:00
João Capucho
e1552fd9d5 wgsl-in: Implement matrix construction from scalar 2021-12-17 10:39:31 -05:00
Dzmitry Malyshau
6df9656e96 spv-out: Force wrapping of push constant structs 2021-12-16 16:21:06 -05:00
João Capucho
9c75f3cdce glsl-in: Flatten entry point arguments
The IR doesn't allow having structs has bindings for entry point
input/output, so the glsl frontend must flatten them.

Glsl defines that the locations are sequential from the block base location.
2021-12-16 10:55:06 -05:00
João Capucho
4334f0e6a9 Support bitwise And on booleans 2021-12-15 23:53:23 -05:00
João Capucho
c64d5eff50 Support bitwise Or on booleans 2021-12-15 23:53:23 -05:00
Dzmitry Malyshau
8ffd6ba929 Remove top_level property of structs 2021-12-15 09:33:33 -05:00
Jim Blandy
3867ef4f6c [msl-out] Correctly construct out-of-bounds values for all types. 2021-12-14 23:00:03 -05:00
Lain-dono
e200e44ede
[spv-out] Fixing incorrect pack/unpack (#1587)
* [spv-out] Fixing incorrect pack/unpack

* [spv-out] Fixing incorrect pack/unpack: make tests happy

* [spv-out] Fixing incorrect pack/unpack: remove unexpected newline
2021-12-11 21:29:31 -05:00
Jim Blandy
f51f468a47 [msl-out] Implement index bounds check policies for non-texture accesses. 2021-12-06 15:53:41 -05:00
João Capucho
14719553a6 glsl-in: fix pre/postfix ops on swizzles 2021-12-05 22:16:28 -05:00
Dzmitry Malyshau
6fbd668bd3 Add missing GLSL tests 2021-12-02 13:11:23 -05:00
João Capucho
9fac7c48a6 glsl-in: Allow vector/matrix in vector constructor
The glsl spec defines that vector constructors flatten their arguments
and consume them in order, ignoring the remaining arguments if there are
more than needed
2021-11-29 11:06:18 -05:00
Igor Shaposhnik
dba6beb941 [wgsl-in] Don't allow redefinition of module scope identifiers 2021-11-28 21:23:22 -05:00
Igor Shaposhnik
20b96ef47b Avoid function name redefinition in tests 2021-11-28 21:23:22 -05:00
Dzmitry Malyshau
daa61b5fcb Fix shapshots to run without deserialize feature 2021-11-26 12:16:50 -05:00
Dzmitry Malyshau
74132ba947 Actually disable explicit types on most WGSL outputs 2021-11-26 11:36:46 -05:00
Dzmitry Malyshau
f4ba74544a Refactor snapshot test arguments to avoid checking for deserialize feature too often.
We can safely assume that deserialize is enabled for all output tests.
Supporting other modes of operation has low utility.

This change also adds an option to skip the explicit types for WGSL output.
2021-11-26 11:36:46 -05:00
Dzmitry Malyshau
ddbc1c4b1f WGSL: use underscore prefix like the other backends 2021-11-25 16:23:24 -05:00
Igor Shaposhnik
2107b20561 [wgsl-in] Don't allow keywords to be used as identifiers 2021-11-24 16:34:17 -05:00
Jim Blandy
cc930180d9 Tighten checks on pointers to unsized values, and pointer arguments.
Pointers should not be `DATA`: they can never be stored in anything. (Function
arguments are not storage; they're like `let` bindings.)

Un-`SIZED` values may only live in the `Storage` storage class, so creating
pointers to them in other storage classes is meaningless.

The `ARGUMENT` flag should be set only on pointers in those storage classes that
are permitted to be passed to functions.

See comments in code for details.

Fixes #1513.
2021-11-18 17:39:56 -05:00
Jim Blandy
633f1b3377 [wgsl-in] Don't be confused by pointers to globals.
The WGSL front end knows that globals in the `Handle` storage class do not
produce references, but it attempts to manage this in two places which trip over
each other. As a consequence, referring to a `let` binding holding a pointer to
a global flips the variable's type from WGSL `ptr` to WGSL reference, with
bewildering consequences.
2021-11-18 17:39:56 -05:00
Jim Blandy
6a5b33fa24
Move BoundsCheckPolicy/Policies into proc, from back. (#1537) 2021-11-17 19:15:59 -08:00
Igor Shaposhnik
30a0a37af0 Update dependencies 2021-11-16 23:46:54 -05:00
Jim Blandy
ce18eba695 Check that stores are permitted by the pointer's storage access.
Fixes #1533.
2021-11-16 23:40:56 -05:00
Boris-Chengbiao Zhou
1dcde48d09
[valid] Check that switches have a default case (#1529)
From the WGSL spec: "Each switch statement must have exactly one default clause."
2021-11-15 00:07:55 +00:00
Jay Oster
66c3499df8
[spv-out] Fix scalar-times-matrix operations (#1524) 2021-11-14 19:07:38 -05:00
Jim Blandy
e69a70bfb7
[spv-in] Permit pointers to runtime arrays only in StorageBuffer. (#1522)
* [spv-in] Change shadow.spv test input to use StorageBuffer.

The ecosystem around Naga will generally not be able to use Vulkan adapters that
don't support the SPV_KHR_storage_buffer_storage_class (which was incorporated
into SPIR-V 1.3), so we can assume it is present.

Changing the test not to use runtime-sized arrays in the Uniform storage class
will allow Naga to tighten up some validation checks.

* [spv-in] Permit pointers to runtime arrays only in StorageBuffer.

Fixes #1519.
2021-11-10 16:58:57 -05:00
João Capucho
d168f15d81
[glsl-in] Allow constructors from non-scalar to scalar (#1520) 2021-11-10 12:15:43 -05:00
João Capucho
c3c4ab7548 [glsl-in] Add test for matrix from matrix constructor 2021-11-09 15:15:11 +00:00
João Capucho
7234d19d00 [glsl-in] Implement matrix to matrix constructor 2021-11-09 15:15:11 +00:00
Dzmitry Malyshau
8bc3aa824b
Refactor namer scheme, fix trailing digits (#1510) 2021-11-09 09:24:41 -05:00
Dzmitry Malyshau
28c45321e5
hlsl: respect array stride in storage buffers (#1507) 2021-11-03 22:44:46 -04:00
Jim Blandy
c1b378842e
Make tests properly exercise Some("") global names. (#1503)
The GLSL empty-global-name.frag test doesn't suffice because the GLSL front end
doesn't produce the same IR as the SPIR-V included in the bug report. As far as
I know, only a genuine SPIR-V input test can produce a global whose name is
`Some("")`.

Include the SPIR-V assembly source.
2021-11-01 14:07:11 -04:00
Igor Shaposhnik
d1cfdd15a0 Add test for last falltrough switch case 2021-10-27 11:12:35 +01:00
Igor Shaposhnik
00bbbed90a
Handle empty variable names in namer (#1484)
* Handle empty variable names in namer

* Add glsl-in test with empty global name
2021-10-26 17:46:27 -04:00
João Capucho
63dbd38edc
Make default a switch case (#1477)
* Make default a switch case

Previously the default case of a switch statement was encoded as a block
in the statement but the wgsl spec defines it in such a way that the
default case ordering matters.

* [spv-out] Support for the new switch IR

* [dot-out] Use different labels for default cases
2021-10-26 13:31:54 -04:00
Alex Es
ec001c3ead
Use span information in analyzer errors (proof of concept) (#1470)
* Proof-of-concept for adding spans to validation errors.

Still missing: actually printing the damn stuff.

* Emit errors from analyzer in the CLI.

TODO: tests, I guess!

* Simplification refactoring: avoid avoiding allocations so vehemently.

* Mask helper traits with `as _`.

* Fix block iterator throwing up when span feature is disabled.

* Nest use statements.

* Add basic docs.

* Axe AddSpanResult.
2021-10-24 22:47:03 -04:00
Dzmitry Malyshau
fd5085277a Switch the constant in bevy-pbr to avoid display incosistencies 2021-10-23 23:39:49 -04:00
João Capucho
c3a0d71f8b
[spv-out] Write function arguments names (#1472) 2021-10-23 23:20:12 -04:00
João Capucho
70ad084ad4
[spv-in]: Cull unused builtins inside structs (#1469)
Some compilers like shaderc introduce a full gl_PerVertex struct, this
includes gl_ClipDistance. Normally this isn't a problem since most
drivers optimize it away, but naga zero inits globals if they weren't
previously initialized. This causes gl_ClipDistance to be initialized to
zero which can be really bad for performance.
2021-10-19 22:55:20 -04:00
Jim Blandy
ed4cc8e4d8
Use Cow to reduce allocation in proc::Namer. (#1465)
Minimize allocation in the namer. Heap-allocate string only when needed to
provide an owned key for a hash table, or to hold synthesized text. Try to reuse
allocations.

Many unnecessary trailing `_` characters are removed from test output. These
were all superfluous; separators are still inserted where necessary.
2021-10-16 17:56:59 +00:00
Dzmitry Malyshau
ee450c1ee4
Fix float-bool casts in MSL, SPV, and HLSL backends (#1459) 2021-10-12 11:42:20 -04:00
Igor Shaposhnik
943235cd5e
[glsl-out] Convert modulo operator on float to SPIR-V OpFRem equivalent function (#1452) 2021-10-07 16:59:39 -04:00
Jim Blandy
0e3fbc8166
Replace pointer-access.spv snapshot test with WGSL source. (#1450)
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.
2021-10-06 16:30:36 -04:00
Dzmitry Malyshau
943e321bc6 Fix lazy CI for snapshots 2021-10-05 21:58:39 -04:00
Connor Fitzgerald
2f5a41cce9
Add insert/extractBits and pack/unpack functions (#1449) 2021-10-05 20:32:57 -04:00
João Capucho
da00bf2be6
[glsl-in] Always use uint for array size (#1448) 2021-10-05 13:05:47 -04:00
João Capucho
71a75d727d
[glsl-out] Es: convert 1D images to 2D (#1436) 2021-10-03 23:01:44 -04:00
João Capucho
b34fa5f2cc
[glsl-in] Fix array index parsing for 1D images (#1445) 2021-10-03 16:22:14 +00:00
João Capucho
f01eb72378
[Snapshots] Allow a blacklist of entrypoints for glsl-out (#1444) 2021-10-02 23:22:49 -04:00
Jim Blandy
f30f3a3db6
Properly type-check Expression::Select arguments. (#1442)
Require the `accept` and `reject` arguments to `select` to be scalars or
vectors, per WGSL spec.
2021-10-01 12:47:39 -04:00
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
Jim Blandy
4ef1cc403b
Remove Namer::call_unique. (#1439)
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.
2021-09-29 19:33:38 -04:00
Igor Shaposhnik
a4bf25a0d5
Emit std430 layout qualifiers for storage buffers (#1435)
* Remove unused petgraph dependency from glsl-out

* Emit std430 layout qualifiers for storage buffers
2021-09-29 12:24:34 -04:00
Jim Blandy
2e73e48657
When writing snapshots, reliably identify which writer has failed. (#1427) 2021-09-28 13:42:26 -04:00
Dzmitry Malyshau
004a12e21d
[spv-out] option to clamp frag_depth (#1431) 2021-09-27 23:00:10 +00: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
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
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
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
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
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
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
Dzmitry Malyshau
115d170584 wgsl-out: update reserved words 2021-09-21 13:51:12 -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
João Capucho
7895e7f036 Don't output identifiers starting with _ 2021-09-19 15:18:17 -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
Jasper St. Pierre
27d6e442d2 [glsl-in] Also apply vector splatting to bitwise ops 2021-09-17 10:19:28 -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
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
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
4abf22c4d1 snapshot tests: Always write IR when requested, even if validation fails. 2021-09-15 10:37:12 -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
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
Jasper St. Pierre
ba39fd47c3
Output parentheses around dereference (#1348)
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.
2021-09-11 23:32:10 -07:00
João Capucho
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
7681f4a21f msl-out: fix as_type expressions 2021-09-09 21:09:20 -04:00
Dzmitry Malyshau
135df311b1 hlsl: avoid using texture keyword 2021-09-09 16:02:17 -04:00
Dzmitry Malyshau
e226cf3f1d spv-out: option to skip OpName for varyings 2021-09-08 16:52:10 -04:00
Dzmitry Malyshau
c1eed779fe Infer types of module-scope let declarations 2021-09-08 09:42:36 -04:00
Dzmitry Malyshau
7138876625 [spv-out]: ability to separate entry points 2021-09-07 14:22:39 -04:00
João Capucho
4fa280d931 [glsl-out] Fix select order 2021-09-04 13:07:44 -04:00
Dzmitry Malyshau
a4f19833b5 hlsl: implement struct constructors 2021-09-03 12:43:54 -04:00
Hans Christian Schmitz
8417f849b1
Fix GLSL output for non-fallthrough switch cases (#1310)
* Fix GLSL output for non-fallthrough switch cases

Partially reverts 02c74b5002 and
fixes #1309.

* Fix indentation of control-flow WGSL code

* Clean up glsl-out switch case fallthrough handling

Only insert a break if needed
and if a case is fallthrough, insert a comment indicating this.
2021-08-31 17:48:28 -04:00
Jim Blandy
b226c5108a [spv-out] Add test for duplicate OpTypeImage instructions. 2021-08-30 13:24:41 -04:00
Jim Blandy
5b1c2e59f6 [spv-out] Write debug names for all types, not just structs.
This affects a lot of snapshots, so it's in its own commit, for easier review.
2021-08-30 13:24:41 -04:00
Jim Blandy
846dbb5a3e [spv-out] Request proper capabilities for storage image formats. 2021-08-30 09:02:46 -07:00
Jim Blandy
cb0ad2504c [spv-out] Handle break and continue in switch statements.
Fixes #1030.
Fixes #1017.
2021-08-27 16:39:59 -07:00
Jim Blandy
28547e3d3b Gather index, buffer, and texture bounds check policies into a single struct. 2021-08-26 19:08:06 -04:00
Jim Blandy
1b95e023e7 [spv-out] Support a separate bounds check policy for buffers. 2021-08-26 19:08:06 -04:00
Jim Blandy
140e3223e2 snapshot tests: Parse bounds checks policy properly. 2021-08-26 19:08:06 -04:00
Jim Blandy
bdf774aa8b Rename BoundsCheckPolicy::UndefinedBehavior to Unchecked.
When we are leaning on robust buffer access to do the job for us, there's no
undefined behavior going on. So `UndefinedBehavior` suggests people are doing
something reckless even if they're not. The policy just says what Naga is doing,
and it shouldn't pretend to say what the rest of the system is doing.
2021-08-26 19:08:06 -04:00
Dzmitry Malyshau
1e9f2b9287 Add atomicSubtract support 2021-08-26 11:50:21 -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
Jim Blandy
9713dbbbc1 [spv-out] Quick tests for capability requests. 2021-08-23 09:10:16 -07:00
Jim Blandy
b56349e9bf [spv-out] Fix the processing of cube array images.
Using 1D images should require either the `Sampled1D` or `Image1D` capability.

Using cube array images should require either the `SampledCubeArray` or
`ImageCubeArray` capability.
2021-08-23 09:10:16 -07:00
Jim Blandy
901e2c0694 [spv-out] Implement BoundsCheckPolicy for image access 2021-08-22 23:41:27 -04:00
Jim Blandy
c6ecd973e7 [spv-out] Use Selection for building conditionals.
Introduce a helper type that manages the details of emitting SPIR-V
conditionals, tracking labels, branches, merge annotations and phi nodes.

Change index bounds checks to use this helper.
2021-08-22 23:41:27 -04:00
Jim Blandy
de114e479b Rename IndexBoundsCheckPolicy to BoundsCheckPolicy. 2021-08-22 23:41:27 -04:00
Dzmitry Malyshau
81f4ff032f
HLSL: rewrite handling of interface matching rules (#1276)
* [hlsl-out] flatten the entry point inputs

Previously, the logic was re-ordering the inputs according to the binding.
This breaks if one of the inputs is a struct. With this change, the struct
fields are also flattened into the fake entry point struct. We also
construct the original arguments at the beginning of the function.

* hlsl-out: completely separate the flattened IO structs from the original IR structs

Previously, we had heuristics to detect if a particular struct needs the fields
to be re-ordered. We'd re-order interface structs without layout, and the detection
was very fragile and easily wrong.
The new logic is spawning separate struct types if we need any re-ordering to happen.
It's solid, there are no heuristics.
2021-08-22 22:40:31 -04:00
Jim Blandy
63e58f2022
[wgsl-in] Print errors nicely in convert_wgsl snapshot tests. (#1274) 2021-08-22 22:31:11 -04:00
Igor Shaposhnik
464788dc8d
[hlsl-out] Implement switch statement (#1265)
* [hlsl-out] Implement switch statement

* [hlsl-out] Implement switch statement

* Add switch tests to control-flow snapshot
2021-08-22 22:30:22 -04:00
Zicklag
897afbd710 [wgsl-in] [wgsl-out] Implement bitcast() 2021-08-20 17:19:23 -04:00
João Capucho
778049f97a Apply comments 2021-08-20 16:57:18 -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
Dzmitry Malyshau
644fa684ba Fix quad testcase parameters 2021-08-20 16:56:32 -04:00
sigaloid
9050108a95 Fix some clippy suggestions 2021-08-20 16:42:47 -04:00
Jim Blandy
2b08525ed1 [spv-out] Request Sample1D capability when texture_1d is used.
Fixes #1241.
2021-08-19 19:23:10 -04:00
Dzmitry Malyshau
dad4b1bb10 [hlsl-out] fix array arguments in functions 2021-08-19 10:05:57 -04:00
João Capucho
b05ca6e403 [glsl-in] Builtin redefinition and calls fixes 2021-08-17 22:22:30 -04:00
Dzmitry Malyshau
79d899fe4c Support num_workgroups builtin 2021-08-17 22:22:22 -04:00
Connor Fitzgerald
73be8c7454 [hlsl-out] Implicitly transpose all matrices 2021-08-17 14:05:27 -04:00
João Capucho
b11f094287 [wgsl-out] Write pointers types and loads 2021-08-17 13:39:31 -04:00
Dzmitry Malyshau
ab1e932e16 [glsl-out] use common bake prefix 2021-08-17 00:22:51 -04:00
Dzmitry Malyshau
5415d8c7c4 Fix atomics in workgroup storage 2021-08-13 23:01:25 -04:00
Dzmitry Malyshau
69b70f8cc3 [hlsl-out] reorder fields when composing structs 2021-08-13 01:45:43 -04:00
Dzmitry Malyshau
27e4ba59e4 Validate that SampleLevel::Exact isn't used for comparisons 2021-08-13 01:45:43 -04:00
Dzmitry Malyshau
0feea58a34
[hlsl-out] re-order interface struct fields (#1189) 2021-08-12 13:08:29 -04:00
Jim Blandy
47b9f4a2e5
[spv-out] Writer::write_texture_coordinates: Fix result type. (#1188)
Some SPIR-V texture access instructions take coordinates as integers, others as
floats. The types of coordinates in Naga expressions generally match those in
SPIR-V, but Naga indices for arrayed textures are always integers, whereas
SPIR-V combines coordinates and array indices into a single vector, so indices
need to be cast to match the coordinate component type.

This commit makes `write_texture_coordinates` properly cast array indices to
match the coordinates' component type before combining them all into a single
result vector.

Fixes #1186.
2021-08-11 14:55:54 -07:00
Jim Blandy
e2fc7ffd03 [spv-out]: Use OpCompositeConstruct's schmear behavior.
In `back::spv::Writer::write_texture_coordinates`, OpCompositeConstruct can
concatenate scalars and vectors, so when combining coordinates with an array
index, there is no need to extract the coordinate vector's components
individually: once the index has been converted to the appropriate component
type, it can be combined with the coordinates in a single instruction.
2021-08-11 11:22:43 -04:00
Dzmitry Malyshau
67dd604b0c [wgsl-out] atomic load/stores, [glsl-out] revert the prefix 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
1121a815ac Separate enum for atomic binary operations 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
78f225a37a Implemented atomics in HLSL-out 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
bc4576c0a2 Make atomic operations to be statements 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
88c1c9037d Add atomic exchange function 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
8c371e8063 Atomic expressions, support in backends except HLSL and the validator. 2021-08-10 21:48:02 -04:00
Dzmitry Malyshau
021bfd5289 [hlsl-out] fix member offset consideration for storage buffers 2021-08-09 16:45:07 -04:00
João Capucho
1aaf77489b [glsl-in] Improve error api and make more errors deferred 2021-08-09 10:51:15 -04:00
João Capucho
a8a316da15 [glsl-in] API revamp
The new api allows for reuse while keeping some allocations and to
please the borrow checker in future work, it also splits the parser into
logical modules to make it easier to work on.
2021-08-09 10:51:15 -04:00
Dzmitry Malyshau
7c3cc904a0 [spv-in] fix storage buffer access decorations 2021-08-05 12:59:19 -04:00
Gordon-F
4080bfe502 Add vec select to operators snapshot 2021-08-05 09:43:47 -04:00
João Capucho
a1395ddb99 [glsl-in] Fix matrix constructor with a scalar
Glsl defines that if a matrix constructor is called with only a scalar
it's result will be the matrix where the scalar is used if the row and
column are equal and everywhere else a zero
2021-08-04 12:39:36 -04:00
João Capucho
de6399a9c7 [glsl-in] Follow spec when choosing default layout 2021-08-04 12:39:36 -04:00
Dzmitry Malyshau
6f21004369 Allow mixing on a scalar selector 2021-08-04 12:09:05 -04:00
João Capucho
a90aa9817b [glsl-in] Add support for non constant global init
Glsl allows things such as

```glsl
layout (location = 0) in vec4 a;
vec4 b = a;
```

In this case `b` depends on `a` which can't be known at compile time,
so it's necessary to add a small prologue to the entry point to
initialize it.
2021-08-04 12:07:17 -04:00
João Capucho
057dc3100d [glsl-in] Remove support for multiple entry points 2021-08-04 11:06:57 -04:00
João Capucho
56ce439ff5 [glsl-in] Implement layouting for composite types 2021-07-31 23:25:22 -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
João Capucho
677e040462 [glsl-in] Long form matrix support 2021-07-27 11:35:47 -04:00
Dzmitry Malyshau
a7ac13a61d hlsl: special constants for base vertex/index 2021-07-27 01:49:03 -04:00
Gordon-F
d3243bd774 [glsl-out] Enable access snapshot testing 2021-07-26 13:53:48 -04:00
Dzmitry Malyshau
e97c8f9441 hlsl: fix storage offset, continuing statement 2021-07-26 01:29:42 -04:00
Dzmitry Malyshau
a5c2cef9ab hlsl: transpose storage matrices 2021-07-26 01:29:42 -04:00
Dzmitry Malyshau
284cfcce47 hlsl: storage writes 2021-07-26 01:29:42 -04:00
Dzmitry Malyshau
4b6846d5da hlsl: storage reads support, array length 2021-07-26 01:29:42 -04:00
Gordon-F
526a29e2b8 [glsl-out] Fix array type writing and zero initialization for local variables 2021-07-24 17:53:24 -04:00
Dzmitry Malyshau
bbfa9a0f9e hlsl: remove the boolean casts for unary operators 2021-07-23 10:41:36 -04:00
Dzmitry Malyshau
cc91c77f7a hlsl: fix vector multiplication 2021-07-23 02:11:32 -04:00
Dzmitry Malyshau
c526383cf8 hlsl-out: write StructuredBuffer 2021-07-22 15:44:26 -04:00
Dzmitry Malyshau
20c4d2c3d1 Add MSAA depth texture type 2021-07-22 10:39:24 -04:00
Gordon-F
82b2fe4410 [glsl-out] Fix zero initialization 2021-07-20 16:28:44 -04:00
Gordon-F
e017cb402e [glsl-out] Add stage postfix for block structs 2021-07-20 16:28:44 -04:00
Zicklag
34b486f74b Add Explicit Int Precision for GLSL ES Backend 2021-07-20 10:16:33 -04:00
Dzmitry Malyshau
7b9b56a6ab hlsl-out: use * for vector by vector multiplication 2021-07-20 09:57:59 -04:00
Gordon-F
3c98cc5ae1 [hlsl-out] Validate all entry points in Makefile 2021-07-20 01:03:58 -04:00
Jim Blandy
f3c7537609 Add tests for sampling mipmapped and multisampled images.
Prior to this change, nothing in the test suite exercised the SPIR-V backend
code for generating LOD or Sample arguments to OpImageFetch instructions.
2021-07-20 01:01:55 -04:00
Dzmitry Malyshau
39eaa57a77 hlsl-out: implement constant buffer support 2021-07-18 02:21:01 -04:00
Dzmitry Malyshau
16206f2eb2 hlsl-out: unlock globals.wgsl test, override skybox bindings 2021-07-18 02:21:01 -04:00
Dzmitry Malyshau
0d94b76d1e hlsl-out: rewrite texture coordinate construction 2021-07-18 02:21:01 -04:00
Dzmitry Malyshau
51fb9bb77a hlsl-out: remap bindings 2021-07-18 02:21:01 -04:00
Dzmitry Malyshau
2a253ab838 hlsl-out: derive register based on storage class 2021-07-18 02:21:01 -04:00
Jasper St. Pierre
c7dd717b4c
wgsl: Don't output interpolate(flat) for non-float arguments (#1103) 2021-07-17 01:19:11 -04:00
Dzmitry Malyshau
8f71a368ef
Validate the exact MSL version (#1101) 2021-07-16 23:56:15 -04:00
Jim Blandy
337e40a2be
Enable logging in WGSL and SPIR-V tests. (#1098)
Use env_logger::try_init to avoid complaints about repeated initialization. This
function is thread-safe.
2021-07-16 23:09:48 -04:00
Dzmitry Malyshau
e76824aba3
glsl-out: fix emission of location/binding attributes (#1100) 2021-07-16 23:04:55 -04:00
initial-algebra
602368d9f0
Support builtin(primitive_index) (#1097)
* Hack in support for PrimitiveID on Vulkan

* Rename to PrimitiveIndex and add preliminary support for GLSL, HLSL and MSL

* Implement as an extra WGSL built-in

* Update extra.wgsl outputs

* Run rustfmt; fix WGSL writer

* Add rustfmt changes I forgot

* Update extra.wgsl test output for WGSL fix

* Bump macOS version to 10.15 in validate-msl to support primitive_index
2021-07-16 22:18:20 -04:00
Dzmitry Malyshau
8eef784416 WGSL: Flip true/false arguments of select() 2021-07-16 11:42:12 -04:00
Gordon-F
4ef754bb9d [hlsl-out] Enable image snapshot 2021-07-16 10:31:01 -04:00
Gordon-F
2716d368a1 [hlsl-out] Implement barrier statement 2021-07-16 10:31:01 -04:00
Jasper St. Pierre
0995c7161e [glsl-in] Keep around extra linkage variables
WGSL will require this. Note that this still might
cause some issues with multi-entry-point GLSL
that I didn't know how to handle. That is, we will
handle unused builtin inputs but not unused
builtin outputs correctly right now. This is an existing
issue though, not a regression.

This is also provided as an option, but I feel like
the more correct approach is to never strip linkage
variables. We'll see though.
2021-07-14 17:48:54 -04:00
Jasper St. Pierre
0b69aa8b8a Init env_logger in snapshots tests
For debugging. Maybe there's a way to do it for all tests,
not sure...
2021-07-14 17:48:54 -04:00
pyrotechnick
1d1aea243f
Improve WGSL interpolation attributes (#1083)
* [wgsl-in] Map interpolate(..., center) to Sampling::Center

* [wgsl-out] Improve interpolation attributes

* [wgsl] Fix tests/in/interpolate.wgsl typo/format

* [wgsl] Snapshot WGSL artefacts

* [wgsl-out] Stack-only writing of interpolation
2021-07-13 21:57:52 -04:00
Gordon-F
ccf3fe9707 Fix type info of texture dimensions function with texture cube parameter 2021-07-13 17:28:09 -04:00
Dzmitry Malyshau
458db0b522 [hlsl-out] expose profile string conversions 2021-07-11 23:14:07 -04:00
João Capucho
105a2ae5e1 [glsl-in] Check type dimensions in function calls 2021-07-07 12:59:20 -04:00
Gordon-F
9e61390626 [hlsl-out] Zero initialize variables. Write interpolation and sampling qualifier 2021-07-07 10:57:28 -04:00
João Capucho
ee1004d443 [glsl-in] Use cast for implicit conversion
Previously this was a bitcast
2021-07-06 11:24:05 -04:00
João Capucho
2b475ecc96 [spv-out] Support object-wise select 2021-07-06 10:12:24 -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
Gordon-F
65fbbf1101 [hlsl-out] Return only real names on entry point in ReflectionInfo 2021-07-05 18:54:42 -04:00
Gordon-F
d5776879de [hlsl-out] Enable interface snapshot testing 2021-07-05 18:54:42 -04:00
Joshua Groves
9192f7b882 wgsl-in: add more error tests 2021-07-05 02:24:18 -04:00
João Capucho
2f002a0594 [spv-out] Load texture arguments ahead of time 2021-07-05 02:23:00 -04:00
João Capucho
c7b98f5ab9 [spv-out] accept texture trough function argument 2021-07-05 02:23:00 -04:00
Joshua Groves
c5805a9e10 wgsl-in: add more error tests 2021-07-04 01:00:21 -04:00
Jasper St. Pierre
78e1304d42 [glsl-in] Convert bool -> scalar cast to Select 2021-07-02 01:34:34 -04:00
Jasper St. Pierre
cb8e9f2cad [glsl-in] Implicitly splat the inputs of clamp() 2021-07-01 18:32:33 +01:00
João Capucho
a1749ab9c5 [glsl-out] Fix argument skipping 2021-07-01 11:19:28 -04:00
João Capucho
2bb15eb0a8 [glsl-in] Add support for texture arguments 2021-07-01 11:19:28 -04:00
João Capucho
4da665d3ba Address comments 2021-07-01 11:19:28 -04:00
João Capucho
7df4a52af9 [valid] Handle texture/sampler function argument 2021-07-01 11:19:28 -04:00
Gordon-F
607206f9a5 [hlsl-out] Enable operators snapshot test 2021-06-29 09:49:00 -04:00
Gordon-F
925c92d12f Add entry point to operators wgsl test 2021-06-29 09:49:00 -04:00
Gordon-F
6723c8f6ae [hlsl-out] Implement Derivative expression and enable standard snapshot test for HLSL 2021-06-29 09:49:00 -04:00
Dzmitry Malyshau
68a2efd3c5 glsl-out: make the cs adjustment to also flip Y 2021-06-29 02:18:56 -04:00
Dzmitry Malyshau
ba066c83e7 glsl-out: proper continuing block 2021-06-29 01:44:54 -04:00
Dzmitry Malyshau
e8b71b8dc5 [glsl-out] Support extended shadow sampling instructions, and the offset 2021-06-28 15:01:39 -04:00
Dzmitry Malyshau
cfbe83e384 glsl-out: adjust coordinate space 2021-06-28 15:01:39 -04:00
Dzmitry Malyshau
57b3256020 [glsl-out] binding location mapping 2021-06-27 01:09:53 -04:00
Gordon-F
19de60f6e4 [hlsl-out] Implement more expressions 2021-06-26 13:15:44 -04:00
Gordon-F
a8119f005e Add extra fragment entry point to wgsl quad snapshot 2021-06-24 10:47:17 -04:00
Gordon-F
e28344edbb [hlsl-out] Return entry points name to users 2021-06-24 10:47:17 -04:00
Gordon-F
1c5d538ab4 [glsl-out] Add entry point name to snapshot file name 2021-06-24 10:47:17 -04:00
João Capucho
4bc4c60663 [glsl-in] Implicit casts for function calls 2021-06-19 13:58:21 -04:00