Skip to content

Commit 2405593

Browse files
authored
wgsl: Filter atan2 tests based on if const-eval or not (#3089)
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
1 parent b929ebb commit 2405593

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts

+25-33
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Returns the arc tangent of e1 over e2. Component-wise when T is a vector.
99

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

2120
export const g = makeTestGroup(GPUTest);
2221

23-
export const d = makeCaseCache('atan2', {
24-
f32: () => {
25-
// Using sparse range since there are N^2 cases being generated, and also including extra values
26-
// around 0, where there is a discontinuity that implementations may behave badly at.
27-
const numeric_range = [
28-
...sparseF32Range(),
29-
...linearRange(kValue.f32.negative.max, kValue.f32.positive.min, 10),
30-
];
31-
return FP.f32.generateScalarPairToIntervalCases(
32-
numeric_range,
33-
numeric_range,
34-
'unfiltered',
35-
FP.f32.atan2Interval
36-
);
37-
},
38-
f16: () => {
39-
// Using sparse range since there are N^2 cases being generated, and also including extra values
40-
// around 0, where there is a discontinuity that implementations may behave badly at.
41-
const numeric_range = [
42-
...sparseF16Range(),
43-
...linearRange(kValue.f16.negative.max, kValue.f16.positive.min, 10),
44-
];
45-
return FP.f16.generateScalarPairToIntervalCases(
46-
numeric_range,
47-
numeric_range,
48-
'unfiltered',
49-
FP.f16.atan2Interval
50-
);
51-
},
52-
});
22+
const cases = (['f32', 'f16'] as const)
23+
.flatMap(kind =>
24+
([true, false] as const).map(nonConst => ({
25+
[`${kind}_${nonConst ? 'non_const' : 'const'}`]: () => {
26+
const fp = FP[kind];
27+
// Using sparse range since there are N^2 cases being generated, and also including extra values
28+
// around 0, where there is a discontinuity that implementations may behave badly at.
29+
const numeric_range = [
30+
...(kind === 'f32' ? sparseF32Range() : sparseF16Range()),
31+
...linearRange(fp.constants().negative.max, fp.constants().positive.min, 10),
32+
];
33+
return fp.generateScalarPairToIntervalCases(
34+
numeric_range,
35+
numeric_range,
36+
nonConst ? 'unfiltered' : 'finite',
37+
fp.atan2Interval
38+
);
39+
},
40+
}))
41+
)
42+
.reduce((a, b) => ({ ...a, ...b }), {});
43+
44+
export const d = makeCaseCache('atan2', cases);
5345

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

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

0 commit comments

Comments
 (0)