diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 27945b7a4a71..8acfa8e5cd9e 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,109 +1,109 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "5067132e", - "webgpu/shader/execution/binary/af_logical.bin": "a7bde13e", - "webgpu/shader/execution/binary/af_division.bin": "19678742", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "42689934", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "c6322f74", - "webgpu/shader/execution/binary/af_multiplication.bin": "5f12d793", - "webgpu/shader/execution/binary/af_remainder.bin": "df05ecb8", - "webgpu/shader/execution/binary/af_subtraction.bin": "a13ed62f", - "webgpu/shader/execution/binary/f16_addition.bin": "14e49495", - "webgpu/shader/execution/binary/f16_logical.bin": "9e733738", - "webgpu/shader/execution/binary/f16_division.bin": "f42b09dc", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "517b60f1", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "66a87207", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "a9c3e5f1", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "f2a25933", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "a886a0b5", - "webgpu/shader/execution/binary/f16_multiplication.bin": "be77033b", - "webgpu/shader/execution/binary/f16_remainder.bin": "50b0b02", - "webgpu/shader/execution/binary/f16_subtraction.bin": "93f65d9", - "webgpu/shader/execution/binary/f32_addition.bin": "278d2454", - "webgpu/shader/execution/binary/f32_logical.bin": "55bcf58e", - "webgpu/shader/execution/binary/f32_division.bin": "3a457201", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "660aad6a", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "a278509a", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "ace2da73", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "8f986eff", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "c26e2700", - "webgpu/shader/execution/binary/f32_multiplication.bin": "4cdfcb27", - "webgpu/shader/execution/binary/f32_remainder.bin": "e3119b6d", - "webgpu/shader/execution/binary/f32_subtraction.bin": "d71a5a86", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "b880610d", - "webgpu/shader/execution/binary/i32_comparison.bin": "f2f668b2", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "164ebf51", - "webgpu/shader/execution/binary/u32_comparison.bin": "35a31af1", - "webgpu/shader/execution/abs.bin": "ec6cc570", - "webgpu/shader/execution/acos.bin": "d61bb028", - "webgpu/shader/execution/acosh.bin": "609af763", - "webgpu/shader/execution/asin.bin": "64bf727b", - "webgpu/shader/execution/asinh.bin": "273b8028", - "webgpu/shader/execution/atan.bin": "f6384fbb", - "webgpu/shader/execution/atan2.bin": "64163f99", - "webgpu/shader/execution/atanh.bin": "bacbfd59", - "webgpu/shader/execution/bitcast.bin": "4a0d7d41", - "webgpu/shader/execution/ceil.bin": "48020ceb", - "webgpu/shader/execution/clamp.bin": "402bf6c9", - "webgpu/shader/execution/cos.bin": "6b4d2358", - "webgpu/shader/execution/cosh.bin": "dccbe75f", - "webgpu/shader/execution/cross.bin": "a550a630", - "webgpu/shader/execution/degrees.bin": "72d5163b", - "webgpu/shader/execution/determinant.bin": "f1378c53", - "webgpu/shader/execution/distance.bin": "48ee3f00", - "webgpu/shader/execution/dot.bin": "d2f81d75", - "webgpu/shader/execution/exp.bin": "36af62ed", - "webgpu/shader/execution/exp2.bin": "8675703d", - "webgpu/shader/execution/faceForward.bin": "568cc6b8", - "webgpu/shader/execution/floor.bin": "e7ab0a1e", - "webgpu/shader/execution/fma.bin": "3b4ebf3f", - "webgpu/shader/execution/fract.bin": "130ceb8a", - "webgpu/shader/execution/frexp.bin": "a5868197", - "webgpu/shader/execution/inverseSqrt.bin": "e2a63a07", - "webgpu/shader/execution/ldexp.bin": "62948ba1", - "webgpu/shader/execution/length.bin": "ce1440e5", - "webgpu/shader/execution/log.bin": "69b69fa1", - "webgpu/shader/execution/log2.bin": "dc5c999d", - "webgpu/shader/execution/max.bin": "58fc2b9a", - "webgpu/shader/execution/min.bin": "84eec3dd", - "webgpu/shader/execution/mix.bin": "8c176bc2", - "webgpu/shader/execution/modf.bin": "9fcb3629", - "webgpu/shader/execution/normalize.bin": "4bf45f2a", - "webgpu/shader/execution/pack2x16float.bin": "74aac2f5", - "webgpu/shader/execution/pow.bin": "976aaac6", - "webgpu/shader/execution/quantizeToF16.bin": "9b60dec9", - "webgpu/shader/execution/radians.bin": "f37fa7ad", - "webgpu/shader/execution/reflect.bin": "d0da3a14", - "webgpu/shader/execution/refract.bin": "f426dd6e", - "webgpu/shader/execution/round.bin": "ffc365ff", - "webgpu/shader/execution/saturate.bin": "253ffcc7", - "webgpu/shader/execution/sign.bin": "ee72deed", - "webgpu/shader/execution/sin.bin": "c685df75", - "webgpu/shader/execution/sinh.bin": "404bade3", - "webgpu/shader/execution/smoothstep.bin": "4631743e", - "webgpu/shader/execution/sqrt.bin": "29d895f1", - "webgpu/shader/execution/step.bin": "e246e2ed", - "webgpu/shader/execution/tan.bin": "37d5e55c", - "webgpu/shader/execution/tanh.bin": "4964f0af", - "webgpu/shader/execution/transpose.bin": "c0688654", - "webgpu/shader/execution/trunc.bin": "29a4bedf", - "webgpu/shader/execution/unpack2x16float.bin": "45a53d8d", - "webgpu/shader/execution/unpack2x16snorm.bin": "827b024f", - "webgpu/shader/execution/unpack2x16unorm.bin": "dc1bd85a", - "webgpu/shader/execution/unpack4x8snorm.bin": "f9525320", - "webgpu/shader/execution/unpack4x8unorm.bin": "27facc7f", - "webgpu/shader/execution/unary/af_arithmetic.bin": "213bf535", - "webgpu/shader/execution/unary/af_assignment.bin": "7d092411", - "webgpu/shader/execution/unary/bool_conversion.bin": "ef64f29e", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "e7a930c", - "webgpu/shader/execution/unary/f16_conversion.bin": "ed0ad482", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "e32dcdbd", - "webgpu/shader/execution/unary/f32_conversion.bin": "b0b23a1a", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "5a180128", - "webgpu/shader/execution/unary/i32_complement.bin": "7266637b", - "webgpu/shader/execution/unary/i32_conversion.bin": "5f788044", - "webgpu/shader/execution/unary/u32_complement.bin": "44efa30e", - "webgpu/shader/execution/unary/u32_conversion.bin": "d9aec403", - "webgpu/shader/execution/unary/ai_assignment.bin": "cb574671", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "9c9ef2a4", - "webgpu/shader/execution/unary/ai_arithmetic.bin": "6fadb5ac" + "webgpu/shader/execution/binary/af_addition.bin": "bbc5103c", + "webgpu/shader/execution/binary/af_logical.bin": "a483b968", + "webgpu/shader/execution/binary/af_division.bin": "7c221c28", + "webgpu/shader/execution/binary/af_matrix_addition.bin": "ebab2b30", + "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "6078475c", + "webgpu/shader/execution/binary/af_multiplication.bin": "66ad501", + "webgpu/shader/execution/binary/af_remainder.bin": "5a87ed27", + "webgpu/shader/execution/binary/af_subtraction.bin": "66bad739", + "webgpu/shader/execution/binary/f16_addition.bin": "3ff7fed3", + "webgpu/shader/execution/binary/f16_logical.bin": "b89ca9b9", + "webgpu/shader/execution/binary/f16_division.bin": "a01c2499", + "webgpu/shader/execution/binary/f16_matrix_addition.bin": "cb64b0b6", + "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "edbbdd7b", + "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "f5ded61d", + "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "11ad421b", + "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "5ef65699", + "webgpu/shader/execution/binary/f16_multiplication.bin": "24c6a56f", + "webgpu/shader/execution/binary/f16_remainder.bin": "d47a8347", + "webgpu/shader/execution/binary/f16_subtraction.bin": "755f4b0b", + "webgpu/shader/execution/binary/f32_addition.bin": "6db93d07", + "webgpu/shader/execution/binary/f32_logical.bin": "c7370c09", + "webgpu/shader/execution/binary/f32_division.bin": "c28058b5", + "webgpu/shader/execution/binary/f32_matrix_addition.bin": "3f49bac9", + "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "592cc2c4", + "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "e3750b3c", + "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "b16d21e2", + "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "c982cd63", + "webgpu/shader/execution/binary/f32_multiplication.bin": "835ec6ee", + "webgpu/shader/execution/binary/f32_remainder.bin": "daf70203", + "webgpu/shader/execution/binary/f32_subtraction.bin": "2fc781f8", + "webgpu/shader/execution/binary/i32_arithmetic.bin": "a0b0a016", + "webgpu/shader/execution/binary/i32_comparison.bin": "f3d9b3f9", + "webgpu/shader/execution/binary/u32_arithmetic.bin": "16e32fd", + "webgpu/shader/execution/binary/u32_comparison.bin": "da33cc5d", + "webgpu/shader/execution/abs.bin": "e8dce87a", + "webgpu/shader/execution/acos.bin": "2762bad", + "webgpu/shader/execution/acosh.bin": "a3b96c53", + "webgpu/shader/execution/asin.bin": "1d9d590", + "webgpu/shader/execution/asinh.bin": "c2cc05", + "webgpu/shader/execution/atan.bin": "3f701bba", + "webgpu/shader/execution/atan2.bin": "559fb65a", + "webgpu/shader/execution/atanh.bin": "6d352d21", + "webgpu/shader/execution/bitcast.bin": "ec72fa7", + "webgpu/shader/execution/ceil.bin": "42f80be0", + "webgpu/shader/execution/clamp.bin": "1440b818", + "webgpu/shader/execution/cos.bin": "c5da20d", + "webgpu/shader/execution/cosh.bin": "a01e8091", + "webgpu/shader/execution/cross.bin": "c756d650", + "webgpu/shader/execution/degrees.bin": "2c481603", + "webgpu/shader/execution/determinant.bin": "1e67d0f3", + "webgpu/shader/execution/distance.bin": "9a305a9d", + "webgpu/shader/execution/dot.bin": "1a3853b8", + "webgpu/shader/execution/exp.bin": "11112dba", + "webgpu/shader/execution/exp2.bin": "583e9c6a", + "webgpu/shader/execution/faceForward.bin": "7528aff7", + "webgpu/shader/execution/floor.bin": "96044530", + "webgpu/shader/execution/fma.bin": "8e795844", + "webgpu/shader/execution/fract.bin": "997d1bb5", + "webgpu/shader/execution/frexp.bin": "4a1efc69", + "webgpu/shader/execution/inverseSqrt.bin": "3e7d725", + "webgpu/shader/execution/ldexp.bin": "79646a61", + "webgpu/shader/execution/length.bin": "177f62e6", + "webgpu/shader/execution/log.bin": "4e0f535c", + "webgpu/shader/execution/log2.bin": "a961449", + "webgpu/shader/execution/max.bin": "3d764667", + "webgpu/shader/execution/min.bin": "c02f865", + "webgpu/shader/execution/mix.bin": "9431b1b0", + "webgpu/shader/execution/modf.bin": "1fdcef82", + "webgpu/shader/execution/normalize.bin": "78dd7ec5", + "webgpu/shader/execution/pack2x16float.bin": "e6859c1a", + "webgpu/shader/execution/pow.bin": "4877dcfb", + "webgpu/shader/execution/quantizeToF16.bin": "c80d80ea", + "webgpu/shader/execution/radians.bin": "ac062ec8", + "webgpu/shader/execution/reflect.bin": "a4e70e5a", + "webgpu/shader/execution/refract.bin": "2ca0bc97", + "webgpu/shader/execution/round.bin": "3471eaad", + "webgpu/shader/execution/saturate.bin": "5bb3dced", + "webgpu/shader/execution/sign.bin": "5b54134", + "webgpu/shader/execution/sin.bin": "c5bb923c", + "webgpu/shader/execution/sinh.bin": "122dba1b", + "webgpu/shader/execution/smoothstep.bin": "91223043", + "webgpu/shader/execution/sqrt.bin": "e630cb4e", + "webgpu/shader/execution/step.bin": "a3349b96", + "webgpu/shader/execution/tan.bin": "ecc23f5e", + "webgpu/shader/execution/tanh.bin": "96c30607", + "webgpu/shader/execution/transpose.bin": "8968d6f9", + "webgpu/shader/execution/trunc.bin": "6c17efc2", + "webgpu/shader/execution/unpack2x16float.bin": "f035f149", + "webgpu/shader/execution/unpack2x16snorm.bin": "e92a1762", + "webgpu/shader/execution/unpack2x16unorm.bin": "abe4e594", + "webgpu/shader/execution/unpack4x8snorm.bin": "9bb9c594", + "webgpu/shader/execution/unpack4x8unorm.bin": "53ceebc", + "webgpu/shader/execution/unary/af_arithmetic.bin": "cd5b7fa3", + "webgpu/shader/execution/unary/af_assignment.bin": "86b66309", + "webgpu/shader/execution/unary/bool_conversion.bin": "dd71f171", + "webgpu/shader/execution/unary/f16_arithmetic.bin": "9537b14", + "webgpu/shader/execution/unary/f16_conversion.bin": "3948e7eb", + "webgpu/shader/execution/unary/f32_arithmetic.bin": "f8aa7493", + "webgpu/shader/execution/unary/f32_conversion.bin": "7ee18c9e", + "webgpu/shader/execution/unary/i32_arithmetic.bin": "c69716e2", + "webgpu/shader/execution/unary/i32_complement.bin": "70c49c98", + "webgpu/shader/execution/unary/i32_conversion.bin": "83218e69", + "webgpu/shader/execution/unary/u32_complement.bin": "84f3d299", + "webgpu/shader/execution/unary/u32_conversion.bin": "8f5bad00", + "webgpu/shader/execution/unary/ai_assignment.bin": "c7e6ac33", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "81c11ec2", + "webgpu/shader/execution/unary/ai_arithmetic.bin": "3d27dc97" } \ No newline at end of file diff --git a/src/resources/cache/webgpu/shader/execution/dot.bin b/src/resources/cache/webgpu/shader/execution/dot.bin index 9783146bff44..c40881d3ffda 100644 Binary files a/src/resources/cache/webgpu/shader/execution/dot.bin and b/src/resources/cache/webgpu/shader/execution/dot.bin differ diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 2730fbe84a73..f2d021a7287b 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1263,8 +1263,14 @@ "webgpu:shader,execution,expression,call,builtin,dot:f32_vec2:*": { "subcaseMS": 210.350 }, "webgpu:shader,execution,expression,call,builtin,dot:f32_vec3:*": { "subcaseMS": 11.176 }, "webgpu:shader,execution,expression,call,builtin,dot:f32_vec4:*": { "subcaseMS": 11.876 }, - "webgpu:shader,execution,expression,call,builtin,dot:i32:*": { "subcaseMS": 3.103 }, - "webgpu:shader,execution,expression,call,builtin,dot:u32:*": { "subcaseMS": 3.101 }, + "webgpu:shader,execution,expression,call,builtin,dot:i32_vec2:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot:i32_vec3:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot:i32_vec4:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot:u32_vec2:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot:u32_vec3:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot:u32_vec4:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,call,builtin,dot4I8Packed:basic:*": { "subcaseMS": 1.000 }, + "webgpu:shader,execution,expression,call,builtin,dot4U8Packed:basic:*": { "subcaseMS": 1.000 }, "webgpu:shader,execution,expression,call,builtin,dpdx:f32:*": { "subcaseMS": 22.804 }, "webgpu:shader,execution,expression,call,builtin,dpdxCoarse:f32:*": { "subcaseMS": 22.404 }, "webgpu:shader,execution,expression,call,builtin,dpdxFine:f32:*": { "subcaseMS": 17.708 }, diff --git a/src/webgpu/shader/execution/expression/call/builtin/dot.cache.ts b/src/webgpu/shader/execution/expression/call/builtin/dot.cache.ts index 73b78c11d725..881327e70118 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/dot.cache.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/dot.cache.ts @@ -4,10 +4,18 @@ import { kValue } from '../../../../../util/constants.js'; import { FP } from '../../../../../util/floating_point.js'; import { calculatePermutations, + sparseVectorI32Range, sparseVectorI64Range, + sparseVectorU32Range, + vectorI32Range, vectorI64Range, + vectorU32Range, } from '../../../../../util/math.js'; -import { generateVectorVectorToI64Cases } from '../../case.js'; +import { + generateVectorVectorToI32Cases, + generateVectorVectorToI64Cases, + generateVectorVectorToU32Cases, +} from '../../case.js'; import { makeCaseCache } from '../../case_cache.js'; function ai_dot(x: bigint[], y: bigint[]): bigint | undefined { @@ -44,6 +52,11 @@ function ai_dot(x: bigint[], y: bigint[]): bigint | undefined { return !kValue.i64.isOOB(result) ? result : undefined; } +function ci_dot(x: number[], y: number[]): number | undefined { + assert(x.length === y.length, 'Cannot calculate dot for vectors of different lengths'); + return x.reduce((prev, _, idx) => prev + Math.imul(x[idx], y[idx]), 0); +} + // Cases: [f32|f16]_vecN_[non_]const const float_cases = (['f32', 'f16'] as const) .flatMap(trait => @@ -75,6 +88,24 @@ const cases = { abstract_int_vec4: () => { return generateVectorVectorToI64Cases(sparseVectorI64Range(4), sparseVectorI64Range(4), ai_dot); }, + i32_vec2: () => { + return generateVectorVectorToI32Cases(vectorI32Range(2), vectorI32Range(2), ci_dot); + }, + i32_vec3: () => { + return generateVectorVectorToI32Cases(sparseVectorI32Range(3), sparseVectorI32Range(3), ci_dot); + }, + i32_vec4: () => { + return generateVectorVectorToI32Cases(sparseVectorI32Range(4), sparseVectorI32Range(4), ci_dot); + }, + u32_vec2: () => { + return generateVectorVectorToU32Cases(vectorU32Range(2), vectorU32Range(2), ci_dot); + }, + u32_vec3: () => { + return generateVectorVectorToU32Cases(sparseVectorU32Range(3), sparseVectorU32Range(3), ci_dot); + }, + u32_vec4: () => { + return generateVectorVectorToU32Cases(sparseVectorU32Range(4), sparseVectorU32Range(4), ci_dot); + }, }; export const d = makeCaseCache('dot', cases); diff --git a/src/webgpu/shader/execution/expression/call/builtin/dot.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/dot.spec.ts index 6e9eb18b558e..5d27e5044dea 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/dot.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/dot.spec.ts @@ -8,7 +8,14 @@ Returns the dot product of e1 and e2. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../../gpu_test.js'; -import { TypeAbstractInt, TypeF16, TypeF32, TypeVec } from '../../../../../util/conversion.js'; +import { + TypeAbstractInt, + TypeF16, + TypeF32, + TypeI32, + TypeU32, + TypeVec, +} from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; import { abstractIntBuiltin, builtin } from './builtin.js'; @@ -18,7 +25,7 @@ export const g = makeTestGroup(GPUTest); g.test('abstract_int_vec2') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') - .desc(`abstract float tests using vec2s`) + .desc(`abstract integer tests using vec2s`) .params(u => u.combine('inputSource', onlyConstInputSource)) .fn(async t => { const cases = await d.get('abstract_int_vec2'); @@ -34,7 +41,7 @@ g.test('abstract_int_vec2') g.test('abstract_int_vec3') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') - .desc(`abstract float tests using vec3s`) + .desc(`abstract integer tests using vec3s`) .params(u => u.combine('inputSource', onlyConstInputSource)) .fn(async t => { const cases = await d.get('abstract_int_vec3'); @@ -50,7 +57,7 @@ g.test('abstract_int_vec3') g.test('abstract_int_vec4') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') - .desc(`abstract float tests using vec4s`) + .desc(`abstract integer tests using vec4s`) .params(u => u.combine('inputSource', onlyConstInputSource)) .fn(async t => { const cases = await d.get('abstract_int_vec4'); @@ -64,17 +71,101 @@ g.test('abstract_int_vec4') ); }); -g.test('i32') +g.test('i32_vec2') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') - .desc(`i32 tests`) + .desc(`i32 tests using vec2s`) .params(u => u.combine('inputSource', allInputSources)) - .unimplemented(); + .fn(async t => { + const cases = await d.get('i32_vec2'); + await run( + t, + builtin('dot'), + [TypeVec(2, TypeI32), TypeVec(2, TypeI32)], + TypeI32, + t.params, + cases + ); + }); -g.test('u32') +g.test('i32_vec3') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') - .desc(`u32 tests`) + .desc(`i32 tests using vec3s`) .params(u => u.combine('inputSource', allInputSources)) - .unimplemented(); + .fn(async t => { + const cases = await d.get('i32_vec3'); + await run( + t, + builtin('dot'), + [TypeVec(3, TypeI32), TypeVec(3, TypeI32)], + TypeI32, + t.params, + cases + ); + }); + +g.test('i32_vec4') + .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') + .desc(`i32 tests using vec4s`) + .params(u => u.combine('inputSource', allInputSources)) + .fn(async t => { + const cases = await d.get('i32_vec4'); + await run( + t, + builtin('dot'), + [TypeVec(4, TypeI32), TypeVec(4, TypeI32)], + TypeI32, + t.params, + cases + ); + }); + +g.test('u32_vec2') + .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') + .desc(`u32 tests using vec2s`) + .params(u => u.combine('inputSource', allInputSources)) + .fn(async t => { + const cases = await d.get('u32_vec2'); + await run( + t, + builtin('dot'), + [TypeVec(2, TypeU32), TypeVec(2, TypeU32)], + TypeU32, + t.params, + cases + ); + }); + +g.test('u32_vec3') + .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') + .desc(`u32 tests using vec3s`) + .params(u => u.combine('inputSource', allInputSources)) + .fn(async t => { + const cases = await d.get('u32_vec3'); + await run( + t, + builtin('dot'), + [TypeVec(3, TypeU32), TypeVec(3, TypeU32)], + TypeU32, + t.params, + cases + ); + }); + +g.test('u32_vec4') + .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') + .desc(`u32 tests using vec4s`) + .params(u => u.combine('inputSource', allInputSources)) + .fn(async t => { + const cases = await d.get('u32_vec4'); + await run( + t, + builtin('dot'), + [TypeVec(4, TypeU32), TypeVec(4, TypeU32)], + TypeU32, + t.params, + cases + ); + }); g.test('abstract_float') .specURL('https://www.w3.org/TR/WGSL/#vector-builtin-functions') diff --git a/src/webgpu/shader/execution/expression/case.ts b/src/webgpu/shader/execution/expression/case.ts index 1f79b003a833..1cbde7be754f 100644 --- a/src/webgpu/shader/execution/expression/case.ts +++ b/src/webgpu/shader/execution/expression/case.ts @@ -348,6 +348,34 @@ function generateVectorVectorToScalarCases( }); } +/** + * @returns array of Case for the input params with op applied + * @param param0s array of vector params (2, 3, or 4 elements) for the first param + * @param param1s array of vector params (2, 3, or 4 elements) for the second param + * @param op the op to apply to each pair of vectors + */ +export function generateVectorVectorToI32Cases( + param0s: ROArrayArray, + param1s: ROArrayArray, + op: VectorVectorToScalarOp +): Case[] { + return generateVectorVectorToScalarCases(param0s, param1s, op, quantizeToI32, i32); +} + +/** + * @returns array of Case for the input params with op applied + * @param param0s array of vector params (2, 3, or 4 elements) for the first param + * @param param1s array of vector params (2, 3, or 4 elements) for the second param + * @param op the op to apply to each pair of vectors + */ +export function generateVectorVectorToU32Cases( + param0s: ROArrayArray, + param1s: ROArrayArray, + op: VectorVectorToScalarOp +): Case[] { + return generateVectorVectorToScalarCases(param0s, param1s, op, quantizeToU32, u32); +} + /** * @returns array of Case for the input params with op applied * @param param0s array of vector params (2, 3, or 4 elements) for the first param diff --git a/src/webgpu/util/math.ts b/src/webgpu/util/math.ts index 090fcf0fe208..45ea48557b89 100644 --- a/src/webgpu/util/math.ts +++ b/src/webgpu/util/math.ts @@ -1204,6 +1204,38 @@ export function vectorI32Range(dim: number): ROArrayArray { return kVectorI32Values[dim]; } +const kSparseVectorI32Values = { + 2: sparseI32Range().map((i, idx) => [idx % 2 === 0 ? i : idx, idx % 2 === 1 ? i : -idx]), + 3: sparseI32Range().map((i, idx) => [ + idx % 3 === 0 ? i : idx, + idx % 3 === 1 ? i : -idx, + idx % 3 === 2 ? i : idx, + ]), + 4: sparseI32Range().map((i, idx) => [ + idx % 4 === 0 ? i : idx, + idx % 4 === 1 ? i : -idx, + idx % 4 === 2 ? i : idx, + idx % 4 === 3 ? i : -idx, + ]), +}; + +/** + * Minimal set of vectors, indexed by dimension, that contain interesting + * abstract integer values. + * + * This is an even more stripped down version of `vectorI32Range` for when + * pairs of vectors are being tested. + * All interesting integers from sparseI32Range are guaranteed to be + * tested, but not in every position. + */ +export function sparseVectorI32Range(dim: number): ROArrayArray { + assert( + dim === 2 || dim === 3 || dim === 4, + 'sparseVectorI32Range only accepts dimensions 2, 3, and 4' + ); + return kSparseVectorI32Values[dim]; +} + /** * @returns an ascending sorted array of numbers spread over the entire range of 32-bit signed ints * @@ -1282,6 +1314,38 @@ export function vectorU32Range(dim: number): ROArrayArray { return kVectorU32Values[dim]; } +const kSparseVectorU32Values = { + 2: sparseU32Range().map((i, idx) => [idx % 2 === 0 ? i : idx, idx % 2 === 1 ? i : -idx]), + 3: sparseU32Range().map((i, idx) => [ + idx % 3 === 0 ? i : idx, + idx % 3 === 1 ? i : -idx, + idx % 3 === 2 ? i : idx, + ]), + 4: sparseU32Range().map((i, idx) => [ + idx % 4 === 0 ? i : idx, + idx % 4 === 1 ? i : -idx, + idx % 4 === 2 ? i : idx, + idx % 4 === 3 ? i : -idx, + ]), +}; + +/** + * Minimal set of vectors, indexed by dimension, that contain interesting + * abstract integer values. + * + * This is an even more stripped down version of `vectorU32Range` for when + * pairs of vectors are being tested. + * All interesting integers from sparseU32Range are guaranteed to be + * tested, but not in every position. + */ +export function sparseVectorU32Range(dim: number): ROArrayArray { + assert( + dim === 2 || dim === 3 || dim === 4, + 'sparseVectorU32Range only accepts dimensions 2, 3, and 4' + ); + return kSparseVectorU32Values[dim]; +} + /** * @returns an ascending sorted array of numbers spread over the entire range of 32-bit unsigned ints *