From 6493b876ade082dc4e4d883691e8900d5b42f01c Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 7 Feb 2024 16:48:40 -0500 Subject: [PATCH] wgsl: Implement AbstractInt `abs` execution tests (#3372) Issue #1297 --- src/resources/cache/hashes.json | 210 +++++++++--------- .../cache/webgpu/shader/execution/abs.bin | Bin 14696 -> 17976 bytes .../expression/call/builtin/abs.cache.ts | 35 +-- .../expression/call/builtin/abs.spec.ts | 23 +- .../expression/call/builtin/builtin.ts | 8 +- .../expression/call/builtin/clamp.spec.ts | 4 +- .../expression/call/builtin/cross.spec.ts | 4 +- .../expression/call/builtin/degrees.spec.ts | 4 +- .../expression/call/builtin/floor.spec.ts | 11 +- .../expression/call/builtin/fma.spec.ts | 4 +- .../expression/call/builtin/max.spec.ts | 4 +- .../expression/call/builtin/min.spec.ts | 4 +- .../expression/call/builtin/mix.spec.ts | 10 +- .../expression/call/builtin/radians.spec.ts | 4 +- .../expression/call/builtin/round.spec.ts | 11 +- .../expression/call/builtin/saturate.spec.ts | 4 +- .../expression/call/builtin/select.spec.ts | 6 +- .../expression/call/builtin/sign.spec.ts | 11 +- .../expression/call/builtin/transpose.spec.ts | 4 +- .../expression/call/builtin/trunc.spec.ts | 11 +- src/webgpu/util/math.ts | 40 ++-- 21 files changed, 234 insertions(+), 178 deletions(-) diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 4ea6f2bbb6a4..a825a4d57297 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,107 +1,107 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "aa27047a", - "webgpu/shader/execution/binary/af_logical.bin": "1be45a15", - "webgpu/shader/execution/binary/af_division.bin": "1d5478a3", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "22e327bb", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "535adbcf", - "webgpu/shader/execution/binary/af_multiplication.bin": "a1a524dd", - "webgpu/shader/execution/binary/af_remainder.bin": "64da4005", - "webgpu/shader/execution/binary/af_subtraction.bin": "7499bd8f", - "webgpu/shader/execution/binary/f16_addition.bin": "a79e7634", - "webgpu/shader/execution/binary/f16_logical.bin": "6d6d84f0", - "webgpu/shader/execution/binary/f16_division.bin": "8dad99dd", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "dfff55ea", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "ef3d6371", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "474d4d62", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "9f65b81e", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "a7c61fa8", - "webgpu/shader/execution/binary/f16_multiplication.bin": "3ec0a3fa", - "webgpu/shader/execution/binary/f16_remainder.bin": "eff48d50", - "webgpu/shader/execution/binary/f16_subtraction.bin": "a0308540", - "webgpu/shader/execution/binary/f32_addition.bin": "8e83afd5", - "webgpu/shader/execution/binary/f32_logical.bin": "4125d7f7", - "webgpu/shader/execution/binary/f32_division.bin": "60d96931", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "10925c0f", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "bc662f4b", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "6cc9356", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "6122185c", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "fba16690", - "webgpu/shader/execution/binary/f32_multiplication.bin": "864c571a", - "webgpu/shader/execution/binary/f32_remainder.bin": "3426f2d", - "webgpu/shader/execution/binary/f32_subtraction.bin": "210cf552", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "c2ec2f0d", - "webgpu/shader/execution/binary/i32_comparison.bin": "49ca656", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "75343a93", - "webgpu/shader/execution/binary/u32_comparison.bin": "d686732c", - "webgpu/shader/execution/abs.bin": "4897157f", - "webgpu/shader/execution/acos.bin": "b1569965", - "webgpu/shader/execution/acosh.bin": "7aed8429", - "webgpu/shader/execution/asin.bin": "6dd6d472", - "webgpu/shader/execution/asinh.bin": "ed7035da", - "webgpu/shader/execution/atan.bin": "6471489d", - "webgpu/shader/execution/atan2.bin": "5ca1736c", - "webgpu/shader/execution/atanh.bin": "d914536a", - "webgpu/shader/execution/bitcast.bin": "411d035b", - "webgpu/shader/execution/ceil.bin": "c1d71a4a", - "webgpu/shader/execution/clamp.bin": "b419a6af", - "webgpu/shader/execution/cos.bin": "915d48e6", - "webgpu/shader/execution/cosh.bin": "ac2e16ef", - "webgpu/shader/execution/cross.bin": "2a28bf13", - "webgpu/shader/execution/degrees.bin": "8cb08f02", - "webgpu/shader/execution/determinant.bin": "5123cd87", - "webgpu/shader/execution/distance.bin": "5922de8d", - "webgpu/shader/execution/dot.bin": "179cb14c", - "webgpu/shader/execution/exp.bin": "5b8a41ac", - "webgpu/shader/execution/exp2.bin": "79f67b6f", - "webgpu/shader/execution/faceForward.bin": "bef1acc1", - "webgpu/shader/execution/floor.bin": "4ab82df2", - "webgpu/shader/execution/fma.bin": "3d1e954f", - "webgpu/shader/execution/fract.bin": "87b4e968", - "webgpu/shader/execution/frexp.bin": "8a5719ed", - "webgpu/shader/execution/inverseSqrt.bin": "a4e761a1", - "webgpu/shader/execution/ldexp.bin": "405cd0e8", - "webgpu/shader/execution/length.bin": "49306c8d", - "webgpu/shader/execution/log.bin": "1da6254", - "webgpu/shader/execution/log2.bin": "453872cb", - "webgpu/shader/execution/max.bin": "3733f691", - "webgpu/shader/execution/min.bin": "ec95807c", - "webgpu/shader/execution/mix.bin": "6ad867d0", - "webgpu/shader/execution/modf.bin": "f5f3d76c", - "webgpu/shader/execution/normalize.bin": "1129c001", - "webgpu/shader/execution/pack2x16float.bin": "21ef7dac", - "webgpu/shader/execution/pow.bin": "c683aef1", - "webgpu/shader/execution/quantizeToF16.bin": "928a0377", - "webgpu/shader/execution/radians.bin": "96d83aad", - "webgpu/shader/execution/reflect.bin": "a9e90f92", - "webgpu/shader/execution/refract.bin": "6bcf301c", - "webgpu/shader/execution/round.bin": "848a274f", - "webgpu/shader/execution/saturate.bin": "ba26c060", - "webgpu/shader/execution/sign.bin": "b5491fd0", - "webgpu/shader/execution/sin.bin": "6a5ccc2e", - "webgpu/shader/execution/sinh.bin": "87fdbef0", - "webgpu/shader/execution/smoothstep.bin": "79d09859", - "webgpu/shader/execution/sqrt.bin": "80e706d7", - "webgpu/shader/execution/step.bin": "5d1e998e", - "webgpu/shader/execution/tan.bin": "5fb554c8", - "webgpu/shader/execution/tanh.bin": "36f0abea", - "webgpu/shader/execution/transpose.bin": "f093512c", - "webgpu/shader/execution/trunc.bin": "b4e061", - "webgpu/shader/execution/unpack2x16float.bin": "7e352e7b", - "webgpu/shader/execution/unpack2x16snorm.bin": "1dd02f60", - "webgpu/shader/execution/unpack2x16unorm.bin": "fc393ee2", - "webgpu/shader/execution/unpack4x8snorm.bin": "c2dfa32c", - "webgpu/shader/execution/unpack4x8unorm.bin": "e657b33a", - "webgpu/shader/execution/unary/af_arithmetic.bin": "df9fb9ed", - "webgpu/shader/execution/unary/af_assignment.bin": "9f6a07fa", - "webgpu/shader/execution/unary/bool_conversion.bin": "740698f1", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "2d6ff5f9", - "webgpu/shader/execution/unary/f16_conversion.bin": "bf5e8c3c", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "1170ad1b", - "webgpu/shader/execution/unary/f32_conversion.bin": "83d099ec", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "8bb3b84d", - "webgpu/shader/execution/unary/i32_complement.bin": "e5fe3ec6", - "webgpu/shader/execution/unary/i32_conversion.bin": "a2c4961", - "webgpu/shader/execution/unary/u32_complement.bin": "11bcaed", - "webgpu/shader/execution/unary/u32_conversion.bin": "55f3f929", - "webgpu/shader/execution/unary/ai_assignment.bin": "4c502a7e" + "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" } \ No newline at end of file diff --git a/src/resources/cache/webgpu/shader/execution/abs.bin b/src/resources/cache/webgpu/shader/execution/abs.bin index 16111ac66a32c2290a9d7f22be4b0e7d3ef23aab..4cba9b72dff4e34c6a8b77120479331d2a28ab39 100644 GIT binary patch delta 3347 zcmZ|ReKgf~90%~<6&2Fh@=(O2v|6^xL#HP;hf``T<)M@iT^UMUmxTJ2NS=C9-54P% zq4cPx<4kKh4b`%>MOb0SLud3vMcD89{@&lU@7Dd}-uwE#KfmAip5MLa_r7hitH~0H z>Ul}7@x;*_$F1djxlm5d$%J=)!mBsu&joWKg5+GJkf%ZaoRY3)c;O@!)+8M zr9#GWnnTax(~kE!eDAs37(*?ZCvINqxvk|nkNKb5mQMDP+R%Ku{<#M^=|AywATXVe zRNEU#2aZU0#Px2Dqxq4Bjg#!=*U>z1!hyQ-A12XU649CEQ02N48xF?n_*}Cp+z$8W zTFC1E=%D#9&zcmok9l1>ki2$U#_*_&7#tu!_KV+}SifzsNBFhFZ(j!Nf=?wl1P;?w zM8n@1X|%?6JIBHcn!636G>W6(0#}3mS<$X>uzO)^h!4N3Q20K`C9Z2O8M(Vjwi`A# za(cCOe9BfhLshqS;7(CIysodqTr$HY0)ARDQ=(z7k^pNv-5%&J>ko%x%OAadlqySv zqwP#a@Fu}2VOYpt{q@2{!2?O~%DnSeE~iT5u=k#*F2|}9DR9n~SnX1)RWjIZ)NFq( z^?-eF;ftGT&wCV`;0DtYtM#`X55Q)PPJGqTnWY=Ckhk|nP4Xt&RM>O#Jd4nM*Ms4= z$@_0Pq%S`VtA>Wmx+Xmn2)7!I*W0%!Mgfm)Zff6jd0POitvbi@L~V5%{Irj+s9t4m z>5m2DD~{90C@eGJriG<UnSn->w#_Kj3uN%HCp_*I1!&*FL4@jD>G!H&?D!*tgXLIKeqS3H+KrwMt>{tneMj$31t1-Dk8M zwVs$=CYt98?ijAGeCTbDfsE7v_3ZW~*Wq=+k{)lp3$}1r{DYbdYyAp1DPppPUuD}I zIJw3?Nb1vf3zl1y9ZJtqodsJL2d^&I>8mCdZXZ?7sd;vts+JfqZZb<>FRV)a||3+uXo+q^UhPHmHTsXX6?4cxidb%K<{66CrhT>=!S=XSnlEU z+dK_;P1TB^ut~r6!ns!YhZ5^PRf7k`2P{!;GW7UYmk2AGL;H)N@`Vhr2e95k%7)If zzDLT2=B$HA*9bXJHvDISSV78$o`AIqDI4K)k$Khwq-`F z4q zHc@sBudp=2z|g`w9!JW?7&+@Vq-;!)v(_hNGZ8s!xzIJdP&V|=q+EE{C8TVo-~_B^ zk+PYFob@YGHlHJBEp!d9EE{_370ZX3CuL)U6R delta 38 tcmdnd!}y|zk$EHIVmUz$1_p*ih9rh!h7yJ%AS-$DK{?^gH{=#b0RYe*3itp3 diff --git a/src/webgpu/shader/execution/expression/call/builtin/abs.cache.ts b/src/webgpu/shader/execution/expression/call/builtin/abs.cache.ts index caed2f469678..9634ae8f347a 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/abs.cache.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/abs.cache.ts @@ -1,17 +1,26 @@ +import { abstractInt } from '../../../../../util/conversion.js'; import { FP } from '../../../../../util/floating_point.js'; -import { makeCaseCache } from '../../case_cache.js'; +import { absBigInt, fullI64Range } from '../../../../../util/math.js'; +import { CaseListBuilder, makeCaseCache } from '../../case_cache.js'; -// Cases: [f32|f16|abstract] -const cases = (['f32', 'f16', 'abstract'] as const) - .map(trait => ({ - [`${trait}`]: () => { - return FP[trait].generateScalarToIntervalCases( - FP[trait].scalarRange(), - 'unfiltered', - FP[trait].absInterval - ); - }, - })) - .reduce((a, b) => ({ ...a, ...b }), {}); +// Cases: [f32|f16|abstract_float|abstract_int] +const cases: Record = { + ...(['f32', 'f16', 'abstract'] as const) + .map(trait => ({ + [`${trait === 'abstract' ? 'abstract_float' : trait}`]: () => { + return FP[trait].generateScalarToIntervalCases( + FP[trait].scalarRange(), + 'unfiltered', + FP[trait].absInterval + ); + }, + })) + .reduce((a, b) => ({ ...a, ...b }), {}), + abstract_int: () => { + return fullI64Range().map(e => { + return { input: abstractInt(e), expected: abstractInt(absBigInt(e)) }; + }); + }, +}; export const d = makeCaseCache('abs', cases); diff --git a/src/webgpu/shader/execution/expression/call/builtin/abs.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/abs.spec.ts index b0736cb22fb6..c7f6d1d57cae 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/abs.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/abs.spec.ts @@ -26,11 +26,12 @@ import { TypeU32, u32Bits, TypeAbstractFloat, + TypeAbstractInt, } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; import { d } from './abs.cache.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, abstractIntBuiltin, builtin } from './builtin.js'; export const g = makeTestGroup(GPUTest); @@ -38,9 +39,14 @@ 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('abs'), [TypeAbstractInt], TypeAbstractInt, t.params, cases); + }); g.test('u32') .specURL('https://www.w3.org/TR/WGSL/#integer-builtin-functions') @@ -148,8 +154,15 @@ g.test('abstract_float') .combine('vectorize', [undefined, 2, 3, 4] as const) ) .fn(async t => { - const cases = await d.get('abstract'); - await run(t, abstractBuiltin('abs'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + const cases = await d.get('abstract_float'); + await run( + t, + abstractFloatBuiltin('abs'), + [TypeAbstractFloat], + TypeAbstractFloat, + t.params, + cases + ); }); g.test('f32') diff --git a/src/webgpu/shader/execution/expression/call/builtin/builtin.ts b/src/webgpu/shader/execution/expression/call/builtin/builtin.ts index 282feea70306..0afd8c398005 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/builtin.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/builtin.ts @@ -1,5 +1,6 @@ import { abstractFloatShaderBuilder, + abstractIntShaderBuilder, basicExpressionBuilder, basicExpressionWithPredeclarationBuilder, ShaderBuilder, @@ -11,10 +12,15 @@ export function builtin(name: string): ShaderBuilder { } /* @returns a ShaderBuilder that calls the builtin with the given name that returns AbstractFloats */ -export function abstractBuiltin(name: string): ShaderBuilder { +export function abstractFloatBuiltin(name: string): ShaderBuilder { return abstractFloatShaderBuilder(values => `${name}(${values.join(', ')})`); } +/* @returns a ShaderBuilder that calls the builtin with the given name that returns AbstractInts */ +export function abstractIntBuiltin(name: string): ShaderBuilder { + return abstractIntShaderBuilder(values => `${name}(${values.join(', ')})`); +} + /* @returns a ShaderBuilder that calls the builtin with the given name and has given predeclaration */ export function builtinWithPredeclaration(name: string, predeclaration: string): ShaderBuilder { return basicExpressionWithPredeclarationBuilder( diff --git a/src/webgpu/shader/execution/expression/call/builtin/clamp.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/clamp.spec.ts index 75abf1f11d8d..cd0a49020434 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/clamp.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/clamp.spec.ts @@ -24,7 +24,7 @@ import { } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './clamp.cache.js'; export const g = makeTestGroup(GPUTest); @@ -71,7 +71,7 @@ g.test('abstract_float') const cases = await d.get('abstract_const'); await run( t, - abstractBuiltin('clamp'), + abstractFloatBuiltin('clamp'), [TypeAbstractFloat, TypeAbstractFloat, TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/cross.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/cross.spec.ts index bf26a42f2f5e..95b39f45c5b3 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/cross.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/cross.spec.ts @@ -11,7 +11,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32, TypeVec } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './cross.cache.js'; export const g = makeTestGroup(GPUTest); @@ -24,7 +24,7 @@ g.test('abstract_float') const cases = await d.get('abstract_const'); await run( t, - abstractBuiltin('cross'), + abstractFloatBuiltin('cross'), [TypeVec(3, TypeAbstractFloat), TypeVec(3, TypeAbstractFloat)], TypeVec(3, TypeAbstractFloat), t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/degrees.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/degrees.spec.ts index 0e52c52c11a3..f69a92cf5f45 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/degrees.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/degrees.spec.ts @@ -12,7 +12,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './degrees.cache.js'; export const g = makeTestGroup(GPUTest); @@ -29,7 +29,7 @@ g.test('abstract_float') const cases = await d.get('abstract_const'); await run( t, - abstractBuiltin('degrees'), + abstractFloatBuiltin('degrees'), [TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts index 08a29ed3e5f4..63b0a138a045 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/floor.spec.ts @@ -12,7 +12,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './floor.cache.js'; export const g = makeTestGroup(GPUTest); @@ -27,7 +27,14 @@ g.test('abstract_float') ) .fn(async t => { const cases = await d.get('abstract'); - await run(t, abstractBuiltin('floor'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + await run( + t, + abstractFloatBuiltin('floor'), + [TypeAbstractFloat], + TypeAbstractFloat, + t.params, + cases + ); }); g.test('f32') diff --git a/src/webgpu/shader/execution/expression/call/builtin/fma.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/fma.spec.ts index 39360cb5bc51..2488603d8077 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/fma.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/fma.spec.ts @@ -12,7 +12,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './fma.cache.js'; export const g = makeTestGroup(GPUTest); @@ -29,7 +29,7 @@ g.test('abstract_float') const cases = await d.get('abstract_const'); await run( t, - abstractBuiltin('fma'), + abstractFloatBuiltin('fma'), [TypeAbstractFloat, TypeAbstractFloat, TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts index a596c3f12486..55bd5fb28405 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/max.spec.ts @@ -30,7 +30,7 @@ import { import { Case } from '../../case.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './max.cache.js'; /** Generate set of max test cases from list of interesting values */ @@ -103,7 +103,7 @@ g.test('abstract_float') const cases = await d.get('abstract'); await run( t, - abstractBuiltin('max'), + abstractFloatBuiltin('max'), [TypeAbstractFloat, TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/min.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/min.spec.ts index a9ada22da702..edfa95d9466f 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/min.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/min.spec.ts @@ -29,7 +29,7 @@ import { import { Case } from '../../case.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './min.cache.js'; export const g = makeTestGroup(GPUTest); @@ -102,7 +102,7 @@ g.test('abstract_float') const cases = await d.get('abstract'); await run( t, - abstractBuiltin('min'), + abstractFloatBuiltin('min'), [TypeAbstractFloat, TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/mix.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/mix.spec.ts index 91a66646b6b1..d502c639620b 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/mix.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/mix.spec.ts @@ -19,7 +19,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32, TypeVec } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './mix.cache.js'; export const g = makeTestGroup(GPUTest); @@ -36,7 +36,7 @@ g.test('abstract_float_matching') const cases = await d.get('abstract_const'); await run( t, - abstractBuiltin('mix'), + abstractFloatBuiltin('mix'), [TypeAbstractFloat, TypeAbstractFloat, TypeAbstractFloat], TypeAbstractFloat, t.params, @@ -52,7 +52,7 @@ g.test('abstract_float_nonmatching_vec2') const cases = await d.get('abstract_vec2_scalar_const'); await run( t, - abstractBuiltin('mix'), + abstractFloatBuiltin('mix'), [TypeVec(2, TypeAbstractFloat), TypeVec(2, TypeAbstractFloat), TypeAbstractFloat], TypeVec(2, TypeAbstractFloat), t.params, @@ -68,7 +68,7 @@ g.test('abstract_float_nonmatching_vec3') const cases = await d.get('abstract_vec3_scalar_const'); await run( t, - abstractBuiltin('mix'), + abstractFloatBuiltin('mix'), [TypeVec(3, TypeAbstractFloat), TypeVec(3, TypeAbstractFloat), TypeAbstractFloat], TypeVec(3, TypeAbstractFloat), t.params, @@ -84,7 +84,7 @@ g.test('abstract_float_nonmatching_vec4') const cases = await d.get('abstract_vec4_scalar_const'); await run( t, - abstractBuiltin('mix'), + abstractFloatBuiltin('mix'), [TypeVec(4, TypeAbstractFloat), TypeVec(4, TypeAbstractFloat), TypeAbstractFloat], TypeVec(4, TypeAbstractFloat), t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/radians.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/radians.spec.ts index f83f89b9154e..afc7da6d8cdb 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/radians.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/radians.spec.ts @@ -13,7 +13,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './radians.cache.js'; export const g = makeTestGroup(GPUTest); @@ -30,7 +30,7 @@ g.test('abstract_float') const cases = await d.get('abstract'); await run( t, - abstractBuiltin('radians'), + abstractFloatBuiltin('radians'), [TypeAbstractFloat], TypeAbstractFloat, t.params, 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 de2d6acfd0e1..8d215b952d59 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/round.spec.ts @@ -15,7 +15,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './round.cache.js'; export const g = makeTestGroup(GPUTest); @@ -30,7 +30,14 @@ g.test('abstract_float') ) .fn(async t => { const cases = await d.get('abstract'); - await run(t, abstractBuiltin('round'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + await run( + t, + abstractFloatBuiltin('round'), + [TypeAbstractFloat], + TypeAbstractFloat, + t.params, + cases + ); }); g.test('f32') diff --git a/src/webgpu/shader/execution/expression/call/builtin/saturate.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/saturate.spec.ts index bf19a3c6cb23..216ffb734578 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/saturate.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/saturate.spec.ts @@ -12,7 +12,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './saturate.cache.js'; export const g = makeTestGroup(GPUTest); @@ -29,7 +29,7 @@ g.test('abstract_float') const cases = await d.get('abstract'); await run( t, - abstractBuiltin('saturate'), + abstractFloatBuiltin('saturate'), [TypeAbstractFloat], TypeAbstractFloat, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/select.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/select.spec.ts index e69ab1886e03..e1acef7b04bf 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/select.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/select.spec.ts @@ -36,7 +36,7 @@ import { import { CaseList } from '../../case.js'; import { run, allInputSources } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; export const g = makeTestGroup(GPUTest); @@ -141,7 +141,7 @@ g.test('scalar') await run( t, - t.params.component === 'af' ? abstractBuiltin('select') : builtin('select'), + t.params.component === 'af' ? abstractFloatBuiltin('select') : builtin('select'), [overload.type, overload.type, TypeBool], overload.type, t.params, @@ -245,7 +245,7 @@ g.test('vector') await run( t, - t.params.component === 'af' ? abstractBuiltin('select') : builtin('select'), + t.params.component === 'af' ? abstractFloatBuiltin('select') : builtin('select'), [tests.dataType, tests.dataType, tests.boolType], tests.dataType, t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/sign.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/sign.spec.ts index a17bb7b205ac..bc91bf05a833 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/sign.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/sign.spec.ts @@ -12,7 +12,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32, TypeI32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './sign.cache.js'; export const g = makeTestGroup(GPUTest); @@ -27,7 +27,14 @@ g.test('abstract_float') ) .fn(async t => { const cases = await d.get('abstract'); - await run(t, abstractBuiltin('sign'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + await run( + t, + abstractFloatBuiltin('sign'), + [TypeAbstractFloat], + TypeAbstractFloat, + t.params, + cases + ); }); g.test('abstract_int') diff --git a/src/webgpu/shader/execution/expression/call/builtin/transpose.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/transpose.spec.ts index 82250cb985cf..90fa226a01e3 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/transpose.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/transpose.spec.ts @@ -11,7 +11,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32, TypeMat } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './transpose.cache.js'; export const g = makeTestGroup(GPUTest); @@ -31,7 +31,7 @@ g.test('abstract_float') const cases = await d.get(`abstract_mat${cols}x${rows}_const`); await run( t, - abstractBuiltin('transpose'), + abstractFloatBuiltin('transpose'), [TypeMat(cols, rows, TypeAbstractFloat)], TypeMat(rows, cols, TypeAbstractFloat), t.params, diff --git a/src/webgpu/shader/execution/expression/call/builtin/trunc.spec.ts b/src/webgpu/shader/execution/expression/call/builtin/trunc.spec.ts index 7dcc9395c3e3..022248ae5b97 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/trunc.spec.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/trunc.spec.ts @@ -13,7 +13,7 @@ import { GPUTest } from '../../../../../gpu_test.js'; import { TypeAbstractFloat, TypeF16, TypeF32 } from '../../../../../util/conversion.js'; import { allInputSources, onlyConstInputSource, run } from '../../expression.js'; -import { abstractBuiltin, builtin } from './builtin.js'; +import { abstractFloatBuiltin, builtin } from './builtin.js'; import { d } from './trunc.cache.js'; export const g = makeTestGroup(GPUTest); @@ -28,7 +28,14 @@ g.test('abstract_float') ) .fn(async t => { const cases = await d.get('abstract'); - await run(t, abstractBuiltin('trunc'), [TypeAbstractFloat], TypeAbstractFloat, t.params, cases); + await run( + t, + abstractFloatBuiltin('trunc'), + [TypeAbstractFloat], + TypeAbstractFloat, + t.params, + cases + ); }); g.test('f32') diff --git a/src/webgpu/util/math.ts b/src/webgpu/util/math.ts index 41ee14fcaa10..036552847f78 100644 --- a/src/webgpu/util/math.ts +++ b/src/webgpu/util/math.ts @@ -1293,26 +1293,6 @@ export function fullU32Range(count: number = 50): Array { return [0, ...biasedRange(1, kValue.u32.max, count)].map(Math.trunc); } -/** Short list of f32 values of interest to test against */ -const kInterestingF32Values: readonly number[] = [ - kValue.f32.negative.min, - -10.0, - -1.0, - -0.125, - kValue.f32.negative.max, - kValue.f32.negative.subnormal.min, - kValue.f32.negative.subnormal.max, - -0.0, - 0.0, - kValue.f32.positive.subnormal.min, - kValue.f32.positive.subnormal.max, - kValue.f32.positive.min, - 0.125, - 1.0, - 10.0, - kValue.f32.positive.max, -]; - /** * @returns an ascending sorted array of numbers spread over the entire range of 64-bit signed ints * @@ -1335,6 +1315,26 @@ export function fullI64Range( ]; } +/** Short list of f32 values of interest to test against */ +const kInterestingF32Values: readonly number[] = [ + kValue.f32.negative.min, + -10.0, + -1.0, + -0.125, + kValue.f32.negative.max, + kValue.f32.negative.subnormal.min, + kValue.f32.negative.subnormal.max, + -0.0, + 0.0, + kValue.f32.positive.subnormal.min, + kValue.f32.positive.subnormal.max, + kValue.f32.positive.min, + 0.125, + 1.0, + 10.0, + kValue.f32.positive.max, +]; + /** @returns minimal f32 values that cover the entire range of f32 behaviours * * Has specially selected values that cover edge cases, normals, and subnormals.