Skip to content

Commit

Permalink
Begin basic vector indexing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-clayton committed Mar 11, 2024
1 parent 19fc59b commit f9f6c90
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@
"webgpu:shader,execution,expression,access,index,array:abstract_scalar:*": { "subcaseMS": 189.344 },
"webgpu:shader,execution,expression,access,index,array:concrete_scalar:*": { "subcaseMS": 989.619 },
"webgpu:shader,execution,expression,access,index,array:vector:*": { "subcaseMS": 1546.461 },
"webgpu:shader,execution,expression,access,index,vector:abstract_scalar:*": { "subcaseMS": 213.529 },
"webgpu:shader,execution,expression,access,index,vector:concrete_scalar:*": { "subcaseMS": 1918.096 },
"webgpu:shader,execution,expression,binary,af_addition:scalar:*": { "subcaseMS": 815.300 },
"webgpu:shader,execution,expression,binary,af_addition:scalar_vector:*": { "subcaseMS": 1803.434 },
"webgpu:shader,execution,expression,binary,af_addition:vector:*": { "subcaseMS": 719.600 },
Expand Down
83 changes: 83 additions & 0 deletions src/webgpu/shader/execution/expression/access/index/vector.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
export const description = `
Execution Tests for vector indexing expressions
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } 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);

g.test('concrete_scalar')
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr')
.desc(`Test indexing of an array of concrete scalars`)
.params(u =>
u
.combine('inputSource', allInputSources)
.combine('elementType', ['i32', 'u32', 'f32', 'f16'] as const)
.combine('indexType', ['i32', 'u32'] as const)
.combine('width', [2, 3, 4] as const)
)
.beforeAllSubcases(t => {
if (t.params.elementType === 'f16') {
t.selectDeviceOrSkipTestCase('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);
const elements: ScalarValue[] = [];
for (let i = 0; i < t.params.width; i++) {
elements.push(elementType.create((i + 1) * 10));
}
const vector = new VectorValue(elements);
const cases: Case[] = [];
for (let i = 0; i < t.params.width; i++) {
cases.push({ input: [vector, indexType.create(i)], expected: elements[i] });
}

await run(
t,
basicExpressionBuilder(ops => `${ops[0]}[${ops[1]}]`),
[vectorType, indexType],
elementType,
t.params,
cases
);
});

g.test('abstract_scalar')
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr')
.desc(`Test indexing of an array of scalars`)
.params(u =>
u
.combine('elementType', ['abstract-int', 'abstract-float'] as const)
.combine('indexType', ['i32', 'u32'] as const)
.combine('width', [2, 3, 4] as const)
)
.fn(async t => {
const elementType = Type[t.params.elementType];
const indexType = Type[t.params.indexType];
const vectorType = Type.vec(t.params.width, elementType);
const elements: ScalarValue[] = [];
for (let i = 0; i < t.params.width; i++) {
elements.push(elementType.create((i + 1) * 0x100000000));
}
const vector = new VectorValue(elements);
const cases: Case[] = [];
for (let i = 0; i < t.params.width; i++) {
cases.push({ input: [vector, indexType.create(i)], expected: f32(i + 1) });
}

await run(
t,
basicExpressionBuilder(ops => `${ops[0]}[${ops[1]}] / 0x100000000`),
[vectorType, indexType],
Type.f32,
{ inputSource: 'const' },
cases
);
});

0 comments on commit f9f6c90

Please sign in to comment.