Commit Graph

394 Commits

Author SHA1 Message Date
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