From 73d762f506760693439c8d4ba7ba7dcd32eb89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 3 Apr 2017 16:19:10 +0200 Subject: [PATCH] Reorganize raster state mapping --- GPU/D3D11/StateMappingD3D11.cpp | 14 +++++++----- GPU/Directx9/StateMappingDX9.cpp | 27 ++++++++++++----------- GPU/GLES/StateMappingGLES.cpp | 36 ++++++++++++++++--------------- GPU/Vulkan/StateMappingVulkan.cpp | 15 ++++++++----- 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index f3be8cb4bb..997f1cd0f0 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -236,10 +236,18 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { dynState_.useStencil = false; { - // Set ColorMask/Stencil/Depth if (gstate.isModeClear()) { keys_.raster.cullMode = D3D11_CULL_NONE; + } else { + // Set cull + bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE; + } + } + { + // Set ColorMask/Stencil/Depth + if (gstate.isModeClear()) { keys_.depthStencil.depthTestEnable = true; keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_ALWAYS; keys_.depthStencil.depthWriteEnable = gstate.isClearModeDepthMask(); @@ -267,10 +275,6 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { } } else { - // Set cull - bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE; - // Depth Test if (gstate.isDepthTestEnabled()) { keys_.depthStencil.depthTestEnable = true; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index 078e90a078..5130f3cf7d 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -198,19 +198,26 @@ void DrawEngineDX9::ApplyDrawState(int prim) { bool alwaysDepthWrite = g_Config.bAlwaysDepthWrite; bool enableStencilTest = !g_Config.bDisableStencilTest; - // Set Dither - if (gstate.isDitherEnabled()) { - dxstate.dither.enable(); - } else { - dxstate.dither.disable(); + { + // Set Dither + if (gstate.isDitherEnabled()) { + dxstate.dither.enable(); + } else { + dxstate.dither.disable(); + } + if (gstate.isModeClear()) { + // Set Cull + dxstate.cullMode.set(false, false); + } else { + // Set cull + bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + dxstate.cullMode.set(wantCull, gstate.getCullMode()); + } } { // Set Stencil/Depth if (gstate.isModeClear()) { - // Set Cull - dxstate.cullMode.set(false, false); - // Depth Test dxstate.depthTest.enable(); dxstate.depthFunc.set(D3DCMP_ALWAYS); @@ -231,10 +238,6 @@ void DrawEngineDX9::ApplyDrawState(int prim) { } } else { - // Set cull - bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - dxstate.cullMode.set(wantCull, gstate.getCullMode()); - // Depth Test if (gstate.isDepthTestEnabled()) { dxstate.depthTest.enable(); diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index 3dc6f007d9..c3929b4c87 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -252,25 +252,27 @@ void DrawEngineGLES::ApplyDrawState(int prim) { } } - // Dither - if (gstate.isDitherEnabled()) { - glstate.dither.enable(); - glstate.dither.set(GL_TRUE); - } else { - glstate.dither.disable(); - } - - if (gstate.isModeClear()) { - // Culling - glstate.cullFace.disable(); - } else { - // Set cull - bool cullEnabled = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - if (cullEnabled) { - glstate.cullFace.enable(); - glstate.cullFaceMode.set(cullingMode[gstate.getCullMode() ^ !useBufferedRendering]); + { + // Dither + if (gstate.isDitherEnabled()) { + glstate.dither.enable(); + glstate.dither.set(GL_TRUE); } else { + glstate.dither.disable(); + } + + if (gstate.isModeClear()) { + // Culling glstate.cullFace.disable(); + } else { + // Set cull + bool cullEnabled = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + if (cullEnabled) { + glstate.cullFace.enable(); + glstate.cullFaceMode.set(cullingMode[gstate.getCullMode() ^ !useBufferedRendering]); + } else { + glstate.cullFace.disable(); + } } } diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index dc9ef50d9e..3af2223cdc 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -221,10 +221,18 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag } { - // Set Stencil/Depth if (gstate.isModeClear()) { key.cullMode = VK_CULL_MODE_NONE; + } else { + // Set cull + bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + key.cullMode = wantCull ? (gstate.getCullMode() ? VK_CULL_MODE_FRONT_BIT : VK_CULL_MODE_BACK_BIT) : VK_CULL_MODE_NONE; + } + } + { + // Set Stencil/Depth + if (gstate.isModeClear()) { key.depthTestEnable = true; key.depthCompareOp = VK_COMPARE_OP_ALWAYS; key.depthWriteEnable = gstate.isClearModeDepthMask(); @@ -261,10 +269,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag } } - // Set cull - bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - key.cullMode = wantCull ? (gstate.getCullMode() ? VK_CULL_MODE_FRONT_BIT : VK_CULL_MODE_BACK_BIT) : VK_CULL_MODE_NONE; - // Depth Test if (gstate.isDepthTestEnabled()) { key.depthTestEnable = true; @@ -333,5 +337,6 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag gstate_c.Dirty(DIRTY_DEPTHRANGE); } } + key.topology = primToVulkan[prim]; }