mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 22:11:01 +01:00
Instead allow the const to be converted each time it is const evaluated as part of another expression. This allows an abstract const to be used as a different type depending on the context. As a result, abstract types may now find their way in to the IR, which we don't want. This occurs because the compact pass treats named expressions as used, mostly so that our snapshot tests are more useful, and therefore does not remove them. To prevent this, we avoid adding abstract-typed local consts to the named expressions list. This will have no functional effect on any shaders produced by the backends, but some unused local const declarations will no longer be present.
21 lines
511 B
WebGPU Shading Language
21 lines
511 B
WebGPU Shading Language
// Sourced from https://www.w3.org/TR/WGSL/#const-assert-statement
|
|
const x = 1;
|
|
const y = 2;
|
|
const_assert x < y; // valid at module-scope.
|
|
const_assert(y != 0); // parentheses are optional.
|
|
|
|
// Ensure abstract-typed consts can be compared to different concrete types
|
|
const_assert x == 1i;
|
|
const_assert x > 0u;
|
|
const_assert x < 2.0f;
|
|
|
|
fn foo() {
|
|
const z = x + y - 2;
|
|
const_assert z > 0; // valid in functions.
|
|
const_assert(z > 0);
|
|
|
|
const_assert z == 1i;
|
|
const_assert z > 0u;
|
|
const_assert z < 2.0f;
|
|
}
|