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 <shrekshao@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-05-13 18:53:27 +00:00 committed by Dawn LUCI CQ
parent 59e23943f3
commit a064872983
1 changed files with 6 additions and 11 deletions

View File

@ -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<uint64_t>(largestMipBytesPerRow) *
(largestMipSize.height / blockInfo.height),
512llu);
(largestMipSize.width / blockInfo.width) * blockInfo.byteSize;
uint64_t largestMipBytesPerImage = static_cast<uint64_t>(largestMipBytesPerRow) *
(largestMipSize.height / blockInfo.height);
uint64_t bufferSize = largestMipBytesPerImage * largestMipSize.depthOrArrayLayers;
if (bufferSize > std::numeric_limits<NSUInteger>::max()) {