Commit Graph
49 Commits
Author SHA1 Message Date
teoxoy a730236b68 [wgsl-in] eagerly evaluate const-expressions
[wgsl-in] support const-expressions in attributes

allow `Splat` as an evaluated const-expression type
2023-10-12 13:13:26 +02:00
Jim Blandy 8b267218a4 Implement module compaction.
Add a new Naga feature, `"compact"`, which adds a new function
`naga::compact::compact`, which removes unused expressions, types, and
constants from a `Module`.
2023-09-20 18:46:33 +02:00
Evan Mark Hopkins f7de1942c1 [spv-out] Cache OpConstantNull (#2414) 2023-08-02 18:05:16 +02:00
teoxoy ee81f569df add constructors test file 2023-07-17 16:26:08 -07:00
teoxoy d348d843e1 implement const-expressions (phase 1) 2023-07-17 16:26:08 -07:00
teoxoy 08105461ce omit non referenced expressions 2023-06-12 17:49:06 -07:00
Teodor Tanasoaia 62b287e761 Change type of constant sized arrays to NonZeroU32 (#2337) 2023-05-12 14:38:50 +02:00
Jim Blandy 412d5aa62e [wgsl-in] Generate Expression::Literal. 2023-05-11 07:09:53 -07:00
Teodor Tanasoaia 4d87401fac Use Expression::ZeroValue in SPIR-V and WGSL front ends. 2023-05-10 19:30:03 -07:00
Evan Mark Hopkins 60c0fc0284 [spv-out] Cache constant composites (#2257) 2023-02-20 15:24:20 +01:00
6035b07b78 [wgsl-in] Implement module-level scoping.
Fixes #1745: Support out-of-order module scope declarations in WGSL
Fixes #1044: Forbid local variable shadowing in WGSL
Fixes #2076: [wgsl-in] no error for duplicated type definition
Fixes #2071: Global item does not support 'const'
Fixes #2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument
Fixes #1775: Referencing a function without a return type yields an unknown identifier error.
Fixes #2089: Error span reported on the declaration of a variable instead of its use
Fixes #1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'"

Separate parsing from lowering by generating an AST, which desugars as
much as possible down to something like Naga IR. The AST is then used
to resolve identifiers while lowering to Naga IR.

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2023-01-12 09:37:08 -08:00
Erich GublerandDzmitry Malyshau aa22301b4b Parenthesize unary negations to avoid -- (#2087)
* fix(glsl-out,hlsl-out,msl-out): parenthesize unary negations a la `wgsl` everywhere

Unify parenthesization of unary negations across all backends with what the `wgsl` backend does,
which is `<op>(<expr>)`. This avoids ambiguity with output languages for which `--` is a different
operation; in this case, we've been accidentally emitting prefix decrements.

* build: update `rspirv` 0.11 -> 0.12 (FIXME: use upstream release)

* test: add `operators::negation_avoids_prefix_decrement` test

Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com>
2022-11-17 11:43:56 +01:00
João Capucho db1321cfb6 wgsl-in: Splat on compound assignments
Compound assignments on wgsl follow the same semantics as their
underlying operation, this includes the splatting behavior when mixing
scalar and vector operands, which was done for binary operations but not
for compound assignments.
2022-09-10 10:17:20 -07:00
Jim Blandy 7505187476 [spv-out] Don't emit no-op OpBitCast instructions.
As reported in #2015, some drivers trip over these.
2022-09-03 16:39:07 +01:00
teoxoy 6dae3ac7e0 [wgsl-in] support partial vector & matrix identity constructors 2022-05-12 22:15:45 -07:00
teoxoy f48174a0b4 [spv-out] use OpCopyObject for matrix identity casts 2022-05-12 22:15:45 -07:00
teoxoy b7ff50619c [spv-out] use OpCopyObject for bool - bool conversion due to OpBitcast not being feasible for booleans 2022-05-12 22:15:45 -07:00
teoxoy afb6504b8b add support for identity matrix constructor 2022-05-12 22:15:45 -07:00
teoxoy fea33c682e [wgsl-in] fix incr/decr not matching ValuePointer 2022-05-11 20:01:46 -07:00
teoxoy 239bbbbed4 [spv-out] zero init variables in function and private address spaces 2022-05-10 10:44:40 +02:00
teoxoy 7109cffb20 [spv-out] use SRem instead of SMod 2022-05-09 20:48:09 -07:00
teoxoy 062b66ca31 implement phony assignment 2022-04-26 21:40:31 -07:00
teoxoy d3b37dcdb1 add tests for remaining vector - scalar ops 2022-04-15 11:21:51 +02:00
teoxoy 95b84c4403 [spv-out] add support for int vector scalar mult 2022-04-15 11:21:51 +02:00
teoxoy 2cda40396a comment out problematic negative int 2022-04-15 11:21:51 +02:00
teoxoy 4ea7dc3381 [spv-out] add support for matrix add and sub 2022-04-15 11:21:51 +02:00
teoxoy 4366e65609 add support for unary vector operators 2022-04-15 11:21:51 +02:00
teoxoy e4c017cb7c add more tests for operators 2022-04-15 11:21:51 +02:00
Teodor Tanasoaia cfcf625019 [wgsl-in] Constructor improvements (#1790)
* add support for zero value constructors and constructors that infer their type from their parameters

* address comments

* extract constructor machinery into new module

* fix doc link
2022-03-29 22:51:54 -07:00
teoxoy 9dddfeec37 [wgsl-in] implement increment and decrement 2022-03-27 00:34:53 -07:00
Dzmitry Malyshau c0b7ac7f54 WGSL: assignment binary operators 2022-01-11 11:01:24 -05:00
João Capucho 70b5ddaaad spv-out: use OpFRem instead of OpFMod 2022-01-07 20:19:15 -05:00
João Capucho e1552fd9d5 wgsl-in: Implement matrix construction from scalar 2021-12-17 10:39:31 -05:00
João Capucho 4334f0e6a9 Support bitwise And on booleans 2021-12-15 23:53:23 -05:00
João Capucho c64d5eff50 Support bitwise Or on booleans 2021-12-15 23:53:23 -05:00
Jay Oster 66c3499df8 [spv-out] Fix scalar-times-matrix operations (#1524) 2021-11-14 19:07:38 -05:00
Dzmitry Malyshau ee450c1ee4 Fix float-bool casts in MSL, SPV, and HLSL backends (#1459) 2021-10-12 11:42:20 -04:00
Igor Shaposhnik 943235cd5e [glsl-out] Convert modulo operator on float to SPIR-V OpFRem equivalent function (#1452) 2021-10-07 16:59:39 -04:00
Dzmitry Malyshau 52d74e91a4 spv-out: option to emit PointSize 2021-09-15 18:48:18 -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 7681f4a21f msl-out: fix as_type expressions 2021-09-09 21:09:20 -04:00
Dzmitry Malyshau a4f19833b5 hlsl: implement struct constructors 2021-09-03 12:43:54 -04:00
Zicklag 897afbd710 [wgsl-in] [wgsl-out] Implement bitcast() 2021-08-20 17:19:23 -04:00
Gordon-F 4080bfe502 Add vec select to operators snapshot 2021-08-05 09:43:47 -04:00
Dzmitry Malyshau 6f21004369 Allow mixing on a scalar selector 2021-08-04 12:09:05 -04:00
Dzmitry Malyshau 8eef784416 WGSL: Flip true/false arguments of select() 2021-07-16 11:42:12 -04:00
João Capucho 2b475ecc96 [spv-out] Support object-wise select 2021-07-06 10:12:24 -04:00
Gordon-F 925c92d12f Add entry point to operators wgsl test 2021-06-29 09:49:00 -04:00
Gordon-F 6cdd332cef Reorganize test snapshot folder 2021-06-19 10:19:04 -04:00