From 6f87ccdafc8ef72ba0e6d312190363d682a13060 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Thu, 15 Jun 2023 19:02:26 +0100 Subject: [PATCH] [d3d11] Use FORCE_UNORM depth bias representation for UNORM formats --- src/d3d11/d3d11_context.cpp | 23 ++++++++++++++++++++++- src/d3d11/d3d11_device.cpp | 5 +++++ src/d3d11/d3d11_view_dsv.h | 4 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index d2440135..822c0d5f 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -3389,8 +3389,24 @@ namespace dxvk { } + static VkDepthBiasRepresentationEXT FormatToDepthBiasRepresentation(DXGI_FORMAT format) { + switch (format) { + default: + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + case DXGI_FORMAT_D32_FLOAT: + return VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; + + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_D16_UNORM: + return VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT; + } + } + template void D3D11CommonContext::BindFramebuffer() { + DxvkDepthBiasRepresentation depthBiasRepresentation = + { VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, + m_device->features().extDepthBiasControl.depthBiasExact }; DxvkRenderTargets attachments; uint32_t sampleCount = 0; @@ -3411,12 +3427,17 @@ namespace dxvk { m_state.om.dsv->GetImageView(), m_state.om.dsv->GetRenderLayout() }; sampleCount = m_state.om.dsv->GetSampleCount(); + + if (m_device->features().extDepthBiasControl.leastRepresentableValueForceUnormRepresentation) + depthBiasRepresentation.depthBiasRepresentation = FormatToDepthBiasRepresentation(m_state.om.dsv->GetViewFormat()); } // Create and bind the framebuffer object to the context EmitCs([ - cAttachments = std::move(attachments) + cAttachments = std::move(attachments), + cRepresentation = depthBiasRepresentation ] (DxvkContext* ctx) mutable { + ctx->setDepthBiasRepresentation(cRepresentation); ctx->bindRenderTargets(Forwarder::move(cAttachments), 0u); }); diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 2db6f9e4..bc107eff 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1953,6 +1953,11 @@ namespace dxvk { enabled.core.features.shaderFloat64 = supported.core.features.shaderFloat64; enabled.core.features.shaderInt64 = supported.core.features.shaderInt64; + // Depth bias control + enabled.extDepthBiasControl.depthBiasControl = supported.extDepthBiasControl.depthBiasControl; + enabled.extDepthBiasControl.depthBiasExact = supported.extDepthBiasControl.depthBiasExact; + enabled.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation = supported.extDepthBiasControl.leastRepresentableValueForceUnormRepresentation; + return enabled; } diff --git a/src/d3d11/d3d11_view_dsv.h b/src/d3d11/d3d11_view_dsv.h index a07d29b2..de1958fc 100644 --- a/src/d3d11/d3d11_view_dsv.h +++ b/src/d3d11/d3d11_view_dsv.h @@ -77,6 +77,10 @@ namespace dxvk { return mask; } + DXGI_FORMAT GetViewFormat() const { + return m_desc.Format; + } + D3D10DepthStencilView* GetD3D10Iface() { return &m_d3d10; }