mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-12-03 04:03:32 +00:00
6035b07b78
Fixes #1745: Support out-of-order module scope declarations in WGSL Fixes #1044: Forbid local variable shadowing in WGSL Fixes #2076: [wgsl-in] no error for duplicated type definition Fixes #2071: Global item does not support 'const' Fixes #2105: [wgsl-in] Type aliases for a vecN<T> doesn't work when constructing vec from a single argument Fixes #1775: Referencing a function without a return type yields an unknown identifier error. Fixes #2089: Error span reported on the declaration of a variable instead of its use Fixes #1996: [wgsl-in] Confusing error: "expected unsigned/signed integer literal, found '1'" Separate parsing from lowering by generating an AST, which desugars as much as possible down to something like Naga IR. The AST is then used to resolve identifiers while lowering to Naga IR. Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com> Co-authored-by: Jim Blandy <jimb@red-bean.com>
79 lines
1.8 KiB
WebGPU Shading Language
79 lines
1.8 KiB
WebGPU Shading Language
// Global variable & constant declarations
|
|
|
|
const Foo: bool = true;
|
|
|
|
var<workgroup> wg : array<f32, 10u>;
|
|
var<workgroup> at: atomic<u32>;
|
|
|
|
struct FooStruct {
|
|
v3: vec3<f32>,
|
|
// test packed vec3
|
|
v1: f32,
|
|
}
|
|
@group(0) @binding(1)
|
|
var<storage, read_write> alignment: FooStruct;
|
|
|
|
@group(0) @binding(2)
|
|
var<storage> dummy: array<vec2<f32>>;
|
|
|
|
@group(0) @binding(3)
|
|
var<uniform> float_vecs: array<vec4<f32>, 20>;
|
|
|
|
@group(0) @binding(4)
|
|
var<uniform> global_vec: vec3<f32>;
|
|
|
|
@group(0) @binding(5)
|
|
var<uniform> global_mat: mat3x2<f32>;
|
|
|
|
@group(0) @binding(6)
|
|
var<uniform> global_nested_arrays_of_matrices_2x4: array<array<mat2x4<f32>, 2>, 2>;
|
|
|
|
@group(0) @binding(7)
|
|
var<uniform> global_nested_arrays_of_matrices_4x2: array<array<mat4x2<f32>, 2>, 2>;
|
|
|
|
fn test_msl_packed_vec3_as_arg(arg: vec3<f32>) {}
|
|
|
|
fn test_msl_packed_vec3() {
|
|
// stores
|
|
alignment.v3 = vec3<f32>(1.0);
|
|
var idx = 1;
|
|
alignment.v3.x = 1.0;
|
|
alignment.v3[0] = 2.0;
|
|
alignment.v3[idx] = 3.0;
|
|
|
|
// force load to happen here
|
|
let data = alignment;
|
|
|
|
// loads
|
|
_ = data.v3;
|
|
_ = data.v3.zx;
|
|
test_msl_packed_vec3_as_arg(data.v3);
|
|
|
|
// matrix vector multiplication
|
|
_ = data.v3 * mat3x3<f32>();
|
|
_ = mat3x3<f32>() * data.v3;
|
|
|
|
// scalar vector multiplication
|
|
_ = data.v3 * 2.0;
|
|
_ = 2.0 * data.v3;
|
|
}
|
|
|
|
@compute @workgroup_size(1)
|
|
fn main() {
|
|
test_msl_packed_vec3();
|
|
|
|
wg[7] = (global_nested_arrays_of_matrices_4x2[0][0] * global_nested_arrays_of_matrices_2x4[0][0][0]).x;
|
|
wg[6] = (global_mat * global_vec).x;
|
|
wg[5] = dummy[1].y;
|
|
wg[4] = float_vecs[0].w;
|
|
wg[3] = alignment.v1;
|
|
wg[2] = alignment.v3.x;
|
|
alignment.v1 = 4.0;
|
|
wg[1] = f32(arrayLength(&dummy));
|
|
atomicStore(&at, 2u);
|
|
|
|
// Valid, Foo and at is in function scope
|
|
var Foo: f32 = 1.0;
|
|
var at: bool = true;
|
|
}
|