From b710041e48922c818fc472322d315e4899213208 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Fri, 20 Dec 2024 00:28:51 -0800 Subject: [PATCH] Reduce the number of subcases in null_bind_group_layouts (#4107) --- src/common/util/util.ts | 9 + src/resources/cache/hashes.json | 220 +++++++++--------- .../validation/createPipelineLayout.spec.ts | 74 ++---- 3 files changed, 135 insertions(+), 168 deletions(-) diff --git a/src/common/util/util.ts b/src/common/util/util.ts index ac60401abca3..bc1204bbe63d 100644 --- a/src/common/util/util.ts +++ b/src/common/util/util.ts @@ -258,6 +258,15 @@ export function mapLazy(xs: Iterable, f: (x: T) => R): Iterable { }; } +/** Count the number of elements `x` for which `predicate(x)` is true. */ +export function count(xs: Iterable, predicate: (x: T) => boolean): number { + let count = 0; + for (const x of xs) { + if (predicate(x)) count++; + } + return count; +} + const ReorderOrders = { forward: true, backward: true, diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index e2224325944f..16ed2d6f855f 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -1,112 +1,112 @@ { - "webgpu/shader/execution/binary/af_addition.bin": "d0c1b760", - "webgpu/shader/execution/binary/af_logical.bin": "ca60ce77", - "webgpu/shader/execution/binary/af_division.bin": "47ae1ca1", - "webgpu/shader/execution/binary/af_matrix_addition.bin": "afaf9bae", - "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "42433bf3", - "webgpu/shader/execution/binary/af_multiplication.bin": "babfc501", - "webgpu/shader/execution/binary/af_remainder.bin": "19995293", - "webgpu/shader/execution/binary/af_subtraction.bin": "62f090b9", - "webgpu/shader/execution/binary/f16_addition.bin": "540ae334", - "webgpu/shader/execution/binary/f16_logical.bin": "c1f09c30", - "webgpu/shader/execution/binary/f16_division.bin": "b4eabc05", - "webgpu/shader/execution/binary/f16_matrix_addition.bin": "6b9113b", - "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "a7362ff1", - "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "4ac4e5bb", - "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "93d4d43a", - "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "beed89d5", - "webgpu/shader/execution/binary/f16_multiplication.bin": "6b5f0d51", - "webgpu/shader/execution/binary/f16_remainder.bin": "a1f499b3", - "webgpu/shader/execution/binary/f16_subtraction.bin": "61a571d5", - "webgpu/shader/execution/binary/f32_addition.bin": "fa6cc596", - "webgpu/shader/execution/binary/f32_logical.bin": "2b155b60", - "webgpu/shader/execution/binary/f32_division.bin": "243c9ce6", - "webgpu/shader/execution/binary/f32_matrix_addition.bin": "d3bc6ed6", - "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "2a4c1527", - "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "d695442", - "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "b306b19", - "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "aac6cbfd", - "webgpu/shader/execution/binary/f32_multiplication.bin": "a21303f5", - "webgpu/shader/execution/binary/f32_remainder.bin": "79e462a1", - "webgpu/shader/execution/binary/f32_subtraction.bin": "4e6bbf38", - "webgpu/shader/execution/binary/i32_arithmetic.bin": "167760cc", - "webgpu/shader/execution/binary/i32_comparison.bin": "6a9f856a", - "webgpu/shader/execution/binary/u32_arithmetic.bin": "ac424b44", - "webgpu/shader/execution/binary/u32_comparison.bin": "a9e71302", - "webgpu/shader/execution/abs.bin": "a42729c4", - "webgpu/shader/execution/acos.bin": "664a5662", - "webgpu/shader/execution/acosh.bin": "d3fb8eb0", - "webgpu/shader/execution/asin.bin": "5a4f5b9e", - "webgpu/shader/execution/asinh.bin": "3ce3fe4d", - "webgpu/shader/execution/atan.bin": "759d432", - "webgpu/shader/execution/atan2.bin": "95008607", - "webgpu/shader/execution/atanh.bin": "569bd1b6", - "webgpu/shader/execution/bitcast.bin": "4329e501", - "webgpu/shader/execution/ceil.bin": "55cc76e5", - "webgpu/shader/execution/clamp.bin": "d580a273", - "webgpu/shader/execution/cos.bin": "3107bc4b", - "webgpu/shader/execution/cosh.bin": "d36c86cc", - "webgpu/shader/execution/cross.bin": "e48c39ba", - "webgpu/shader/execution/degrees.bin": "f74b63d2", - "webgpu/shader/execution/determinant.bin": "f07e1160", - "webgpu/shader/execution/distance.bin": "93156a89", - "webgpu/shader/execution/dot.bin": "4e2fe407", - "webgpu/shader/execution/exp.bin": "3b269b18", - "webgpu/shader/execution/exp2.bin": "7aeeeaf6", - "webgpu/shader/execution/faceForward.bin": "451ffbd8", - "webgpu/shader/execution/floor.bin": "37131d74", - "webgpu/shader/execution/fma.bin": "30111350", - "webgpu/shader/execution/fract.bin": "5ef13392", - "webgpu/shader/execution/frexp.bin": "da764bc0", - "webgpu/shader/execution/inverseSqrt.bin": "6ff34703", - "webgpu/shader/execution/ldexp.bin": "5016cec9", - "webgpu/shader/execution/length.bin": "f236d2e7", - "webgpu/shader/execution/log.bin": "1c54f128", - "webgpu/shader/execution/log2.bin": "e44e2370", - "webgpu/shader/execution/max.bin": "eb4c1901", - "webgpu/shader/execution/min.bin": "f8c70a2b", - "webgpu/shader/execution/mix.bin": "df3b3f62", - "webgpu/shader/execution/modf.bin": "b600b26f", - "webgpu/shader/execution/normalize.bin": "7af3a3d2", - "webgpu/shader/execution/pack2x16float.bin": "7c67b10e", - "webgpu/shader/execution/pow.bin": "ee37f4ba", - "webgpu/shader/execution/quantizeToF16.bin": "a7a65754", - "webgpu/shader/execution/radians.bin": "51d423b9", - "webgpu/shader/execution/reflect.bin": "3ba4eda6", - "webgpu/shader/execution/refract.bin": "13fc4914", - "webgpu/shader/execution/round.bin": "9155b88b", - "webgpu/shader/execution/saturate.bin": "73cecf71", - "webgpu/shader/execution/sign.bin": "68d61a83", - "webgpu/shader/execution/sin.bin": "44219876", - "webgpu/shader/execution/sinh.bin": "158d261d", - "webgpu/shader/execution/smoothstep.bin": "7129c56b", - "webgpu/shader/execution/sqrt.bin": "9aaaf8aa", - "webgpu/shader/execution/step.bin": "85858027", - "webgpu/shader/execution/tan.bin": "dbbda634", - "webgpu/shader/execution/tanh.bin": "8c540d5c", - "webgpu/shader/execution/transpose.bin": "a676fc9a", - "webgpu/shader/execution/trunc.bin": "35ab398d", - "webgpu/shader/execution/unpack2x16float.bin": "eb9294c9", - "webgpu/shader/execution/unpack2x16snorm.bin": "7208eb73", - "webgpu/shader/execution/unpack2x16unorm.bin": "20d9669b", - "webgpu/shader/execution/unpack4x8snorm.bin": "c77e1a72", - "webgpu/shader/execution/unpack4x8unorm.bin": "d80caf66", - "webgpu/shader/execution/unary/af_arithmetic.bin": "963c3185", - "webgpu/shader/execution/unary/af_assignment.bin": "9e8a3b3f", - "webgpu/shader/execution/unary/bool_conversion.bin": "eee7a40c", - "webgpu/shader/execution/unary/f16_arithmetic.bin": "aaea9f75", - "webgpu/shader/execution/unary/f16_conversion.bin": "5b26998a", - "webgpu/shader/execution/unary/f32_arithmetic.bin": "65dfc2ac", - "webgpu/shader/execution/unary/f32_conversion.bin": "cd874be3", - "webgpu/shader/execution/unary/i32_arithmetic.bin": "af4c0e43", - "webgpu/shader/execution/unary/i32_conversion.bin": "5b6e4d9", - "webgpu/shader/execution/unary/u32_conversion.bin": "229649a6", - "webgpu/shader/execution/unary/ai_assignment.bin": "8efcf261", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "a57ee284", - "webgpu/shader/execution/unary/ai_arithmetic.bin": "948016b6", - "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "52c24212", - "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "256556e1", - "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "38085521", - "webgpu/shader/execution/derivatives.bin": "f38a38ff", - "webgpu/shader/execution/fwidth.bin": "4e9fc55d" + "webgpu/shader/execution/binary/af_addition.bin": "e5d3d0ec", + "webgpu/shader/execution/binary/af_logical.bin": "4cadb0c4", + "webgpu/shader/execution/binary/af_division.bin": "24d5c047", + "webgpu/shader/execution/binary/af_matrix_addition.bin": "27b5045f", + "webgpu/shader/execution/binary/af_matrix_subtraction.bin": "e51ed65c", + "webgpu/shader/execution/binary/af_multiplication.bin": "ccdd9db3", + "webgpu/shader/execution/binary/af_remainder.bin": "7ba7561", + "webgpu/shader/execution/binary/af_subtraction.bin": "77ae32fd", + "webgpu/shader/execution/binary/f16_addition.bin": "7cf4d65a", + "webgpu/shader/execution/binary/f16_logical.bin": "b9e93570", + "webgpu/shader/execution/binary/f16_division.bin": "9ec5ad6a", + "webgpu/shader/execution/binary/f16_matrix_addition.bin": "e89ed3cb", + "webgpu/shader/execution/binary/f16_matrix_matrix_multiplication.bin": "375d5af3", + "webgpu/shader/execution/binary/f16_matrix_scalar_multiplication.bin": "9bd3af4e", + "webgpu/shader/execution/binary/f16_matrix_subtraction.bin": "43350bb3", + "webgpu/shader/execution/binary/f16_matrix_vector_multiplication.bin": "1edb6630", + "webgpu/shader/execution/binary/f16_multiplication.bin": "7485e77b", + "webgpu/shader/execution/binary/f16_remainder.bin": "ec817ba", + "webgpu/shader/execution/binary/f16_subtraction.bin": "aae1c57a", + "webgpu/shader/execution/binary/f32_addition.bin": "7134e85", + "webgpu/shader/execution/binary/f32_logical.bin": "24ba1a54", + "webgpu/shader/execution/binary/f32_division.bin": "f51e95fe", + "webgpu/shader/execution/binary/f32_matrix_addition.bin": "97f4a153", + "webgpu/shader/execution/binary/f32_matrix_matrix_multiplication.bin": "70677010", + "webgpu/shader/execution/binary/f32_matrix_scalar_multiplication.bin": "355c0954", + "webgpu/shader/execution/binary/f32_matrix_subtraction.bin": "85135fad", + "webgpu/shader/execution/binary/f32_matrix_vector_multiplication.bin": "a3fa2750", + "webgpu/shader/execution/binary/f32_multiplication.bin": "ba41fc13", + "webgpu/shader/execution/binary/f32_remainder.bin": "142765dd", + "webgpu/shader/execution/binary/f32_subtraction.bin": "c1523f1c", + "webgpu/shader/execution/binary/i32_arithmetic.bin": "bcff0350", + "webgpu/shader/execution/binary/i32_comparison.bin": "396f7bad", + "webgpu/shader/execution/binary/u32_arithmetic.bin": "7357b8e9", + "webgpu/shader/execution/binary/u32_comparison.bin": "374b246a", + "webgpu/shader/execution/abs.bin": "1ab55590", + "webgpu/shader/execution/acos.bin": "d85ca70", + "webgpu/shader/execution/acosh.bin": "e28fd395", + "webgpu/shader/execution/asin.bin": "eced623b", + "webgpu/shader/execution/asinh.bin": "223989ea", + "webgpu/shader/execution/atan.bin": "d896ec78", + "webgpu/shader/execution/atan2.bin": "b394e737", + "webgpu/shader/execution/atanh.bin": "9e4a5a", + "webgpu/shader/execution/bitcast.bin": "51bb8e9f", + "webgpu/shader/execution/ceil.bin": "11d3b9aa", + "webgpu/shader/execution/clamp.bin": "b2860448", + "webgpu/shader/execution/cos.bin": "c965712f", + "webgpu/shader/execution/cosh.bin": "89f1ce32", + "webgpu/shader/execution/cross.bin": "8b3df30b", + "webgpu/shader/execution/degrees.bin": "182a521e", + "webgpu/shader/execution/determinant.bin": "d5b3ed92", + "webgpu/shader/execution/distance.bin": "d21d853b", + "webgpu/shader/execution/dot.bin": "c91e716", + "webgpu/shader/execution/exp.bin": "4240da7", + "webgpu/shader/execution/exp2.bin": "11938883", + "webgpu/shader/execution/faceForward.bin": "a2e27acc", + "webgpu/shader/execution/floor.bin": "c06553ca", + "webgpu/shader/execution/fma.bin": "7dea01cf", + "webgpu/shader/execution/fract.bin": "677b1105", + "webgpu/shader/execution/frexp.bin": "3dbf112c", + "webgpu/shader/execution/inverseSqrt.bin": "8f6bb04e", + "webgpu/shader/execution/ldexp.bin": "287a7307", + "webgpu/shader/execution/length.bin": "908ff679", + "webgpu/shader/execution/log.bin": "8585f4ac", + "webgpu/shader/execution/log2.bin": "6847e7ca", + "webgpu/shader/execution/max.bin": "777cfa16", + "webgpu/shader/execution/min.bin": "51ae81f5", + "webgpu/shader/execution/mix.bin": "56c2fa65", + "webgpu/shader/execution/modf.bin": "4e106c58", + "webgpu/shader/execution/normalize.bin": "32c44235", + "webgpu/shader/execution/pack2x16float.bin": "133f1db3", + "webgpu/shader/execution/pow.bin": "370df2fa", + "webgpu/shader/execution/quantizeToF16.bin": "8a4fa4a8", + "webgpu/shader/execution/radians.bin": "c4684d86", + "webgpu/shader/execution/reflect.bin": "3620e893", + "webgpu/shader/execution/refract.bin": "f6bd722f", + "webgpu/shader/execution/round.bin": "765d4e71", + "webgpu/shader/execution/saturate.bin": "772a5d55", + "webgpu/shader/execution/sign.bin": "b99ea52d", + "webgpu/shader/execution/sin.bin": "69c8cce9", + "webgpu/shader/execution/sinh.bin": "3bc5f870", + "webgpu/shader/execution/smoothstep.bin": "bc6be719", + "webgpu/shader/execution/sqrt.bin": "c3960a52", + "webgpu/shader/execution/step.bin": "8a715292", + "webgpu/shader/execution/tan.bin": "5c531104", + "webgpu/shader/execution/tanh.bin": "ff9cadf1", + "webgpu/shader/execution/transpose.bin": "f9cebed4", + "webgpu/shader/execution/trunc.bin": "1c0edd1b", + "webgpu/shader/execution/unpack2x16float.bin": "1d4051b9", + "webgpu/shader/execution/unpack2x16snorm.bin": "f9a16118", + "webgpu/shader/execution/unpack2x16unorm.bin": "cad45023", + "webgpu/shader/execution/unpack4x8snorm.bin": "26f9cbc4", + "webgpu/shader/execution/unpack4x8unorm.bin": "76de2d56", + "webgpu/shader/execution/unary/af_arithmetic.bin": "7044a2b4", + "webgpu/shader/execution/unary/af_assignment.bin": "fca7094b", + "webgpu/shader/execution/unary/bool_conversion.bin": "ac26e6b8", + "webgpu/shader/execution/unary/f16_arithmetic.bin": "913af76", + "webgpu/shader/execution/unary/f16_conversion.bin": "1fb4a7a4", + "webgpu/shader/execution/unary/f32_arithmetic.bin": "7c274ba7", + "webgpu/shader/execution/unary/f32_conversion.bin": "1175ae48", + "webgpu/shader/execution/unary/i32_arithmetic.bin": "7bf685a3", + "webgpu/shader/execution/unary/i32_conversion.bin": "60437023", + "webgpu/shader/execution/unary/u32_conversion.bin": "3bc30fc0", + "webgpu/shader/execution/unary/ai_assignment.bin": "66d85afa", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "3c6c91e3", + "webgpu/shader/execution/unary/ai_arithmetic.bin": "37cc249a", + "webgpu/shader/execution/binary/af_matrix_matrix_multiplication.bin": "c22028c6", + "webgpu/shader/execution/binary/af_matrix_scalar_multiplication.bin": "8fa6602", + "webgpu/shader/execution/binary/af_matrix_vector_multiplication.bin": "f1bc0050", + "webgpu/shader/execution/derivatives.bin": "d96a3465", + "webgpu/shader/execution/fwidth.bin": "c63db6a9" } \ No newline at end of file diff --git a/src/webgpu/api/validation/createPipelineLayout.spec.ts b/src/webgpu/api/validation/createPipelineLayout.spec.ts index be0ce7191a9d..366d06993ac7 100644 --- a/src/webgpu/api/validation/createPipelineLayout.spec.ts +++ b/src/webgpu/api/validation/createPipelineLayout.spec.ts @@ -5,6 +5,7 @@ TODO: review existing tests, write descriptions, and make sure tests are complet `; import { makeTestGroup } from '../../../common/framework/test_group.js'; +import { count } from '../../../common/util/util.js'; import { bufferBindingTypeInfo, kBufferBindingTypes } from '../../capability_info.js'; import { GPUConst } from '../../constants.js'; @@ -174,41 +175,17 @@ g.test('bind_group_layouts,null_bind_group_layouts') ) .paramsSubcasesOnly(u => u // - .combine('bindGroupLayoutCount', [1, 2, 3, 4] as const) - .combine('bindGroupLayout0', MaybeNullBindGroupLayoutTypes) - .expand('bindGroupLayout1', p => - p.bindGroupLayoutCount > 1 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const) - ) - .expand('bindGroupLayout2', p => - p.bindGroupLayoutCount > 2 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const) - ) - .expand('bindGroupLayout3', p => - p.bindGroupLayoutCount > 3 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const) - ) - .filter(p => { - // Only test cases where at least one of the bind group layouts is null. - const allBGLs = [ - p.bindGroupLayout0, - p.bindGroupLayout1, - p.bindGroupLayout2, - p.bindGroupLayout3, - ]; - const bgls = allBGLs.slice(0, p.bindGroupLayoutCount); - return bgls.includes('Null') || bgls.includes('Undefined'); - }) + .combine('_bglCount', [1, 2, 3, 4] as const) + .combine('_bgl0', MaybeNullBindGroupLayoutTypes) + .expand('_bgl1', p => (p._bglCount > 1 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const))) + .expand('_bgl2', p => (p._bglCount > 2 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const))) + .expand('_bgl3', p => (p._bglCount > 3 ? MaybeNullBindGroupLayoutTypes : (['Null'] as const))) + // Flatten the result down into a single subcase arg which is an array of BGL types. + .expand('bindGroupLayouts', p => [[p._bgl0, p._bgl1, p._bgl2, p._bgl3].slice(0, p._bglCount)]) + // Only test combinations where exactly one of the BGLs is null|undefined|empty. + .filter(p => count(p.bindGroupLayouts, x => x !== 'NonEmpty') === 1) ) .fn(t => { - const { - bindGroupLayoutCount, - bindGroupLayout0, - bindGroupLayout1, - bindGroupLayout2, - bindGroupLayout3, - } = t.params; - - const emptyBindGroupLayout = t.device.createBindGroupLayout({ - entries: [], - }); const nonEmptyBindGroupLayout = t.device.createBindGroupLayout({ entries: [ { @@ -219,37 +196,18 @@ g.test('bind_group_layouts,null_bind_group_layouts') ], }); - const bindGroupLayouts: (GPUBindGroupLayout | null | undefined)[] = []; - - const AddBindGroupLayout = function ( - bindGroupLayoutType: (typeof MaybeNullBindGroupLayoutTypes)[number] - ) { + const bindGroupLayouts = t.params.bindGroupLayouts.map(bindGroupLayoutType => { switch (bindGroupLayoutType) { case 'Null': - bindGroupLayouts.push(null); - break; + return null; case 'Undefined': - bindGroupLayouts.push(undefined); - break; + return undefined; case 'Empty': - bindGroupLayouts.push(emptyBindGroupLayout); - break; + return t.device.createBindGroupLayout({ entries: [] }); case 'NonEmpty': - bindGroupLayouts.push(nonEmptyBindGroupLayout); - break; + return nonEmptyBindGroupLayout; } - }; - - AddBindGroupLayout(bindGroupLayout0); - if (bindGroupLayoutCount > 1) { - AddBindGroupLayout(bindGroupLayout1); - } - if (bindGroupLayoutCount > 2) { - AddBindGroupLayout(bindGroupLayout2); - } - if (bindGroupLayoutCount > 3) { - AddBindGroupLayout(bindGroupLayout3); - } + }); const kShouldError = false; t.expectValidationError(() => {