From 5a0f388db55013527a4f87f473663d2096884067 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Mon, 23 Oct 2023 15:21:59 -0400 Subject: [PATCH] wgsl: Add AbstractFloat `round` execution tests Fixes #2509 --- src/unittests/floating_point.spec.ts | 14 ++++++-- src/webgpu/listing_meta.json | 2 +- .../expression/call/builtin/round.spec.ts | 32 +++++++++++++++---- src/webgpu/util/floating_point.ts | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/unittests/floating_point.spec.ts b/src/unittests/floating_point.spec.ts index 052ee84bc6d4..b68c96640cd1 100644 --- a/src/unittests/floating_point.spec.ts +++ b/src/unittests/floating_point.spec.ts @@ -3538,19 +3538,27 @@ const kRoundIntervalCases = { f32: [ { input: 2 ** 30, expected: 2 ** 30 }, { input: -(2 ** 30), expected: -(2 ** 30) }, - { input: 0x80000000, expected: 0x80000000 }, // https://github.com/gpuweb/cts/issues/2766 + { input: 0x8000_0000, expected: 0x8000_0000 }, // https://github.com/gpuweb/cts/issues/2766 ], f16: [ { input: 2 ** 14, expected: 2 ** 14 }, { input: -(2 ** 14), expected: -(2 ** 14) }, { input: 0x8000, expected: 0x8000 }, // https://github.com/gpuweb/cts/issues/2766 ], + abstract: [ + { input: 2 ** 62, expected: 2 ** 62 }, + { input: -(2 ** 62), expected: -(2 ** 62) }, + { + input: reinterpretU64AsF64(0x8000_0000_0000_0000n), + expected: reinterpretU64AsF64(0x8000_0000_0000_0000n), + }, // https://github.com/gpuweb/cts/issues/2766 + ], } as const; g.test('roundInterval') .params(u => u - .combine('trait', ['f32', 'f16'] as const) + .combine('trait', ['f32', 'f16', 'abstract'] as const) .beginSubcases() .expandWithParams(p => { const constants = FP[p.trait].constants(); @@ -3581,7 +3589,7 @@ g.test('roundInterval') { input: constants.negative.max, expected: 0 }, ...kRoundIntervalCases[p.trait], - // 32-bit subnormals + // Subnormals { input: constants.positive.subnormal.max, expected: 0 }, { input: constants.positive.subnormal.min, expected: 0 }, { input: constants.negative.subnormal.min, expected: 0 }, diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index fa57ff978139..0f747036f730 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1348,7 +1348,7 @@ "webgpu:shader,execution,expression,call,builtin,refract:f32_vec4:*": { "subcaseMS": 610.150 }, "webgpu:shader,execution,expression,call,builtin,reverseBits:i32:*": { "subcaseMS": 9.594 }, "webgpu:shader,execution,expression,call,builtin,reverseBits:u32:*": { "subcaseMS": 7.969 }, - "webgpu:shader,execution,expression,call,builtin,round:abstract_float:*": { "subcaseMS": 19.408 }, + "webgpu:shader,execution,expression,call,builtin,round:abstract_float:*": { "subcaseMS": 450.551 }, "webgpu:shader,execution,expression,call,builtin,round:f16:*": { "subcaseMS": 30.509 }, "webgpu:shader,execution,expression,call,builtin,round:f32:*": { "subcaseMS": 12.407 }, "webgpu:shader,execution,expression,call,builtin,saturate:abstract_float:*": { "subcaseMS": 527.425 }, diff --git a/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts index bd40ed4b2a3e..aff7107410b7 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts @@ -12,13 +12,18 @@ Component-wise when T is a vector. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../../gpu_test.js'; -import { TypeF32, TypeF16 } from '../../../../../util/conversion.js'; +import { TypeF32, TypeF16, TypeAbstractFloat } from '../../../../../util/conversion.js'; import { FP } from '../../../../../util/floating_point.js'; -import { fullF32Range, fullF16Range } from '../../../../../util/math.js'; +import { + fullF32Range, + fullF16Range, + reinterpretU64AsF64, + fullF64Range, +} from '../../../../../util/math.js'; import { makeCaseCache } from '../../case_cache.js'; -import { allInputSources, run } from '../../expression.js'; +import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { builtin } from './builtin.js'; +import { abstractBuiltin, builtin } from './builtin.js'; export const g = makeTestGroup(GPUTest); @@ -43,15 +48,30 @@ export const d = makeCaseCache('round', { FP.f16.roundInterval ); }, + abstract: () => { + return FP.abstract.generateScalarToIntervalCases( + [ + reinterpretU64AsF64(0x8000_0000_0000_0000n), // https://github.com/gpuweb/cts/issues/2766 + ...fullF64Range(), + ], + 'unfiltered', + FP.abstract.roundInterval + ); + }, }); g.test('abstract_float') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') .desc(`abstract float 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 cases = await d.get('abstract'); + await run(t, abstractBuiltin('round'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + }); g.test('f32') .specURL('https://www.w3.org/TR/WGSL/#float-builtin-functions') diff --git a/src/webgpu/util/floating_point.ts b/src/webgpu/util/floating_point.ts index 4d2f9a324cb5..383d9304bbaa 100644 --- a/src/webgpu/util/floating_point.ts +++ b/src/webgpu/util/floating_point.ts @@ -5068,7 +5068,7 @@ class FPAbstractTraits extends FPTraits { public readonly remainderInterval = (x: number, y: number): FPInterval => { return this.toInterval(kF32Traits.remainderInterval(x, y)); }; - public readonly roundInterval = this.unimplementedScalarToInterval.bind(this, 'roundInterval'); + public readonly roundInterval = this.roundIntervalImpl.bind(this); public readonly saturateInterval = this.saturateIntervalImpl.bind(this); public readonly signInterval = this.signIntervalImpl.bind(this); public readonly sinInterval = this.unimplementedScalarToInterval.bind(this, 'sinInterval');