Skip to content

Commit e4fffaa

Browse files
committed
Refactor shader/execution/expression/access
Issue #4178
1 parent c34b24e commit e4fffaa

File tree

5 files changed

+41
-67
lines changed

5 files changed

+41
-67
lines changed

src/webgpu/shader/execution/expression/access/array/index.spec.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Execution Tests for array indexing expressions
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
77
import {
88
False,
99
True,
@@ -17,7 +17,7 @@ import { align } from '../../../../../util/math.js';
1717
import { Case } from '../../case.js';
1818
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';
1919

20-
export const g = makeTestGroup(GPUTest);
20+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
2121

2222
g.test('concrete_scalar')
2323
.specURL('https://www.w3.org/TR/WGSL/#array-access-expr')
@@ -32,12 +32,10 @@ g.test('concrete_scalar')
3232
.combine('elementType', ['i32', 'u32', 'f32', 'f16'] as const)
3333
.combine('indexType', ['i32', 'u32'] as const)
3434
)
35-
.beforeAllSubcases(t => {
35+
.fn(async t => {
3636
if (t.params.elementType === 'f16') {
37-
t.selectDeviceOrSkipTestCase('shader-f16');
37+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
3838
}
39-
})
40-
.fn(async t => {
4139
const elementType = Type[t.params.elementType];
4240
const indexType = Type[t.params.indexType];
4341
const cases: Case[] = [
@@ -196,17 +194,16 @@ g.test('runtime_sized')
196194
] as const)
197195
.combine('indexType', ['i32', 'u32'] as const)
198196
)
199-
.beforeAllSubcases(t => {
200-
if (scalarTypeOf(Type[t.params.elementType]).kind === 'f16') {
201-
t.selectDeviceOrSkipTestCase('shader-f16');
202-
}
203-
})
204197
.fn(t => {
205198
const elementType = Type[t.params.elementType];
206199
const valueArrayType = Type.array(0, elementType);
207200
const indexType = Type[t.params.indexType];
208201
const indexArrayType = Type.array(0, indexType);
209202

203+
if (scalarTypeOf(elementType).kind === 'f16') {
204+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
205+
}
206+
210207
const wgsl = `
211208
${scalarTypeOf(elementType).kind === 'f16' ? 'enable f16;' : ''}
212209
@@ -300,14 +297,13 @@ g.test('vector')
300297
)
301298
.combine('indexType', ['i32', 'u32'] as const)
302299
)
303-
.beforeAllSubcases(t => {
300+
.fn(async t => {
304301
if (t.params.elementType === 'vec4h') {
305-
t.selectDeviceOrSkipTestCase('shader-f16');
302+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
306303
}
307-
})
308-
.fn(async t => {
309304
const elementType = Type[t.params.elementType];
310305
const indexType = Type[t.params.indexType];
306+
311307
const cases: Case[] = [
312308
{
313309
input: [
@@ -372,12 +368,10 @@ g.test('matrix')
372368
return (align(mat.size, mat.alignment) & 15) === 0;
373369
})
374370
)
375-
.beforeAllSubcases(t => {
371+
.fn(async t => {
376372
if (t.params.elementType === 'f16') {
377-
t.selectDeviceOrSkipTestCase('shader-f16');
373+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
378374
}
379-
})
380-
.fn(async t => {
381375
const elementType = Type[t.params.elementType];
382376
const indexType = Type[t.params.indexType];
383377
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);

src/webgpu/shader/execution/expression/access/matrix/index.spec.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Execution Tests for matrix indexing expressions
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
77
import {
88
MatrixValue,
99
ScalarValue,
@@ -17,7 +17,7 @@ import { align } from '../../../../../util/math.js';
1717
import { Case } from '../../case.js';
1818
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';
1919

20-
export const g = makeTestGroup(GPUTest);
20+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
2121

2222
g.test('concrete_float_column')
2323
.specURL('https://www.w3.org/TR/WGSL/#matrix-access-expr')
@@ -30,12 +30,10 @@ g.test('concrete_float_column')
3030
.combine('columns', [2, 3, 4] as const)
3131
.combine('rows', [2, 3, 4] as const)
3232
)
33-
.beforeAllSubcases(t => {
33+
.fn(async t => {
3434
if (t.params.elementType === 'f16') {
35-
t.selectDeviceOrSkipTestCase('shader-f16');
35+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
3636
}
37-
})
38-
.fn(async t => {
3937
const elementType = Type[t.params.elementType];
4038
const indexType = Type[t.params.indexType];
4139
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);
@@ -78,12 +76,10 @@ g.test('concrete_float_element')
7876
.combine('columns', [2, 3, 4] as const)
7977
.combine('rows', [2, 3, 4] as const)
8078
)
81-
.beforeAllSubcases(t => {
79+
.fn(async t => {
8280
if (t.params.elementType === 'f16') {
83-
t.selectDeviceOrSkipTestCase('shader-f16');
81+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
8482
}
85-
})
86-
.fn(async t => {
8783
const elementType = Type[t.params.elementType];
8884
const indexType = Type[t.params.indexType];
8985
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);

src/webgpu/shader/execution/expression/access/structure/index.spec.ts

+14-26
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ Execution Tests for structure member accessing expressions
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../../gpu_test.js';
77
import { ScalarKind, Type, Value, u32 } from '../../../../../util/conversion.js';
88
import { align } from '../../../../../util/math.js';
99
import { toComparator } from '../../expectation.js';
1010
import { InputSource, structLayout, structStride } from '../../expression.js';
1111

12-
export const g = makeTestGroup(GPUTest);
12+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
1313

1414
const kMemberTypes = [
1515
['bool'],
@@ -140,12 +140,10 @@ g.test('buffer')
140140
.beginSubcases()
141141
.expand('member_index', t => t.member_types.map((_, i) => i))
142142
)
143-
.beforeAllSubcases(t => {
143+
.fn(async t => {
144144
if (t.params.member_types.includes('f16')) {
145-
t.selectDeviceOrSkipTestCase('shader-f16');
145+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
146146
}
147-
})
148-
.fn(async t => {
149147
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
150148
const expected = values[t.params.member_index];
151149

@@ -286,12 +284,10 @@ g.test('buffer_pointer')
286284
.beginSubcases()
287285
.expand('member_index', t => t.member_types.map((_, i) => i))
288286
)
289-
.beforeAllSubcases(t => {
287+
.fn(async t => {
290288
if (t.params.member_types.includes('f16')) {
291-
t.selectDeviceOrSkipTestCase('shader-f16');
289+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
292290
}
293-
})
294-
.fn(async t => {
295291
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
296292
const expected = values[t.params.member_index];
297293

@@ -328,12 +324,10 @@ g.test('let')
328324
.beginSubcases()
329325
.expand('member_index', t => t.member_types.map((_, i) => i))
330326
)
331-
.beforeAllSubcases(t => {
327+
.fn(async t => {
332328
if (t.params.member_types.includes('f16')) {
333-
t.selectDeviceOrSkipTestCase('shader-f16');
329+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
334330
}
335-
})
336-
.fn(async t => {
337331
const memberType = Type[t.params.member_types[t.params.member_index]];
338332
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
339333
const expected =
@@ -374,12 +368,10 @@ g.test('param')
374368
.beginSubcases()
375369
.expand('member_index', t => t.member_types.map((_, i) => i))
376370
)
377-
.beforeAllSubcases(t => {
371+
.fn(async t => {
378372
if (t.params.member_types.includes('f16')) {
379-
t.selectDeviceOrSkipTestCase('shader-f16');
373+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
380374
}
381-
})
382-
.fn(async t => {
383375
const memberType = Type[t.params.member_types[t.params.member_index]];
384376
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
385377
const expected =
@@ -423,12 +415,10 @@ g.test('const')
423415
.beginSubcases()
424416
.expand('member_index', t => t.member_types.map((_, i) => i))
425417
)
426-
.beforeAllSubcases(t => {
418+
.fn(async t => {
427419
if (t.params.member_types.includes('f16')) {
428-
t.selectDeviceOrSkipTestCase('shader-f16');
420+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
429421
}
430-
})
431-
.fn(async t => {
432422
const memberType = Type[t.params.member_types[t.params.member_index]];
433423
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
434424
const expected =
@@ -470,12 +460,10 @@ g.test('const_nested')
470460
.beginSubcases()
471461
.expand('member_index', t => t.member_types.map((_, i) => i))
472462
)
473-
.beforeAllSubcases(t => {
463+
.fn(async t => {
474464
if (t.params.member_types.includes('f16')) {
475-
t.selectDeviceOrSkipTestCase('shader-f16');
465+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
476466
}
477-
})
478-
.fn(async t => {
479467
const memberType = Type[t.params.member_types[t.params.member_index]];
480468
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
481469
const expected =

src/webgpu/shader/execution/expression/access/vector/components.spec.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Execution Tests for vector component selection expressions
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
77
import { ScalarValue, Type, VectorValue, f32 } from '../../../../../util/conversion.js';
88
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';
99

10-
export const g = makeTestGroup(GPUTest);
10+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
1111

1212
/** @returns the full permutation of component indices used to component select a vector of width 'n' */
1313
function indices(n: number) {
@@ -41,12 +41,10 @@ g.test('concrete_scalar')
4141
.beginSubcases()
4242
.expand('indices', u => indices(u.width))
4343
)
44-
.beforeAllSubcases(t => {
44+
.fn(async t => {
4545
if (t.params.elementType === 'f16') {
46-
t.selectDeviceOrSkipTestCase('shader-f16');
46+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
4747
}
48-
})
49-
.fn(async t => {
5048
const elementType = Type[t.params.elementType];
5149
const vectorType = Type.vec(t.params.width, elementType);
5250
const elementValues =

src/webgpu/shader/execution/expression/access/vector/index.spec.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Execution Tests for vector indexing expressions
33
`;
44

55
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6-
import { GPUTest } from '../../../../../gpu_test.js';
6+
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
77
import { ScalarValue, Type, VectorValue, f32 } from '../../../../../util/conversion.js';
88
import { Case } from '../../case.js';
99
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';
1010

11-
export const g = makeTestGroup(GPUTest);
11+
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);
1212

1313
g.test('concrete_scalar')
1414
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr')
@@ -20,12 +20,10 @@ g.test('concrete_scalar')
2020
.combine('indexType', ['i32', 'u32'] as const)
2121
.combine('width', [2, 3, 4] as const)
2222
)
23-
.beforeAllSubcases(t => {
23+
.fn(async t => {
2424
if (t.params.elementType === 'f16') {
25-
t.selectDeviceOrSkipTestCase('shader-f16');
25+
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
2626
}
27-
})
28-
.fn(async t => {
2927
const elementType = Type[t.params.elementType];
3028
const indexType = Type[t.params.indexType];
3129
const vectorType = Type.vec(t.params.width, elementType);

0 commit comments

Comments
 (0)