From 2e05d22eb7a0faaea03d72018726b11b6a4fbedb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 19 May 2020 22:12:30 -0700 Subject: [PATCH 1/3] Vulkan: Move Harvest Moon fix to Draw::Bugs. Also, make it so you can skip using ini settings. --- GPU/Vulkan/StateMappingVulkan.cpp | 2 +- ext/native/thin3d/thin3d.h | 1 + ext/native/thin3d/thin3d_vulkan.cpp | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index dde593bdd3..d2a3e8591c 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -239,7 +239,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag key.colorWriteMask = (rmask ? VK_COLOR_COMPONENT_R_BIT : 0) | (gmask ? VK_COLOR_COMPONENT_G_BIT : 0) | (bmask ? VK_COLOR_COMPONENT_B_BIT : 0) | (amask ? VK_COLOR_COMPONENT_A_BIT : 0); // Workaround proposed in #10421, for bug where the color write mask is not applied correctly on Adreno. - if ((gstate.pmskc & 0x00FFFFFF) == 0x00FFFFFF && vulkan_->GetPhysicalDeviceProperties().properties.vendorID == VULKAN_VENDOR_QUALCOMM) { + if ((gstate.pmskc & 0x00FFFFFF) == 0x00FFFFFF && g_Config.bVendorBugChecksEnabled && draw_->GetBugs().Has(Draw::Bugs::COLORWRITEMASK_BROKEN_WITH_DEPTHTEST)) { key.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; if (!key.blendEnable) { key.blendEnable = true; diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index 97320ae52e..bf5f9bb87e 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -335,6 +335,7 @@ public: ANY_MAP_BUFFER_RANGE_SLOW = 2, PVR_GENMIPMAP_HEIGHT_GREATER = 3, BROKEN_NAN_IN_CONDITIONAL = 4, + COLORWRITEMASK_BROKEN_WITH_DEPTHTEST = 5, }; protected: diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 794fa2c8c2..78703fdd9b 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -774,6 +774,9 @@ VKContext::VKContext(VulkanContext *vulkan, bool splitSubmit) if (deviceProps.deviceID >= 0x05000000 && deviceProps.deviceID < 0x06000000) { bugs_.Infest(Bugs::NO_DEPTH_CANNOT_DISCARD_STENCIL); } + // Color write mask not masking write in certain scenarios with a depth test, see #10421. + // Known still present on driver 0x80180000 and Adreno 5xx (possibly more.) + bugs_.Infest(Bugs::COLORWRITEMASK_BROKEN_WITH_DEPTHTEST); } else if (caps_.vendor == GPUVendor::VENDOR_AMD) { // See issue #10074, and also #10065 (AMD) and #10109 for the choice of the driver version to check for. if (deviceProps.driverVersion < 0x00407000) { From 8d900bb432db648d1378a37b2d340139536fd2e3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 19 May 2020 22:13:15 -0700 Subject: [PATCH 2/3] Vulkan: Check driver version for Adreno 5xx bug. It's now fixed at least as of this version (possibly earlier.) --- GPU/Vulkan/StencilBufferVulkan.cpp | 2 +- ext/native/thin3d/thin3d_vulkan.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/Vulkan/StencilBufferVulkan.cpp b/GPU/Vulkan/StencilBufferVulkan.cpp index a025763d54..8b8b21090f 100644 --- a/GPU/Vulkan/StencilBufferVulkan.cpp +++ b/GPU/Vulkan/StencilBufferVulkan.cpp @@ -149,7 +149,7 @@ bool FramebufferManagerVulkan::NotifyStencilUpload(u32 addr, int size, StencilUp const char *stencil_fs_source = stencil_fs; // See comment above the stencil_fs_adreno definition. u32 vendorID = vulkan_->GetPhysicalDeviceProperties().properties.vendorID; - if (vendorID == VULKAN_VENDOR_QUALCOMM || vendorID == VULKAN_VENDOR_ARM) + if (g_Config.bVendorBugChecksEnabled && (draw_->GetBugs().Has(Draw::Bugs::NO_DEPTH_CANNOT_DISCARD_STENCIL) || vendorID == VULKAN_VENDOR_ARM)) stencil_fs_source = stencil_fs_adreno; stencilVs_ = CompileShaderModule(vulkan_, VK_SHADER_STAGE_VERTEX_BIT, stencil_vs, &error); diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 78703fdd9b..919f3f59ac 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -772,7 +772,9 @@ VKContext::VKContext(VulkanContext *vulkan, bool splitSubmit) // Adreno 5xx devices, all known driver versions, fail to discard stencil when depth write is off. // See: https://github.com/hrydgard/ppsspp/pull/11684 if (deviceProps.deviceID >= 0x05000000 && deviceProps.deviceID < 0x06000000) { - bugs_.Infest(Bugs::NO_DEPTH_CANNOT_DISCARD_STENCIL); + if (deviceProps.driverVersion < 0x80180000) { + bugs_.Infest(Bugs::NO_DEPTH_CANNOT_DISCARD_STENCIL); + } } // Color write mask not masking write in certain scenarios with a depth test, see #10421. // Known still present on driver 0x80180000 and Adreno 5xx (possibly more.) From 86bbb447d3d9b41b26e9a7caf9fe2d75f92ea940 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 19 May 2020 22:14:47 -0700 Subject: [PATCH 3/3] Vulkan: Avoid stencilAction != depthAction. This is the only place we do it, and apparently there can be bugs on some drivers when you do that. Let's not. --- GPU/Vulkan/StencilBufferVulkan.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Vulkan/StencilBufferVulkan.cpp b/GPU/Vulkan/StencilBufferVulkan.cpp index 8b8b21090f..ec39e42c5b 100644 --- a/GPU/Vulkan/StencilBufferVulkan.cpp +++ b/GPU/Vulkan/StencilBufferVulkan.cpp @@ -171,9 +171,9 @@ bool FramebufferManagerVulkan::NotifyStencilUpload(u32 addr, int size, StencilUp return false; if (dstBuffer->fbo) { + // Use keep because some drivers have trouble when stencilAction != depthAction. // Typically, STENCIL_IS_ZERO means it's already bound, so this bind will be optimized away. - Draw::RPAction stencilAction = flags == StencilUpload::STENCIL_IS_ZERO ? Draw::RPAction::KEEP : Draw::RPAction::CLEAR; - draw_->BindFramebufferAsRenderTarget(dstBuffer->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, stencilAction }); + draw_->BindFramebufferAsRenderTarget(dstBuffer->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, Draw::RPAction::KEEP }); } else { // something is wrong... }