Merge pull request #9801 from Techjar/bbox-rounding-hack

VideoCommon: Only include centered pixels in bounding box
This commit is contained in:
JMC47 2021-06-11 00:41:11 -04:00 committed by GitHub
commit 0c6e00ce0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -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
@ -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) {{
@ -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));
}
}