From 2329c71b6fad69c5edbf66e8de3e9427b1757520 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 25 Aug 2022 16:05:15 +0200 Subject: [PATCH] [dxvk] Implement sampler reduction mode --- src/d3d11/d3d11_sampler.cpp | 2 ++ src/d3d11/d3d11_video.cpp | 1 + src/d3d9/d3d9_device.cpp | 1 + src/dxvk/dxvk_sampler.cpp | 6 ++++++ src/dxvk/dxvk_sampler.h | 5 ++++- src/dxvk/dxvk_swapchain_blitter.cpp | 1 + src/dxvk/dxvk_unbound.cpp | 1 + src/dxvk/hud/dxvk_hud_renderer.cpp | 1 + 8 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/d3d11/d3d11_sampler.cpp b/src/d3d11/d3d11_sampler.cpp index 8150c29c3..335717766 100644 --- a/src/d3d11/d3d11_sampler.cpp +++ b/src/d3d11/d3d11_sampler.cpp @@ -34,6 +34,8 @@ namespace dxvk { info.compareToDepth = (filterBits & 0x80) ? VK_TRUE : VK_FALSE; info.compareOp = DecodeCompareOp(desc.ComparisonFunc); + info.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; + for (uint32_t i = 0; i < 4; i++) info.borderColor.float32[i] = desc.BorderColor[i]; diff --git a/src/d3d11/d3d11_video.cpp b/src/d3d11/d3d11_video.cpp index d3422466f..8635f63d6 100644 --- a/src/d3d11/d3d11_video.cpp +++ b/src/d3d11/d3d11_video.cpp @@ -362,6 +362,7 @@ namespace dxvk { samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; samplerInfo.compareToDepth = VK_FALSE; samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; + samplerInfo.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; samplerInfo.borderColor = VkClearColorValue(); samplerInfo.usePixelCoord = VK_FALSE; samplerInfo.nonSeamless = VK_FALSE; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index bbb6c3a73..54b1ab10b 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -5978,6 +5978,7 @@ namespace dxvk { info.mipmapLodBias = cKey.MipmapLodBias; info.mipmapLodMin = mipFilter.MipsEnabled ? float(cKey.MaxMipLevel) : 0; info.mipmapLodMax = mipFilter.MipsEnabled ? FLT_MAX : 0; + info.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; info.usePixelCoord = VK_FALSE; info.nonSeamless = m_dxvkDevice->features().extNonSeamlessCubeMap.nonSeamlessCubeMap && !m_d3d9Options.seamlessCubes; diff --git a/src/dxvk/dxvk_sampler.cpp b/src/dxvk/dxvk_sampler.cpp index 00d926555..49a35f47e 100644 --- a/src/dxvk/dxvk_sampler.cpp +++ b/src/dxvk/dxvk_sampler.cpp @@ -10,6 +10,9 @@ namespace dxvk { VkSamplerCustomBorderColorCreateInfoEXT borderColorInfo = { VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT }; borderColorInfo.customBorderColor = info.borderColor; + VkSamplerReductionModeCreateInfo reductionInfo = { VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO }; + reductionInfo.reductionMode = info.reductionMode; + VkSamplerCreateInfo samplerInfo = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; samplerInfo.flags = info.nonSeamless ? VK_SAMPLER_CREATE_NON_SEAMLESS_CUBE_MAP_BIT_EXT : 0; samplerInfo.magFilter = info.magFilter; @@ -39,6 +42,9 @@ namespace dxvk { if (samplerInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) borderColorInfo.pNext = std::exchange(samplerInfo.pNext, &borderColorInfo); + if (reductionInfo.reductionMode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE) + reductionInfo.pNext = std::exchange(samplerInfo.pNext, &reductionInfo); + if (m_vkd->vkCreateSampler(m_vkd->device(), &samplerInfo, nullptr, &m_sampler) != VK_SUCCESS) throw DxvkError("DxvkSampler::DxvkSampler: Failed to create sampler"); diff --git a/src/dxvk/dxvk_sampler.h b/src/dxvk/dxvk_sampler.h index e2e421b35..61d64a076 100644 --- a/src/dxvk/dxvk_sampler.h +++ b/src/dxvk/dxvk_sampler.h @@ -33,9 +33,12 @@ namespace dxvk { VkBool32 compareToDepth; VkCompareOp compareOp; + /// Reduction mode for min/max samplers + VkSamplerReductionMode reductionMode; + /// Texture border color VkClearColorValue borderColor; - + /// Enables unnormalized coordinates VkBool32 usePixelCoord; diff --git a/src/dxvk/dxvk_swapchain_blitter.cpp b/src/dxvk/dxvk_swapchain_blitter.cpp index 846dd8916..d1c03a7f5 100644 --- a/src/dxvk/dxvk_swapchain_blitter.cpp +++ b/src/dxvk/dxvk_swapchain_blitter.cpp @@ -301,6 +301,7 @@ namespace dxvk { samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; samplerInfo.compareToDepth = VK_FALSE; samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS; + samplerInfo.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; samplerInfo.borderColor = VkClearColorValue(); samplerInfo.usePixelCoord = VK_TRUE; samplerInfo.nonSeamless = VK_FALSE; diff --git a/src/dxvk/dxvk_unbound.cpp b/src/dxvk/dxvk_unbound.cpp index 39f390ce8..a06eafe98 100644 --- a/src/dxvk/dxvk_unbound.cpp +++ b/src/dxvk/dxvk_unbound.cpp @@ -29,6 +29,7 @@ namespace dxvk { info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; info.compareToDepth = VK_FALSE; info.compareOp = VK_COMPARE_OP_NEVER; + info.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; info.borderColor = VkClearColorValue(); info.usePixelCoord = VK_FALSE; info.nonSeamless = VK_FALSE; diff --git a/src/dxvk/hud/dxvk_hud_renderer.cpp b/src/dxvk/hud/dxvk_hud_renderer.cpp index 893d6d346..b797d68e3 100644 --- a/src/dxvk/hud/dxvk_hud_renderer.cpp +++ b/src/dxvk/hud/dxvk_hud_renderer.cpp @@ -309,6 +309,7 @@ namespace dxvk::hud { info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; info.compareToDepth = VK_FALSE; info.compareOp = VK_COMPARE_OP_NEVER; + info.reductionMode = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE; info.borderColor = VkClearColorValue(); info.usePixelCoord = VK_TRUE; info.nonSeamless = VK_FALSE;