Skip to content

Commit

Permalink
Merge pull request #16379 from unknownbrackets/stencil-android
Browse files Browse the repository at this point in the history
Fix alpha/stencil replace on Adreno when color masked
  • Loading branch information
hrydgard authored Nov 13, 2022
2 parents 1a0e5c1 + 3f875af commit 1ae6047
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,9 @@ VKContext::VKContext(VulkanContext *vulkan)
}
// 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);
// Known working on driver 0x801EA000 and Adreno 620.
if (deviceProps.driverVersion < 0x801EA000 || deviceProps.deviceID < 0x06000000)
bugs_.Infest(Bugs::COLORWRITEMASK_BROKEN_WITH_DEPTHTEST);

// Trying to follow all the rules in https://registry.khronos.org/vulkan/specs/1.3/html/vkspec.html#synchronization-pipeline-barriers-subpass-self-dependencies
// and https://registry.khronos.org/vulkan/specs/1.3/html/vkspec.html#renderpass-feedbackloop, but still it doesn't
Expand Down
9 changes: 9 additions & 0 deletions GPU/Common/GPUStateUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,15 @@ static void ConvertMaskState(GenericMaskState &maskState, bool shaderBitOpsSuppo
maskState.channelMask &= ~8;
maskState.uniformMask &= ~0xFF000000;
}

// For 5551, only the top alpha bit matters. We might even want to swizzle 4444.
// Alpha should correctly read as 255 from a 5551 texture.
if (gstate.FrameBufFormat() == GE_FORMAT_5551) {
if ((maskState.uniformMask & 0x80000000) != 0)
maskState.uniformMask |= 0xFF000000;
else
maskState.uniformMask &= ~0xFF000000;
}
}

// Called even if AlphaBlendEnable == false - it also deals with stencil-related blend state.
Expand Down
5 changes: 3 additions & 2 deletions GPU/Vulkan/StateMappingVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
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) {
bool writeAlpha = maskState.channelMask & 8;
key.blendEnable = true;
key.blendOpAlpha = VK_BLEND_OP_ADD;
key.srcAlpha = VK_BLEND_FACTOR_ZERO;
key.destAlpha = VK_BLEND_FACTOR_ONE;
key.srcAlpha = writeAlpha ? VK_BLEND_FACTOR_ONE : VK_BLEND_FACTOR_ZERO;
key.destAlpha = writeAlpha ? VK_BLEND_FACTOR_ZERO : VK_BLEND_FACTOR_ONE;
}
key.blendOpColor = VK_BLEND_OP_ADD;
key.srcColor = VK_BLEND_FACTOR_ZERO;
Expand Down

0 comments on commit 1ae6047

Please sign in to comment.