Skip to content

Commit

Permalink
wgsl: Add AbstractFloat round execution tests
Browse files Browse the repository at this point in the history
Fixes #2509
  • Loading branch information
zoddicus committed Oct 23, 2023
1 parent 2499ea9 commit 5a0f388
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/unittests/floating_point.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarToIntervalCase>(p => {
const constants = FP[p.trait].constants();
Expand Down Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
32 changes: 26 additions & 6 deletions src/webgpu/shader/execution/expression/call/builtin/round.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/webgpu/util/floating_point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 5a0f388

Please sign in to comment.