GS: Fix region repeat bounds checking for zero crossings

This commit is contained in:
TellowKrinkle 2022-02-01 00:02:17 -06:00 committed by tellowkrinkle
parent 598a3b5d7b
commit b55e59e665
1 changed files with 9 additions and 0 deletions

View File

@ -2664,6 +2664,15 @@ __forceinline void GSState::VertexKick(u32 skip)
/// Also calculates the real min and max values seen after applying the region repeat to all values in min...max
static bool UsesRegionRepeat(int fix, int msk, int min, int max, int* min_out, int* max_out)
{
if ((min < 0) != (max < 0))
{
// Algorithm doesn't work properly if bits overflow when incrementing (happens on the -1 → 0 crossing)
// Conveniently, crossing zero guarantees you use the full range
*min_out = fix;
*max_out = (fix | msk) + 1;
return true;
}
const int cleared_bits = ~msk & ~fix; // Bits that are always cleared by applying msk and fix
const int set_bits = fix; // Bits that are always set by applying msk and fix
unsigned long msb;