From 55a67988b24eec159f97805530a48eee106fa4bb Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 27 May 2021 16:17:24 +0200 Subject: [PATCH] [dxvk] Support multi-plane formats in computeImageSize --- src/dxvk/dxvk_util.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_util.cpp b/src/dxvk/dxvk_util.cpp index 6fc47e29..95e0aa76 100644 --- a/src/dxvk/dxvk_util.cpp +++ b/src/dxvk/dxvk_util.cpp @@ -75,7 +75,25 @@ namespace dxvk::util { VkDeviceSize computeImageDataSize(VkFormat format, VkExtent3D extent) { const DxvkFormatInfo* formatInfo = imageFormatInfo(format); - return formatInfo->elementSize * flattenImageExtent(computeBlockCount(extent, formatInfo->blockSize)); + + VkDeviceSize size = 0; + + for (auto aspects = formatInfo->aspectMask; aspects; ) { + auto aspect = vk::getNextAspect(aspects); + auto elementSize = formatInfo->elementSize; + auto planeExtent = extent; + + if (formatInfo->flags.test(DxvkFormatFlag::MultiPlane)) { + auto plane = &formatInfo->planes[vk::getPlaneIndex(aspect)]; + planeExtent.width /= plane->blockSize.width; + planeExtent.height /= plane->blockSize.height; + elementSize = plane->elementSize; + } + + size += elementSize * flattenImageExtent(computeBlockCount(planeExtent, formatInfo->blockSize)); + } + + return size; }