From 24f06187df8d253f19074e098ed2846a2339af80 Mon Sep 17 00:00:00 2001 From: lightningterror Date: Sat, 23 May 2020 00:58:53 +0200 Subject: [PATCH] gsdx-d3d11: Port/add depth mask support to EmulateZbuffer. Add support for depthmasking to EmulateZbuffer, previous old code had support but wasn't ported properly with the new code a few years back. VS Constant buffer is now properly setup. --- plugins/GSdx/Renderers/DX11/GSDevice11.h | 10 ++++++---- plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp | 2 ++ plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp | 1 - plugins/GSdx/res/tfx.fx | 14 ++++---------- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.h b/plugins/GSdx/Renderers/DX11/GSDevice11.h index 93daf827c5..db7e2ed1a8 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.h +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.h @@ -42,11 +42,14 @@ public: GSVector4 VertexOffset; GSVector4 Texture_Scale_Offset; + GSVector2i DepthMask; + VSConstantBuffer() { - VertexScale = GSVector4::zero(); - VertexOffset = GSVector4::zero(); + VertexScale = GSVector4::zero(); + VertexOffset = GSVector4::zero(); Texture_Scale_Offset = GSVector4::zero(); + DepthMask = GSVector2i(0); } __forceinline bool Update(const VSConstantBuffer* cb) @@ -74,11 +77,10 @@ public: { struct { - uint32 bppz:2; uint32 tme:1; uint32 fst:1; - uint32 _free:28; + uint32 _free:30; }; uint32 key; diff --git a/plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp b/plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp index c79ed43edf..16f4a5560f 100644 --- a/plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp +++ b/plugins/GSdx/Renderers/DX11/GSRendererDX11.cpp @@ -176,6 +176,7 @@ void GSRendererDX11::EmulateZbuffer() // The real GS appears to do no masking based on the Z buffer format and writing larger Z values // than the buffer supports seems to be an error condition on the real GS, causing it to crash. // We are probably receiving bad coordinates from VU1 in these cases. + vs_cb.DepthMask = GSVector2i(0xFFFFFFFF, 0xFFFFFFFF); if (m_om_dssel.ztst >= ZTST_ALWAYS && m_om_dssel.zwe && (m_context->ZBUF.PSM != PSM_PSMZ32)) { @@ -188,6 +189,7 @@ void GSRendererDX11::EmulateZbuffer() #ifdef _DEBUG fprintf(stdout, "%d: Bad Z size on %s buffers\n", s_n, psm_str(m_context->ZBUF.PSM)); #endif + vs_cb.DepthMask = GSVector2i(max_z, max_z); m_om_dssel.ztst = ZTST_ALWAYS; } } diff --git a/plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp b/plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp index c6ffb19458..37a503008f 100644 --- a/plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp +++ b/plugins/GSdx/Renderers/DX11/GSTextureFX11.cpp @@ -101,7 +101,6 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb) { ShaderMacro sm(m_shader.model); - sm.AddMacro("VS_BPPZ", sel.bppz); sm.AddMacro("VS_TME", sel.tme); sm.AddMacro("VS_FST", sel.fst); diff --git a/plugins/GSdx/res/tfx.fx b/plugins/GSdx/res/tfx.fx index 6bc4c8b27c..93dede1cfd 100644 --- a/plugins/GSdx/res/tfx.fx +++ b/plugins/GSdx/res/tfx.fx @@ -4,8 +4,7 @@ #define FMT_24 1 #define FMT_16 2 -#ifndef VS_BPPZ -#define VS_BPPZ 0 +#ifndef VS_TME #define VS_TME 1 #define VS_FST 1 #endif @@ -100,6 +99,8 @@ cbuffer cb0 float4 VertexScale; float4 VertexOffset; float4 Texture_Scale_Offset; + uint DepthMask; + uint3 _pad_cb0; }; cbuffer cb1 @@ -786,14 +787,7 @@ PS_OUTPUT ps_main(PS_INPUT input) VS_OUTPUT vs_main(VS_INPUT input) { - if(VS_BPPZ == 1) // 24 - { - input.z = input.z & 0xffffff; - } - else if(VS_BPPZ == 2) // 16 - { - input.z = input.z & 0xffff; - } + input.z &= DepthMask; VS_OUTPUT output;