diff --git a/src/webgpu/api/validation/capability_checks/limits/maxColorAttachmentBytesPerSample.spec.ts b/src/webgpu/api/validation/capability_checks/limits/maxColorAttachmentBytesPerSample.spec.ts index d1b8eb0701bd..9934757d2b03 100644 --- a/src/webgpu/api/validation/capability_checks/limits/maxColorAttachmentBytesPerSample.spec.ts +++ b/src/webgpu/api/validation/capability_checks/limits/maxColorAttachmentBytesPerSample.spec.ts @@ -1,6 +1,6 @@ import { assert } from '../../../../../common/util/util.js'; import { kTextureSampleCounts } from '../../../../capability_info.js'; -import { kTextureFormatInfo } from '../../../../format_info.js'; +import { getColorRenderAlignment, getColorRenderByteCost } from '../../../../format_info.js'; import { align } from '../../../../util/math.js'; import { @@ -10,30 +10,26 @@ import { makeLimitTestGroup, } from './limit_utils.js'; -const kFormatsToUseBySize: GPUTextureFormat[] = [ +const kFormatsToUseBySize = [ 'rgba32uint', 'rgba16uint', 'rgba8unorm', 'rg8unorm', 'r8unorm', -]; +] as const; -const kInterleaveFormats: GPUTextureFormat[] = [ - 'rgba16uint', - 'rg16uint', - 'rgba8unorm', - 'rg8unorm', - 'r8unorm', -]; +const kInterleaveFormats = ['rgba16uint', 'rg16uint', 'rgba8unorm', 'rg8unorm', 'r8unorm'] as const; + +const kFormatsUsedInTest = [...kFormatsToUseBySize, ...kInterleaveFormats] as const; +type FormatUsedInTest = (typeof kFormatsUsedInTest)[number]; -function getAttachments(interleaveFormat: GPUTextureFormat, testValue: number) { +function getAttachments(interleaveFormat: FormatUsedInTest, testValue: number) { let bytesPerSample = 0; const targets: GPUColorTargetState[] = []; - const addTexture = (format: GPUTextureFormat) => { - const info = kTextureFormatInfo[format]; + const addTexture = (format: FormatUsedInTest) => { const newBytesPerSample = - align(bytesPerSample, info.colorRender!.alignment) + info.colorRender!.byteCost; + align(bytesPerSample, getColorRenderAlignment(format)) + getColorRenderByteCost(format); if (newBytesPerSample > testValue) { return false; } @@ -70,12 +66,13 @@ function getDescription( let offset = 0; return targets .map(({ format }) => { - const info = kTextureFormatInfo[format]; - offset = align(offset, info.colorRender!.alignment); - const s = `// ${format.padEnd(11)} (offset: ${offset.toString().padStart(2)}, align: ${ - info.colorRender!.alignment - }, size: ${info.colorRender!.byteCost})`; - offset += info.colorRender!.byteCost; + const alignment = getColorRenderAlignment(format as FormatUsedInTest); + const byteCost = getColorRenderByteCost(format as FormatUsedInTest); + offset = align(offset, alignment); + const s = `// ${format.padEnd(11)} (offset: ${offset + .toString() + .padStart(2)}, align: ${alignment}, size: ${byteCost})`; + offset += byteCost; return s; }) .join('\n '); @@ -86,7 +83,7 @@ function getDescription( function getPipelineDescriptor( device: GPUDevice, actualLimit: number, - interleaveFormat: GPUTextureFormat, + interleaveFormat: FormatUsedInTest, sampleCount: number, testValue: number ): { pipelineDescriptor: GPURenderPipelineDescriptor; code: string } | undefined { diff --git a/src/webgpu/format_info.ts b/src/webgpu/format_info.ts index 84d3434d5fcd..de8cccc43667 100644 --- a/src/webgpu/format_info.ts +++ b/src/webgpu/format_info.ts @@ -1899,6 +1899,21 @@ export function getColorRenderByteCost(format: PossibleColorRenderTextureFormat) return byteCost; } +/** + * Returns the "alignment" of rendering to a color texture format. + * MAINTENANCE_TODO: remove `rg11b10ufloat' from here and add its data to table + * once CTS is refactored. See issue #4181 + */ +export function getColorRenderAlignment(format: PossibleColorRenderTextureFormat) { + const alignment = + format === 'rg11b10ufloat' ? 1 : kTextureFormatInfo[format].colorRender?.alignment; + // MAINTENANCE_TODO: remove this assert. The issue is typescript thinks + // PossibleColorRenderTextureFormat contains all texture formats and not just + // a filtered list. + assert(alignment !== undefined); + return alignment; +} + /** * Gets the baseFormat for a texture format. */