From e9851bee861f4b8dbee7b5bf7213b55234581c77 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 5 Sep 2022 04:30:38 +0200 Subject: [PATCH] [dxvk] Introduce per-aspect version of computeImageDataSize --- src/dxvk/dxvk_util.cpp | 8 +++++++- src/dxvk/dxvk_util.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_util.cpp b/src/dxvk/dxvk_util.cpp index 4066c20fb..4f9879c4f 100644 --- a/src/dxvk/dxvk_util.cpp +++ b/src/dxvk/dxvk_util.cpp @@ -145,10 +145,16 @@ namespace dxvk::util { VkDeviceSize computeImageDataSize(VkFormat format, VkExtent3D extent) { const DxvkFormatInfo* formatInfo = lookupFormatInfo(format); + return computeImageDataSize(format, extent, formatInfo->aspectMask); + } + + + VkDeviceSize computeImageDataSize(VkFormat format, VkExtent3D extent, VkImageAspectFlags aspects) { + const DxvkFormatInfo* formatInfo = lookupFormatInfo(format); VkDeviceSize size = 0; - for (auto aspects = formatInfo->aspectMask; aspects; ) { + while (aspects) { auto aspect = vk::getNextAspect(aspects); auto elementSize = formatInfo->elementSize; auto planeExtent = extent; diff --git a/src/dxvk/dxvk_util.h b/src/dxvk/dxvk_util.h index a9a4b7ee4..967458faf 100644 --- a/src/dxvk/dxvk_util.h +++ b/src/dxvk/dxvk_util.h @@ -298,6 +298,19 @@ namespace dxvk::util { */ VkDeviceSize computeImageDataSize(VkFormat format, VkExtent3D extent); + /** + * \brief Computes image data size, in bytes + * + * Convenience method that can be used to compute the number + * of bytes required to store image data in a given format + * for the given aspects. + * \param [in] format The image format + * \param [in] extent Image size, in pixels + * \param [in] aspects Aspect mask + * \returns Data size, in bytes + */ + VkDeviceSize computeImageDataSize(VkFormat format, VkExtent3D extent, VkImageAspectFlags aspects); + /** * \brief Applies a component mapping to a component mask *