From 292a0b498a70e09c01cc64249681cd14d35bbfd7 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 10 Mar 2025 20:05:51 +0100 Subject: [PATCH] [dxvk] Add convenience function to query default resolve mode Removes some code duplication. --- src/dxvk/dxvk_context.cpp | 15 +++------------ src/dxvk/dxvk_format.h | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 5316e8148..84266ab71 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -1961,11 +1961,7 @@ namespace dxvk { if (useRp) { // Work out resolve mode based on format properties. For color images, // we must use AVERAGE unless the resolve uses an integer format. - VkResolveModeFlagBits mode = VK_RESOLVE_MODE_AVERAGE_BIT; - - if (formatInfo->flags.any(DxvkFormatFlag::SampledSInt, DxvkFormatFlag::SampledUInt) - || (formatInfo->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) - mode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; + VkResolveModeFlagBits mode = getDefaultResolveMode(formatInfo); this->resolveImageRp(dstImage, srcImage, region, format, mode, mode); @@ -7777,17 +7773,12 @@ namespace dxvk { // Always do a SAMPLE_ZERO resolve here since that's less expensive and closer to what // happens on native AMD anyway. Need to use a shader in case we are dealing with a // non-integer color image since render pass resolves only support AVERAGE. - auto formatInfo = lookupFormatInfo(op.resolveFormat); - - bool useRp = (formatInfo->flags.any(DxvkFormatFlag::SampledSInt, DxvkFormatFlag::SampledUInt)) - || (formatInfo->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); - - if (useRp) { + if (getDefaultResolveMode(op.resolveFormat) == VK_RESOLVE_MODE_SAMPLE_ZERO_BIT) { resolveImageRp(op.resolveImage, op.inputImage, op.resolveRegion, op.resolveFormat, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT); } else { resolveImageFb(op.resolveImage, op.inputImage, op.resolveRegion, - op.resolveFormat, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, VK_RESOLVE_MODE_NONE); + op.resolveFormat, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT); } } } diff --git a/src/dxvk/dxvk_format.h b/src/dxvk/dxvk_format.h index 127d99115..fcdadb74d 100644 --- a/src/dxvk/dxvk_format.h +++ b/src/dxvk/dxvk_format.h @@ -114,4 +114,23 @@ namespace dxvk { return lookupFormatInfoSlow(format); } -} \ No newline at end of file + /** + * \brief Queries default resolve mode for format + * + * For depth-stencil formats, this will return SAMPLE_ZERO. + * \param [in] format Format to look up + * \returns Default resolve mode + */ + inline VkResolveModeFlagBits getDefaultResolveMode(const DxvkFormatInfo* format) { + if ((format->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) + || (format->flags.any(DxvkFormatFlag::SampledSInt, DxvkFormatFlag::SampledUInt))) + return VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; + + return VK_RESOLVE_MODE_AVERAGE_BIT; + } + + inline VkResolveModeFlagBits getDefaultResolveMode(VkFormat format) { + return getDefaultResolveMode(lookupFormatInfo(format)); + } + +}