diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 37e856ae42..32c80be7bb 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -495,9 +495,18 @@ void UpdateBoundingBoxBuffer(int2 min_pos, int2 max_pos) {{ }} void UpdateBoundingBox(float2 rawpos) {{ + // We only want to include coordinates for pixels aligned with the native resolution pixel centers. + // This makes bounding box sizes more accurate (though not perfect) at higher resolutions, + // avoiding EFB copy buffer overflow in affected games. + // + // For a more detailed explanation, see https://dolp.in/pr9801 + int2 int_efb_scale = iround(1 / {efb_scale}.xy); + if (any(int2(rawpos) % int_efb_scale != int_efb_scale >> 1)) // divide by two + return; + // The rightmost shaded pixel is not included in the right bounding box register, // such that width = right - left + 1. This has been verified on hardware. - int2 pos = int2(rawpos * cefbscale); + int2 pos = int2(rawpos * {efb_scale}.xy); #ifdef API_OPENGL // We need to invert the Y coordinate due to OpenGL's lower-left origin @@ -506,8 +515,8 @@ void UpdateBoundingBox(float2 rawpos) {{ // The GC/Wii GPU rasterizes in 2x2 pixel groups, so bounding box values will be rounded to the // extents of these groups, rather than the exact pixel. - int2 pos_tl = pos & ~1; - int2 pos_br = pos | 1; + int2 pos_tl = pos & ~1; // round down to even + int2 pos_br = pos | 1; // round up to odd #ifdef SUPPORTS_SUBGROUP_REDUCTION if (CAN_USE_SUBGROUP_REDUCTION) {{ @@ -526,7 +535,7 @@ void UpdateBoundingBox(float2 rawpos) {{ }} )", - fmt::arg("efb_height", EFB_HEIGHT)); + fmt::arg("efb_height", EFB_HEIGHT), fmt::arg("efb_scale", I_EFBSCALE)); } }