This is for the same reason that we ignore `dead_code`:
// A lot of the code can be unused based on configuration flags,
// the corresponding warnings aren't helpful.
When lowering `Select` expressions the position could be wrongfully
updated from `AccessBase { constant_index: false }` to
`AccessBase { constant_index: true }` this caused dynamic indexing
in an array behind a structure to fail if it was stored in a constant.
Furthermore the position could also be updated from `Rhs` to
`AccessBase`, this could cause issues because `AccessBase` doesn't
load variables (which `Rhs` does), so accessing a member from a
structure behind a pointer would return the wrong result.
* 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>
* 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`
* 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
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.
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.
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.
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.
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.
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
* 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
* [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
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.
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.
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.
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.
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.
* 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>
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.
* [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
* hlsl-out: don't output interpolation modifier if it's the default (linear/`Interpolation::Perspective`)
* Remove linear interpolation modifiers from HLSL output tests
* 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
- samplerCubeShadow requires vec3 gradients
- Bias must be written after offset
- sampler1D hack on GLES requires vec2 gradients
- textureSize doesn't accept a lod argument for MS samplers
- sampler1DArray hack on GLES requires a y component on imageLoad
This one grew out of hand quick. Initially it was just replacing the bit
loops with a function driving the declarations to make the code sharing
better and support different scalar kinds.
Now it includes a lot of fixes:
- `textureSize` now also returns the array layers as the last component
on the return (only for arrayed textures)
- `textureSize` now supports multisampled textures
- the `texture` family of functions now consumes a `vec3` coordinate
vector for all 1D shadow textures
- Shadow textures can use the bias version of `texture` functions
(temporarily disabled since naga doesn't support it)
- 3D textures can be used in `textureProj`
- `sampler2DArrayShadow` can't be used in `textureLod` or in `texture` with bias
- Cube textures cannot be used with offsets
Updates the tests to cover all functions
The _buffer_sizes argument should be inserted regardless of whether or not `
`options.fake_missing_bindings` is set, so lift the computation of
`supports_array_length` out of that conditional.
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.
* Allow vecN<i32> and vecN<u32> in `dot()`, first changes
* Added a test case
* Fix the test
* Changes to baking of expressions, incl args of integer dot product
* Implemented requested changes for glsl backend
* Added support for integer dot product on MSL backend
* Removed outdated code for hlsl and wgls writers
* Implement in spv backend
* Commit modified outputs from running the tests
* cargo fmt
* Applied requested changes for both MSL and GLSL back
* Changes to spv back
* Committed all test output changes
* Cargo fmt
* Added a comment w.r.t. VK_KHR_shader_integer_dot_product
* Implemented requested svp change
* Minor change to test case
This is because I wanted to highlight the fact that the correct
id is used in the last sum of the integer dot product expression
* Changed function signature
since it could not fail, changed it to simply return `void`
* Rewrite front/back doc summaries
- Use line comments instead of block comments
- Standardize language for each front/backend
- Add reference link for each format
- Minor punctuation changes
* Add documentation for keywords module
* Clarify contents of keywords module in summary
* Refer to modules by their type name
* Add basic summary for valid module
* Adjust EarlyDepthTest and ConservativeDepth docs
* Remove "in" from list
* Adjust wording
* Standardize format of docstrings
* Adjust module links to be consistent with other links
* Add summary for reserved keywords list
* Remove extraneous doc spaces with `cargo fmt`
* Correct spelling of whether and rewrite some lines
* Fill out GLSL backend docs
* Remove unnecessary link targets
* Fill out DOT backend docs
* Change module line comments to block comments
* Remove unnecessary spaces
* Fix mistake during rebasing
* WGSL storage address space should always correspond to MSL device address space.
See MSL spec section 4.2.
* Update baselines
* Add error for storage address space if MSL version < 2.
* Update default MSL version to 2.0.