Commit Graph

1323 Commits

Author SHA1 Message Date
Dzmitry Malyshau
c1eed779fe Infer types of module-scope let declarations 2021-09-08 09:42:36 -04:00
Jim Blandy
d4bedafbda Move #[must_use] attr on Capabilities to where it'll take effect.
This was causing warnings in nightly (1.56.0).
2021-09-07 17:30:08 -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
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
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
Hans Christian Schmitz
2069ea698f Implement fuzzing for the GLSL parser (#1301)
* Implement fuzzing for the GLSL parser

* Remove arbitrary dependency from naga

Derive `Arbitrary` for proxy objects in `fuzz/fuzz_targets/glsl_parser.rs`
instead.
2021-08-31 13:00:50 -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
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
b226c5108a [spv-out] Add test for duplicate OpTypeImage instructions. 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
496525b7d3 Improve help messages, defaults for CLI bounds checking options. 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
Dzmitry Malyshau
715a53f891 [msl-out] don't pack location fields 2021-08-25 16:52:45 -04:00
Hans Christian Schmitz
db845347f2 Fix fuzzing setup
Set naga features in `fuzz/Cargo.toml` to those required for SPIR-V and
WGSL input.
Also bump libfuzzer-sys version.
2021-08-25 11:45:52 -04:00
fsh
f11afd4fcf [glsl-in] Avoid infinite loop when parsing invalid statements (#1280) 2021-08-24 19:46:54 +00:00
aentity
a35de06f33 Update deps petgraph and rose-tree 2021-08-24 01:51:52 -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
Dzmitry Malyshau
ea883d98e2 [spv-in] track function parameter sampling flags across handle permutation 2021-08-23 01:48:45 -04: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
Jim Blandy
63e58f2022 [wgsl-in] Print errors nicely in convert_wgsl snapshot tests. (#1274) 2021-08-22 22:31:11 -04:00