summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/flow_control/while.spec.ts
blob: 88ce6838a5cf80ae4e8541c0175b2f0810f7c1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
export const description = `
Flow control tests for while-loops.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { GPUTest } from '../../../gpu_test.js';

import { runFlowControlTest } from './harness.js';

export const g = makeTestGroup(GPUTest);

g.test('while_basic')
  .desc('Test that flow control executes a while-loop body the correct number of times')
  .params(u => u.combine('preventValueOptimizations', [true, false]))
  .fn(t => {
    runFlowControlTest(
      t,
      f =>
        `
  ${f.expect_order(0)}
  var i = ${f.value(0)};
  while (i < ${f.value(5)}) {
    ${f.expect_order(1, 2, 3, 4, 5)}
    i++;
  }
  ${f.expect_order(6)}
`
    );
  });

g.test('while_break')
  .desc('Test that flow control exits a while-loop when reaching a break statement')
  .params(u => u.combine('preventValueOptimizations', [true, false]))
  .fn(t => {
    runFlowControlTest(
      t,
      f =>
        `
  ${f.expect_order(0)}
  var i = ${f.value(0)};
  while (i < ${f.value(5)}) {
    ${f.expect_order(1, 3, 5, 7)}
    if (i == 3) {
      break;
      ${f.expect_not_reached()}
    }
    ${f.expect_order(2, 4, 6)}
    i++;
  }
  ${f.expect_order(8)}
`
    );
  });

g.test('while_continue')
  .desc('Test flow control for a while-loop continue statement')
  .params(u => u.combine('preventValueOptimizations', [true, false]))
  .fn(t => {
    runFlowControlTest(
      t,
      f =>
        `
  ${f.expect_order(0)}
  var i = ${f.value(0)};
  while (i < ${f.value(5)}) {
    ${f.expect_order(1, 3, 5, 7, 8)}
    if (i == 3) {
      i++;
      continue;
      ${f.expect_not_reached()}
    }
    ${f.expect_order(2, 4, 6, 9)}
    i++;
  }
  ${f.expect_order(10)}
`
    );
  });

g.test('while_nested_break')
  .desc('Test that flow control exits a nested while-loop when reaching a break statement')
  .params(u => u.combine('preventValueOptimizations', [true, false]))
  .fn(t => {
    runFlowControlTest(
      t,
      f =>
        `
  ${f.expect_order(0)}
  var i = ${f.value(0)};
  while (i < ${f.value(3)}) {
    ${f.expect_order(1, 5, 11)}
    i++;
    var j = ${f.value(0)};
    while (j < i) {
      ${f.expect_order(2, 6, 8, 12)}
      j++;
      if ((i+j) & 2) == 0 {
        ${f.expect_order(9, 13)}
        break;
        ${f.expect_not_reached()}
      }
      ${f.expect_order(3, 7)}
    }
    ${f.expect_order(4, 10, 14)}
  }
  ${f.expect_order(15)}
`
    );
  });

g.test('while_nested_continue')
  .desc('Test flow control for a nested while-loop with a continue statement')
  .params(u => u.combine('preventValueOptimizations', [true, false]))
  .fn(t => {
    runFlowControlTest(
      t,
      f =>
        `
  ${f.expect_order(0)}
  var i = ${f.value(0)};
  while (i < ${f.value(3)}) {
    ${f.expect_order(1, 5, 11)}
    i++;
    var j = ${f.value(0)};
    while (j < i) {
      ${f.expect_order(2, 6, 8, 12, 14, 16)}
      j++;
      if ((i+j) & 2) == 0 {
        ${f.expect_order(9, 13, 15)}
        continue;
        ${f.expect_not_reached()}
      }
      ${f.expect_order(3, 7, 17)}
    }
    ${f.expect_order(4, 10, 18)}
  }
  ${f.expect_order(19)}
`
    );
  });