Commit Graph

201 Commits

Author SHA1 Message Date
Jim Blandy
4ea2d96cfb Various doc fixes. (#1440) 2021-09-30 08:56:09 -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
Jim Blandy
92a97fb7d5 Simplify implementation of Namer::namespace. (#1438)
Eliminate `Namer::namespace_index` and remove namespace indices from
`Namer::unique` keys. Instead, implement `Namer::namespace` by just swapping in
a fresh table for the duration of the call.

Create the fresh hash table with the right initial capacity. The prior
implementation did manage to avoid allocations by sharing a hash table, and we'd
like to not lose that advantage entirely.

This has no effect on generated code.
2021-09-29 15:55:37 -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
73f9d07207 [Typifier] Some relational functions output vectors
Previously the typifier flagged all relational functions as producing a
scalar boolean but with the exception of `all` and `any`, according to
the wgsl spec, all other relational functions output a type the same
size as the input.
2021-09-26 21:19:08 -04:00
João Capucho
7895e7f036 Don't output identifiers starting with _ 2021-09-19 15:18:17 -04:00
Jim Blandy
c03427b154 Document TypeResolution and TypeInner::ValuePointer. 2021-09-14 09:41:28 -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
Alex Es
fd70116668 Proof of concept for "span" feature, with WGSL & GLSL parsing augmented. (#1092)
* Proof of concept for "span" feature, with WGSL parsing augmented.

* Review:

1) add_span was actually a bad idea, make it set_span and add
set_span_if_unknown too.
2) panics on getting/setting span for invalid handles.
3) only set span for constants with a name
4) don't overwrite spans for types.

* Added spans to blocks & more expressions getting spans in frontends.

Definitely the shotgunny type of commit, but what can you do. The design
I went with made spans mandatory to specify, so I had to go and wire
them through wherever I could.

* Moved Block to a separate module, +clippy

* More spans for types in GLSL.

* Remove pointless body method.

* Make Arena interface require spans.

Another shotgun commit, oh boy...

* Fix tests.

My loathsome habit to "quickly fix things along the way" made a lot of
extra work for me here, having to fix my "fixes" for WGSL parser.

* Rustfmt + clippy.

* Fix compile-errors with span feature enabled.

* Nuked set_span* from orbit. Deleting code feels great!

* Code review - move feature flags inside functions.

* Fix build with "deserialize" feature enabled.
2021-08-11 16:04:32 -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
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
8cb09c24c5 Atomics in the IR 2021-08-10 21:48:02 -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
Dzmitry Malyshau
46d2d6819e Fix matrix size computation 2021-07-26 10:40:47 -04:00
Dzmitry Malyshau
4b6846d5da hlsl: storage reads support, array length 2021-07-26 01:29:42 -04:00
Dzmitry Malyshau
20c4d2c3d1 Add MSAA depth texture type 2021-07-22 10:39:24 -04:00
Gordon-F
ccf3fe9707 Fix type info of texture dimensions function with texture cube parameter 2021-07-13 17:28:09 -04:00
Jim Blandy
70016ce6e3 Address warnings about links from cargo doc --package naga. 2021-06-20 12:18:50 -04:00
Jim Blandy
c16f2097ad [spv-out]: Ensure array subscripts are in bounds. 2021-06-18 20:44:07 -04:00
Frizi
5242d4f5a9 avoid hashmap allocation when entering namer namespace 2021-06-18 13:57:44 -04:00
Frizi
b89da31cc7 reorder namer assignment order to preserve names for reflection 2021-06-18 13:57:44 -04:00
Frizi
b439868c00 move SwizzleComponent impl into proc module 2021-06-17 15:21:47 -04:00
Frizi
3d5e6d51a0 [glsl-in] make sure swizzles never operate on a pointer value 2021-06-17 15:21:47 -04:00
Frizi
bff8b18a01 [glsl-in] lower swizzle store to per-component stores 2021-06-17 15:21:47 -04:00
Igor Shaposhnik
54af830855 Fix nightly clippy suggestions 2021-06-09 10:17:20 -04:00
Jim Blandy
a2a35f2eb3 Permit dynamic indexing of arrays and matrices only behind a pointer. (#949)
This makes Naga IR validation impose the restrictions added to WGSL in
gpuweb/gpuweb#1801.

Remove code in the SPIR-V writer to spill arrays to temporary variables in order
to index them dynamically. If such IR is encountered, treat it as a failure of
validation.
2021-06-04 12:57:20 -04:00
Gordon-F
90c2cf6aa6 Add ability to generate named expressions 2021-06-03 10:40:59 -04:00
Jim Blandy
398d3545b3 Include the type arena in ResolveContext, since it's always needed. 2021-05-26 10:35:59 -04:00
Jim Blandy
50de6ae9ac Improve error messages for missing I/O bindings.
The `apply_common_default_interpolation` helper function would panic if bindings
were missing, but missing bindings should be something that front ends can count
on validation to detect, so the helper should just return silently.

The validator returned `InvalidType` errors for missing bindings, apparently
because variables without bindings must be structs that do have bindings. But
this is unhelpful when you've just forgotten to label an argument. So this patch
adds a new, more specific, `VaryingError` variant.
2021-05-21 23:04:27 -04:00
Jim Blandy
a7100b14eb Flesh out the Naga module-level documentation. 2021-05-19 23:31:19 -04:00
Dzmitry Malyshau
b191c982ec Remove alignment from struct IR 2021-05-17 09:32:52 -04:00
Jim Blandy
9c5f324de2 TypeInner::span: Tolerate bad array length constants for now. 2021-05-13 22:09:22 -04:00
Dzmitry Malyshau
59d1dcab5b Support width changes in As expression 2021-05-08 21:20:23 -04:00
Dzmitry Malyshau
990fd2d3a3 Allow matrix indexing behind a pointer 2021-05-05 09:34:12 -04:00
Dzmitry Malyshau
9fe75ed7f1 Barriers 2021-05-04 22:16:24 -04:00
Gordon-F
dbfc11a196 [glsl-out] Fix writing identifiers starting with gl_ 2021-05-03 21:47:16 -04:00
Ashley Ruglys
33003d8ea2 Add MathFunction::Refract 2021-04-26 14:14:30 -04:00
Dzmitry Malyshau
e8c5242cc7 Fix relational expression type width 2021-04-25 12:57:59 -04:00
Dzmitry Malyshau
5d1746b0b4 Swizzle expression (#734) 2021-04-20 22:03:54 -04:00
Jim Blandy
4f442ff8cc Require binding interpolation to be resolved by the front end.
When validating IR, verify that all `Binding`s for vertex shader outputs and
fragment shader inputs, whether directly in the argument or result, or applied
to a struct member, has specified an interpolation and sampling, not `None`.
This ensures that front ends explicitly state their policies, rather than
coasting through on back ends' default behavior.

In practice, all our front ends have very similar defaults, so provide a utility
function on `Module` to apply these rules. Use this utility function in the
SPIR-V and WGSL front ends; GLSL seems to already fill in interpolation as
required.
2021-04-19 09:42:00 -04:00
Jim Blandy
99a9e1e78e Change Binding::Location to a struct-style enum variant.
This commit makes no other changes. This is in preparation for adding a third
field, at which point tuple variants start to get obscure.
2021-04-19 09:42:00 -04:00
Dzmitry Malyshau
62c2cf7332 Validate composite constants (#729) 2021-04-18 23:19:09 -04:00
Dzmitry Malyshau
d3b39d9e58 Splat expression in the IR 2021-04-14 19:26:20 -04:00
Dzmitry Malyshau
604e10e19b Rewrite IR to have member offsets, full structure span and alignment 2021-04-08 23:15:03 -04:00
Dzmitry Malyshau
7326ba6ddb New struct layout IR 2021-04-08 23:15:03 -04:00
Dzmitry Malyshau
5673603bab [spv-out] flip position Y 2021-04-03 11:27:21 -04:00