From 6696b0e2df59ae2bb5a29a7b1dbb50e4109b6b55 Mon Sep 17 00:00:00 2001 From: jzm-intel Date: Tue, 17 Oct 2023 11:19:42 +0800 Subject: [PATCH] wgsl: make expectation id strat from 1 in flow_control exec tests (#3068) This PR make expectation id start from 1 instead of 0 to be distinguishable from initializaed 0 value. And also improve the generated WGSL shader's readability by adding expectation details in comments next to push_output. Issue: #2312 --- .../shader/execution/flow_control/harness.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/webgpu/shader/execution/flow_control/harness.ts b/src/webgpu/shader/execution/flow_control/harness.ts index 90eab383fb35..8de19fda8e8a 100644 --- a/src/webgpu/shader/execution/flow_control/harness.ts +++ b/src/webgpu/shader/execution/flow_control/harness.ts @@ -119,14 +119,16 @@ export function runFlowControlTest( values: expected, counter: 0, }); - return `push_output(${expectations.length - 1});`; + // Expectation id starts from 1 to distinguish from initialization 0. + return `push_output(${expectations.length}); // expect_order(${expected.join(', ')})`; }, expect_not_reached: () => { expectations.push({ kind: 'not-reached', stack: Error().stack, }); - return `push_output(${expectations.length - 1});`; + // Expectation id starts from 1 to distinguish from initialization 0. + return `push_output(${expectations.length}); // expect_not_reached()`; }, }); @@ -247,7 +249,14 @@ ${main_wgsl.extra} // Each of the outputted values represents an event // Check that each event is as expected for (let event = 0; event < outputCount; event++) { - const expectationIndex = outputs.data[1 + event]; // 0 is count + const eventValue = outputs.data[1 + event]; // outputs.data[0] is count + // Expectation id starts from 1, and 0 is invalid value. + if (eventValue === 0) { + return fail( + `outputs.data[${event}] is initial value 0, doesn't refer to any valid expectations)\n${print_output_value()}` + ); + } + const expectationIndex = eventValue - 1; if (expectationIndex >= expectations.length) { return fail( `outputs.data[${event}] value (${expectationIndex}) exceeds number of expectations (${