diff --git a/src/webgpu/api/operation/command_buffer/image_copy.spec.ts b/src/webgpu/api/operation/command_buffer/image_copy.spec.ts index 9927bfb89872..cff2bd50d575 100644 --- a/src/webgpu/api/operation/command_buffer/image_copy.spec.ts +++ b/src/webgpu/api/operation/command_buffer/image_copy.spec.ts @@ -1595,7 +1595,7 @@ works for every format with 2d and 2d-array textures. }; let textureHeight = 4 * info.blockHeight; let rowsPerImage = rowsPerImageEqualsCopyHeight ? copyHeight : copyHeight + 1; - const bytesPerRow = align(copyWidth * info.bytesPerBlock, 256); + const bytesPerRow = align(copyWidth * info.color.bytes, 256); if (dimension === '1d') { copySize.height = 1; diff --git a/src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts b/src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts index 65e2e8af1f21..5e8357114107 100644 --- a/src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts +++ b/src/webgpu/api/operation/rendering/depth_clip_clamp.spec.ts @@ -4,6 +4,7 @@ depth ranges as well. `; import { makeTestGroup } from '../../../../common/framework/test_group.js'; +import { assert } from '../../../../common/util/util.js'; import { kDepthStencilFormats, kTextureFormatInfo } from '../../../format_info.js'; import { GPUTest } from '../../../gpu_test.js'; import { @@ -52,6 +53,7 @@ have unexpected values then get drawn to the color buffer, which is later checke .fn(async t => { const { format, unclippedDepth, writeDepth, multisampled } = t.params; const info = kTextureFormatInfo[format]; + assert(!!info.depth); /** Number of depth values to test for both vertex output and frag_depth output. */ const kNumDepthValues = 8; @@ -222,16 +224,16 @@ have unexpected values then get drawn to the color buffer, which is later checke : undefined; const dsActual = - !multisampled && info.bytesPerBlock + !multisampled && info.depth.bytes ? t.device.createBuffer({ - size: kNumTestPoints * info.bytesPerBlock, + size: kNumTestPoints * info.depth.bytes, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, }) : undefined; const dsExpected = - !multisampled && info.bytesPerBlock + !multisampled && info.depth.bytes ? t.device.createBuffer({ - size: kNumTestPoints * info.bytesPerBlock, + size: kNumTestPoints * info.depth.bytes, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, }) : undefined; diff --git a/src/webgpu/api/operation/resource_init/check_texture/texture_zero_init_test.ts b/src/webgpu/api/operation/resource_init/check_texture/texture_zero_init_test.ts index 22ffe0a3e518..6ff3ab4c9b41 100644 --- a/src/webgpu/api/operation/resource_init/check_texture/texture_zero_init_test.ts +++ b/src/webgpu/api/operation/resource_init/check_texture/texture_zero_init_test.ts @@ -115,6 +115,14 @@ const initializedStateAsStencil = { [InitializedState.Canary]: 42, }; +function allAspectsCopyDst(info: (typeof kTextureFormatInfo)[UncompressedTextureFormat]) { + return ( + (!info.color || info.color.copyDst) && + (!info.depth || info.depth.copyDst) && + (!info.stencil || info.stencil.copyDst) + ); +} + export function getRequiredTextureUsage( format: UncompressedTextureFormat, sampleCount: number, @@ -159,10 +167,11 @@ export function getRequiredTextureUsage( usage |= GPUConst.TextureUsage.RENDER_ATTACHMENT; } - if (!kTextureFormatInfo[format].copyDst) { + const info = kTextureFormatInfo[format]; + if (!allAspectsCopyDst(info)) { // Copies are not possible. We need OutputAttachment to initialize // canary data. - assert(kTextureFormatInfo[format].renderable); + if (info.color) assert(!!info.colorRender, 'not implemented for non-renderable color'); usage |= GPUConst.TextureUsage.RENDER_ATTACHMENT; } @@ -388,10 +397,11 @@ export class TextureZeroInitTest extends GPUTest { state: InitializedState, subresourceRange: SubresourceRange ): void { - if (this.p.sampleCount > 1 || !kTextureFormatInfo[this.p.format].copyDst) { + const info = kTextureFormatInfo[this.p.format]; + if (this.p.sampleCount > 1 || !allAspectsCopyDst(info)) { // Copies to multisampled textures not yet specified. // Use a storeOp for now. - assert(kTextureFormatInfo[this.p.format].renderable); + if (info.color) assert(!!info.colorRender, 'not implemented for non-renderable color'); this.initializeWithStoreOp(state, texture, subresourceRange); } else { this.initializeWithCopy(texture, state, subresourceRange); @@ -517,20 +527,15 @@ export const kTestParams = kUnitCaseParamsBuilder const info = kTextureFormatInfo[format]; return ( - ((usage & GPUConst.TextureUsage.RENDER_ATTACHMENT) !== 0 && !info.renderable) || + ((usage & GPUConst.TextureUsage.RENDER_ATTACHMENT) !== 0 && + info.color && + !info.colorRender) || ((usage & GPUConst.TextureUsage.STORAGE_BINDING) !== 0 && !info.color?.storage) || (sampleCount > 1 && !info.multisample) ); }) .combine('nonPowerOfTwo', [false, true]) - .combine('canaryOnCreation', [false, true]) - .filter(({ canaryOnCreation, format }) => { - // We can only initialize the texture if it's encodable or renderable. - const canInitialize = format in kTextureFormatInfo || kTextureFormatInfo[format].renderable; - - // Filter out cases where we want canary values but can't initialize. - return !canaryOnCreation || canInitialize; - }); + .combine('canaryOnCreation', [false, true]); type TextureZeroParams = ParamTypeOf; diff --git a/src/webgpu/api/operation/storage_texture/read_only.spec.ts b/src/webgpu/api/operation/storage_texture/read_only.spec.ts index 9a479eee9d15..978924aabd67 100644 --- a/src/webgpu/api/operation/storage_texture/read_only.spec.ts +++ b/src/webgpu/api/operation/storage_texture/read_only.spec.ts @@ -51,7 +51,7 @@ class F extends GPUTest { storageTexture: GPUTexture, format: ColorTextureFormat ): ArrayBuffer { - const bytesPerBlock = kTextureFormatInfo[format].bytesPerBlock; + const bytesPerBlock = kTextureFormatInfo[format].color.bytes; assert(bytesPerBlock !== undefined); const width = storageTexture.width; diff --git a/src/webgpu/api/validation/createTexture.spec.ts b/src/webgpu/api/validation/createTexture.spec.ts index 04c029d78f1d..fc1c8b86b26b 100644 --- a/src/webgpu/api/validation/createTexture.spec.ts +++ b/src/webgpu/api/validation/createTexture.spec.ts @@ -299,7 +299,7 @@ g.test('sampleCount,various_sampleCount_with_all_formats') usage, }; - const success = sampleCount === 1 || (sampleCount === 4 && info.multisample && info.renderable); + const success = sampleCount === 1 || (sampleCount === 4 && info.multisample); t.expectValidationError(() => { t.device.createTexture(descriptor); @@ -1066,16 +1066,13 @@ g.test('texture_usage') // Note that we unconditionally test copy usages for all formats. We don't check copySrc/copyDst in kTextureFormatInfo in capability_info.js // if (!info.copySrc && (usage & GPUTextureUsage.COPY_SRC) !== 0) success = false; // if (!info.copyDst && (usage & GPUTextureUsage.COPY_DST) !== 0) success = false; - if ( - (usage & GPUTextureUsage.STORAGE_BINDING) !== 0 && - !isTextureFormatUsableAsStorageFormat(format, t.isCompatibility) - ) - success = false; - if ( - (!info.renderable || (appliedDimension !== '2d' && appliedDimension !== '3d')) && - (usage & GPUTextureUsage.RENDER_ATTACHMENT) !== 0 - ) - success = false; + if (usage & GPUTextureUsage.STORAGE_BINDING) { + if (!isTextureFormatUsableAsStorageFormat(format, t.isCompatibility)) success = false; + } + if (usage & GPUTextureUsage.RENDER_ATTACHMENT) { + if (appliedDimension === '1d') success = false; + if (info.color && !info.colorRender) success = false; + } t.expectValidationError(() => { t.device.createTexture(descriptor); diff --git a/src/webgpu/api/validation/image_copy/texture_related.spec.ts b/src/webgpu/api/validation/image_copy/texture_related.spec.ts index a0fe38e8e313..cbc36b1431ba 100644 --- a/src/webgpu/api/validation/image_copy/texture_related.spec.ts +++ b/src/webgpu/api/validation/image_copy/texture_related.spec.ts @@ -440,7 +440,7 @@ Test that the copy size must be aligned to the texture's format's block size. const texture = t.createAlignedTexture(format, size, origin, dimension); const bytesPerRow = align( - Math.max(1, Math.ceil(size.width / info.blockWidth)) * info.bytesPerBlock, + Math.max(1, Math.ceil(size.width / info.blockWidth)) * info.color.bytes, 256 ); const rowsPerImage = Math.ceil(size.height / info.blockHeight); diff --git a/src/webgpu/compat/api/validation/encoding/cmds/copyTextureToBuffer.spec.ts b/src/webgpu/compat/api/validation/encoding/cmds/copyTextureToBuffer.spec.ts index a9af7795b3c4..e7d5164c4539 100644 --- a/src/webgpu/compat/api/validation/encoding/cmds/copyTextureToBuffer.spec.ts +++ b/src/webgpu/compat/api/validation/encoding/cmds/copyTextureToBuffer.spec.ts @@ -19,16 +19,17 @@ g.test('compressed') .fn(t => { const { format } = t.params; - const { blockWidth, blockHeight, bytesPerBlock } = kTextureFormatInfo[format]; + const info = kTextureFormatInfo[format]; + const textureSize = [info.blockWidth, info.blockHeight, 1]; const texture = t.device.createTexture({ - size: [blockWidth, blockHeight, 1], + size: textureSize, format, usage: GPUTextureUsage.COPY_SRC, }); t.trackForCleanup(texture); - const bytesPerRow = align(bytesPerBlock, 256); + const bytesPerRow = align(info.color.bytes, 256); const buffer = t.device.createBuffer({ size: bytesPerRow, @@ -37,7 +38,7 @@ g.test('compressed') t.trackForCleanup(buffer); const encoder = t.device.createCommandEncoder(); - encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, [blockWidth, blockHeight, 1]); + encoder.copyTextureToBuffer({ texture }, { buffer, bytesPerRow }, textureSize); t.expectGPUError('validation', () => { encoder.finish(); }); diff --git a/src/webgpu/format_info.ts b/src/webgpu/format_info.ts index 8ed39cdf3d22..be1320d3cdad 100644 --- a/src/webgpu/format_info.ts +++ b/src/webgpu/format_info.ts @@ -31,16 +31,8 @@ const kFormatUniversalDefaults = { /** The base format for srgb formats. Specified on both srgb and equivalent non-srgb formats. */ baseFormat: undefined, - /** @deprecated */ - copyDst: undefined, /** @deprecated Use `.color.bytes`, `.depth.bytes`, or `.stencil.bytes`. */ bytesPerBlock: undefined, - /** @deprecated */ - renderable: false, - /** @deprecated */ - renderTargetPixelByteCost: undefined, - /** @deprecated */ - renderTargetComponentAlignment: undefined, // IMPORTANT: // Add new top-level keys both here and in TextureFormatInfo_TypeCheck. @@ -76,7 +68,7 @@ function formatTableWithDefaults kColorTextureFormatInfo[v].colorRender ); -assert( - kRenderableColorTextureFormats.every( - f => - kAllTextureFormatInfo[f].renderTargetComponentAlignment !== undefined && - kAllTextureFormatInfo[f].renderTargetPixelByteCost !== undefined - ) -); /** Per-GPUTextureFormat-per-aspect info. */ interface TextureFormatAspectInfo { @@ -1608,11 +1483,7 @@ type TextureFormatInfo_TypeCheck = { baseFormat: GPUTextureFormat | undefined; feature: GPUFeatureName | undefined; - copyDst: boolean; bytesPerBlock: number | undefined; - renderable: boolean; - renderTargetPixelByteCost: number | undefined; - renderTargetComponentAlignment: number | undefined; // IMPORTANT: // Add new top-level keys both here and in kUniversalDefaults.