From 24055936ff66119932e4802b823e9283c244bdd4 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 25 Oct 2023 10:05:00 -0400 Subject: [PATCH] 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 --- .../expression/call/builtin/atan2.spec.ts | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts index 3ccdcae67ecc..fbace73dd204 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/atan2.spec.ts @@ -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'; @@ -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') @@ -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); }); @@ -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); });