mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 00:41:07 +01:00
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>
44 lines
911 B
WebGPU Shading Language
44 lines
911 B
WebGPU Shading Language
struct PrimeIndices {
|
|
data: array<u32>,
|
|
}
|
|
|
|
@group(0) @binding(0)
|
|
var<storage, read_write> v_indices: PrimeIndices;
|
|
|
|
fn collatz_iterations(n_base: u32) -> u32 {
|
|
var n: u32;
|
|
var i: u32;
|
|
|
|
n = n_base;
|
|
i = 0u;
|
|
loop {
|
|
let _e4 = n;
|
|
if (_e4 > 1u) {
|
|
} else {
|
|
break;
|
|
}
|
|
{
|
|
let _e7 = n;
|
|
if ((_e7 % 2u) == 0u) {
|
|
let _e12 = n;
|
|
n = (_e12 / 2u);
|
|
} else {
|
|
let _e16 = n;
|
|
n = ((3u * _e16) + 1u);
|
|
}
|
|
let _e20 = i;
|
|
i = (_e20 + 1u);
|
|
}
|
|
}
|
|
let _e23 = i;
|
|
return _e23;
|
|
}
|
|
|
|
@compute @workgroup_size(1, 1, 1)
|
|
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
let _e9 = v_indices.data[global_id.x];
|
|
let _e10 = collatz_iterations(_e9);
|
|
v_indices.data[global_id.x] = _e10;
|
|
return;
|
|
}
|