summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/encoding/beginComputePass.spec.ts
blob: 0b69ba6a91965d7fd2296ab67c10338a273e8232 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
export const description = `
Tests for validation in beginComputePass and GPUComputePassDescriptor as its optional descriptor.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kQueryTypes } from '../../../capability_info.js';
import { ValidationTest } from '../validation_test.js';

class F extends ValidationTest {
  tryComputePass(success: boolean, descriptor: GPUComputePassDescriptor): void {
    const encoder = this.device.createCommandEncoder();
    const computePass = encoder.beginComputePass(descriptor);
    computePass.end();

    this.expectValidationError(() => {
      encoder.finish();
    }, !success);
  }
}

export const g = makeTestGroup(F);

g.test('timestampWrites,same_location')
  .desc(
    `
  Test that entries in timestampWrites do not have the same location in GPUComputePassDescriptor.
  `
  )
  .params(u =>
    u //
      .combine('locationA', ['beginning', 'end'] as const)
      .combine('locationB', ['beginning', 'end'] as const)
  )
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase(['timestamp-query']);
  })
  .fn(async t => {
    const { locationA, locationB } = t.params;

    const querySet = t.device.createQuerySet({
      type: 'timestamp',
      count: 2,
    });

    const timestampWriteA = {
      querySet,
      queryIndex: 0,
      location: locationA,
    };

    const timestampWriteB = {
      querySet,
      queryIndex: 1,
      location: locationB,
    };

    const isValid = locationA !== locationB;

    const descriptor = {
      timestampWrites: [timestampWriteA, timestampWriteB],
    };

    t.tryComputePass(isValid, descriptor);
  });

g.test('timestampWrites,query_set_type')
  .desc(
    `
  Test that all entries of the timestampWrites must have type 'timestamp'. If all query types are
  not 'timestamp' in GPUComputePassDescriptor, a validation error should be generated.
  `
  )
  .params(u =>
    u //
      .combine('queryTypeA', kQueryTypes)
      .combine('queryTypeB', kQueryTypes)
  )
  .beforeAllSubcases(t => {
    t.selectDeviceForQueryTypeOrSkipTestCase([
      'timestamp',
      t.params.queryTypeA,
      t.params.queryTypeB,
    ]);
  })
  .fn(async t => {
    const { queryTypeA, queryTypeB } = t.params;

    const timestampWriteA = {
      querySet: t.device.createQuerySet({ type: queryTypeA, count: 1 }),
      queryIndex: 0,
      location: 'beginning' as const,
    };

    const timestampWriteB = {
      querySet: t.device.createQuerySet({ type: queryTypeB, count: 1 }),
      queryIndex: 0,
      location: 'end' as const,
    };

    const isValid = queryTypeA === 'timestamp' && queryTypeB === 'timestamp';

    const descriptor = {
      timestampWrites: [timestampWriteA, timestampWriteB],
    };

    t.tryComputePass(isValid, descriptor);
  });

g.test('timestampWrites,invalid_query_set')
  .desc(`Tests that timestampWrite that has an invalid query set generates a validation error.`)
  .params(u => u.combine('querySetState', ['valid', 'invalid'] as const))
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase(['timestamp-query']);
  })
  .fn(async t => {
    const { querySetState } = t.params;

    const querySet = t.createQuerySetWithState(querySetState, {
      type: 'timestamp',
      count: 1,
    });

    const timestampWrite = {
      querySet,
      queryIndex: 0,
      location: 'beginning' as const,
    };

    const descriptor = {
      timestampWrites: [timestampWrite],
    };

    t.tryComputePass(querySetState === 'valid', descriptor);
  });

g.test('timestampWrites,query_index_count')
  .desc(`Test that querySet.count should be greater than timestampWrite.queryIndex.`)
  .params(u => u.combine('queryIndex', [0, 1, 2, 3]))
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase(['timestamp-query']);
  })
  .fn(async t => {
    const { queryIndex } = t.params;

    const querySetCount = 2;

    const timestampWrite = {
      querySet: t.device.createQuerySet({ type: 'timestamp', count: querySetCount }),
      queryIndex,
      location: 'beginning' as const,
    };

    const isValid = queryIndex < querySetCount;

    const descriptor = {
      timestampWrites: [timestampWrite],
    };

    t.tryComputePass(isValid, descriptor);
  });

g.test('timestamp_query_set,device_mismatch')
  .desc(
    `
  Tests beginComputePass cannot be called with a timestamp query set created from another device.
  `
  )
  .paramsSubcasesOnly(u => u.combine('mismatched', [true, false]))
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase(['timestamp-query']);
    t.selectMismatchedDeviceOrSkipTestCase('timestamp-query');
  })
  .fn(async t => {
    const { mismatched } = t.params;
    const sourceDevice = mismatched ? t.mismatchedDevice : t.device;

    const timestampQuerySet = sourceDevice.createQuerySet({
      type: 'timestamp',
      count: 1,
    });

    const timestampWrite = {
      querySet: timestampQuerySet,
      queryIndex: 0,
      location: 'beginning' as const,
    };

    const descriptor = {
      timestampWrites: [timestampWrite],
    };

    t.tryComputePass(!mismatched, descriptor);
  });