Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9801 from Techjar/bbox-rounding-hack
VideoCommon: Only include centered pixels in bounding box
  • Loading branch information
JMC47 committed Jun 11, 2021
2 parents a51d01b + b267f54 commit 0c6e00c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/Core/VideoCommon/PixelShaderGen.cpp
Expand Up @@ -489,9 +489,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
Expand All @@ -500,8 +509,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) {{
Expand All @@ -520,7 +529,7 @@ void UpdateBoundingBox(float2 rawpos) {{
}}
)",
fmt::arg("efb_height", EFB_HEIGHT));
fmt::arg("efb_height", EFB_HEIGHT), fmt::arg("efb_scale", I_EFBSCALE));
}
}

Expand Down

0 comments on commit 0c6e00c

Please sign in to comment.