From cbeeb8fdf14e416c27b836d38c617ee0f2f819e6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 8 Sep 2020 15:52:01 -0700 Subject: [PATCH 1/3] GPU: Allow culling in through mode. It works per tests and is used in Soul Caliber. Fixes #13400. --- GPU/Common/TextureCacheCommon.cpp | 2 +- GPU/D3D11/StateMappingD3D11.cpp | 7 +++---- GPU/Directx9/StateMappingDX9.cpp | 7 ++----- GPU/GLES/StateMappingGLES.cpp | 8 +------- GPU/Vulkan/StateMappingVulkan.cpp | 6 +++--- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index d9405f468e..4df49bac7d 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1853,7 +1853,7 @@ bool TextureCacheCommon::CheckFullHash(TexCacheEntry *entry, bool &doDelete) { return true; } } else { - // It wasn't found, so we're about to throw away entry and rebuild a texture. + // It wasn't found, so we're about to throw away the entry and rebuild a texture. // Let's save this in the secondary cache in case it gets used again. secondKey = entry->fullhash | ((u64)entry->cluthash << 32); secondCacheSizeEstimate_ += EstimateTexMemoryUsage(entry); diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index cb10fd96f2..5f8e0d4ae4 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -276,14 +276,13 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) { keys_.raster.value = 0; + bool wantCull = !gstate.isModeClear() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE; + if (gstate.isModeClear() || gstate.isModeThrough()) { - keys_.raster.cullMode = D3D11_CULL_NONE; // TODO: Might happen in clear mode if not through... keys_.raster.depthClipEnable = 1; } else { - // Set cull - bool wantCull = prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - keys_.raster.cullMode = wantCull ? (gstate.getCullMode() ? D3D11_CULL_FRONT : D3D11_CULL_BACK) : D3D11_CULL_NONE; if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) { // TODO: Still has a bug where we clamp to depth range if one is not the full range. // But the alternate is not clamping in either direction... diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index f1c5309853..e37c60eaef 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -202,15 +202,12 @@ void DrawEngineDX9::ApplyDrawState(int prim) { } else { dxstate.dither.disable(); } + bool wantCull = !gstate.isModeClear() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + dxstate.cullMode.set(wantCull, gstate.getCullMode()); if (gstate.isModeClear()) { - // Set Cull - dxstate.cullMode.set(false, false); // Well, probably doesn't matter... dxstate.shadeMode.set(D3DSHADE_GOURAUD); } else { - // Set cull - bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - dxstate.cullMode.set(wantCull, gstate.getCullMode()); dxstate.shadeMode.set(gstate.getShadeMode() == GE_SHADE_GOURAUD ? D3DSHADE_GOURAUD : D3DSHADE_FLAT); } } diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index ce958e0403..73a1805a59 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -259,13 +259,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) { bool cullEnable; GLenum cullMode = cullingMode[gstate.getCullMode() ^ !useBufferedRendering]; - if (gstate.isModeClear()) { - // Culling - cullEnable = false; - } else { - // Set cull - cullEnable = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - } + cullEnable = !gstate.isModeClear() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); renderManager->SetRaster(cullEnable, GL_CCW, cullMode, dither); } diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 68f4bffefd..56980441dc 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -255,14 +255,14 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag } if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) { + bool wantCull = !gstate.isModeClear() && 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; + if (gstate.isModeClear() || gstate.isModeThrough()) { - key.cullMode = VK_CULL_MODE_NONE; // TODO: Might happen in clear mode if not through... key.depthClampEnable = false; } else { // Set cull - bool wantCull = 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; if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) { // TODO: Still has a bug where we clamp to depth range if one is not the full range. // But the alternate is not clamping in either direction... From c1ce8383aeadaa489afa9d61a67e03b76882a3f0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 8 Sep 2020 15:52:39 -0700 Subject: [PATCH 2/3] Headless: Setup logman earlier. So we can control all the GPU init logging. --- headless/Headless.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 7f5e5fdcf4..284f709c02 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -328,14 +328,6 @@ int main(int argc, const char* argv[]) if (testFilenames.empty()) return printUsage(argv[0], argc <= 1 ? NULL : "No executables specified"); - HeadlessHost *headlessHost = getHost(gpuCore); - headlessHost->SetGraphicsCore(gpuCore); - host = headlessHost; - - std::string error_string; - GraphicsContext *graphicsContext = nullptr; - bool glWorking = host->InitGraphics(&error_string, &graphicsContext); - LogManager::Init(&g_Config.bEnableLogging); LogManager *logman = LogManager::GetInstance(); @@ -348,6 +340,14 @@ int main(int argc, const char* argv[]) } logman->AddListener(printfLogger); + HeadlessHost *headlessHost = getHost(gpuCore); + headlessHost->SetGraphicsCore(gpuCore); + host = headlessHost; + + std::string error_string; + GraphicsContext *graphicsContext = nullptr; + bool glWorking = host->InitGraphics(&error_string, &graphicsContext); + CoreParameter coreParameter; coreParameter.cpuCore = cpuCore; coreParameter.gpuCore = glWorking ? gpuCore : GPUCORE_NULL; From 5fae2171cc72f22dfb91a11fc98f05f5b5b79eb4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 8 Sep 2020 16:16:41 -0700 Subject: [PATCH 3/3] softgpu: Correct cull handling for sprites. --- GPU/Software/Clipper.cpp | 2 +- GPU/Software/RasterizerRectangle.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/Software/Clipper.cpp b/GPU/Software/Clipper.cpp index 86142582b9..b462bd5977 100644 --- a/GPU/Software/Clipper.cpp +++ b/GPU/Software/Clipper.cpp @@ -206,7 +206,7 @@ void ProcessRect(const VertexData& v0, const VertexData& v1) VertexData* bottomleft = &buf[2]; VertexData* bottomright = &buf[3]; - // Um. Why is this stuff needed? + // DrawTriangle always culls, so sort out the drawing order. for (int i = 0; i < 4; ++i) { if (buf[i].screenpos.x < topleft->screenpos.x && buf[i].screenpos.y < topleft->screenpos.y) topleft = &buf[i]; diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index b6697b52c7..db9c5bdcf9 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -237,8 +237,10 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1) { bool coord_check = (xdiff == udiff || xdiff == -udiff) && (ydiff == vdiff || ydiff == -vdiff); + // Currently only works for TL/BR, which is the most common but not required. + bool orient_check = xdiff >= 0 && ydiff >= 0; bool state_check = !gstate.isModeClear(); // TODO: Add support for clear modes in Rasterizer::DrawSprite. - if ((coord_check || !gstate.isTextureMapEnabled()) && state_check) { + if ((coord_check || !gstate.isTextureMapEnabled()) && orient_check && state_check) { Rasterizer::DrawSprite(v0, v1); return true; }