From b30a4f0cc7b672f9adf7b4c2697fb84baf69acd4 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 15 Jun 2023 13:01:01 +0100 Subject: [PATCH] [d3d9] Use FLOAT or FORCE_UNORM depth bias representation --- src/d3d9/d3d9_device.cpp | 32 ++++++++++++++++++++++++++++++-- src/d3d9/d3d9_device.h | 1 + src/d3d9/d3d9_util.h | 8 ++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 33c724dc..02fa688b 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -116,6 +116,25 @@ namespace dxvk { m_usingGraphicsPipelines = dxvkDevice->features().extGraphicsPipelineLibrary.graphicsPipelineLibrary; + m_depthBiasRepresentation = { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, false }; + if (dxvkDevice->features().extDepthBiasControl.depthBiasControl) { + if (dxvkDevice->features().extDepthBiasControl.depthBiasExact) + m_depthBiasRepresentation.depthBiasExact = true; + + if (dxvkDevice->features().extDepthBiasControl.floatRepresentation) { + m_depthBiasRepresentation.depthBiasRepresentation = VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT; + m_depthBiasScale = 1.0f; + } + else if (dxvkDevice->features().extDepthBiasControl.leastRepresentableValueForceUnormRepresentation) + m_depthBiasRepresentation.depthBiasRepresentation = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT; + } + + EmitCs([ + cRepresentation = m_depthBiasRepresentation + ] (DxvkContext* ctx) { + ctx->setDepthBiasRepresentation(cRepresentation); + }); + CreateConstantBuffers(); m_availableMemory = DetermineInitialTextureMemory(); @@ -1505,9 +1524,11 @@ namespace dxvk { FlushImplicit(FALSE); m_flags.set(D3D9DeviceFlag::DirtyFramebuffer); - if (ds != nullptr) { + if (ds != nullptr && m_depthBiasRepresentation.depthBiasRepresentation != VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT) { const int32_t vendorId = m_dxvkDevice->adapter()->deviceProperties().vendorID; - float rValue = GetDepthBufferRValue(ds->GetCommonTexture()->GetFormatMapping().FormatColor, vendorId); + const bool exact = m_depthBiasRepresentation.depthBiasExact; + const bool forceUnorm = m_depthBiasRepresentation.depthBiasRepresentation == VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT; + const float rValue = GetDepthBufferRValue(ds->GetCommonTexture()->GetFormatMapping().FormatColor, vendorId, exact, forceUnorm); if (m_depthBiasScale != rValue) { m_depthBiasScale = rValue; m_flags.set(D3D9DeviceFlag::DirtyDepthBias); @@ -4140,6 +4161,13 @@ namespace dxvk { enabled.extNonSeamlessCubeMap.nonSeamlessCubeMap = supported.extNonSeamlessCubeMap.nonSeamlessCubeMap; + enabled.extDepthBiasControl.depthBiasControl = supported.extDepthBiasControl.depthBiasControl; + enabled.extDepthBiasControl.depthBiasExact = supported.extDepthBiasControl.depthBiasExact; + if (supported.extDepthBiasControl.floatRepresentation) + enabled.extDepthBiasControl.floatRepresentation = VK_TRUE; + else if (supported.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation) + enabled.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation = VK_TRUE; + return enabled; } diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index feeae318..fa10b09d 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -1318,6 +1318,7 @@ namespace dxvk { bool m_usingGraphicsPipelines = false; + DxvkDepthBiasRepresentation m_depthBiasRepresentation = { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, false }; float m_depthBiasScale = 0.0f; uint32_t m_robustSSBOAlignment = 1; diff --git a/src/d3d9/d3d9_util.h b/src/d3d9/d3d9_util.h index 5da8e95d..3003b5ac 100644 --- a/src/d3d9/d3d9_util.h +++ b/src/d3d9/d3d9_util.h @@ -176,19 +176,19 @@ namespace dxvk { void ConvertRect(RECT rect, VkOffset2D& offset, VkExtent2D& extent); - inline float GetDepthBufferRValue(VkFormat Format, int32_t vendorId) { + inline float GetDepthBufferRValue(VkFormat Format, int32_t vendorId, bool exact, bool forceUnorm) { switch (Format) { case VK_FORMAT_D16_UNORM_S8_UINT: case VK_FORMAT_D16_UNORM: - return vendorId == 0x10de ? float(1 << 15) : float(1 << 16); + return (vendorId == 0x10de && !exact) ? float(1 << 15) : float(1 << 16); case VK_FORMAT_D24_UNORM_S8_UINT: - return vendorId == 0x10de ? float(1 << 23) : float(1 << 24); + return (vendorId == 0x10de && !exact) ? float(1 << 23) : float(1 << 24); default: case VK_FORMAT_D32_SFLOAT_S8_UINT: case VK_FORMAT_D32_SFLOAT: - return float(1 << 23); + return forceUnorm ? float(1 << 24) : float(1 << 23); } }