From c10b2bcb9aebc88938ede7e114e9b96ab55a0698 Mon Sep 17 00:00:00 2001 From: Alan Baker Date: Thu, 26 Nov 2026 13:06:29 -0500 Subject: [PATCH 1/3] Add zero-init cases for vars declared in a loop * Expand the zero-init tests for function address space variables to cover declaration within a loop --- src/webgpu/shader/execution/zero_init.spec.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/webgpu/shader/execution/zero_init.spec.ts b/src/webgpu/shader/execution/zero_init.spec.ts index fe6a3c2b5d63..23d068e7392c 100644 --- a/src/webgpu/shader/execution/zero_init.spec.ts +++ b/src/webgpu/shader/execution/zero_init.spec.ts @@ -77,6 +77,8 @@ g.test('compute,zero_init') } }) .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 +399,26 @@ g.test('compute,zero_init') } })('testVar', t.params._type); + let body = `${functionScope}\n${checkZeroCode}`; + if (t.params.loop !== 'none') { + switch (t.params.loop) { + case 'loop': + body = `var idx = 0;\nloop {\nif idx > 0 {\n${body}\n}\ncontinuing {\nidx++;\nbreak if idx > 1;\n}\n}\n`; + break; + case 'for': + body = `for (var idx = 0; idx < 4; idx++) {\nif idx == 2 {\n${body}\n}\n}\n`; + break; + case 'while': + body = `var idx = 0;\nwhile idx < 3 {\nif idx == 1 {\n${body}\n}\n}\n`; + break; + } + } + const wgsl = ` ${moduleScope} @compute @workgroup_size(${t.params.workgroupSize}) fn main() { - ${functionScope} - ${checkZeroCode} + ${body} _ = zero; } `; From 75b51f4825ff2deaf1dba31b7206f71c8834fe5a Mon Sep 17 00:00:00 2001 From: Alan Baker Date: Thu, 26 Nov 2026 13:13:33 -0500 Subject: [PATCH 2/3] formatting --- src/webgpu/shader/execution/zero_init.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webgpu/shader/execution/zero_init.spec.ts b/src/webgpu/shader/execution/zero_init.spec.ts index 23d068e7392c..6b7eb6bb809a 100644 --- a/src/webgpu/shader/execution/zero_init.spec.ts +++ b/src/webgpu/shader/execution/zero_init.spec.ts @@ -78,7 +78,9 @@ g.test('compute,zero_init') }) .beginSubcases() .combine('loop', ['none', 'loop', 'for', 'while'] as const) - .filter(t => { return t.loop === 'none' || t.addressSpace === 'function'; }) + .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) { From 08235da87e43bf72f24d5bf79e6e7859d7eccc9e Mon Sep 17 00:00:00 2001 From: Alan Baker Date: Thu, 26 Nov 2026 14:25:05 -0500 Subject: [PATCH 3/3] improve legibility --- src/webgpu/shader/execution/zero_init.spec.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/webgpu/shader/execution/zero_init.spec.ts b/src/webgpu/shader/execution/zero_init.spec.ts index 6b7eb6bb809a..f225dc852477 100644 --- a/src/webgpu/shader/execution/zero_init.spec.ts +++ b/src/webgpu/shader/execution/zero_init.spec.ts @@ -405,13 +405,35 @@ g.test('compute,zero_init') if (t.params.loop !== 'none') { switch (t.params.loop) { case 'loop': - body = `var idx = 0;\nloop {\nif idx > 0 {\n${body}\n}\ncontinuing {\nidx++;\nbreak if idx > 1;\n}\n}\n`; + 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++) {\nif idx == 2 {\n${body}\n}\n}\n`; + body = ` +for (var idx = 0; idx < 4; idx++) { + if idx == 2 { + ${body} + } +}`; break; case 'while': - body = `var idx = 0;\nwhile idx < 3 {\nif idx == 1 {\n${body}\n}\n}\n`; + body = ` +var idx = 0; +while idx < 3 { + if idx == 1 { + ${body} + } + idx++; +}`; break; } }