Commit Graph

697 Commits

Author SHA1 Message Date
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
João Capucho
d64d78ff0b wgsl-in: Implement lexical scopes
Previously the wgsl frontend wasn't aware of lexical scopes causing all
variables and named expressions to share a single function scope, this
meant that if a variable was defined in a block with the same name as a
variable in the function body, the variable in the function body would
be lost and exiting the block all references to the variable in the
function body would be replaced with the variable of the block.

This commit fixes that by using the previously introduced `SymbolTable`
to track the lexical and perform the variable lookups, scopes are pushed
and popped as defined in the wgsl specification.
2022-09-01 17:31:50 -07:00
Jim Blandy
b209d91168 [spv-out] Properly combine the fixes for #2035 and #2038.
The Vulkan decoration rules require us to distinguish vertex shader
inputs, fragment shader inputs, and everything else, so just pass the
stage to `Writer::write_varying`. Together with the SPIRV storage
class, this is sufficient to distinguish all the cases in a way that
closely follows the spec language.
2022-09-01 15:55:42 -07:00
Nicolas Silva
b63436af36 Decorate most builtins as Flat in the spirv writer.
Fixes #2032
2022-09-01 10:27:19 -07:00
Nicolas Silva
6b3c111f3f Don't decorate varyings with interpolation modes at the beginning and end of the pipeline.
Fixes #2036.
2022-09-01 10:17:55 -07:00
João Capucho
9df243c42c
hlsl-out: Add support for push constants (#2005)
Push constants need to be configured by the consumer which must pass the
bind target of the constant buffer used for the push constants.
2022-08-29 11:58:02 +01:00
Adeline
e7ddd3564c
glsl-in: Fix missing stores for local declarations (#2029)
Previously, if a local variable was declared with a constant value, we
would elide the store and instead give the variable an initial value (as
if it was a global variable). This caused variables to not be
re-initialized each time through a loop.
2022-08-24 22:05:11 +01:00
Evan Mark Hopkins
a80967f860
Add support for the saturate function (#2025)
uses clamp in place of saturate in spv and glsl
2022-08-16 10:43:41 +00:00
SpaceCat~Chan
f2624ea378
[glsl-in] add support for .length() (#2017)
Adds parsing support for methods on the glsl frontend, while `.length` is the only method in the base extensions, there might be more in extensions.

Adds support for the `.length` method and tests for it.
2022-08-08 18:09:22 +01:00
João Capucho
c6f34fa4d8 dot-out: Improvements
Improves the dot backend output by:
- Linking new nodes to the end of other blocks, instead of the beginning
- Generating merge nodes for conditional statements
- Generating connections from break/continue nodes to their target
- Introducing a "cfg only" mode that only generates statements
2022-08-03 15:01:26 -07:00
Ashley
e2d688088a
Support for the OVR_multiview2 WebGL extension (#1933)
* Make some (currently hacky) changes to enable multiview in webgl

* Fix ViewIndex built in for this extension

* Run cargo fmt, fix tests

* Allow specifying if we're targetting webgl in the glsl version

* Document multiview2 extension

* fn embedded -> const fn embedded

* Fix tests

* Fix benches

* Add snapshot tests

* Revamp so that the glsl options have some multiview options. Also add tests

* Make clippy happier

* Go back to having is_webgl be part of Version

* Use wgsl as input for tests

* Rename Version::new_embedded to Version::new_gles, fix glsl validation

* Run cargo fmt

* Fix brand new clippy warnings
2022-06-30 17:58:47 +01:00
Teodor Tanasoaia
27d38aae33
[hlsl-out] More matCx2 fixes (#1989)
* [hlsl-out] fix matCx2 as global uniform

* [hlsl-out] update comments

* [hlsl-out] fix `row_major` not being written on global arrays of matrices and also write it on nested arrays of matrices

* [hlsl-out] fix matCx2's nested inside global arrays

* [hlsl-out] fix struct members of type array<matCx2>

* [hlsl-out] test mat2x4 to make sure our matCx2 code behaves properly
2022-06-27 15:56:10 -07:00
João Capucho
67ef37ae99 Add support for 'break if' to IR, wgsl-in, and all backends. 2022-06-24 17:47:07 -07:00
Ashley
ea832a9eec
[glsl-out] Handle vector bitcasts (#1966)
* [spv-in] Fix bitcasts on non-scalars

* Fix ::As handling in glsl

* Cargo fmt

* Make cargo clippy happy

* Add snapshot tests

* Use write_type_value

* target_vector_kind -> target_vector_type
2022-06-20 22:25:13 -07:00
João Capucho
6d78f1c06d hlsl-out: Fix indentation for continuing block
The continuing block in hlsl was being generated with the same indentation as the loop body
2022-06-17 16:34:23 +02:00
João Capucho
cafdb160ae glsl-out: Fix indentation for continuing block 2022-06-17 16:17:22 +02:00
teoxoy
89f24b6cfe [msl-out] insert padding initialization for global constants 2022-06-17 10:55:28 +02:00
teoxoy
531d563f0e [wgsl-in] implement complete validation for size and align attributes 2022-06-16 12:13:08 -07:00
João Capucho
357da63076
Patch ron version (#1986)
Require at least version 0.7.1 of ron, this version changed how floating points are
serialized by forcing them to always have the decimal part, this makes it backwards
incompatible with our tests because we do a syntatic diff and not a semantic one.
2022-06-15 15:17:59 -04:00
João Capucho
ae58fbf4d0 Add tests 2022-06-14 16:04:08 -07:00
João Capucho
dab932e8ce glsl-in: Fix last case falltrough and empty switch
GLSL allows the last case of a switch statement to not have a `break`
statement causing it to be marked as fall-trough, naga's IR on the other
hand doesn't allow the last case to be fall-trough, this is fixed by
force marking it in the glsl frontend as not fall-trough.

GLSL also allows empty switch statements and without default cases,
naga's IR requires there be a default case, this is fixed by adding an
empty default case in the glsl frontend if no default case was present
in the switch statement.
2022-06-14 22:31:27 +01:00
João Capucho
52bb25179b glsl-in: Splat inputs for smoothstep if needed
Glsl defines two overloads for smoothstep that accept `min` and `max` as
scalars and the value as a vector, naga's IR is stricter and only allows
operators with the same dimensions, so this inputs must be splatted.
2022-06-14 13:15:08 -07:00
João Capucho
c7e6769001 Add tests 2022-06-14 13:14:43 -07:00
João Capucho
81e2b006e1 glsl-in: Add test for nested depth texture calls
Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
2022-06-14 13:11:30 -07:00
Jim Blandy
89bed99bcc Forbid returning pointers and atomics from functions.
Introduce a new `TypeFlags::CONSTRUCTIBLE` flag, corresponding to
WGSL's "constructible types". Set this on the appropriate types.
Check for this flag on function return types.
2022-06-01 14:20:55 -07:00
João Capucho
e461d30865 glsl-in: Fix matrix multiplication check
The previous check compared rows to rows and columns to columns but
multiplication of matrices only needs the columns of the left matrix to
be equal to the rows of the right matrix.
2022-05-30 22:54:14 +01:00
teoxoy
768e1fe703 [hlsl-out] avoid error X3504: array index out of bounds 2022-05-30 13:15:40 -07:00
teoxoy
a8256e94c2 [hlsl-out] avoid error X3694: race condition writing to shared resource detected 2022-05-30 13:14:00 -07:00
teoxoy
91ee407c87 [hlsl-out] fix fallthrough in switch statements 2022-05-30 13:11:56 -07:00
teoxoy
7c7e96276a [hlsl-out] fix missing break statements (for FXC) 2022-05-30 12:15:16 -07:00
João Capucho
0aa7681165
glsl-out: Implement bounds checks for ImageLoad (#1889)
* glsl-out: Implement bounds checks for `ImageLoad`

* Enable image bounds check snapshot tests for GLSL.

In addition to the snapshot.rs changes, this entails adding an entry
point function to `bounds-check-image-restrict.wgsl` and
`bounds-check-image-rzsw.wgsl`, including appropriate data in the
param.ron files.

* Apply comments

Snapshot test changes:
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2022-05-30 12:13:58 -07:00
grovesNL
60ae549fe1 Add error for non-floating-point matrix 2022-05-14 17:00:15 +02:00
teoxoy
ab2806e05f [hlsl-out] fix array constructor return type (for FXC) 2022-05-12 22:17:40 -07:00
teoxoy
5f47d6d31f [msl-out] use matrix identity constructor 2022-05-12 22:15:45 -07: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
b688584d87 [msl-out] fix pointers to private or workgroup address spaces possibly being read only 2022-05-11 20:10:18 -07:00
teoxoy
fea33c682e [wgsl-in] fix incr/decr not matching ValuePointer 2022-05-11 20:01:46 -07:00
Hasan Ali
205ea6cc5c Fix hlsl output for writes to scalar/vector storage buffer 2022-05-10 22:46:47 +02:00
teoxoy
b3d5e6d807 [msl-out] zero init variables in function address space 2022-05-10 10:44:40 +02:00
teoxoy
239bbbbed4 [spv-out] zero init variables in function and private address spaces 2022-05-10 10:44:40 +02:00
teoxoy
ceb92921c2 remove named expression entry for phony assignment 2022-05-10 10:43:25 +02:00
teoxoy
7109cffb20 [spv-out] use SRem instead of SMod 2022-05-09 20:48:09 -07:00
teoxoy
c03d840755 [glsl-in] translate mod fn correctly 2022-05-09 20:48:09 -07:00
teoxoy
c584331f39 [hlsl-out] use fmod instead of % 2022-05-09 20:48:09 -07:00
Teodor Tanasoaia
e312a7adeb
[hlsl-out] use wrapped constructors when loading from storage address space (#1893) 2022-05-09 20:40:42 -07:00
Hasan Ali
934fa16919
Implement reverseBits and countOneBits for SPIR-V (#1897)
* Implement reverseBits and countOneBits for spir-v

* Update tests

* Fix type error for glsl countOneBits implementation
2022-05-09 23:24:28 +02:00
teoxoy
1869c6831e [hlsl-out] zero init struct constructor 2022-05-03 19:51:51 +02:00
Jim Blandy
57e1793143 Properly check that user-defined IO uses IO-shareable types.
Only numeric scalars and vectors, and structs whose members are such
values, are permitted as the types of user-defined IO.
2022-05-02 10:28:16 +02:00
Jim Blandy
dec07027ee Split out check_one_validation macro from check_validation.
The new `check_one_validation` macro permits the source code to be a
computed expression, not just a string literal. This also cleans up
some of the handling of the optional guard expression.
2022-05-02 10:28:16 +02:00
Jim Blandy
a8e1e11437 Rename check_validation_error macro to check_validation.
The macro can check for both success and failure, so the new name is
more accurate, and shorter.
2022-05-02 10:28:16 +02:00
João Capucho
883a88580f glsl-in: Apply comments 2022-05-01 13:52:04 -07:00
João Capucho
1c02de537b glsl-in: Fix the ternary to behave as an if
The GLSL specification defines that only one of the branches should be
evaluated making the ternary operator syntatic sugar for an `if`.
2022-05-01 13:52:04 -07:00
Igor Shaposhnik
f76af4e53a [wgsl] Remove buffer, texture, in, out, input, output from reserved keywords 2022-04-29 20:06:09 +02:00
Teodor Tanasoaia
f2e7818e71
[wgsl-in] implement firstTrailingBit/firstLeadingBit u32 overloads (#1865)
* [wgsl-in] implement firstTrailingBit/firstLeadingBit u32 overloads

* fix MSL type issue

reverts b9162e443d
2022-04-26 22:25:53 -07:00
teoxoy
062b66ca31 implement phony assignment 2022-04-26 21:40:31 -07:00
Connor Fitzgerald
1aa9154964
Binding arrays play nice with bounds checks (#1855) 2022-04-25 04:17:51 +00:00
Connor Fitzgerald
ad28396851
Implement Binding Arrays (#1845) 2022-04-19 14:23:07 -04:00
Teodor Tanasoaia
dc075e66e3
[wgsl-in] Update reserved keywords (#1847) 2022-04-17 15:56:54 +02:00
Jim Blandy
ef387f73a6 [hlsl-out] Emit row_major qualifier on matrix uniform globals.
Fixes #1836.
2022-04-16 23:50:17 -07:00
Igor Shaposhnik
1720725014 [wgsl-out] Update entry point stage attributes 2022-04-15 18:02:48 +01:00
Igor Shaposhnik
fbb77aa0dc [wgsl-in] Update entry point stage attributes 2022-04-15 18:02:48 +01:00
teoxoy
8584507fb6 [glsl-out] remove redundant space from unary ops 2022-04-15 11:21:51 +02:00
teoxoy
7f4e07e5cd [glsl-out] add support for boolean vector ~, | and & ops 2022-04-15 11:21:51 +02: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
6e6daad4d4 [hlsl-out] fix bool splat 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
Jim Blandy
bdbf821c32 Test matrix-typed uniform globals. 2022-04-14 11:54:47 -07:00
Jim Blandy
27d0fee2e7 More tests for non-struct global types. 2022-04-14 11:45:42 -07:00
Jim Blandy
f11d27af6f
Reject empty struct types. (#1826) 2022-04-14 09:36:53 -07:00
Jim Blandy
170faab6db
Move invariant bit from Binding::Builtin to Builtin::Position. (#1822)
Use the type system to enforce the rule that the invariant attribute
may only appear on `Position` builtins.
2022-04-13 14:57:05 -07:00
Jim Blandy
78975f25da [msl-out] Permit invariant qualifier on vertex shader outputs. 2022-04-12 22:22:20 +02:00
Teodor Tanasoaia
bd62887a13
[hlsl-out] Add more padding when necessary (#1814)
* [hlsl-out] add padding at the end of structs and after struct members of type matrix and array (when necessary)

* use wrapped constructor fn for constants

* add array as fn arg test

* fix glsl array fn arg

* add wrapped constructor for arrays

* [glsl-out] support multidimensional arrays

* address comments
2022-04-11 20:34:06 -07:00
teoxoy
0e77d26241 cast packed vec3's to vec3 for expressions that require it 2022-04-11 20:30:00 -07:00
teoxoy
32cdb27230 add better tests for msl packed vec3 2022-04-11 20:30:00 -07:00
teoxoy
d7f4c340a7 add matrix vector multiplication test 2022-04-11 20:30:00 -07:00
teoxoy
1688a767bb fix packed vec3 stores 2022-04-11 20:30:00 -07:00
teoxoy
1f797fdc2f add more packed vec3 load/stores to test 2022-04-11 20:30:00 -07:00
Teodor Tanasoaia
7aaac25fbf
[hlsl-out] fix matCx2 translation for uniform buffers (#1802)
* [hlsl-out] fix matCx2 translation

* fix msl validation (warning: unused variable)

* fix msl buffer declaration

* address comments
2022-04-10 22:29:11 -07:00
teoxoy
6ee1fd4929 fix MSL issue 2022-04-10 21:49:23 -07:00
teoxoy
d3957c1186 implement invariant attribute 2022-04-10 21:49:23 -07:00
Noel Tautges
a3d968e795
[hlsl-out] Don't output interpolation modifier if it's the default (#1809)
* hlsl-out: don't output interpolation modifier if it's the default (linear/`Interpolation::Perspective`)

* Remove linear interpolation modifiers from HLSL output tests
2022-04-09 22:36:36 -07: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
Teodor Tanasoaia
012f2a6b2e
Merge pull request #1784 from teoxoy/patch-2
[hlsl-out] fix matrix not being declared as transposed
2022-03-27 22:24:09 -07:00
João Capucho
4146cb24d0 glsl-in: Allow nested accesses in lhs positions
Also fixes access to runtime sized arrays behind named blocks
2022-03-27 21:47:51 -07:00
João Capucho
21f89b65e4 glsl-in: use forced conversions for vector/matrix constructors
The spec defines that for vector and matrix constructors all arguments
should use the same conversions as scalar constructors (forced conversions)
2022-03-27 21:44:17 -07:00
João Capucho
767d970312 glsl-in: Resume expression emit after imageStore
This wasn't done before which caused the frontend to crash if anything
appeared after it.
2022-03-27 21:42:02 -07:00
teoxoy
9dddfeec37 [wgsl-in] implement increment and decrement 2022-03-27 00:34:53 -07:00
Pu Xingyu
b17e6cfe43 wgsl-out: Do not output semicolon after struct decl 2022-03-27 00:22:58 -07:00
Pu Xingyu
3c313564ac wgsl-in: Make semicolon after struct decl optional 2022-03-27 00:22:58 -07:00
João Capucho
54ef2e39a0 glsl-in: Allow multiple array specifiers 2022-03-27 00:18:20 -07:00
João Capucho
b568bfbbdf glsl-in: Fix memory qualifiers being inverted
Adds some documentation to better explain how the memory qualifier works
troughout the parser and some storage textures tests.
2022-03-27 00:02:26 -07:00
teoxoy
cf992a9a95 [wgsl-in] implement while loop 2022-03-22 22:47:47 -07:00