DriverDetails: Add broken discard with early-Z bug on Apple Silicon GPUs

This commit is contained in:
OatmealDome
2021-12-25 00:27:43 -05:00
parent e7f5e5172c
commit 259a5fc7c0
6 changed files with 70 additions and 16 deletions

View File

@ -57,7 +57,9 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
const bool use_shader_blend = !use_dual_source && host_config.backend_shader_framebuffer_fetch;
const bool use_shader_logic_op =
!host_config.backend_logic_op && host_config.backend_shader_framebuffer_fetch;
const bool use_framebuffer_fetch = use_shader_blend || use_shader_logic_op;
const bool use_framebuffer_fetch =
use_shader_blend || use_shader_logic_op ||
DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z);
const bool early_depth = uid_data->early_depth != 0;
const bool per_pixel_depth = uid_data->per_pixel_depth != 0;
const bool bounding_box = host_config.bounding_box;
@ -1007,8 +1009,21 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
out.Write(" depth = float(zbuffer_zCoord) / 16777216.0;\n");
}
out.Write(" // Alpha Test\n"
" if (bpmem_alphaTest != 0u) {{\n"
out.Write(" // Alpha Test\n");
if (early_depth && DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z))
{
// Instead of using discard, fetch the framebuffer's color value and use it as the output
// for this fragment.
out.Write(" #define discard_fragment {{ {} = float4(initial_ocol0.xyz, 1.0); return; }}\n",
use_shader_blend ? "real_ocol0" : "ocol0");
}
else
{
out.Write(" #define discard_fragment discard\n");
}
out.Write(" if (bpmem_alphaTest != 0u) {{\n"
" bool comp0 = alphaCompare(TevResult.a, " I_ALPHA ".r, {});\n",
BitfieldExtract<&AlphaTest::comp0>("bpmem_alphaTest"));
out.Write(" bool comp1 = alphaCompare(TevResult.a, " I_ALPHA ".g, {});\n",
@ -1019,13 +1034,13 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
" switch ({}) {{\n",
BitfieldExtract<&AlphaTest::logic>("bpmem_alphaTest"));
out.Write(" case 0u: // AND\n"
" if (comp0 && comp1) break; else discard; break;\n"
" if (comp0 && comp1) break; else discard_fragment; break;\n"
" case 1u: // OR\n"
" if (comp0 || comp1) break; else discard; break;\n"
" if (comp0 || comp1) break; else discard_fragment; break;\n"
" case 2u: // XOR\n"
" if (comp0 != comp1) break; else discard; break;\n"
" if (comp0 != comp1) break; else discard_fragment; break;\n"
" case 3u: // XNOR\n"
" if (comp0 == comp1) break; else discard; break;\n"
" if (comp0 == comp1) break; else discard_fragment; break;\n"
" }}\n"
" }}\n"
"\n");