diff --git a/src/webgpu/shader/execution/robust_access.spec.ts b/src/webgpu/shader/execution/robust_access.spec.ts index 55e2620bf06c..66c71370222e 100644 --- a/src/webgpu/shader/execution/robust_access.spec.ts +++ b/src/webgpu/shader/execution/robust_access.spec.ts @@ -199,13 +199,6 @@ g.test('linear_memory') assert(_kTypeInfo !== undefined, 'not an indexable type'); assert('arrayLength' in _kTypeInfo); - if (baseType === 'f16' && addressSpace === 'uniform' && containerType === 'array') { - // Array elements must be aligned to 16 bytes, but the logic in generateTypes - // creates an array of vec4 of the baseType. But for f16 that's only 8 bytes. - // We would need to write more complex logic for that. - t.skip('Test logic does not handle array of f16 in the uniform address space'); - } - let usesCanary = false; let globalSource = ''; let testFunctionSource = ''; diff --git a/src/webgpu/shader/types.ts b/src/webgpu/shader/types.ts index d31d7f5d9043..e26605e5d7ce 100644 --- a/src/webgpu/shader/types.ts +++ b/src/webgpu/shader/types.ts @@ -314,6 +314,7 @@ export function* generateTypes({ let supportsAtomics = scalarInfo.supportsAtomics; let layout: undefined | AlignmentAndSize = undefined; let accessSuffixes: undefined | string[] = undefined; + let validLayoutForAddressSpace = true; if (scalarInfo.layout) { // Compute the layout of the array type. // Adjust the array element count or element type as needed. @@ -326,7 +327,9 @@ export function* generateTypes({ supportsAtomics = false; accessSuffixes = ['.x', '.y', '.z', '.w']; const arrayElemLayout = vectorLayout('vec4', baseType) as AlignmentAndSize; - // assert(arrayElemLayout.alignment % 16 === 0); // Callers responsibility to avoid + // Arrays in uniform address space have to be 16 byte-aligned. + // An array of vec4 is only 8byte aligned. + validLayoutForAddressSpace = arrayElemLayout.alignment % 16 === 0; arrayElementCount = align(arrayElementCount, 4) / 4; const arrayByteSize = arrayElementCount * arrayElemLayout.size; layout = { alignment: arrayElemLayout.alignment, size: arrayByteSize }; @@ -354,11 +357,13 @@ export function* generateTypes({ accessSuffixes, }; - // Sized - yield { type: `array<${arrayElemType},${arrayElementCount}>`, _kTypeInfo: arrayTypeInfo }; - // Unsized - if (addressSpace === 'storage') { - yield { type: `array<${arrayElemType}>`, _kTypeInfo: arrayTypeInfo }; + if (validLayoutForAddressSpace) { + // Sized + yield { type: `array<${arrayElemType},${arrayElementCount}>`, _kTypeInfo: arrayTypeInfo }; + // Unsized + if (addressSpace === 'storage') { + yield { type: `array<${arrayElemType}>`, _kTypeInfo: arrayTypeInfo }; + } } }