Commit Graph
416 Commits
Author SHA1 Message Date
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 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 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