Skip to content

Commit

Permalink
wgsl: Implement AbstractInt negation execution tests (#3390)
Browse files Browse the repository at this point in the history
Issue #1626
  • Loading branch information
zoddicus authored Feb 13, 2024
1 parent 817df41 commit 2920b0f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
"webgpu/shader/execution/unary/i32_conversion.bin": "70bd317b",
"webgpu/shader/execution/unary/u32_complement.bin": "b8dd9928",
"webgpu/shader/execution/unary/u32_conversion.bin": "750cf298",
"webgpu/shader/execution/unary/ai_assignment.bin": "8123c23d"
"webgpu/shader/execution/unary/ai_assignment.bin": "8123c23d",
"webgpu/shader/execution/unary/ai_arithmetic.bin": "ada333c7"
}
Binary file not shown.
1 change: 1 addition & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@
"webgpu:shader,execution,expression,call,user,ptr_params:write_ptr_to_member:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,call,user,ptr_params:write_ptr_to_element:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,call,user,ptr_params:mixed_ptr_parameters:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,unary,ai_arithmetic:negation:*": { "subcaseMS": 0.000 },
"webgpu:shader,execution,expression,unary,af_arithmetic:negation:*": { "subcaseMS": 2165.950 },
"webgpu:shader,execution,expression,unary,af_assignment:abstract:*": { "subcaseMS": 788.400 },
"webgpu:shader,execution,expression,unary,af_assignment:f16:*": { "subcaseMS": 1.000 },
Expand Down
12 changes: 10 additions & 2 deletions src/webgpu/shader/execution/expression/unary/af_arithmetic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TypeAbstractFloat } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './af_arithmetic.cache.js';
import { abstractUnary } from './unary.js';
import { abstractFloatUnary } from './unary.js';

export const g = makeTestGroup(GPUTest);

Expand All @@ -27,5 +27,13 @@ Accuracy: Correctly rounded
)
.fn(async t => {
const cases = await d.get('negation');
await run(t, abstractUnary('-'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases, 1);
await run(
t,
abstractFloatUnary('-'),
[TypeAbstractFloat],
TypeAbstractFloat,
t.params,
cases,
1
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { abstractInt } from '../../../../util/conversion.js';
import { fullI64Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';

export const d = makeCaseCache('unary/ai_arithmetic', {
negation: () => {
return fullI64Range().map(e => {
return { input: abstractInt(e), expected: abstractInt(-e) };
});
},
});
30 changes: 30 additions & 0 deletions src/webgpu/shader/execution/expression/unary/ai_arithmetic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const description = `
Execution Tests for the abstract integer arithmetic unary expression operations
`;

import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { TypeAbstractInt } from '../../../../util/conversion.js';
import { onlyConstInputSource, run } from '../expression.js';

import { d } from './ai_arithmetic.cache.js';
import { abstractIntUnary } from './unary.js';

export const g = makeTestGroup(GPUTest);

g.test('negation')
.specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr')
.desc(
`
Expression: -x
`
)
.params(u =>
u
.combine('inputSource', onlyConstInputSource)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('negation');
await run(t, abstractIntUnary('-'), [TypeAbstractInt], TypeAbstractInt, t.params, cases);
});
8 changes: 7 additions & 1 deletion src/webgpu/shader/execution/expression/unary/unary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
abstractFloatShaderBuilder,
abstractIntShaderBuilder,
basicExpressionBuilder,
ShaderBuilder,
} from '../expression.js';
Expand All @@ -10,6 +11,11 @@ export function unary(op: string): ShaderBuilder {
}

/* @returns a ShaderBuilder that evaluates a prefix unary operation that returns AbstractFloats */
export function abstractUnary(op: string): ShaderBuilder {
export function abstractFloatUnary(op: string): ShaderBuilder {
return abstractFloatShaderBuilder(value => `${op}(${value})`);
}

/* @returns a ShaderBuilder that evaluates a prefix unary operation that returns AbstractInts */
export function abstractIntUnary(op: string): ShaderBuilder {
return abstractIntShaderBuilder(value => `${op}(${value})`);
}

0 comments on commit 2920b0f

Please sign in to comment.