Skip to content

Commit

Permalink
Refactor shader/execution/expression/access
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Feb 26, 2025
1 parent c34b24e commit e4fffaa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 67 deletions.
32 changes: 13 additions & 19 deletions src/webgpu/shader/execution/expression/access/array/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Execution Tests for array indexing expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
import {
False,
True,
Expand All @@ -17,7 +17,7 @@ import { align } from '../../../../../util/math.js';
import { Case } from '../../case.js';
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('concrete_scalar')
.specURL('https://www.w3.org/TR/WGSL/#array-access-expr')
Expand All @@ -32,12 +32,10 @@ g.test('concrete_scalar')
.combine('elementType', ['i32', 'u32', 'f32', 'f16'] as const)
.combine('indexType', ['i32', 'u32'] as const)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const cases: Case[] = [
Expand Down Expand Up @@ -196,17 +194,16 @@ g.test('runtime_sized')
] as const)
.combine('indexType', ['i32', 'u32'] as const)
)
.beforeAllSubcases(t => {
if (scalarTypeOf(Type[t.params.elementType]).kind === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
}
})
.fn(t => {
const elementType = Type[t.params.elementType];
const valueArrayType = Type.array(0, elementType);
const indexType = Type[t.params.indexType];
const indexArrayType = Type.array(0, indexType);

if (scalarTypeOf(elementType).kind === 'f16') {
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}

const wgsl = `
${scalarTypeOf(elementType).kind === 'f16' ? 'enable f16;' : ''}
Expand Down Expand Up @@ -300,14 +297,13 @@ g.test('vector')
)
.combine('indexType', ['i32', 'u32'] as const)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'vec4h') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];

const cases: Case[] = [
{
input: [
Expand Down Expand Up @@ -372,12 +368,10 @@ g.test('matrix')
return (align(mat.size, mat.alignment) & 15) === 0;
})
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);
Expand Down
16 changes: 6 additions & 10 deletions src/webgpu/shader/execution/expression/access/matrix/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Execution Tests for matrix indexing expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
import {
MatrixValue,
ScalarValue,
Expand All @@ -17,7 +17,7 @@ import { align } from '../../../../../util/math.js';
import { Case } from '../../case.js';
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('concrete_float_column')
.specURL('https://www.w3.org/TR/WGSL/#matrix-access-expr')
Expand All @@ -30,12 +30,10 @@ g.test('concrete_float_column')
.combine('columns', [2, 3, 4] as const)
.combine('rows', [2, 3, 4] as const)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);
Expand Down Expand Up @@ -78,12 +76,10 @@ g.test('concrete_float_element')
.combine('columns', [2, 3, 4] as const)
.combine('rows', [2, 3, 4] as const)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const matrixType = Type.mat(t.params.columns, t.params.rows, elementType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Execution Tests for structure member accessing expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest, GPUTest } from '../../../../../gpu_test.js';
import { ScalarKind, Type, Value, u32 } from '../../../../../util/conversion.js';
import { align } from '../../../../../util/math.js';
import { toComparator } from '../../expectation.js';
import { InputSource, structLayout, structStride } from '../../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

const kMemberTypes = [
['bool'],
Expand Down Expand Up @@ -140,12 +140,10 @@ g.test('buffer')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected = values[t.params.member_index];

Expand Down Expand Up @@ -286,12 +284,10 @@ g.test('buffer_pointer')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected = values[t.params.member_index];

Expand Down Expand Up @@ -328,12 +324,10 @@ g.test('let')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const memberType = Type[t.params.member_types[t.params.member_index]];
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected =
Expand Down Expand Up @@ -374,12 +368,10 @@ g.test('param')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const memberType = Type[t.params.member_types[t.params.member_index]];
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected =
Expand Down Expand Up @@ -423,12 +415,10 @@ g.test('const')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const memberType = Type[t.params.member_types[t.params.member_index]];
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected =
Expand Down Expand Up @@ -470,12 +460,10 @@ g.test('const_nested')
.beginSubcases()
.expand('member_index', t => t.member_types.map((_, i) => i))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.member_types.includes('f16')) {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const memberType = Type[t.params.member_types[t.params.member_index]];
const values = t.params.member_types.map((ty, i) => Type[ty].create(i));
const expected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Execution Tests for vector component selection expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
import { ScalarValue, Type, VectorValue, f32 } from '../../../../../util/conversion.js';
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

/** @returns the full permutation of component indices used to component select a vector of width 'n' */
function indices(n: number) {
Expand Down Expand Up @@ -41,12 +41,10 @@ g.test('concrete_scalar')
.beginSubcases()
.expand('indices', u => indices(u.width))
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const vectorType = Type.vec(t.params.width, elementType);
const elementValues =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Execution Tests for vector indexing expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { AllFeaturesMaxLimitsGPUTest } from '../../../../../gpu_test.js';
import { ScalarValue, Type, VectorValue, f32 } from '../../../../../util/conversion.js';
import { Case } from '../../case.js';
import { allInputSources, basicExpressionBuilder, run } from '../../expression.js';

export const g = makeTestGroup(GPUTest);
export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest);

g.test('concrete_scalar')
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr')
Expand All @@ -20,12 +20,10 @@ g.test('concrete_scalar')
.combine('indexType', ['i32', 'u32'] as const)
.combine('width', [2, 3, 4] as const)
)
.beforeAllSubcases(t => {
.fn(async t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('shader-f16');
t.skipIfDeviceDoesNotHaveFeature('shader-f16');
}
})
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const vectorType = Type.vec(t.params.width, elementType);
Expand Down

0 comments on commit e4fffaa

Please sign in to comment.