Commit Graph

2054 Commits

Author SHA1 Message Date
Teodor Tanasoaia
5b79cca384
bump MSRV to 1.63 (#2129) 2022-11-18 16:29:49 +00:00
Erich Gubler
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
Teodor Tanasoaia
e056805784
[msl-out] use back::COMPONENTS (#2124) 2022-11-16 11:12:45 -08:00
Erich Gubler
1650581fe7
refactor(cli): simplify output_paths w/ <&[T]>::get and Option::unwrap (#2114) 2022-11-04 16:20:47 +01:00
Teodor Tanasoaia
01fbdea21f
fix 1.65 clippy lints (#2112) 2022-11-03 18:32:20 +01:00
Erich Gubler
21c7092762
Satisfy latest clippy lints (up to Rust 1.64) (#2081)
* refactor: satisfy `clippy::borrow_deref_ref`

* chore: satisfy `clippy::ptr_arg`

* refactor: satisfy `clippy::needless_update`

* chore: `allow(clippy::too_many_arguments)` on `write_output_glsl` test

Since this is test code, I don't think there's a strong impetus to refactor types to consolidate
or otherwise alter arguments here. Let's just `allow` this.

* refactor: satisfy `clippy::single_match`

I think it's sixes whether to keep this code as-is or to `allow(...)` as-is. 🤷🏻‍♂️

* refactor: satisfy `clippy::single_char_pattern`

* refactor: satisfy `clippy::reversed_empty_ranges`

The lint fires because it generally doesn't make sense to use a `Range` built this way; [upstream
`Range` docs]) states:

> It is empty if `start >= end`.

`clippy` wants to help us from naively iterating over a `Range` like this! Thanks, `clippy`!
However, we're not actually using the offending `addresses` variables for iteration. We're using
them as a flat data structure with fields that happen to conceptually match. We can, therefore,
sidestep this lint by "just" inlining into separate variables for start and end instead.

[upstream `Range` docs]: https://doc.rust-lang.org/stable/std/ops/struct.Range.html

* refactor: satisfy `clippy::pattern_type_mismatch`

* chore: `allow(clippy::panic)` for `test`

We definitely should let `panic!(...)` calls exist in `cfg(test)`! It's a very standard way to fail
`#[test]` functions. It seems that previous test authors agree! 😅

* fixup! refactor: satisfy `clippy::pattern_type_mismatch`

* fixup! refactor: satisfy `clippy::single_match`
2022-11-03 09:32:15 -07:00
Xiaopeng Li
e7fc8e64f2
Fix textureGather compatibility on macOS 10.13 (#2104)
* Fix textureGather compatibility on macOS 10.13

* Fix tests

* Update src/back/msl/writer.rs

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

Co-authored-by: Jet Spark <lixiaopeng.jetspark@bytedance.com>
Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com>
2022-10-27 09:28:46 +02:00
Erich Gubler
df4e40327c refactor(wgsl-out): use for loop for function arg. writing 2022-10-26 16:31:48 -04:00
Erich Gubler
469272c613 refactor(valid): s/error/source member name for ValidationError 2022-10-26 16:31:48 -04:00
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