Skip to content

Commit

Permalink
wgsl: Filter atan2 tests based on if const-eval or not (#3089)
Browse files Browse the repository at this point in the history
Rewrites how test cases are generated for atan2, so that if running in
const-eval unbounded results will not be generated, since those will
cause compilation errors.

Fixes #3088
  • Loading branch information
zoddicus authored Oct 25, 2023
1 parent b929ebb commit 2405593
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Returns the arc tangent of e1 over e2. Component-wise when T is a vector.

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../../gpu_test.js';
import { kValue } from '../../../../../util/constants.js';
import { TypeF32, TypeF16 } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { linearRange, sparseF32Range, sparseF16Range } from '../../../../../util/math.js';
Expand All @@ -20,36 +19,29 @@ import { builtin } from './builtin.js';

export const g = makeTestGroup(GPUTest);

export const d = makeCaseCache('atan2', {
f32: () => {
// Using sparse range since there are N^2 cases being generated, and also including extra values
// around 0, where there is a discontinuity that implementations may behave badly at.
const numeric_range = [
...sparseF32Range(),
...linearRange(kValue.f32.negative.max, kValue.f32.positive.min, 10),
];
return FP.f32.generateScalarPairToIntervalCases(
numeric_range,
numeric_range,
'unfiltered',
FP.f32.atan2Interval
);
},
f16: () => {
// Using sparse range since there are N^2 cases being generated, and also including extra values
// around 0, where there is a discontinuity that implementations may behave badly at.
const numeric_range = [
...sparseF16Range(),
...linearRange(kValue.f16.negative.max, kValue.f16.positive.min, 10),
];
return FP.f16.generateScalarPairToIntervalCases(
numeric_range,
numeric_range,
'unfiltered',
FP.f16.atan2Interval
);
},
});
const cases = (['f32', 'f16'] as const)
.flatMap(kind =>
([true, false] as const).map(nonConst => ({
[`${kind}_${nonConst ? 'non_const' : 'const'}`]: () => {
const fp = FP[kind];
// Using sparse range since there are N^2 cases being generated, and also including extra values
// around 0, where there is a discontinuity that implementations may behave badly at.
const numeric_range = [
...(kind === 'f32' ? sparseF32Range() : sparseF16Range()),
...linearRange(fp.constants().negative.max, fp.constants().positive.min, 10),
];
return fp.generateScalarPairToIntervalCases(
numeric_range,
numeric_range,
nonConst ? 'unfiltered' : 'finite',
fp.atan2Interval
);
},
}))
)
.reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('atan2', cases);

g.test('abstract_float')
.specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions')
Expand All @@ -72,7 +64,7 @@ TODO(#792): Decide what the ground-truth is for these tests. [1]
u.combine('inputSource', allInputSources).combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('f32');
const cases = await d.get(`f32_${t.params.inputSource === 'const' ? 'const' : 'non_const'}`);
await run(t, builtin('atan2'), [TypeF32, TypeF32], TypeF32, t.params, cases);
});

Expand All @@ -86,6 +78,6 @@ g.test('f16')
t.selectDeviceOrSkipTestCase('shader-f16');
})
.fn(async t => {
const cases = await d.get('f16');
const cases = await d.get(`f16_${t.params.inputSource === 'const' ? 'const' : 'non_const'}`);
await run(t, builtin('atan2'), [TypeF16, TypeF16], TypeF16, t.params, cases);
});

0 comments on commit 2405593

Please sign in to comment.