From 7750ee9f7b9b9717efe5cc887496a27109a50594 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 10 Feb 2017 11:36:09 +0100 Subject: [PATCH] D3D11: Fix reversed colors, stencil improvements --- GPU/D3D11/StateMappingD3D11.cpp | 27 ++++++++++++++--------- GPU/D3D11/TextureCacheD3D11.cpp | 2 +- GPU/Directx9/VertexShaderGeneratorDX9.cpp | 6 ++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index d88285d181..02f9329dcf 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -156,10 +156,12 @@ struct D3D11DepthStencilKey { unsigned int depthWriteEnable : 1; unsigned int depthCompareOp : 4; // D3D11_COMPARISON (-1 and we could fit it in 3 bits) unsigned int stencilTestEnable : 1; - unsigned int stencilCompareOp : 4; // D3D11_COMPARISON + unsigned int stencilCompareFunc : 4; // D3D11_COMPARISON unsigned int stencilPassOp : 4; // D3D11_STENCIL_OP unsigned int stencilFailOp : 4; // D3D11_STENCIL_OP unsigned int stencilDepthFailOp : 4; // D3D11_STENCIL_OP + unsigned int stencilWriteMask : 8; // Unfortunately these are baked into the state on D3D11 + unsigned int stencilCompareMask : 8; }; struct D3D11RasterKey { @@ -179,8 +181,6 @@ struct D3D11DynamicState { uint32_t blendColor; bool useStencil; uint8_t stencilRef; - uint8_t stencilWriteMask; - uint8_t stencilCompareMask; D3D11_VIEWPORT viewport; D3D11_RECT scissor; }; @@ -259,7 +259,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { // Stencil Test if (alphaMask) { key.depthStencil.stencilTestEnable = true; - key.depthStencil.stencilCompareOp = D3D11_COMPARISON_ALWAYS; + key.depthStencil.stencilCompareFunc = D3D11_COMPARISON_ALWAYS; key.depthStencil.stencilPassOp = D3D11_STENCIL_OP_REPLACE; key.depthStencil.stencilFailOp = D3D11_STENCIL_OP_REPLACE; key.depthStencil.stencilDepthFailOp = D3D11_STENCIL_OP_REPLACE; @@ -268,7 +268,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { // A normal clear will be 2 points, the second point has the color. // We override this value in the pipeline from software transform for clear rectangles. dynState.stencilRef = 0xFF; - dynState.stencilWriteMask = 0xFF; + key.depthStencil.stencilWriteMask = 0xFF; } else { key.depthStencil.stencilTestEnable = false; dynState.useStencil = false; @@ -341,14 +341,14 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { // Stencil Test if (stencilState.enabled) { key.depthStencil.stencilTestEnable = true; - key.depthStencil.stencilCompareOp = compareOps[stencilState.testFunc]; + key.depthStencil.stencilCompareFunc = compareOps[stencilState.testFunc]; key.depthStencil.stencilPassOp = stencilOps[stencilState.zPass]; key.depthStencil.stencilFailOp = stencilOps[stencilState.sFail]; key.depthStencil.stencilDepthFailOp = stencilOps[stencilState.zFail]; + key.depthStencil.stencilCompareMask = stencilState.testMask; + key.depthStencil.stencilWriteMask = stencilState.writeMask; dynState.useStencil = true; dynState.stencilRef = stencilState.testRef; - dynState.stencilCompareMask = stencilState.testMask; - dynState.stencilWriteMask = stencilState.writeMask; } else { key.depthStencil.stencilTestEnable = false; dynState.useStencil = false; @@ -426,9 +426,14 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { desc.DepthEnable = key.depthStencil.depthTestEnable; desc.DepthWriteMask = key.depthStencil.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; desc.DepthFunc = (D3D11_COMPARISON_FUNC)key.depthStencil.depthCompareOp; - desc.StencilEnable = FALSE; // keys.depthStencil.stencilTestEnable; - - // ... + desc.StencilEnable = key.depthStencil.stencilTestEnable; + desc.StencilReadMask = key.depthStencil.stencilCompareMask; + desc.StencilWriteMask = key.depthStencil.stencilWriteMask; + desc.FrontFace.StencilFailOp = (D3D11_STENCIL_OP)key.depthStencil.stencilFailOp; + desc.FrontFace.StencilPassOp = (D3D11_STENCIL_OP)key.depthStencil.stencilPassOp; + desc.FrontFace.StencilDepthFailOp = (D3D11_STENCIL_OP)key.depthStencil.stencilDepthFailOp; + desc.FrontFace.StencilFunc = (D3D11_COMPARISON_FUNC)key.depthStencil.stencilCompareFunc; + desc.BackFace = desc.FrontFace; device_->CreateDepthStencilState(&desc, &ds); depthStencilCache_.insert(std::pair(depthKey, ds)); } else { diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 7603aa27fc..97318afb4c 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -644,7 +644,7 @@ void TextureCacheD3D11::SetTexture(bool force) { TexCache::iterator iter = cache.find(cachekey); TexCacheEntry *entry = NULL; gstate_c.needShaderTexClamp = false; - gstate_c.bgraTexture = true; + gstate_c.bgraTexture = false; gstate_c.skipDrawReason &= ~SKIPDRAW_BAD_FB_TEXTURE; bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.cpp b/GPU/Directx9/VertexShaderGeneratorDX9.cpp index c5f8b734e5..b9ff0f0dd1 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.cpp +++ b/GPU/Directx9/VertexShaderGeneratorDX9.cpp @@ -124,7 +124,7 @@ void GenerateVertexShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage l WRITE(p, "float4x3 u_world : register(c%i);\n", CONST_VS_WORLD); WRITE(p, "float4x3 u_view : register(c%i);\n", CONST_VS_VIEW); if (doTextureTransform) - WRITE(p, "float4x3 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX); + WRITE(p, "float4x3 u_tex : register(c%i);\n", CONST_VS_TEXMTX); if (enableBones) { #ifdef USE_BONE_ARRAY WRITE(p, "float4x3 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0); @@ -586,9 +586,9 @@ void GenerateVertexShaderHLSL(const ShaderID &id, char *buffer, ShaderLanguage l } // Transform by texture matrix. XYZ as we are doing projection mapping. if (lang == HLSL_D3D11) { - WRITE(p, " Out.v_texcoord.xyz = (mul(%s, u_texmtx) * float4(u_uvscaleoffset.xy, 1.0, 0.0)).xyz;\n", temp_tc.c_str()); + WRITE(p, " Out.v_texcoord.xyz = (mul(u_tex, %s) * float4(u_uvscaleoffset.xy, 1.0, 0.0)).xyz;\n", temp_tc.c_str()); } else { - WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_texmtx) * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str()); + WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_tex) * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str()); } } break;