From 3e45aee0b16dc724a79a0feb0490e2ddb06c9f0d Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 7 Mar 2024 11:00:27 +0000 Subject: [PATCH] Add ArrayType / ArrayValue Not currently used by anything --- src/resources/cache/hashes.json | 216 +++++++++--------- .../expression/call/builtin/abs.spec.ts | 4 +- .../expression/call/builtin/acos.spec.ts | 4 +- .../expression/call/builtin/acosh.spec.ts | 6 +- .../expression/call/builtin/asin.spec.ts | 4 +- .../expression/call/builtin/asinh.spec.ts | 6 +- .../expression/call/builtin/atan.spec.ts | 4 +- .../expression/call/builtin/atan2.spec.ts | 6 +- .../expression/call/builtin/atanh.spec.ts | 4 +- .../expression/call/builtin/ceil.spec.ts | 4 +- .../expression/call/builtin/clamp.spec.ts | 4 +- .../call/builtin/const_override_validation.ts | 15 +- .../expression/call/builtin/cos.spec.ts | 4 +- .../expression/call/builtin/cosh.spec.ts | 6 +- .../expression/call/builtin/degrees.spec.ts | 6 +- .../call/builtin/derivatives.spec.ts | 6 +- .../expression/call/builtin/exp.spec.ts | 6 +- .../expression/call/builtin/exp2.spec.ts | 6 +- .../expression/call/builtin/floor.spec.ts | 4 +- .../call/builtin/inverseSqrt.spec.ts | 6 +- .../expression/call/builtin/length.spec.ts | 20 +- .../expression/call/builtin/log.spec.ts | 4 +- .../expression/call/builtin/log2.spec.ts | 4 +- .../expression/call/builtin/modf.spec.ts | 4 +- .../expression/call/builtin/radians.spec.ts | 4 +- .../expression/call/builtin/round.spec.ts | 8 +- .../expression/call/builtin/saturate.spec.ts | 4 +- .../expression/call/builtin/sign.spec.ts | 4 +- .../expression/call/builtin/sin.spec.ts | 4 +- .../expression/call/builtin/sinh.spec.ts | 6 +- .../expression/call/builtin/sqrt.spec.ts | 6 +- .../expression/call/builtin/tan.spec.ts | 6 +- src/webgpu/util/conversion.ts | 184 +++++++++++++-- 33 files changed, 360 insertions(+), 219 deletions(-) diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 6733022574c8..6c9518de081e 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,110 +1,110 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "45a00f48", - "webgpu/shader/execution/binary/af_logical.bin": "458eba4", - "webgpu/shader/execution/binary/af_division.bin": "ed6916d6", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "ddeaa1d3", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "bdc18f23", - "webgpu/shader/execution/binary/af_multiplication.bin": "e6e11b40", - "webgpu/shader/execution/binary/af_remainder.bin": "61849bd4", - "webgpu/shader/execution/binary/af_subtraction.bin": "6afd0c9a", - "webgpu/shader/execution/binary/f16_addition.bin": "118a69b1", - "webgpu/shader/execution/binary/f16_logical.bin": "53cbe093", - "webgpu/shader/execution/binary/f16_division.bin": "6cf5db74", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "37b3e5b1", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "f9f9c546", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "10c32980", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "4a992ee0", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "3969786a", - "webgpu/shader/execution/binary/f16_multiplication.bin": "27375c0a", - "webgpu/shader/execution/binary/f16_remainder.bin": "1e5d8fc7", - "webgpu/shader/execution/binary/f16_subtraction.bin": "daffd0ed", - "webgpu/shader/execution/binary/f32_addition.bin": "384766d0", - "webgpu/shader/execution/binary/f32_logical.bin": "d4f9fd6a", - "webgpu/shader/execution/binary/f32_division.bin": "760f650f", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "504aac15", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "740e31c4", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "3c5abc3c", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "c41fee39", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "43bfea5a", - "webgpu/shader/execution/binary/f32_multiplication.bin": "d6b990a9", - "webgpu/shader/execution/binary/f32_remainder.bin": "53f7d8e9", - "webgpu/shader/execution/binary/f32_subtraction.bin": "f644082", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "8ce49cc7", - "webgpu/shader/execution/binary/i32_comparison.bin": "ac0e960f", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "68560dc0", - "webgpu/shader/execution/binary/u32_comparison.bin": "ec9ec4c6", - "webgpu/shader/execution/abs.bin": "d7043582", - "webgpu/shader/execution/acos.bin": "a7a01d03", - "webgpu/shader/execution/acosh.bin": "3bfd9ebc", - "webgpu/shader/execution/asin.bin": "f91850f1", - "webgpu/shader/execution/asinh.bin": "19169ea3", - "webgpu/shader/execution/atan.bin": "51a04ddb", - "webgpu/shader/execution/atan2.bin": "e732e242", - "webgpu/shader/execution/atanh.bin": "4763b613", - "webgpu/shader/execution/bitcast.bin": "195c00a7", - "webgpu/shader/execution/ceil.bin": "9856b786", - "webgpu/shader/execution/clamp.bin": "5a700a65", - "webgpu/shader/execution/cos.bin": "ff14c921", - "webgpu/shader/execution/cosh.bin": "21c587ad", - "webgpu/shader/execution/cross.bin": "c159771f", - "webgpu/shader/execution/degrees.bin": "b0de92be", - "webgpu/shader/execution/determinant.bin": "83d642d4", - "webgpu/shader/execution/distance.bin": "e65d0cb7", - "webgpu/shader/execution/dot.bin": "dc57a00c", - "webgpu/shader/execution/exp.bin": "f0c6b19", - "webgpu/shader/execution/exp2.bin": "5d3dd4e0", - "webgpu/shader/execution/faceForward.bin": "3979a4de", - "webgpu/shader/execution/floor.bin": "3fecf76d", - "webgpu/shader/execution/fma.bin": "e7fe86b8", - "webgpu/shader/execution/fract.bin": "71caa066", - "webgpu/shader/execution/frexp.bin": "ed72dcec", - "webgpu/shader/execution/inverseSqrt.bin": "383e6e9c", - "webgpu/shader/execution/ldexp.bin": "bedfc1d5", - "webgpu/shader/execution/length.bin": "38e35ab4", - "webgpu/shader/execution/log.bin": "2517404c", - "webgpu/shader/execution/log2.bin": "a833136", - "webgpu/shader/execution/max.bin": "8c2f7c51", - "webgpu/shader/execution/min.bin": "7f732adb", - "webgpu/shader/execution/mix.bin": "982c982c", - "webgpu/shader/execution/modf.bin": "743632fc", - "webgpu/shader/execution/normalize.bin": "52adf424", - "webgpu/shader/execution/pack2x16float.bin": "2c879955", - "webgpu/shader/execution/pow.bin": "ba686c94", - "webgpu/shader/execution/quantizeToF16.bin": "e704252d", - "webgpu/shader/execution/radians.bin": "afe57c6e", - "webgpu/shader/execution/reflect.bin": "332e001e", - "webgpu/shader/execution/refract.bin": "246f6c0b", - "webgpu/shader/execution/round.bin": "e555383f", - "webgpu/shader/execution/saturate.bin": "9dce4047", - "webgpu/shader/execution/sign.bin": "3ef39d2e", - "webgpu/shader/execution/sin.bin": "8546b36c", - "webgpu/shader/execution/sinh.bin": "72ae8d37", - "webgpu/shader/execution/smoothstep.bin": "79eca0b6", - "webgpu/shader/execution/sqrt.bin": "ac8f95e9", - "webgpu/shader/execution/step.bin": "34ce6432", - "webgpu/shader/execution/tan.bin": "928e0e2f", - "webgpu/shader/execution/tanh.bin": "be078de7", - "webgpu/shader/execution/transpose.bin": "2ce22a5b", - "webgpu/shader/execution/trunc.bin": "26115486", - "webgpu/shader/execution/unpack2x16float.bin": "d052cda6", - "webgpu/shader/execution/unpack2x16snorm.bin": "a3ab8e29", - "webgpu/shader/execution/unpack2x16unorm.bin": "f42b9498", - "webgpu/shader/execution/unpack4x8snorm.bin": "5c90b367", - "webgpu/shader/execution/unpack4x8unorm.bin": "ef24abbe", - "webgpu/shader/execution/unary/af_arithmetic.bin": "28b510fa", - "webgpu/shader/execution/unary/af_assignment.bin": "4f4d507a", - "webgpu/shader/execution/unary/bool_conversion.bin": "5cbbd5e2", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "55ff626f", - "webgpu/shader/execution/unary/f16_conversion.bin": "e16712e2", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "672609de", - "webgpu/shader/execution/unary/f32_conversion.bin": "daa3ffb8", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "eecbb027", - "webgpu/shader/execution/unary/i32_conversion.bin": "c3f19a9", - "webgpu/shader/execution/unary/u32_conversion.bin": "b58b1876", - "webgpu/shader/execution/unary/ai_assignment.bin": "326020c6", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "40123e00", - "webgpu/shader/execution/unary/ai_arithmetic.bin": "37ffc69", - "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "35e08b61", - "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "6f31c22f", - "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "7b17ec2a" + "webgpu/shader/execution/binary/af_addition.bin": "25dcfcce", + "webgpu/shader/execution/binary/af_logical.bin": "409d37cf", + "webgpu/shader/execution/binary/af_division.bin": "bfcb23bd", + "webgpu/shader/execution/binary/af_matrix_addition.bin": "cefea21a", + "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "624d816d", + "webgpu/shader/execution/binary/af_multiplication.bin": "34077746", + "webgpu/shader/execution/binary/af_remainder.bin": "9eddf765", + "webgpu/shader/execution/binary/af_subtraction.bin": "629bbf4", + "webgpu/shader/execution/binary/f16_addition.bin": "e3ff1263", + "webgpu/shader/execution/binary/f16_logical.bin": "99c0a0ed", + "webgpu/shader/execution/binary/f16_division.bin": "c0f3376", + "webgpu/shader/execution/binary/f16_matrix_addition.bin": "3054016e", + "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "9cb6bbb9", + "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "82f32c1d", + "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "29e9e0c7", + "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "109260c1", + "webgpu/shader/execution/binary/f16_multiplication.bin": "39287c38", + "webgpu/shader/execution/binary/f16_remainder.bin": "98b48517", + "webgpu/shader/execution/binary/f16_subtraction.bin": "a4975dc4", + "webgpu/shader/execution/binary/f32_addition.bin": "b0e6fddd", + "webgpu/shader/execution/binary/f32_logical.bin": "71a0f0be", + "webgpu/shader/execution/binary/f32_division.bin": "29a37cf9", + "webgpu/shader/execution/binary/f32_matrix_addition.bin": "76e48aa9", + "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "37f3a30b", + "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "f00c4cd8", + "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "25553482", + "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "26750bd3", + "webgpu/shader/execution/binary/f32_multiplication.bin": "68a7516b", + "webgpu/shader/execution/binary/f32_remainder.bin": "fb22b625", + "webgpu/shader/execution/binary/f32_subtraction.bin": "2e26b05f", + "webgpu/shader/execution/binary/i32_arithmetic.bin": "9256ccab", + "webgpu/shader/execution/binary/i32_comparison.bin": "c813abfa", + "webgpu/shader/execution/binary/u32_arithmetic.bin": "498f877e", + "webgpu/shader/execution/binary/u32_comparison.bin": "d69e1738", + "webgpu/shader/execution/abs.bin": "a6b6fed1", + "webgpu/shader/execution/acos.bin": "2a8f33b0", + "webgpu/shader/execution/acosh.bin": "3b39f532", + "webgpu/shader/execution/asin.bin": "94c67af3", + "webgpu/shader/execution/asinh.bin": "34c8547a", + "webgpu/shader/execution/atan.bin": "c5f98dae", + "webgpu/shader/execution/atan2.bin": "5c666ada", + "webgpu/shader/execution/atanh.bin": "5efbba8b", + "webgpu/shader/execution/bitcast.bin": "e90abd26", + "webgpu/shader/execution/ceil.bin": "fe43b603", + "webgpu/shader/execution/clamp.bin": "f4ec869a", + "webgpu/shader/execution/cos.bin": "78f30673", + "webgpu/shader/execution/cosh.bin": "15c18b89", + "webgpu/shader/execution/cross.bin": "72823897", + "webgpu/shader/execution/degrees.bin": "3b06fea4", + "webgpu/shader/execution/determinant.bin": "f0f66549", + "webgpu/shader/execution/distance.bin": "593c41fb", + "webgpu/shader/execution/dot.bin": "3eee146b", + "webgpu/shader/execution/exp.bin": "7f926769", + "webgpu/shader/execution/exp2.bin": "715c82a", + "webgpu/shader/execution/faceForward.bin": "8a365384", + "webgpu/shader/execution/floor.bin": "7b9a6254", + "webgpu/shader/execution/fma.bin": "88549fc7", + "webgpu/shader/execution/fract.bin": "e4eff2f9", + "webgpu/shader/execution/frexp.bin": "18a53421", + "webgpu/shader/execution/inverseSqrt.bin": "71016a37", + "webgpu/shader/execution/ldexp.bin": "450c6068", + "webgpu/shader/execution/length.bin": "62190368", + "webgpu/shader/execution/log.bin": "c4b1985b", + "webgpu/shader/execution/log2.bin": "28ccd982", + "webgpu/shader/execution/max.bin": "ba573f18", + "webgpu/shader/execution/min.bin": "5a834580", + "webgpu/shader/execution/mix.bin": "bf942d40", + "webgpu/shader/execution/modf.bin": "a8de3f36", + "webgpu/shader/execution/normalize.bin": "4bf84190", + "webgpu/shader/execution/pack2x16float.bin": "cc42ef45", + "webgpu/shader/execution/pow.bin": "6e8d08d1", + "webgpu/shader/execution/quantizeToF16.bin": "8c615e93", + "webgpu/shader/execution/radians.bin": "624ff571", + "webgpu/shader/execution/reflect.bin": "d0d624ae", + "webgpu/shader/execution/refract.bin": "3dd68359", + "webgpu/shader/execution/round.bin": "502c36a8", + "webgpu/shader/execution/saturate.bin": "be4cf88f", + "webgpu/shader/execution/sign.bin": "91310555", + "webgpu/shader/execution/sin.bin": "441d6be3", + "webgpu/shader/execution/sinh.bin": "4ebaa2e7", + "webgpu/shader/execution/smoothstep.bin": "6298e644", + "webgpu/shader/execution/sqrt.bin": "3cf64df1", + "webgpu/shader/execution/step.bin": "90148c99", + "webgpu/shader/execution/tan.bin": "e753749c", + "webgpu/shader/execution/tanh.bin": "62c99641", + "webgpu/shader/execution/transpose.bin": "2a4448c6", + "webgpu/shader/execution/trunc.bin": "ed9a0d22", + "webgpu/shader/execution/unpack2x16float.bin": "e81297f7", + "webgpu/shader/execution/unpack2x16snorm.bin": "513f9a8b", + "webgpu/shader/execution/unpack2x16unorm.bin": "8b56d0ce", + "webgpu/shader/execution/unpack4x8snorm.bin": "51af8a63", + "webgpu/shader/execution/unpack4x8unorm.bin": "302cf4a6", + "webgpu/shader/execution/unary/af_arithmetic.bin": "cd4618d", + "webgpu/shader/execution/unary/af_assignment.bin": "7d5de0f1", + "webgpu/shader/execution/unary/bool_conversion.bin": "401fb8c5", + "webgpu/shader/execution/unary/f16_arithmetic.bin": "ad86d013", + "webgpu/shader/execution/unary/f16_conversion.bin": "86e35a85", + "webgpu/shader/execution/unary/f32_arithmetic.bin": "fe97afd1", + "webgpu/shader/execution/unary/f32_conversion.bin": "97730c3c", + "webgpu/shader/execution/unary/i32_arithmetic.bin": "69f783bb", + "webgpu/shader/execution/unary/i32_conversion.bin": "4fec061e", + "webgpu/shader/execution/unary/u32_conversion.bin": "1a298dea", + "webgpu/shader/execution/unary/ai_assignment.bin": "1c2edca2", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "657f2fb7", + "webgpu/shader/execution/unary/ai_arithmetic.bin": "216769d9", + "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "544f4363", + "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "14212e77", + "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "57f19c15" } \ No newline at end of file diff --git a/src/webgpu/shader/validation/expression/call/builtin/abs.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/abs.spec.ts index f7084b5d07d4..3fc9eeb22c3d 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/abs.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/abs.spec.ts @@ -5,7 +5,7 @@ Validation tests for the ${builtin}() builtin. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; -import { Type, elementType, kAllScalarsAndVectors } from '../../../../../util/conversion.js'; +import { Type, kAllScalarsAndVectors, scalarTypeOf } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; import { @@ -34,7 +34,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() never .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/acos.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/acos.spec.ts index 13e3492a5146..9b6438aaec65 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/acos.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/acos.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { absBigInt } from '../../../../../util/math.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/acosh.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/acosh.spec.ts index 8e60459676f6..c3644befc9ba 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/acosh.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/acosh.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -56,7 +56,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.acosh(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/asin.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/asin.spec.ts index fef4540f4304..bff34f104dee 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/asin.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/asin.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { absBigInt } from '../../../../../util/math.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/asinh.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/asinh.spec.ts index a029e38d02f3..cec4b73c6094 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/asinh.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/asinh.spec.ts @@ -6,9 +6,9 @@ Validation tests for the ${builtin}() builtin. import { makeTestGroup } from '../../../../../../common/framework/test_group.js'; import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, Type, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; @@ -50,7 +50,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -59,7 +59,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.asinh(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/atan.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/atan.spec.ts index e8f325be5b94..76bafbbcca8a 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/atan.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/atan.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -46,7 +46,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/atan2.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/atan2.spec.ts index 712695ed0eb4..1a6776a018fa 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/atan2.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/atan2.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { VectorValue, - elementType, kFloatScalarsAndVectors, kConcreteIntegerScalarsAndVectors, + scalarTypeOf, Type, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; @@ -54,7 +54,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -62,7 +62,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const type = kValuesTypes[t.params.type]; const expectedResult = isRepresentable( Math.abs(Math.atan2(Number(t.params.x), Number(t.params.y))), - elementType(type) + scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/atanh.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/atanh.spec.ts index 460977c78878..1a9184a7416c 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/atanh.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/atanh.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { absBigInt } from '../../../../../util/math.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/ceil.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/ceil.spec.ts index 02fdbf70fc98..951958d02c12 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/ceil.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/ceil.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() never .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/clamp.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/clamp.spec.ts index 5e8b3f3fe6ef..9a23328d650f 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/clamp.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/clamp.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kFloatScalarsAndVectors, kConcreteIntegerScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -44,7 +44,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('high', u => fullRangeForType(kValuesTypes[u.type], 4)) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/const_override_validation.ts b/src/webgpu/shader/validation/expression/call/builtin/const_override_validation.ts index 440673c99265..6c46bfb0a054 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/const_override_validation.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/const_override_validation.ts @@ -3,9 +3,10 @@ import { kValue } from '../../../../../util/constants.js'; import { Type, Value, - elementType, - elementsOf, + elementTypeOf, isAbstractType, + scalarElementsOf, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { scalarF16Range, @@ -22,7 +23,7 @@ export function rangeForType( bigint_range: readonly bigint[] ): (type: Type) => readonly (number | bigint)[] { return (type: Type): readonly (number | bigint)[] => { - switch (elementType(type).kind) { + switch (scalarTypeOf(type).kind) { case 'abstract-float': case 'f32': case 'f16': @@ -131,7 +132,7 @@ export type ConstantOrOverrideStage = 'constant' | 'override'; * @returns true if evaluation stage `stage` supports expressions of type @p. */ export function stageSupportsType(stage: ConstantOrOverrideStage, type: Type) { - if (stage === 'override' && isAbstractType(elementType(type)!)) { + if (stage === 'override' && isAbstractType(elementTypeOf(type)!)) { // Abstract numerics are concretized before being used in an override expression. return false; } @@ -154,7 +155,7 @@ export function validateConstOrOverrideBuiltinEval( args: Value[], stage: ConstantOrOverrideStage ) { - const elTys = args.map(arg => elementType(arg.type)!); + const elTys = args.map(arg => elementTypeOf(arg.type)!); const enables = elTys.some(ty => ty === Type.f16) ? 'enable f16;' : ''; switch (stage) { @@ -174,7 +175,7 @@ const v = ${builtin}(${args.map(arg => arg.wgsl()).join(', ')});` let numOverrides = 0; for (const arg of args) { const argOverrides: string[] = []; - for (const el of elementsOf(arg)) { + for (const el of scalarElementsOf(arg)) { const name = `o${numOverrides++}`; overrideDecls.push(`override ${name} : ${el.type};`); argOverrides.push(name); @@ -200,7 +201,7 @@ export function fullRangeForType(type: Type, count?: number): readonly (number | if (count === undefined) { count = 25; } - switch (elementType(type)?.kind) { + switch (scalarTypeOf(type)?.kind) { case 'abstract-float': return scalarF64Range({ pos_sub: Math.ceil((count * 1) / 5), diff --git a/src/webgpu/shader/validation/expression/call/builtin/cos.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/cos.spec.ts index 09b807c1039d..81d283abb299 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/cos.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/cos.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -46,7 +46,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/cosh.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/cosh.spec.ts index ffb01b707671..4178f5760d87 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/cosh.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/cosh.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -40,7 +40,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -49,7 +49,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.cosh(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/degrees.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/degrees.spec.ts index 35c7ff3c9062..f1cba6a6aef8 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/degrees.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/degrees.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -40,7 +40,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -49,7 +49,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input const expectedResult = isRepresentable( (Number(t.params.value) * 180) / Math.PI, // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/derivatives.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/derivatives.spec.ts index dd0a3fb595a8..54620ce17904 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/derivatives.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/derivatives.spec.ts @@ -6,9 +6,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConcreteF16ScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -113,14 +113,14 @@ Derivative builtins only accept f32 scalar and vector types. u.combine('type', keysOf(kArgumentTypes)).combine('call', ['', ...kDerivativeBuiltins]) ) .beforeAllSubcases(t => { - if (elementType(kArgumentTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kArgumentTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) .fn(t => { const type = kArgumentTypes[t.params.type]; const code = ` -${elementType(kArgumentTypes[t.params.type]) === Type.f16 ? 'enable f16;' : ''} +${scalarTypeOf(kArgumentTypes[t.params.type]) === Type.f16 ? 'enable f16;' : ''} fn foo() { let x: ${type.toString()} = ${t.params.call}(${type.create(1).wgsl()}); diff --git a/src/webgpu/shader/validation/expression/call/builtin/exp.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/exp.spec.ts index edac1c0c529d..dcbd5b79e51d 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/exp.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/exp.spec.ts @@ -8,9 +8,9 @@ import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tabl import { kValue } from '../../../../../util/constants.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -70,7 +70,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('value', u => valueForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -79,7 +79,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.exp(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/exp2.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/exp2.spec.ts index 4f961e4259bc..0144abeefb04 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/exp2.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/exp2.spec.ts @@ -8,9 +8,9 @@ import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tabl import { kValue } from '../../../../../util/constants.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -70,7 +70,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('value', u => valueForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -79,7 +79,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.pow(2, Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/floor.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/floor.spec.ts index f075b5e25c1b..b65fafc74466 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/floor.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/floor.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() never .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/inverseSqrt.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/inverseSqrt.spec.ts index 4ab15948664b..6310bfe25fee 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/inverseSqrt.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/inverseSqrt.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -58,7 +58,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input isRepresentable( 1 / Math.sqrt(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/length.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/length.spec.ts index 620f09837329..003ad6811d72 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/length.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/length.spec.ts @@ -8,12 +8,12 @@ import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tabl import { ScalarType, Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalar, kConvertableToFloatVec2, kConvertableToFloatVec3, kConvertableToFloatVec4, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -55,12 +55,12 @@ function calculate( isIntermediateRepresentable: isRepresentable( squareSum, // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ), isResultRepresentable: isRepresentable( result, // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ), result, }; @@ -84,7 +84,7 @@ the input scalar value always compiles without error .expand('value', u => fullRangeForType(kScalarTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kScalarTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kScalarTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -116,11 +116,11 @@ Validates that constant evaluation and override evaluation of ${builtin}() with .beginSubcases() .expand('x', u => fullRangeForType(kVec2Types[u.type], 5)) .expand('y', u => fullRangeForType(kVec2Types[u.type], 5)) - .expand('_result', u => [calculate([u.x, u.y], elementType(kVec2Types[u.type]))]) + .expand('_result', u => [calculate([u.x, u.y], scalarTypeOf(kVec2Types[u.type]))]) .filter(u => u._result.isResultRepresentable === u._result.isIntermediateRepresentable) ) .beforeAllSubcases(t => { - if (elementType(kVec2Types[t.params.type]) === Type.f16) { + if (scalarTypeOf(kVec2Types[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -152,11 +152,11 @@ Validates that constant evaluation and override evaluation of ${builtin}() with .expand('x', u => fullRangeForType(kVec3Types[u.type], 4)) .expand('y', u => fullRangeForType(kVec3Types[u.type], 4)) .expand('z', u => fullRangeForType(kVec3Types[u.type], 4)) - .expand('_result', u => [calculate([u.x, u.y, u.z], elementType(kVec3Types[u.type]))]) + .expand('_result', u => [calculate([u.x, u.y, u.z], scalarTypeOf(kVec3Types[u.type]))]) .filter(u => u._result.isResultRepresentable === u._result.isIntermediateRepresentable) ) .beforeAllSubcases(t => { - if (elementType(kVec3Types[t.params.type]) === Type.f16) { + if (scalarTypeOf(kVec3Types[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -189,11 +189,11 @@ Validates that constant evaluation and override evaluation of ${builtin}() with .expand('y', u => fullRangeForType(kVec4Types[u.type], 3)) .expand('z', u => fullRangeForType(kVec4Types[u.type], 3)) .expand('w', u => fullRangeForType(kVec4Types[u.type], 3)) - .expand('_result', u => [calculate([u.x, u.y, u.z, u.w], elementType(kVec4Types[u.type]))]) + .expand('_result', u => [calculate([u.x, u.y, u.z, u.w], scalarTypeOf(kVec4Types[u.type]))]) .filter(u => u._result.isResultRepresentable === u._result.isIntermediateRepresentable) ) .beforeAllSubcases(t => { - if (elementType(kVec4Types[t.params.type]) === Type.f16) { + if (scalarTypeOf(kVec4Types[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts index 18ea19c3e341..6d755304f2ff 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts index b3a6c338c595..0dfe64153651 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/modf.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/modf.spec.ts index 3f0b4a6064ab..2a90fa878ea6 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/modf.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/modf.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/radians.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/radians.spec.ts index f7f60ec8f478..8689bc3dbbe8 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/radians.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/radians.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/round.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/round.spec.ts index 821fc0f3c382..dae7482c18ce 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/round.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/round.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { fpTraitsFor } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,10 +39,10 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .filter(u => stageSupportsType(u.stage, kValuesTypes[u.type])) .beginSubcases() .expand('value', u => { - if (elementType(kValuesTypes[u.type]).kind === 'abstract-int') { + if (scalarTypeOf(kValuesTypes[u.type]).kind === 'abstract-int') { return fullRangeForType(kValuesTypes[u.type]); } else { - const constants = fpTraitsFor(elementType(kValuesTypes[u.type])).constants(); + const constants = fpTraitsFor(scalarTypeOf(kValuesTypes[u.type])).constants(); return unique(fullRangeForType(kValuesTypes[u.type]), [ constants.negative.min + 0.1, constants.positive.max - 0.1, @@ -51,7 +51,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input }) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/saturate.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/saturate.spec.ts index 354248e205ba..cbd1b3f369ff 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/saturate.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/saturate.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -39,7 +39,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/sign.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/sign.spec.ts index 238bb51d8bc7..f8e00ab9486d 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/sign.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/sign.spec.ts @@ -7,10 +7,10 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kFloatScalarsAndVectors, kConcreteSignedIntegerScalarsAndVectors, kConcreteUnsignedIntegerScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -43,7 +43,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/sin.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/sin.spec.ts index a408323e3a82..3c807d094c5c 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/sin.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/sin.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -46,7 +46,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) diff --git a/src/webgpu/shader/validation/expression/call/builtin/sinh.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/sinh.spec.ts index 8f5a4c0c60aa..1983d0e1a7e4 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/sinh.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/sinh.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -40,7 +40,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec .expand('value', u => fullRangeForType(kValuesTypes[u.type])) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -49,7 +49,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const expectedResult = isRepresentable( Math.sinh(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/sqrt.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/sqrt.spec.ts index ff72a63379bc..7e983adf188c 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/sqrt.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/sqrt.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { isRepresentable } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -58,7 +58,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() input isRepresentable( Math.sqrt(Number(t.params.value)), // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); validateConstOrOverrideBuiltinEval( t, diff --git a/src/webgpu/shader/validation/expression/call/builtin/tan.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/tan.spec.ts index ed5286781d56..097c2b374d95 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/tan.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/tan.spec.ts @@ -7,9 +7,9 @@ import { makeTestGroup } from '../../../../../../common/framework/test_group.js' import { keysOf, objectsToRecord } from '../../../../../../common/util/data_tables.js'; import { Type, - elementType, kConcreteIntegerScalarsAndVectors, kConvertableToFloatScalarsAndVectors, + scalarTypeOf, } from '../../../../../util/conversion.js'; import { fpTraitsFor } from '../../../../../util/floating_point.js'; import { ShaderValidationTest } from '../../../shader_validation_test.js'; @@ -47,7 +47,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec ) ) .beforeAllSubcases(t => { - if (elementType(kValuesTypes[t.params.type]) === Type.f16) { + if (scalarTypeOf(kValuesTypes[t.params.type]) === Type.f16) { t.selectDeviceOrSkipTestCase('shader-f16'); } }) @@ -55,7 +55,7 @@ Validates that constant evaluation and override evaluation of ${builtin}() rejec const type = kValuesTypes[t.params.type]; const fp = fpTraitsFor( // AbstractInt is converted to AbstractFloat before calling into the builtin - elementType(type).kind === 'abstract-int' ? Type.abstractFloat : elementType(type) + scalarTypeOf(type).kind === 'abstract-int' ? Type.abstractFloat : scalarTypeOf(type) ); const smallestPositive = fp.constants().positive.min; const v = fp.quantize(Number(t.params.value)); diff --git a/src/webgpu/util/conversion.ts b/src/webgpu/util/conversion.ts index 2b9e7989bcdb..a44f34cedfeb 100644 --- a/src/webgpu/util/conversion.ts +++ b/src/webgpu/util/conversion.ts @@ -616,6 +616,10 @@ export class ScalarType { return this._size; } + public get alignment(): number { + return this._size; + } + /** Constructs a ScalarValue of this type with `value` */ public create(value: number | bigint): ScalarValue { switch (typeof value) { @@ -663,14 +667,17 @@ export class VectorType { readonly width: number; // Number of elements in the vector readonly elementType: ScalarType; // Element type + // Maps a string representation of a vector type to vector type. + private static instances = new Map(); + static create(width: number, elementType: ScalarType): VectorType { const key = `${elementType.toString()} ${width}}`; - let ty = vectorTypes.get(key); + let ty = this.instances.get(key); if (ty !== undefined) { return ty; } ty = new VectorType(width, elementType); - vectorTypes.set(key, ty); + this.instances.set(key, ty); return ty; } @@ -700,6 +707,14 @@ export class VectorType { return this.elementType.size * this.width; } + public get alignment(): number { + return VectorType.alignmentOf(this.width, this.elementType); + } + + public static alignmentOf(width: number, elementType: ScalarType) { + return elementType.size * (width === 3 ? 4 : width); + } + /** Constructs a Vector of this type with the given values */ public create(value: (number | bigint) | readonly (number | bigint)[]): VectorValue { if (value instanceof Array) { @@ -711,23 +726,23 @@ export class VectorType { } } -// Maps a string representation of a vector type to vector type. -const vectorTypes = new Map(); - /** MatrixType describes the type of WGSL Matrix. */ export class MatrixType { readonly cols: number; // Number of columns in the Matrix readonly rows: number; // Number of elements per column in the Matrix readonly elementType: ScalarType; // Element type + // Maps a string representation of a Matrix type to Matrix type. + private static instances = new Map(); + static create(cols: number, rows: number, elementType: ScalarType): MatrixType { const key = `${elementType.toString()} ${cols} ${rows}`; - let ty = matrixTypes.get(key); + let ty = this.instances.get(key); if (ty !== undefined) { return ty; } ty = new MatrixType(cols, rows, elementType); - matrixTypes.set(key, ty); + this.instances.set(key, ty); return ty; } @@ -767,6 +782,14 @@ export class MatrixType { return `mat${this.cols}x${this.rows}<${this.elementType}>`; } + public get size(): number { + return VectorType.alignmentOf(this.rows, this.elementType) * this.cols; + } + + public get alignment(): number { + return VectorType.alignmentOf(this.rows, this.elementType); + } + /** Constructs a Matrix of this type with the given values */ public create(value: (number | bigint) | readonly (number | bigint)[]): MatrixValue { if (value instanceof Array) { @@ -783,8 +806,55 @@ export class MatrixType { } } -// Maps a string representation of a Matrix type to Matrix type. -const matrixTypes = new Map(); +/** ArrayType describes the type of WGSL Array. */ +export class ArrayType { + readonly count: number; // Number of elements in the array + readonly elementType: Type; // Element type + + // Maps a string representation of a array type to array type. + private static instances = new Map(); + + static create(count: number, elementType: Type): ArrayType { + const key = `${elementType.toString()} ${count}`; + let ty = this.instances.get(key); + if (ty !== undefined) { + return ty; + } + ty = new ArrayType(count, elementType); + this.instances.set(key, ty); + return ty; + } + + constructor(count: number, elementType: Type) { + this.count = count; + this.elementType = elementType; + } + + /** + * @returns a array constructed from the values read from the buffer at the + * given byte offset + */ + public read(buf: Uint8Array, offset: number): ArrayValue { + const elements: Array = []; + for (let i = 0; i < this.count; i++) { + elements[i] = this.elementType.read(buf, offset); + offset += this.elementType.size; + } + return new ArrayValue(elements); + } + + public toString(): string { + return `array<${this.elementType}, ${this.count}>`; + } + + public get size(): number { + return this.elementType.alignment * this.count; + } + + public get alignment(): number { + return this.elementType.alignment; + } +} /** ArrayElementType infers the element type of the indexable type A */ type ArrayElementType = A extends { [index: number]: infer T } ? T : never; @@ -838,8 +908,8 @@ const boolType = new ScalarType('bool', 4, (buf: Uint8Array, offset: number) => bool(valueFromBytes(workingDataU32, buf, offset) !== 0) ); -/** Type is a ScalarType, VectorType, or MatrixType. */ -export type Type = ScalarType | VectorType | MatrixType; +/** Type is a ScalarType, VectorType, MatrixType or ArrayType. */ +export type Type = ScalarType | VectorType | MatrixType | ArrayType; /** Type holds pre-declared Types along with helper constructor functions. */ export const Type = { @@ -894,6 +964,8 @@ export const Type = { mat3x4h: MatrixType.create(3, 4, f16Type), mat4x4f: MatrixType.create(4, 4, f32Type), mat4x4h: MatrixType.create(4, 4, f16Type), + + array: (count: number, elementType: Type) => ArrayType.create(count, elementType), }; /** @returns the ScalarType from the ScalarKind */ @@ -937,11 +1009,31 @@ export function numElementsOf(ty: Type): number { if (ty instanceof MatrixType) { return ty.cols * ty.rows; } + if (ty instanceof ArrayType) { + return ty.count; + } throw new Error(`unhandled type ${ty}`); } /** @returns the scalar elements of the given Value */ -export function elementsOf(value: Value): ScalarValue[] { +export function elementsOf(value: Value): Value[] { + if (isScalarValue(value)) { + return [value]; + } + if (value instanceof VectorValue) { + return value.elements; + } + if (value instanceof MatrixValue) { + return value.elements.flat(); + } + if (value instanceof ArrayValue) { + return value.elements; + } + throw new Error(`unhandled value ${value}`); +} + +/** @returns the scalar elements of the given Value */ +export function scalarElementsOf(value: Value): ScalarValue[] { if (isScalarValue(value)) { return [value]; } @@ -951,9 +1043,20 @@ export function elementsOf(value: Value): ScalarValue[] { if (value instanceof MatrixValue) { return value.elements.flat(); } + if (value instanceof ArrayValue) { + return value.elements.map(els => scalarElementsOf(els)).flat(); + } throw new Error(`unhandled value ${value}`); } +/** @returns the inner element type of the given type */ +export function elementTypeOf(t: Type) { + if (t instanceof ScalarType) { + return t; + } + return t.elementType; +} + /** @returns the scalar (element) type of the given Type */ export function scalarTypeOf(ty: Type): ScalarType { if (ty instanceof ScalarType) { @@ -965,6 +1068,9 @@ export function scalarTypeOf(ty: Type): ScalarType { if (ty instanceof MatrixType) { return ty.elementType; } + if (ty instanceof ArrayType) { + return scalarTypeOf(ty.elementType); + } throw new Error(`unhandled type ${ty}`); } @@ -1754,6 +1860,48 @@ export class MatrixValue { } } +/** + * Class that encapsulates an Array value. + */ +export class ArrayValue { + readonly elements: Value[]; + readonly type: ArrayType; + + public constructor(elements: Array) { + const elem_type = elements[0].type; + if (!elements.every(c => elements.every(r => objectEquals(r.type, elem_type)))) { + throw new Error(`cannot mix array element types`); + } + + this.elements = elements; + this.type = ArrayType.create(elements.length, elem_type); + } + + /** + * Copies the matrix value to the Uint8Array buffer at the provided byte offset. + * @param buffer the destination buffer + * @param offset the byte offset within buffer + */ + public copyTo(buffer: Uint8Array, offset: number) { + for (const element of this.elements) { + element.copyTo(buffer, offset); + offset += this.type.elementType.size; + } + } + + /** + * @returns the WGSL representation of this matrix value + */ + public wgsl(): string { + const els = this.elements.map(r => r.wgsl()).join(', '); + return `${this.type}(${els})`; + } + + public toString(): string { + return this.wgsl(); + } +} + /** * Helper for constructing Matrices from arrays of numbers * @@ -1776,8 +1924,8 @@ export function toMatrix(m: ROArrayArray, op: (n: number) => ScalarValue return new MatrixValue(elements); } -/** Value is a Scalar, Vector or Matrix value. */ -export type Value = ScalarValue | VectorValue | MatrixValue; +/** Value is a Scalar, Vector, Matrix or Array value. */ +export type Value = ScalarValue | VectorValue | MatrixValue | ArrayValue; export type SerializedScalarValue = { kind: 'scalar'; @@ -2160,11 +2308,3 @@ export const kAllScalarsAndVectors = [ ...kConvertableToFloatScalarsAndVectors, ...kConcreteIntegerScalarsAndVectors, ] as const; - -/** @returns the inner element type of the given type */ -export function elementType(t: ScalarType | VectorType | MatrixType) { - if (t instanceof ScalarType) { - return t; - } - return t.elementType; -}