Commit Graph

1845 Commits

Author SHA1 Message Date
Erich Gubler
b37dda8854
build: move to the Rust 2021 edition (#2085)
* build: move to the Rust 2021 edition

Since the MSRV of `naga` [is currently 1.56][msrv], I don't think there's a strong reason to stay
with the 2018 edition, and there _are_ a [few good reasons][edition-guide] to move to the 2021
edition.

I did this migration mostly automatically, per [official Rust guidelines]:

```sh
$ cargo fix --edition --all-targets
$ sed -i Cargo.toml 's/2018/2021'
$ cargo fix --edition-idioms --allow-dirty # doesn't change anything
```

The only manual edit needed to stymie a new warning introduced was the removal of the `TryFrom`
import in several modules, since it's now in the 2021 prelude.

[msrv]: a7193d652e/.github/workflows/pipeline.yml (L14)
[edition-guide]: https://doc.rust-lang.org/edition-guide/rust-2021/index.html
[official Rust guidelines]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html#edition-migration

* refactor(wgsl-in): use `pat` instead of `pat_param` again

How we were using `pat` in the Rust 2018 edition is actually the use case that
Rust 2021's `pat` fragment specifier is intended to satisfy. So, let's just use
that!
2022-10-25 08:44:17 -07:00
Erich Gubler
2a11d830bb
refactor: factor out new Validator::global_var_ty for expr. validation (#2086) 2022-10-25 08:38:44 -07:00
Raph Levien
ddcd5d3121
Fix incorrect atomic bounds check on metal back-end (#2099)
* Fix incorrect atomic bounds check on metal back-end

Generalize put_atomic_fetch to handle `exchange` as well, rather than special-cased code which didn't do the bounds check (the check handling as fixed in #1703 but only for the fetch cases, exchange was skipped).

Fixes #1848

* Add tests for atomic exchange
2022-10-24 09:20:57 -07:00
Connor Fitzgerald
d974f2f832 [hlsl-out] Properly implement bitcast 2022-10-20 11:00:21 -04:00
Connor Fitzgerald
2754a0136e [hlsl-out] Fix storage access chain through a matrix 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
Sludge
a7193d652e
Fix repository link pointing to the 0.9 branch (#2078) 2022-10-06 19:39:41 -04:00
Connor Fitzgerald
c52d91023d
Add changelog and bump version to 0.10 (#2077) 2022-10-05 17:04:49 -04:00
João Capucho
e07fd981c2
glsl-in: Update initializer list type when parsing (#2066)
Previously when parsing an initializer list, the type passed to
`parse_initializer` was not updated to reflect the child type, this
caused implicit conversions to not work and nested initializer lists to
not be allowed.
2022-10-05 11:17:25 -07:00
Igor Shaposhnik
0f26e5c808 [validate] Fix compiler warning 2022-10-04 15:21:36 +01:00
Max Ammann
abc4e1572a
Explicitely enable std, and don't rely on environment (#2062) 2022-09-17 12:39:34 -07:00
Jim Blandy
7e3750a7f2
[wgsl] Fix line endings on wgsl reserved words list. (#2059) 2022-09-17 00:52:00 +00:00
Jim Blandy
33392382ee
[wgsl-in] Break up long string, reformat rest of file. (#2057)
Whitespace and formatting changes only.

It turns out that if `cargo fmt` comes across a single line it can't
make fit within the margins, then it sort of gives up on the
surrounding construct. So breaking up the error message for
`Error::UnknownScalarType` in `Error::as_parse_error` and then
re-running `cargo fmt` cleans up lots of other stuff in the file.

cargo fmt issue:
https://github.com/rust-lang/rustfmt/issues/3863
2022-09-15 19:06:11 +00:00
Shaye Garg
5166c2a1d8
wgsl-in: Improve assignment diagnostics (#2056)
Fixes #2052.

* improved assignment statement errors

* hint immutable binding

* fix clippy

* add diagnostic tests

* cleanup formatting
2022-09-15 09:17:00 -07:00
SparkyPotato
4f8db997b0 remove trailing trivia 2022-09-14 23:16:24 -07:00
SparkyPotato
5d9cdd361f fix inclusion of trivia in spans 2022-09-14 23:16:24 -07:00
João Capucho
1a99c1cf06 wgsl-in: Fix bad span in assignment lhs error
The wgsl frontend was emiting errors for lhs expressions on assignments
that weren't references using a span that didn't skip blankspaces
causing the span to look weird (like starting at the end of the previous
line)

This is fixed by consuming the blankspace before constructing the span
2022-09-12 13:02:36 -07:00
João Capucho
ff69053bf2 valid: Check regular functions don't have bindings
Checks that all arguments and return types have no bindings in regular functions.
2022-09-10 10:31:11 -07: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
eb6124ec94 Document arithmetic binary operation type rules. 2022-09-10 17:12:35 +01:00
João Capucho
7d0e9847b0 Remove the glsl-validate feature
When it was introduced it was supposed to allow for fast compiles by
skipping glsl specific validation, but as it turns the subset of glsl that's
compilable code is already pretty close to the subset of valid glsl code.

So the current code gated behind glsl-validate amounts to a single branch that
isn't even performance sensitive, and most of the validation is not specific to
glsl and is made by naga's validator which can be turned off, so the original
goal of fast compile times by disabling validation can still be accomplished.
2022-09-05 19:37:39 -07:00
João Capucho
d9c9fe6218 glsl-in: Migrate to SymbolTable 2022-09-05 13:30:55 +01:00
João Capucho
544f14ad2f Add some methods to SymbolTable and implement Debug 2022-09-05 13:30:55 +01:00
Jim Blandy
13a0d28ddc wgsl-in: Rename Scope to Rule, since we now have lexical scope.
Rename related functions and variables appropriately.

Also, make `Rule` private to the WGSL front end, and remove the unused
`ImportDecl` variant.
2022-09-03 08:56:52 -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
João Capucho
66f5506e10 Add a frontend agnostic symbol table
Adds a new type `SymbolTable` to allow sharing code between the
frontends related to variable name lookup and lexical scope management,
this way improvements in variable lookup can be shared among all
frontends.
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
Jim Blandy
5be898e7e7 Use Option::as_deref as appropriate. 2022-09-01 10:46:28 -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
daxpedda
48e79388b5
Implement Clone for Module (#2013)
This is hidden behind the `clone` feature flag
2022-08-16 11:45:19 +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
João Capucho
6f4003ca9b
Fix clippy lints for 1.63 (#2026) 2022-08-15 21:53:14 -04: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
Christofer Nolander
cfbc91d6cf
add emit_to_{stderr,string} helpers for validation errors (#2012)
Mirrors those already found for parse errors.

Also removes the `StringErrorBuffer` writer in favor of the existing `NoColor` writer (from `codespan`) and added the emit_to_string_with_path method to complete the set.
2022-08-06 22:48:07 +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
Jeron Aldaron Lau
a0058217d6
Make termcolor dependency optional (#2014) 2022-07-23 00:46:28 -04:00
Ashley
cc985396da
Handle Unpack2x16float in hlsl (#2002) 2022-07-17 03:18:48 -04:00
ani
8f302a89ef
Update reserved WGSL keywords (#2009) 2022-07-17 00:40:05 -04:00
Ashley
17dcf39a1b
Rename hlsl input/output structs (#2001) 2022-07-06 14:27:54 -04:00
Connor Fitzgerald
350171ed2f
Prepare naga-cli 0.9 for release (#1999) 2022-07-02 04:00:51 +00:00
Connor Fitzgerald
06ae90527d
Release 0.9 (#1998)
* Release 0.9

* Further update changelog

* Apply suggestions from code review

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>

Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2022-06-30 19:51:46 +00: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
João Capucho
b746e0a420
spv-in: Fix incorrect translation of SMod (#1995)
Since spirv's SMod doesn't map to naga's IR modulo operator the
instruction is mapped into it's direct formula, this formula requires
some casts from int to float and back.

These casts were present but their `convert` field was left to `None`
which implied that they were bitcasts, causing some wildly incorrect
results.

This commit fixes it by setting the `convert` field to the same size as
the result type.
2022-06-30 11:34:42 -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
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