Commit Graph

655 Commits

Author SHA1 Message Date
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
Jim Blandy
ce676cf130 [wgsl-out] Correct production of * and & operators.
Fixes #1322.
2021-09-08 15:04:45 -07:00
Dzmitry Malyshau
e226cf3f1d spv-out: option to skip OpName for varyings 2021-09-08 16:52:10 -04:00
Dzmitry Malyshau
7138876625 [spv-out]: ability to separate entry points 2021-09-07 14:22:39 -04:00
Igor Shaposhnik
35f27cfe7e [hlsl-out] Rewrite indent logic. Reduce heap allocation 2021-09-06 21:02:56 -04:00
Igor Shaposhnik
9afb581364 [glsl-out] Rewrite indent logic. Reduce heap allocation 2021-09-06 21:02:56 -04:00
Igor Shaposhnik
f24ea5c534 [wgsl-out] Rewrite indent logic. Reduce heap allocation 2021-09-06 21:02:56 -04:00
Igor Shaposhnik
3b9dcc568f Move Level from msl to backend module 2021-09-06 21:02:56 -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
Igor Shaposhnik
dad26c543c [wgsl-out] Reduce heap allocation 2021-09-03 09:53:43 -04:00
Jim Blandy
8ef92227c1 Document the bake_ref_count hack. (#1315) 2021-09-01 16:34:33 -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
995a7752a9 [spv-out] Replace map_dim with a From implementation. 2021-08-30 13:24:41 -04:00
Jim Blandy
b35e40ec59 [spv-out] Use bit flags in LocalImageType, instead of bools. 2021-08-30 13:24:41 -04:00
Jim Blandy
81fbad182c [spv-out] Avoid generating duplicate OpTypeImage instructions.
Fixes #1305.

Ensure that two `back::spv::LocalType::Image` values are sure to be equal (and
hash equal) whenever they would generate the same `OpTypeImage` instruction, so
that the usual duplicate removal via `Writer::lookup_type` works. Accomplish
this by changing the contents of `LocalType::Image` to more closely match the
operands of `OpTypeImage` instructions.

Previously, `LocalType::Image` included a `ImageClass::Storage::access` value,
which did not affect the `OpTypeImage` instruction generated. If two
`LocalType::Image` values differered only in their `access`, then they would get
separate entries in `Writer::lookup_type`, two identical `OpTypeImage`
instructions would be generated, and SPIR-V validation would fail.
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
6b72099d76 [spv-out] Let write_type_declaration_local handle all LocalTypes.
Change `write_type_declaration_local` to handle any type that can be represented
as a `LocalType`. This means that Image and Sampler types are handled there now.

Change `write_type_declaration_arena` to defer to `write_type_declaration_local`
to handle any type that can be represented as a `LocalType`. This makes the code
for those types in `write_type_declaration_arena` redundant, so remove it.

However, continue to request SPIR-V capabilities for image types from
`write_type_declaration_arena`, since that function is fallible, while
`write_type_declaration_local` is not.
2021-08-30 13:24:41 -04:00
Jim Blandy
e8d35e8035 [spv-out] Avoid duplicate lookup in write_type_declaration_local. 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
Igor Shaposhnik
f7040a2787 [hlsl-out] Fix output struct member names 2021-08-30 10:59:15 -04: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
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
Dzmitry Malyshau
715a53f891 [msl-out] don't pack location fields 2021-08-25 16:52:45 -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
99de387302 [spv-out] Move image operations into their own module.
For ease of review, there should be no meaningful code changes in this commit.
Match arms are merely moved out into their own functions, whose arguments are
the enum variant's fields, along with any free variables from the function
containing the match.
2021-08-22 23:41:27 -04:00
Jim Blandy
3f4cd9dc88 [spv-out] Add GlobalVariable helper functions. 2021-08-22 23:41:27 -04:00
Jim Blandy
c1121a1e62 [spv-out] Use 'image' instead of 'texture', consistent with SPIR-V. 2021-08-22 23:41:27 -04:00
Jim Blandy
de114e479b Rename IndexBoundsCheckPolicy to BoundsCheckPolicy. 2021-08-22 23:41:27 -04:00
João Capucho
fd10b7d9e8 [glsl-out] Modulo operator on float must be converted to mod function (#1271)
Fixes #1266
2021-08-22 22:43:52 -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
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
Mikko Lehtonen
222e0949bd [msl-out] Fix gradient sampling typo 2021-08-22 22:20:42 -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
Jim Blandy
ea168baf56 [spv-out] Clean up capability handling.
Remove `forbidden_caps`.

Accumulate capabilities actually used separately from the permitted
capabilities, so that the latter can be retained across Writer resets, while the
former is cleared between modules.
2021-08-20 18:04:23 -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
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
Connor Fitzgerald
dfcb79880f [hlsl-out] Fix pointer-to-array arguments (#1240) 2021-08-19 16:55:29 +00:00
Dzmitry Malyshau
dad4b1bb10 [hlsl-out] fix array arguments in functions 2021-08-19 10:05:57 -04:00
Jim Blandy
cefaa396d4 [spv-out] Generating constants is not, in fact, fallible. 2021-08-18 14:40:00 -04:00