-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19fc59b
commit f9f6c90
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/webgpu/shader/execution/expression/access/index/vector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}); |