diff options
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts | 106 |
1 files changed, 42 insertions, 64 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts index 6654b4951c..ee7cb0d674 100644 --- a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts +++ b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts @@ -1,12 +1,12 @@ export const description = ` Execution tests for the 'max' builtin function -S is AbstractInt, i32, or u32 +S is abstract-int, i32, or u32 T is S or vecN<S> @const fn max(e1: T ,e2: T) -> T Returns e2 if e1 is less than e2, and e1 otherwise. Component-wise when T is a vector. -S is AbstractFloat, f32, f16 +S is abstract-float, f32, f16 T is vecN<S> @const fn max(e1: T ,e2: T) -> T Returns e2 if e1 is less than e2, and e1 otherwise. @@ -18,72 +18,50 @@ Component-wise when T is a vector. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../../gpu_test.js'; -import { - i32, - TypeF32, - TypeF16, - TypeI32, - TypeU32, - u32, - TypeAbstractFloat, -} from '../../../../../util/conversion.js'; -import { FP } from '../../../../../util/floating_point.js'; -import { fullF32Range, fullF16Range, sparseF64Range } from '../../../../../util/math.js'; -import { makeCaseCache } from '../../case_cache.js'; -import { allInputSources, Case, onlyConstInputSource, run } from '../../expression.js'; - -import { abstractBuiltin, builtin } from './builtin.js'; +import { Type, i32, u32, abstractInt } from '../../../../../util/conversion.js'; +import { maxBigInt } from '../../../../../util/math.js'; +import { Case } from '../../case.js'; +import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; + +import { abstractFloatBuiltin, abstractIntBuiltin, builtin } from './builtin.js'; +import { d } from './max.cache.js'; /** Generate set of max test cases from list of interesting values */ -function generateTestCases( - values: Array<number>, - makeCase: (x: number, y: number) => Case -): Array<Case> { - const cases = new Array<Case>(); - values.forEach(e => { - values.forEach(f => { - cases.push(makeCase(e, f)); +function generateTestCases<Type>(values: Type[], makeCase: (x: Type, y: Type) => Case): Case[] { + return values.flatMap(e => { + return values.map(f => { + return makeCase(e, f); }); }); - return cases; } export const g = makeTestGroup(GPUTest); -export const d = makeCaseCache('max', { - f32: () => { - return FP.f32.generateScalarPairToIntervalCases( - fullF32Range(), - fullF32Range(), - 'unfiltered', - FP.f32.maxInterval - ); - }, - f16: () => { - return FP.f16.generateScalarPairToIntervalCases( - fullF16Range(), - fullF16Range(), - 'unfiltered', - FP.f16.maxInterval - ); - }, - abstract: () => { - return FP.abstract.generateScalarPairToIntervalCases( - sparseF64Range(), - sparseF64Range(), - 'unfiltered', - FP.abstract.maxInterval - ); - }, -}); - g.test('abstract_int') .specURL('https://www.w3.org/TR/WGSL/#integer-builtin-functions') .desc(`abstract int tests`) .params(u => - u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const) + u + .combine('inputSource', onlyConstInputSource) + .combine('vectorize', [undefined, 2, 3, 4] as const) ) - .unimplemented(); + .fn(async t => { + const makeCase = (x: bigint, y: bigint): Case => { + return { input: [abstractInt(x), abstractInt(y)], expected: abstractInt(maxBigInt(x, y)) }; + }; + + const test_values = [-0x70000000n, -2n, -1n, 0n, 1n, 2n, 0x70000000n]; + const cases = generateTestCases(test_values, makeCase); + + await run( + t, + abstractIntBuiltin('max'), + [Type.abstractInt, Type.abstractInt], + Type.abstractInt, + t.params, + cases + ); + }); g.test('u32') .specURL('https://www.w3.org/TR/WGSL/#integer-builtin-functions') @@ -96,10 +74,10 @@ g.test('u32') return { input: [u32(x), u32(y)], expected: u32(Math.max(x, y)) }; }; - const test_values: Array<number> = [0, 1, 2, 0x70000000, 0x80000000, 0xffffffff]; + const test_values: number[] = [0, 1, 2, 0x70000000, 0x80000000, 0xffffffff]; const cases = generateTestCases(test_values, makeCase); - await run(t, builtin('max'), [TypeU32, TypeU32], TypeU32, t.params, cases); + await run(t, builtin('max'), [Type.u32, Type.u32], Type.u32, t.params, cases); }); g.test('i32') @@ -113,10 +91,10 @@ g.test('i32') return { input: [i32(x), i32(y)], expected: i32(Math.max(x, y)) }; }; - const test_values: Array<number> = [-0x70000000, -2, -1, 0, 1, 2, 0x70000000]; + const test_values: number[] = [-0x70000000, -2, -1, 0, 1, 2, 0x70000000]; const cases = generateTestCases(test_values, makeCase); - await run(t, builtin('max'), [TypeI32, TypeI32], TypeI32, t.params, cases); + await run(t, builtin('max'), [Type.i32, Type.i32], Type.i32, t.params, cases); }); g.test('abstract_float') @@ -131,9 +109,9 @@ g.test('abstract_float') const cases = await d.get('abstract'); await run( t, - abstractBuiltin('max'), - [TypeAbstractFloat, TypeAbstractFloat], - TypeAbstractFloat, + abstractFloatBuiltin('max'), + [Type.abstractFloat, Type.abstractFloat], + Type.abstractFloat, t.params, cases ); @@ -147,7 +125,7 @@ g.test('f32') ) .fn(async t => { const cases = await d.get('f32'); - await run(t, builtin('max'), [TypeF32, TypeF32], TypeF32, t.params, cases); + await run(t, builtin('max'), [Type.f32, Type.f32], Type.f32, t.params, cases); }); g.test('f16') @@ -161,5 +139,5 @@ g.test('f16') }) .fn(async t => { const cases = await d.get('f16'); - await run(t, builtin('max'), [TypeF16, TypeF16], TypeF16, t.params, cases); + await run(t, builtin('max'), [Type.f16, Type.f16], Type.f16, t.params, cases); }); |