-
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.
shader/execution: Implement vector component selection tests
Bug: #3170
- Loading branch information
1 parent
5ad7589
commit d97cc72
Showing
4 changed files
with
126 additions
and
7 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
File renamed without changes.
117 changes: 117 additions & 0 deletions
117
src/webgpu/shader/execution/expression/access/vector/components.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,117 @@ | ||
export const description = ` | ||
Execution Tests for vector component selection 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 { allInputSources, basicExpressionBuilder, run } from '../../expression.js'; | ||
|
||
export const g = makeTestGroup(GPUTest); | ||
|
||
/** @returns the full permutation of component indices used to component select a vector of width 'n' */ | ||
function indices(n: number) { | ||
const out: number[][] = []; | ||
for (let width = 1; width < n; width++) { | ||
let generate = (swizzle: number[]) => { | ||
out.push(swizzle); | ||
}; | ||
for (let i = 0; i < width; i++) { | ||
const next = generate; | ||
generate = (swizzle: number[]) => { | ||
for (let j = 0; j < width; j++) { | ||
next([...swizzle, j]); | ||
} | ||
}; | ||
} | ||
generate([]); | ||
} | ||
return out; | ||
} | ||
|
||
g.test('concrete_scalar') | ||
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr') | ||
.desc(`Test vector component selection of concrete vectors`) | ||
.params(u => | ||
u | ||
.combine('inputSource', allInputSources) | ||
.combine('elementType', ['i32', 'u32', 'f32', 'f16'] as const) | ||
.combine('width', [2, 3, 4] as const) | ||
.combine('components', ['rgba', 'xyzw'] as const) | ||
.beginSubcases() | ||
.expand('indices', u => indices(u.width)) | ||
) | ||
.beforeAllSubcases(t => { | ||
if (t.params.elementType === 'f16') { | ||
t.selectDeviceOrSkipTestCase('shader-f16'); | ||
} | ||
}) | ||
.fn(async t => { | ||
const elementType = Type[t.params.elementType]; | ||
const vectorType = Type.vec(t.params.width, elementType); | ||
const elementValues = (i: number) => (i + 1) * 10; | ||
const elements: ScalarValue[] = []; | ||
for (let i = 0; i < t.params.width; i++) { | ||
elements.push(elementType.create(elementValues(i))); | ||
} | ||
const result = (() => { | ||
if (t.params.indices.length === 1) { | ||
return { type: elementType, value: elementType.create(elementValues(0)) }; | ||
} else { | ||
const vec = Type.vec(t.params.indices.length, elementType); | ||
return { type: vec, value: vec.create(t.params.indices.map(i => elementValues(i))) }; | ||
} | ||
})(); | ||
|
||
const components = t.params.indices.map(i => t.params.components[i]).join(''); | ||
await run( | ||
t, | ||
basicExpressionBuilder(ops => `${ops[0]}.${components}`), | ||
[vectorType], | ||
result.type, | ||
t.params, | ||
[{ input: [new VectorValue(elements)], expected: result.value }] | ||
); | ||
}); | ||
|
||
g.test('abstract_scalar') | ||
.specURL('https://www.w3.org/TR/WGSL/#vector-access-expr') | ||
.desc(`Test vector component selection of abstract numeric vectors`) | ||
.params(u => | ||
u | ||
.combine('elementType', ['abstract-int', 'abstract-float'] as const) | ||
.combine('width', [2, 3, 4] as const) | ||
.combine('components', ['rgba', 'xyzw'] as const) | ||
.beginSubcases() | ||
.expand('indices', u => indices(u.width)) | ||
) | ||
.fn(async t => { | ||
const elementType = Type[t.params.elementType]; | ||
const vectorType = Type.vec(t.params.width, elementType); | ||
const elementValues = (i: number) => (i + 1) * 0x100000000; | ||
const elements: ScalarValue[] = []; | ||
for (let i = 0; i < t.params.width; i++) { | ||
elements.push(elementType.create(elementValues(i))); | ||
} | ||
const result = (() => { | ||
if (t.params.indices.length === 1) { | ||
return { type: Type.f32, value: f32(elementValues(0) / 0x100000000) }; | ||
} else { | ||
const vec = Type.vec(t.params.indices.length, Type.f32); | ||
return { | ||
type: vec, | ||
value: vec.create(t.params.indices.map(i => elementValues(i) / 0x100000000)), | ||
}; | ||
} | ||
})(); | ||
|
||
const components = t.params.indices.map(i => t.params.components[i]).join(''); | ||
await run( | ||
t, | ||
basicExpressionBuilder(ops => `${ops[0]}.${components} / 0x100000000`), | ||
[vectorType], | ||
result.type, | ||
{ inputSource: 'const' }, | ||
[{ input: [new VectorValue(elements)], expected: result.value }] | ||
); | ||
}); |
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