Commit Graph
146 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 b586631efe Small cleanups to backend naming. (#2491)
Document `FunctionType` better.

Use `FunctionCtx` name key methods where appropriate in the WGSL and
HLSL backends.
2023-09-20 19:20:47 +02:00
Fredrik Fornwall 5329aa2bd5 [wgsl-in] Handle modf and frexp (#2454) 2023-09-02 08:55:35 +02:00
Frederik Magnus Johansen Vestreandteoxoy 0491d39232 Support dual source blending (#2427)
Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2023-08-30 21:00:35 +02:00
teoxoy d348d843e1 implement const-expressions (phase 1) 2023-07-17 16:26:08 -07:00
Elabajaba adf1cca68d Implement Pack/Unpack for HLSL (#2353) 2023-06-23 15:52:22 +02:00
teoxoy 08105461ce omit non referenced expressions 2023-06-12 17:49:06 -07:00
teoxoy 763ec5d1a5 complete HLSL reserved symbols 2023-06-12 17:41:53 -07:00
Pieter-Jan Briers 544ccf88da Handle case insensitive FXC HLSL keywords. (#2347)
There are a few keywords like "pass" in HLSL that are actually case-insensitive for FXC. This can be disabled with strict mode, but even if you do that FXC will continue to give an error if you try to use them in identifiers (at all, with any casing).

This changes the namer code to escape these keywords even if the casing is different.

If you're wondering where I got the list from: I looked at the list of strings in D3DCompiler_47.dll.
2023-05-31 15:00:23 +02:00
Daniel McNab 907b7c7cda Workgroup uniform load (#2201)
Implement the WGSL `workgroupUniformLoad` function.
2023-05-26 13:32:22 -07:00
Teodor Tanasoaia 62b287e761 Change type of constant sized arrays to NonZeroU32 (#2337) 2023-05-12 14:38:50 +02:00
teoxoy d842d6688d Introduce GlobalCtx 2023-05-11 09:52:40 -07:00
Jim Blandy 02ddf6532c Introduce Expression::Literal. 2023-05-11 07:09:53 -07:00
Teodor Tanasoaia dcc8615c5b Introduce Expression::ZeroValue. 2023-05-10 19:30:03 -07:00
Evan Mark Hopkins 9befaed7e9 [hlsl-out] Fix return type for firstbitlow/high (#2315) 2023-04-25 14:49:26 +02:00
Erich Gubler 99a7773e65 fix(hlsl-out): use Interlocked<op> intrinsic for atomic integers (#2294)
We currently assume that we are using raw `RWByteAddressBuffer` methods for all atomic operations (`<pointer>.Interlocked<op>(<raw_byte_offset>, …)`), which is only true when we use `var<storage, read_write>` globals. For `var<workgroup>` globals, we need `Interlocked<op>(<pointer>, …)`, using the original expression as the first argument.

Fix this by branching on the `pointer`'s address space in `Atomic` statements, and implementing the workgroup address space case with intrinsics.

Remove atomic ops from `access`, add new `atomicOps` test.

Fixes #2284
2023-04-05 19:37:22 -07:00
Dzmitry Malyshau b856625821 Ray query expressions and special types 2023-03-22 17:23:07 -07:00
Dzmitry Malyshau e46c53d212 Add ray query statements to the IR 2023-03-22 17:23:07 -07:00
Evan Mark HopkinsandTeodor Tanasoaia 6db8da72ca Add partial derivative builtins (#2277)
* Add partial derivative builtins

* [dot] emit derivative control

* Fix fmt

---------

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2023-03-17 00:15:44 +01:00
teoxoy 6b0c2a532a enable clippy::match_wildcard_for_single_variants lint 2023-03-16 15:51:59 +01:00
Evan Mark Hopkins 8a72b7a8ad Differentiate between i32 and u32 in switch (#2269)
* Differentiate between i32 and u32 in switch

* Use similar wording to other error messages

* Remove duplicate enum
2023-03-10 17:53:11 +01:00
Teodor Tanasoaia 9742f1616c fix zero initialization of workgroup memory (#2259)
Use the local (not global) invocation id to decide which invocation should do the initialization, so that every workgroup gets initialized, not just the first.
2023-02-20 19:56:24 -08:00
Mauro GentileandTeodor Tanasoaia 810e9d26fc Add countTrailingZeros (#2243)
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2023-02-20 20:40:59 +01:00
Leah 58105a06e2 [glsl/hlsl-out] Write sizes of arrays behind pointers in function arguments (#2250)
arrays can be put behind pointers in inout and out parameters in GLSL and HLSL,
whose dimensions must be specified to let array access
compile. so, we specify their dimensions.

fixes #2248
2023-02-17 00:40:21 +00:00
Evan Mark Hopkinsandteoxoy 6be394dac3 Add countLeadingZeros (#2226)
* Add countLeadingZeros

* [glsl-out] Bake countLeadingZeros

* [hlsl-out] Bake countLeadingZeros

* [hlsl-out] Update Baked expressions

* Remove unnecessary bake for sints

* [glsl-out] CountLeadingZeros without findMSB

* Don't check negatives when uint

* Perform the type conv after mix

* use log2

* fix clippy lints

---------

Co-authored-by: teoxoy <28601907+teoxoy@users.noreply.github.com>
2023-01-31 21:31:05 +01:00
teoxoy a2b39e45bf [hlsl-out] clear named_expressions inserted by duplicated blocks
changed the type of `named_expressions` from `HashMap` to `IndexMap` so that insertion order is preserved
2023-01-31 10:43:02 -08:00
Jim Blandy ca99d8bcbc Inline identifiers into format strings.
[Since Rust 1.58], Rust format strings have been able to "capture
arguments simply by writing {ident} in the string." Clippy 1.67 made
the corresponding warning, `uninlined_format_args`, warn-by-default.
Inlined arguments seem more readable, so Naga should adopt them.

[Since Rust 1.58]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1580-2022-01-13
2023-01-31 11:27:51 +01:00
teoxoy c7d02151f0 add support for zero-initializing workgroup memory 2023-01-25 18:07:48 +01:00
teoxoy a42857d291 [hlsl-out] simplify write_default_init 2023-01-25 18:07:48 +01:00
teoxoy e5121ca012 factor out write_barrier functions 2023-01-25 18:07:48 +01:00
Erich Gubler 461fdda425 Add handle validation pass to Validator (#2090)
Before proceeding with any other validation, check that all Handles are valid for their arenas, and refer only to older handles than themselves. This allows subsequent stages to simply use indexing without panics, assuming validation has passed.
2022-12-17 00:26:43 +00:00
teoxoy 5a1f43d12d [doc] add more switch docs 2022-12-09 10:21:58 -08:00
teoxoy 3455147496 [hlsl-out] omit extra switch case blocks where possible 2022-12-09 10:21:58 -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
Connor Fitzgerald d974f2f832 [hlsl-out] Properly implement bitcast 2022-10-20 11:00:21 -04:00
Connor Fitzgerald 20d5445cb7 Workaround FXC Bug in Matrix Indexing (#2096) 2022-10-20 01:37:35 -04: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
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
Ashley cc985396da Handle Unpack2x16float in hlsl (#2002) 2022-07-17 03:18:48 -04:00
Ashley 17dcf39a1b Rename hlsl input/output structs (#2001) 2022-07-06 14:27:54 -04: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
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
teoxoy 91ee407c87 [hlsl-out] fix fallthrough in switch statements 2022-05-30 13:11:56 -07:00
Hasan Ali 571302e3ff [hlsl-out] Fix countOneBits and reverseBits for signed integers 2022-05-17 00:12:18 +02:00
teoxoy afb6504b8b add support for identity matrix constructor 2022-05-12 22:15:45 -07:00
teoxoy ceb92921c2 remove named expression entry for phony assignment 2022-05-10 10:43:25 +02:00
teoxoy 66337af310 add TODOs for handling undefined behavior 2022-05-09 20:48:09 -07:00
teoxoy c584331f39 [hlsl-out] use fmod instead of % 2022-05-09 20:48:09 -07:00
Connor Fitzgerald ad28396851 Implement Binding Arrays (#1845) 2022-04-19 14:23:07 -04:00