Commit Graph
159 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
teoxoy 7c3c6a9d47 [glsl-in] move module and active body to Context 2023-09-05 14:00:17 -07:00
teoxoy d348d843e1 implement const-expressions (phase 1) 2023-07-17 16:26:08 -07:00
teoxoy 6b0c2a532a enable clippy::match_wildcard_for_single_variants lint 2023-03-16 15:51:59 +01:00
Shaye Garg 67ea8f0c06 [wgsl-in] Split into multiple files (#2207)
Make changes suggested in #2075, but put off to a separate PR because they would interfere with reviewing the change:

- Split the new WGSL front end into modules in a logical way.
- Rename `Parser` to `Frontend`.
2023-01-31 07:17:58 -08:00
João Capucho 883a88580f glsl-in: Apply comments 2022-05-01 13:52:04 -07:00
João Capucho 6a62d009ea glsl-in: Improve the context emitter interface
Adds a new method `emit_restart` to perform the common operation of flushing
the `emitter` to the body and starting it again.

Adds documentation to all context emitter related methods
2022-05-01 13:52:04 -07:00
Jim Blandy fae939f537 [glsl-in] Simplify control flow in search for main. 2022-05-01 00:29:17 +01:00
Shohei JinnoandJCapucho 8f5d8f61a8 glsl-in: better errors for bad constant expression (#1501)
Co-authored-by: JCapucho <jcapucho7@gmail.com>
2022-04-11 11:22:04 -07:00
João Capucho 51e66eceb2 glsl-in: Allow backtracking in the parser 2022-03-03 21:39:45 -08:00
João Capucho e621acc09d glsl-in: Type qualifiers rework (#1713)
The previous implementation had many issues, most importantly it didn't
allow to implement (at least in a sane way) some future features like
default qualifiers and format qualifiers.

This implementations centralizes the qualifiers into a struct with a
hashmap for layout qualifiers, error reporting is also centralized which
means that `add_global_var` and `add_local_var` no longer need to
duplicate effort and the ugly loop + match combo is gone.

Finally some minor fixes are also done as part of this rework, like
a default location being provided for input/outputs variables and layout
qualifiers being allowed to be repeated (overwriting the previous one)
like the spec defines.
2022-02-04 15:06:49 -05:00
João Capucho af44603e47 [glsl-in] Use Span instead of SourceMetadata 2021-09-21 11:00:33 -04:00
João Capucho ca405e3acf [glsl-in] Allow dynamic indexing on constant variables
Previously we always set the lhs flag when lowering to generate a
pointer so that dynamic indexing would work, this would produce an error
on constant variables since they can't be in a lhs context.

Now we introduce an enum which distinguishes not only between lhs and
rhs but also in array base, if lowering in a lhs context the base is
also lowered in a lhs context but if lowering in rhs the base is lowered
in a special array base context which bypasses the mutability check.

Fixes #1237
2021-08-19 17:37:05 -04:00
João Capucho 4e181d6af4 [glsl-in] Only add builtins with double arguments if needed 2021-08-17 22:22:30 -04:00
João Capucho b05ca6e403 [glsl-in] Builtin redefinition and calls fixes 2021-08-17 22:22:30 -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
João Capucho e384bce771 [glsl-in] Don't clone HirExpr when lowering 2021-08-10 11:18:08 -04:00
João Capucho c73c1efe33 [glsl-in] Apply comments 2021-08-09 10:51:15 -04:00
João Capucho 1aaf77489b [glsl-in] Improve error api and make more errors deferred 2021-08-09 10:51:15 -04:00
João Capucho f6e35f5b66 [glsl-in] Improved preprocessor and error handling 2021-08-09 10:51:15 -04:00
João Capucho a8a316da15 [glsl-in] API revamp
The new api allows for reuse while keeping some allocations and to
please the borrow checker in future work, it also splits the parser into
logical modules to make it easier to work on.
2021-08-09 10:51:15 -04:00
João Capucho de6399a9c7 [glsl-in] Follow spec when choosing default layout 2021-08-04 12:39:36 -04:00
João Capucho 5ec129bbf0 [glsl-in] Lower the for loop init expression 2021-08-04 12:39:36 -04:00
João Capucho a90aa9817b [glsl-in] Add support for non constant global init
Glsl allows things such as

```glsl
layout (location = 0) in vec4 a;
vec4 b = a;
```

In this case `b` depends on `a` which can't be known at compile time,
so it's necessary to add a small prologue to the entry point to
initialize it.
2021-08-04 12:07:17 -04:00
João Capucho 057dc3100d [glsl-in] Remove support for multiple entry points 2021-08-04 11:06:57 -04:00
João Capucho bcfe1f6f28 [glsl-in] Parse some more memory qualifiers 2021-08-03 13:58:25 -04:00
João Capucho bd16bf90d0 [glsl-in] Unify depth_set and qualifiers 2021-08-03 13:11:31 -04:00
João Capucho 717063eb21 [glsl-in] Convert Sampled image to depth image 2021-08-03 13:11:31 -04:00
João Capucho 56ce439ff5 [glsl-in] Implement layouting for composite types 2021-07-31 23:25:22 -04:00
João Capucho e0e840b22c [glsl-in] Implement std140 and std430 layouts
Structs are not yet implemented
2021-07-31 23:25:22 -04:00
pyrotechnickandDzmitry Malyshau 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
João Capucho 6303af225f [glsl-in] Add implicit conversion for initializer 2021-07-27 20:16:05 -04:00
João Capucho e8bb7f2503 [glsl-in] Parse array initializers 2021-07-06 11:24:05 -04:00
João Capucho ee1004d443 [glsl-in] Use cast for implicit conversion
Previously this was a bitcast
2021-07-06 11:24:05 -04:00
Dzmitry Malyshau cfbe83e384 glsl-out: adjust coordinate space 2021-06-28 15:01:39 -04:00
Jasper St. Pierre dd791a26ae glsl: Replace todo!() with a NotImplemented error
So we can get a source location rather than a panic.
2021-06-27 21:54:21 +01:00
Jonathan Behrens 42f1f37741 [glsl-in] Deduplicate constants so array types match 2021-06-23 11:13:40 -04:00
João Capucho d3fe1c978b [glsl-in] Add support for precision qualifiers 2021-06-21 21:37:08 +01:00
João Capucho 4bc4c60663 [glsl-in] Implicit casts for function calls 2021-06-19 13:58:21 -04:00
Dzmitry Malyshau f0f8a5f3ba Fix GLSL frontend clippy error 2021-06-18 20:18:52 -04:00
João Capucho a1bd4a8053 [glsl-in] Allow structs as local type 2021-06-18 16:54:45 -04:00
Jakob Hellermann c2cfcbf84b [glsl-in] include information on what was expected in InvalidToken 2021-06-18 16:23:13 +01:00
Frizi 1d39a92c8b [glsl-in] parse structs inside parse_type 2021-06-17 15:21:47 -04:00
Frizi 25c0dd22cc [glsl-in] simplify parse_type identifier case 2021-06-17 15:21:47 -04:00
Frizi f85c896ddf [glsl-in] require at least one item inside struct_declaration_list 2021-06-17 15:21:47 -04:00
Frizi ad260062a0 [glsl-in] parse structs and resolve user-defined types 2021-06-17 15:21:47 -04:00
Frizi e6d142f28f [glsl-in] treat const globals as constants allow them in array size exprs 2021-06-17 15:21:47 -04:00
João Capucho a2ecd8ecff [glsl-in] Refractor global and blocks handling 2021-06-09 12:54:58 -04:00
João Capucho 2023b1a72c [glsl-in] Implicit convert initializers 2021-06-09 12:54:58 -04:00
João Capucho a9dad25b0f [glsl-in] Implement increment and decrement ops 2021-06-09 12:54:58 -04:00