diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 250ddfd17b5f..4708660ab4a9 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -242,8 +242,8 @@ "webgpu:api,validation,buffer,destroy:while_mapped:*": { "subcaseMS": 1.150 }, "webgpu:api,validation,buffer,mapping:gc_behavior,mapAsync:*": { "subcaseMS": 32.200 }, "webgpu:api,validation,buffer,mapping:gc_behavior,mappedAtCreation:*": { "subcaseMS": 76.200 }, - "webgpu:api,validation,buffer,mapping:getMappedRange,disjointRanges_many:*": { "subcaseMS": 73.700 }, "webgpu:api,validation,buffer,mapping:getMappedRange,disjointRanges:*": { "subcaseMS": 2.257 }, + "webgpu:api,validation,buffer,mapping:getMappedRange,disjointRanges_many:*": { "subcaseMS": 73.700 }, "webgpu:api,validation,buffer,mapping:getMappedRange,offsetAndSizeAlignment,mapped:*": { "subcaseMS": 3.119 }, "webgpu:api,validation,buffer,mapping:getMappedRange,offsetAndSizeAlignment,mappedAtCreation:*": { "subcaseMS": 5.611 }, "webgpu:api,validation,buffer,mapping:getMappedRange,sizeAndOffsetOOB,mapped:*": { "subcaseMS": 0.886 }, diff --git a/src/webgpu/shader/execution/robust_access.spec.ts b/src/webgpu/shader/execution/robust_access.spec.ts index 94ff5a76a5dc..55e2620bf06c 100644 --- a/src/webgpu/shader/execution/robust_access.spec.ts +++ b/src/webgpu/shader/execution/robust_access.spec.ts @@ -330,21 +330,21 @@ struct TestData { let index = (${indexToTest})${exprIndexAddon};`; const exprZeroElement = `${_kTypeInfo.elementBaseType}()`; const exprElement = `s.data[index]`; - + const suffices = _kTypeInfo.accessSuffixes ?? ['']; switch (access) { case 'read': { - let exprLoadElement = isAtomic ? `atomicLoad(&${exprElement})` : exprElement; - if (addressSpace === 'uniform' && containerType === 'array') { - // Scalar types will be wrapped in a vec4 to satisfy array element size - // requirements for the uniform address space, so we need an additional index - // accessor expression. - exprLoadElement += '[0]'; + const exprLoadElement = isAtomic ? `atomicLoad(&${exprElement})` : exprElement; + let conditions = suffices.map(x => `${exprLoadElement}${x} != ${exprZeroElement}`); + if (containerType === 'matrix') { + // The comparison is a vector bool result. + // Convert that to a scalar bool. + conditions = conditions.map(c => `any(${c})`); } - let condition = `${exprLoadElement} != ${exprZeroElement}`; - if (containerType === 'matrix') condition = `any(${condition})`; - testFunctionSource += ` - if (${condition}) { return ${nextErrorReturnValue()}; }`; + conditions.forEach(c => { + testFunctionSource += ` + if (${c}) { return ${nextErrorReturnValue()}; }`; + }); } break; @@ -353,8 +353,10 @@ struct TestData { testFunctionSource += ` atomicStore(&s.data[index], ${exprZeroElement});`; } else { - testFunctionSource += ` - s.data[index] = ${exprZeroElement};`; + suffices.forEach(x => { + testFunctionSource += ` + s.data[index]${x} = ${exprZeroElement};`; + }); } break; } diff --git a/src/webgpu/shader/types.ts b/src/webgpu/shader/types.ts index a5a385deb289..d31d7f5d9043 100644 --- a/src/webgpu/shader/types.ts +++ b/src/webgpu/shader/types.ts @@ -210,7 +210,7 @@ export function* generateTypes({ isAtomic = false, }: { addressSpace: AddressSpace; - /** Base scalar type (i32/u32/f32/bool). */ + /** Base scalar type (i32/u32/f16/f32/bool). */ baseType: ScalarType; /** Container type (scalar/vector/matrix/array) */ containerType: ContainerType; @@ -238,6 +238,11 @@ export function* generateTypes({ * For a matrix type, this is the number of rows in the matrix. */ innerLength?: number; + /** + * If defined, the list of array access suffixes to use to access all + * the elements of the array, each yielding an elementBaseType value. + */ + accessSuffixes?: string[]; }; }, void @@ -308,6 +313,7 @@ export function* generateTypes({ let arrayElementCount: number = kDefaultArrayLength; let supportsAtomics = scalarInfo.supportsAtomics; let layout: undefined | AlignmentAndSize = undefined; + let accessSuffixes: undefined | string[] = undefined; if (scalarInfo.layout) { // Compute the layout of the array type. // Adjust the array element count or element type as needed. @@ -318,6 +324,7 @@ export function* generateTypes({ assert(!isAtomic, 'the uniform case is making vec4 of scalar, which cannot handle atomics'); arrayElemType = `vec4<${baseType}>`; supportsAtomics = false; + accessSuffixes = ['.x', '.y', '.z', '.w']; const arrayElemLayout = vectorLayout('vec4', baseType) as AlignmentAndSize; // assert(arrayElemLayout.alignment % 16 === 0); // Callers responsibility to avoid arrayElementCount = align(arrayElementCount, 4) / 4; @@ -344,6 +351,7 @@ export function* generateTypes({ arrayLength: arrayElementCount, layout, supportsAtomics, + accessSuffixes, }; // Sized