Skip to content

Commit

Permalink
wgsl: Implement AbstractInt clamp execution tests (#3380)
Browse files Browse the repository at this point in the history
Issue #1297
  • Loading branch information
zoddicus authored Feb 13, 2024
1 parent 5d354c0 commit d4dad46
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 115 deletions.
210 changes: 105 additions & 105 deletions src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
{
"webgpu/shader/execution/binary/af_addition.bin": "d2a94254",
"webgpu/shader/execution/binary/af_logical.bin": "e32bdae7",
"webgpu/shader/execution/binary/af_division.bin": "998cb6fc",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "496bd4ec",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "dd4e9a4f",
"webgpu/shader/execution/binary/af_multiplication.bin": "e81deb2c",
"webgpu/shader/execution/binary/af_remainder.bin": "5aeed2e",
"webgpu/shader/execution/binary/af_subtraction.bin": "dc69ddc1",
"webgpu/shader/execution/binary/f16_addition.bin": "18815537",
"webgpu/shader/execution/binary/f16_logical.bin": "62ffb51f",
"webgpu/shader/execution/binary/f16_division.bin": "e4bf7770",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "ca4752e2",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "fec02413",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "1a7e0d08",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "8044743e",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "ffb049e3",
"webgpu/shader/execution/binary/f16_multiplication.bin": "321b90f1",
"webgpu/shader/execution/binary/f16_remainder.bin": "bafa853",
"webgpu/shader/execution/binary/f16_subtraction.bin": "95a6af75",
"webgpu/shader/execution/binary/f32_addition.bin": "84b9178a",
"webgpu/shader/execution/binary/f32_logical.bin": "bc43ddfb",
"webgpu/shader/execution/binary/f32_division.bin": "2a526e73",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "23f30d9c",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "955042e6",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "61829041",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "2f60e0a",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "3d6aba5e",
"webgpu/shader/execution/binary/f32_multiplication.bin": "2b4ddfb",
"webgpu/shader/execution/binary/f32_remainder.bin": "a3162fbe",
"webgpu/shader/execution/binary/f32_subtraction.bin": "5844472c",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "77bd762d",
"webgpu/shader/execution/binary/i32_comparison.bin": "deaf3d06",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "91ddc813",
"webgpu/shader/execution/binary/u32_comparison.bin": "82d7e10a",
"webgpu/shader/execution/abs.bin": "c2a08da0",
"webgpu/shader/execution/acos.bin": "ecb8f6e4",
"webgpu/shader/execution/acosh.bin": "e908c085",
"webgpu/shader/execution/asin.bin": "db1956dd",
"webgpu/shader/execution/asinh.bin": "d1c4370e",
"webgpu/shader/execution/atan.bin": "d32f84de",
"webgpu/shader/execution/atan2.bin": "c82ce2a9",
"webgpu/shader/execution/atanh.bin": "1d7fa05e",
"webgpu/shader/execution/bitcast.bin": "e6af5117",
"webgpu/shader/execution/ceil.bin": "6822702d",
"webgpu/shader/execution/clamp.bin": "2dcc8e33",
"webgpu/shader/execution/cos.bin": "1e4b5876",
"webgpu/shader/execution/cosh.bin": "88b43457",
"webgpu/shader/execution/cross.bin": "64b251e3",
"webgpu/shader/execution/degrees.bin": "ff5755de",
"webgpu/shader/execution/determinant.bin": "89ce1093",
"webgpu/shader/execution/distance.bin": "5694ecf1",
"webgpu/shader/execution/dot.bin": "60da4277",
"webgpu/shader/execution/exp.bin": "5ae18fc8",
"webgpu/shader/execution/exp2.bin": "ff8f009b",
"webgpu/shader/execution/faceForward.bin": "6ce196c1",
"webgpu/shader/execution/floor.bin": "addfc3d9",
"webgpu/shader/execution/fma.bin": "668f05ee",
"webgpu/shader/execution/fract.bin": "6d036c34",
"webgpu/shader/execution/frexp.bin": "3609ccd2",
"webgpu/shader/execution/inverseSqrt.bin": "b65957cd",
"webgpu/shader/execution/ldexp.bin": "99dcba57",
"webgpu/shader/execution/length.bin": "48edc788",
"webgpu/shader/execution/log.bin": "59d405b3",
"webgpu/shader/execution/log2.bin": "b897533e",
"webgpu/shader/execution/max.bin": "bb46b974",
"webgpu/shader/execution/min.bin": "e4e95641",
"webgpu/shader/execution/mix.bin": "4b781b3b",
"webgpu/shader/execution/modf.bin": "dda61537",
"webgpu/shader/execution/normalize.bin": "73a2bb69",
"webgpu/shader/execution/pack2x16float.bin": "d4a1d8f6",
"webgpu/shader/execution/pow.bin": "f4b1f7c6",
"webgpu/shader/execution/quantizeToF16.bin": "9632b1a3",
"webgpu/shader/execution/radians.bin": "838c408e",
"webgpu/shader/execution/reflect.bin": "401123c3",
"webgpu/shader/execution/refract.bin": "cf86546c",
"webgpu/shader/execution/round.bin": "d1cf1ebb",
"webgpu/shader/execution/saturate.bin": "6ecf8d76",
"webgpu/shader/execution/sign.bin": "f7757f54",
"webgpu/shader/execution/sin.bin": "aff5ff89",
"webgpu/shader/execution/sinh.bin": "10264f6",
"webgpu/shader/execution/smoothstep.bin": "cc165c8d",
"webgpu/shader/execution/sqrt.bin": "9288e28",
"webgpu/shader/execution/step.bin": "3e730ebc",
"webgpu/shader/execution/tan.bin": "b249b4ca",
"webgpu/shader/execution/tanh.bin": "add851dd",
"webgpu/shader/execution/transpose.bin": "ee64fd10",
"webgpu/shader/execution/trunc.bin": "b6c5fdcc",
"webgpu/shader/execution/unpack2x16float.bin": "46be8a57",
"webgpu/shader/execution/unpack2x16snorm.bin": "f2a50142",
"webgpu/shader/execution/unpack2x16unorm.bin": "6db99ed6",
"webgpu/shader/execution/unpack4x8snorm.bin": "4e88f425",
"webgpu/shader/execution/unpack4x8unorm.bin": "b818c7b",
"webgpu/shader/execution/unary/af_arithmetic.bin": "69e5897a",
"webgpu/shader/execution/unary/af_assignment.bin": "588f3b94",
"webgpu/shader/execution/unary/bool_conversion.bin": "7b22a4bf",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "88bfdf25",
"webgpu/shader/execution/unary/f16_conversion.bin": "257326e2",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "54315cef",
"webgpu/shader/execution/unary/f32_conversion.bin": "15bdedd7",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "d8556f43",
"webgpu/shader/execution/unary/i32_complement.bin": "d044f52",
"webgpu/shader/execution/unary/i32_conversion.bin": "d1d94808",
"webgpu/shader/execution/unary/u32_complement.bin": "5458ccb1",
"webgpu/shader/execution/unary/u32_conversion.bin": "a7b4272e",
"webgpu/shader/execution/unary/ai_assignment.bin": "b15b5af8"
"webgpu/shader/execution/binary/af_addition.bin": "56e73232",
"webgpu/shader/execution/binary/af_logical.bin": "dc84fec2",
"webgpu/shader/execution/binary/af_division.bin": "b99f45a9",
"webgpu/shader/execution/binary/af_matrix_addition.bin": "67fc289e",
"webgpu/shader/execution/binary/af_matrix_subtraction.bin": "e533cd16",
"webgpu/shader/execution/binary/af_multiplication.bin": "b963600",
"webgpu/shader/execution/binary/af_remainder.bin": "4951978",
"webgpu/shader/execution/binary/af_subtraction.bin": "f0bd33da",
"webgpu/shader/execution/binary/f16_addition.bin": "7004a06e",
"webgpu/shader/execution/binary/f16_logical.bin": "cf61b9f0",
"webgpu/shader/execution/binary/f16_division.bin": "d67ffcf4",
"webgpu/shader/execution/binary/f16_matrix_addition.bin": "872caecc",
"webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "d4c1fa65",
"webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "410aa928",
"webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "9fea0f32",
"webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "22245ae6",
"webgpu/shader/execution/binary/f16_multiplication.bin": "bf8b1386",
"webgpu/shader/execution/binary/f16_remainder.bin": "2b2ecca8",
"webgpu/shader/execution/binary/f16_subtraction.bin": "92db6c3b",
"webgpu/shader/execution/binary/f32_addition.bin": "2ad33d40",
"webgpu/shader/execution/binary/f32_logical.bin": "168e00ad",
"webgpu/shader/execution/binary/f32_division.bin": "cda4b47f",
"webgpu/shader/execution/binary/f32_matrix_addition.bin": "a60b0194",
"webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "15ae3f35",
"webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "1c2d0770",
"webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "5f458964",
"webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "3ad4b122",
"webgpu/shader/execution/binary/f32_multiplication.bin": "2cfa41d7",
"webgpu/shader/execution/binary/f32_remainder.bin": "d881a0b5",
"webgpu/shader/execution/binary/f32_subtraction.bin": "5519529",
"webgpu/shader/execution/binary/i32_arithmetic.bin": "1ebfac8e",
"webgpu/shader/execution/binary/i32_comparison.bin": "246410e0",
"webgpu/shader/execution/binary/u32_arithmetic.bin": "5ba346a7",
"webgpu/shader/execution/binary/u32_comparison.bin": "f32cc89a",
"webgpu/shader/execution/abs.bin": "cf7035bb",
"webgpu/shader/execution/acos.bin": "f51b6639",
"webgpu/shader/execution/acosh.bin": "8703b0b9",
"webgpu/shader/execution/asin.bin": "b37659e4",
"webgpu/shader/execution/asinh.bin": "6c077b4d",
"webgpu/shader/execution/atan.bin": "d2cac8e5",
"webgpu/shader/execution/atan2.bin": "a664062f",
"webgpu/shader/execution/atanh.bin": "78678528",
"webgpu/shader/execution/bitcast.bin": "8e6fc660",
"webgpu/shader/execution/ceil.bin": "c3845564",
"webgpu/shader/execution/clamp.bin": "7fe63f9f",
"webgpu/shader/execution/cos.bin": "53e1ecb4",
"webgpu/shader/execution/cosh.bin": "60835146",
"webgpu/shader/execution/cross.bin": "ec9c38bc",
"webgpu/shader/execution/degrees.bin": "dba80a4",
"webgpu/shader/execution/determinant.bin": "df4961fb",
"webgpu/shader/execution/distance.bin": "f1d9a859",
"webgpu/shader/execution/dot.bin": "e645066f",
"webgpu/shader/execution/exp.bin": "365d8b77",
"webgpu/shader/execution/exp2.bin": "6315ce6a",
"webgpu/shader/execution/faceForward.bin": "73136fee",
"webgpu/shader/execution/floor.bin": "a9f45296",
"webgpu/shader/execution/fma.bin": "3ca02e6f",
"webgpu/shader/execution/fract.bin": "ca1a0fe5",
"webgpu/shader/execution/frexp.bin": "43885066",
"webgpu/shader/execution/inverseSqrt.bin": "de8d2609",
"webgpu/shader/execution/ldexp.bin": "d83280fa",
"webgpu/shader/execution/length.bin": "22d7feee",
"webgpu/shader/execution/log.bin": "b5255c2c",
"webgpu/shader/execution/log2.bin": "28bce946",
"webgpu/shader/execution/max.bin": "f336583c",
"webgpu/shader/execution/min.bin": "a0ed442a",
"webgpu/shader/execution/mix.bin": "761f1414",
"webgpu/shader/execution/modf.bin": "415c2c6d",
"webgpu/shader/execution/normalize.bin": "a1ee9fd1",
"webgpu/shader/execution/pack2x16float.bin": "e9c1e049",
"webgpu/shader/execution/pow.bin": "3ae9fddb",
"webgpu/shader/execution/quantizeToF16.bin": "29d70202",
"webgpu/shader/execution/radians.bin": "66df45b8",
"webgpu/shader/execution/reflect.bin": "74c93416",
"webgpu/shader/execution/refract.bin": "db1b6cd7",
"webgpu/shader/execution/round.bin": "6e17fee7",
"webgpu/shader/execution/saturate.bin": "4bd72628",
"webgpu/shader/execution/sign.bin": "516bf087",
"webgpu/shader/execution/sin.bin": "ab201566",
"webgpu/shader/execution/sinh.bin": "d174ff0d",
"webgpu/shader/execution/smoothstep.bin": "c841fdd0",
"webgpu/shader/execution/sqrt.bin": "270f222c",
"webgpu/shader/execution/step.bin": "c69ecf72",
"webgpu/shader/execution/tan.bin": "75633db4",
"webgpu/shader/execution/tanh.bin": "dec6ccb3",
"webgpu/shader/execution/transpose.bin": "a5376a18",
"webgpu/shader/execution/trunc.bin": "cb0fb7d",
"webgpu/shader/execution/unpack2x16float.bin": "f7c17562",
"webgpu/shader/execution/unpack2x16snorm.bin": "900c6570",
"webgpu/shader/execution/unpack2x16unorm.bin": "ce74966b",
"webgpu/shader/execution/unpack4x8snorm.bin": "23003de1",
"webgpu/shader/execution/unpack4x8unorm.bin": "d957b699",
"webgpu/shader/execution/unary/af_arithmetic.bin": "8eb3b38f",
"webgpu/shader/execution/unary/af_assignment.bin": "8b75cfc4",
"webgpu/shader/execution/unary/bool_conversion.bin": "91745a47",
"webgpu/shader/execution/unary/f16_arithmetic.bin": "8f3849cd",
"webgpu/shader/execution/unary/f16_conversion.bin": "b18bf8ca",
"webgpu/shader/execution/unary/f32_arithmetic.bin": "9aaa3916",
"webgpu/shader/execution/unary/f32_conversion.bin": "e435fc67",
"webgpu/shader/execution/unary/i32_arithmetic.bin": "b61cf109",
"webgpu/shader/execution/unary/i32_complement.bin": "fb8983d2",
"webgpu/shader/execution/unary/i32_conversion.bin": "912e87a6",
"webgpu/shader/execution/unary/u32_complement.bin": "57794fd7",
"webgpu/shader/execution/unary/u32_conversion.bin": "eabaa756",
"webgpu/shader/execution/unary/ai_assignment.bin": "e2db3247"
}
Binary file modified src/resources/cache/webgpu/shader/execution/clamp.bin
Binary file not shown.
49 changes: 42 additions & 7 deletions src/webgpu/shader/execution/expression/call/builtin/clamp.cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { kValue } from '../../../../../util/constants.js';
import { ScalarType, TypeI32, TypeU32 } from '../../../../../util/conversion.js';
import { ScalarType, TypeAbstractInt, TypeI32, TypeU32 } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { maxBigInt, minBigInt } from '../../../../../util/math.js';
import { Case } from '../../case.js';
import { makeCaseCache } from '../../case_cache.js';

Expand All @@ -19,8 +20,21 @@ const i32Values = [
kValue.i32.positive.max,
];

/** @returns a set of clamp test cases from an ascending list of integer values */
function generateIntegerTestCases(
const abstractFloatValues = [
kValue.i64.negative.min,
-3n,
-2n,
-1n,
0n,
1n,
2n,
3n,
0x70000000n,
kValue.i64.positive.max,
];

/** @returns a set of clamp test cases from an ascending list of concrete integer values */
function generateConcreteIntegerTestCases(
test_values: Array<number>,
type: ScalarType,
stage: 'const' | 'non_const'
Expand All @@ -37,6 +51,24 @@ function generateIntegerTestCases(
);
}

/** @returns a set of clamp test cases from an ascending list of abstract integer values */
function generateAbstractIntegerTestCases(test_values: Array<bigint>): Array<Case> {
return test_values.flatMap(low =>
test_values.flatMap(high =>
low > high
? []
: test_values.map(e => ({
input: [
TypeAbstractInt.create(e),
TypeAbstractInt.create(low),
TypeAbstractInt.create(high),
],
expected: TypeAbstractInt.create(minBigInt(maxBigInt(e, low), high)),
}))
)
);
}

function generateFloatTestCases(
test_values: readonly number[],
trait: 'f32' | 'f16' | 'abstract',
Expand Down Expand Up @@ -81,16 +113,19 @@ const fp_cases = (['f32', 'f16', 'abstract'] as const)

export const d = makeCaseCache('clamp', {
u32_non_const: () => {
return generateIntegerTestCases(u32Values, TypeU32, 'non_const');
return generateConcreteIntegerTestCases(u32Values, TypeU32, 'non_const');
},
u32_const: () => {
return generateIntegerTestCases(u32Values, TypeU32, 'const');
return generateConcreteIntegerTestCases(u32Values, TypeU32, 'const');
},
i32_non_const: () => {
return generateIntegerTestCases(i32Values, TypeI32, 'non_const');
return generateConcreteIntegerTestCases(i32Values, TypeI32, 'non_const');
},
i32_const: () => {
return generateIntegerTestCases(i32Values, TypeI32, 'const');
return generateConcreteIntegerTestCases(i32Values, TypeI32, 'const');
},
abstract_int: () => {
return generateAbstractIntegerTestCases(abstractFloatValues);
},
...fp_cases,
});
19 changes: 16 additions & 3 deletions src/webgpu/shader/execution/expression/call/builtin/clamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js'
import { GPUTest } from '../../../../../gpu_test.js';
import {
TypeAbstractFloat,
TypeAbstractInt,
TypeF16,
TypeF32,
TypeI32,
TypeU32,
} from '../../../../../util/conversion.js';
import { allInputSources, onlyConstInputSource, run } from '../../expression.js';

import { abstractFloatBuiltin, builtin } from './builtin.js';
import { abstractFloatBuiltin, abstractIntBuiltin, builtin } from './builtin.js';
import { d } from './clamp.cache.js';

export const g = makeTestGroup(GPUTest);
Expand All @@ -33,9 +34,21 @@ g.test('abstract_int')
.specURL('https://www.w3.org/TR/WGSL/#integer-builtin-functions')
.desc(`abstract int 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_int');
await run(
t,
abstractIntBuiltin('clamp'),
[TypeAbstractInt, TypeAbstractInt, TypeAbstractInt],
TypeAbstractInt,
t.params,
cases
);
});

g.test('u32')
.specURL('https://www.w3.org/TR/WGSL/#integer-builtin-functions')
Expand Down
10 changes: 10 additions & 0 deletions src/webgpu/util/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2286,3 +2286,13 @@ export function dotProduct(v1: readonly number[], v2: readonly number[]) {
export function absBigInt(v: bigint): bigint {
return v < 0n ? -v : v;
}

/** @returns the minimum from a list of bigints */
export function minBigInt(...vals: bigint[]): bigint {
return vals.reduce((prev, cur) => (cur < prev ? cur : prev));
}

/** @returns the maximum from a list of bigints */
export function maxBigInt(...vals: bigint[]): bigint {
return vals.reduce((prev, cur) => (cur > prev ? cur : prev));
}

0 comments on commit d4dad46

Please sign in to comment.