Add zero-init cases for vars declared in a loop (#4740) * Expand the zero-init tests for function address space variables to cover declaration within a loop
diff --git a/src/webgpu/shader/execution/zero_init.spec.ts b/src/webgpu/shader/execution/zero_init.spec.ts index fe6a3c2..f225dc8 100644 --- a/src/webgpu/shader/execution/zero_init.spec.ts +++ b/src/webgpu/shader/execution/zero_init.spec.ts
@@ -77,6 +77,10 @@ } }) .beginSubcases() + .combine('loop', ['none', 'loop', 'for', 'while'] as const) + .filter(t => { + return t.loop === 'none' || t.addressSpace === 'function'; + }) // Fewer subcases: Only 0 and 2. If double-nested containers work, single-nested should too. .combine('_containerDepth', [0, 2]) .expandWithParams(function* (p) { @@ -397,12 +401,48 @@ } })('testVar', t.params._type); + let body = `${functionScope}\n${checkZeroCode}`; + if (t.params.loop !== 'none') { + switch (t.params.loop) { + case 'loop': + body = ` +var idx = 0; +loop { + if idx > 0 { + ${body} + } + continuing { + idx++; + break if idx > 1; + } +}`; + break; + case 'for': + body = ` +for (var idx = 0; idx < 4; idx++) { + if idx == 2 { + ${body} + } +}`; + break; + case 'while': + body = ` +var idx = 0; +while idx < 3 { + if idx == 1 { + ${body} + } + idx++; +}`; + break; + } + } + const wgsl = ` ${moduleScope} @compute @workgroup_size(${t.params.workgroupSize}) fn main() { - ${functionScope} - ${checkZeroCode} + ${body} _ = zero; } `;