From a064872983582bfaa06be36b0d0c06cce606224a Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 13 May 2022 18:53:27 +0000 Subject: [PATCH] Metal: use physical size to compute parameters for clearing with a copy Bug: None Change-Id: I720cd7c0b2fe808d54def5b65882f1bd5742a23a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90200 Reviewed-by: Shrek Shao Reviewed-by: Austin Eng Kokoro: Kokoro Commit-Queue: Corentin Wallez --- src/dawn/native/metal/TextureMTL.mm | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm index 38db7cfa32..3a413a9c6f 100644 --- a/src/dawn/native/metal/TextureMTL.mm +++ b/src/dawn/native/metal/TextureMTL.mm @@ -930,23 +930,18 @@ MaybeError Texture::ClearTexture(CommandRecordingContext* commandContext, } } } else { - Extent3D largestMipSize = GetMipLevelVirtualSize(range.baseMipLevel); - // Encode a buffer to texture copy to clear each subresource. for (Aspect aspect : IterateEnumMask(range.aspects)) { // Compute the buffer size big enough to fill the largest mip. const TexelBlockInfo& blockInfo = GetFormat().GetAspectInfo(aspect).block; - // Metal validation layers: sourceBytesPerRow must be at least 64. + // Computations for the bytes per row / image height are done using the physical size + // so that enough data is reserved for compressed textures. + Extent3D largestMipSize = GetMipLevelPhysicalSize(range.baseMipLevel); uint32_t largestMipBytesPerRow = - std::max((largestMipSize.width / blockInfo.width) * blockInfo.byteSize, 64u); - - // Metal validation layers: sourceBytesPerImage must be at least 512. - uint64_t largestMipBytesPerImage = - std::max(static_cast(largestMipBytesPerRow) * - (largestMipSize.height / blockInfo.height), - 512llu); - + (largestMipSize.width / blockInfo.width) * blockInfo.byteSize; + uint64_t largestMipBytesPerImage = static_cast(largestMipBytesPerRow) * + (largestMipSize.height / blockInfo.height); uint64_t bufferSize = largestMipBytesPerImage * largestMipSize.depthOrArrayLayers; if (bufferSize > std::numeric_limits::max()) {