Skip to content

Commit

Permalink
wgsl: make expectation id strat from 1 in flow_control exec tests (#3068
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
jiangzhaoming authored Oct 17, 2023
1 parent b3cefa6 commit 6696b0e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/webgpu/shader/execution/flow_control/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()`;
},
});

Expand Down Expand Up @@ -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 (${
Expand Down

0 comments on commit 6696b0e

Please sign in to comment.