From a84e45bdd20f62776796aae70958a2b9121a75c4 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sat, 20 Jan 2018 20:31:47 +0100 Subject: [PATCH] [dxvk] Added convenience functions to work with compressed image sizes --- src/dxvk/dxvk_util.cpp | 26 -------------------- src/dxvk/dxvk_util.h | 55 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/dxvk/dxvk_util.cpp b/src/dxvk/dxvk_util.cpp index b2386289..e18b20c2 100644 --- a/src/dxvk/dxvk_util.cpp +++ b/src/dxvk/dxvk_util.cpp @@ -35,29 +35,3 @@ namespace dxvk::util { } } - - -bool operator == (VkExtent3D a, VkExtent3D b) { - return a.width == b.width - && a.height == b.height - && a.depth == b.depth; -} - - -bool operator != (VkExtent3D a, VkExtent3D b) { - return a.width != b.width - || a.height != b.height - || a.depth != b.depth; -} - - -bool operator == (VkExtent2D a, VkExtent2D b) { - return a.width == b.width - && a.height == b.height; -} - - -bool operator != (VkExtent2D a, VkExtent2D b) { - return a.width != b.width - || a.height != b.height; -} diff --git a/src/dxvk/dxvk_util.h b/src/dxvk/dxvk_util.h index dacf5a52..58b7bb71 100644 --- a/src/dxvk/dxvk_util.h +++ b/src/dxvk/dxvk_util.h @@ -21,10 +21,57 @@ namespace dxvk::util { */ uint32_t computeMipLevelCount(VkExtent3D imageSize); + /** + * \brief Computes block count for compressed images + * + * Convenience function to compute the size, in + * blocks, of compressed images subresources. + * \param [in] imageSize The image size + * \param [in] blockSize Size per pixel block + * \returns Number of blocks in the image + */ + inline VkExtent3D computeBlockCount(VkExtent3D imageSize, VkExtent3D blockSize) { + return VkExtent3D { + (imageSize.width + blockSize.width - 1) / blockSize.width, + (imageSize.height + blockSize.height - 1) / blockSize.height, + (imageSize.depth + blockSize.depth - 1) / blockSize.depth }; + } + + /** + * \brief Computes number of pixels or blocks of an image + * + * Basically returns the product of width, height and depth. + * \param [in] extent Image extent, in pixels or blocks + * \returns Flattened number of pixels or blocks + */ + inline uint32_t flattenImageExtent(VkExtent3D extent) { + return extent.width * extent.height * extent.depth; + } + } -bool operator == (VkExtent3D a, VkExtent3D b); -bool operator != (VkExtent3D a, VkExtent3D b); -bool operator == (VkExtent2D a, VkExtent2D b); -bool operator != (VkExtent2D a, VkExtent2D b); +inline bool operator == (VkExtent3D a, VkExtent3D b) { + return a.width == b.width + && a.height == b.height + && a.depth == b.depth; +} + + +inline bool operator != (VkExtent3D a, VkExtent3D b) { + return a.width != b.width + || a.height != b.height + || a.depth != b.depth; +} + + +inline bool operator == (VkExtent2D a, VkExtent2D b) { + return a.width == b.width + && a.height == b.height; +} + + +inline bool operator != (VkExtent2D a, VkExtent2D b) { + return a.width != b.width + || a.height != b.height; +}