[naga] Correct override resolution in array lengths.

When the user provides values for a module's overrides, rather than
replacing override-sized array types with ordinary array types (which
could require adjusting type handles throughout the module), instead
edit all overrides to have initializers that are fully-evaluated
constant expressions. Then, change all backends to handle
override-sized arrays by retrieving their overrides' values.

For arrays whose sizes are override expressions, not simple references
to a specific override's value, let front ends built array types that
refer to anonymous overrides whose initializers are the necessary
expression.

This means that all arrays whose sizes are override expressions are
references to some `Override`. Remove `naga::PendingArraySize`, and
let `ArraySize::Pending` hold a `Handle<Override>` in all cases.

Expand `tests/gpu-tests/shader/array_size_overrides.rs` to include the
test case that motivated this approach.
This commit is contained in:
Kent Slaney authored and Jim Blandy committed 2025-03-06 14:21:40 -08:00
1 parent 4e14f2032e
commit 2fac7fa954
25 files changed
+353 -260

No files matched your search

+17 -1
View File
@@ -4,13 +4,29 @@ use wgpu::{BufferDescriptor, BufferUsages, MapMode, PollType};
use wgpu_test::{fail_if, gpu_test, GpuTestConfiguration, TestParameters, TestingContext};
const SHADER: &str = r#"
override n = 8;
const testing_shared: array<i32, 1> = array(8);
override n = testing_shared[0u];
override m = testing_shared[0u];
var<workgroup> arr: array<u32, n - 2>;
@group(0) @binding(0)
var<storage, read_write> output: array<u32>;
// When `n` is overridden to 14 above, it will generate the type `array<u32, 14 - 2>` which
// already exists in the program because of variable declaration. Ensures naga does not panic
// when this happens.
//
// See https://github.com/gfx-rs/wgpu/issues/6722 for more info.
var<workgroup> testing0: array<u32, 12>;
// Tests whether two overrides that are initialized by the same expression
// crashes the unique types arena
//
// See https://github.com/gfx-rs/wgpu/pull/6787#pullrequestreview-2576905294
var<workgroup> testing1: array<u32, n>;
var<workgroup> testing2: array<u32, m>;
@compute @workgroup_size(1) fn main() {
// 1d spiral
for (var i = 0; i < n - 2; i++) {