GPU/TextureCache: Prevent wrapping for replacement lookup

Fixes replacements for 8 and 16-bit textures placed in the right-most
page of VRAM.
This commit is contained in:
Stenzek 2025-01-31 20:56:07 +10:00
parent 635ae5de31
commit b01c06b412
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View File

@ -3663,7 +3663,8 @@ void GPUTextureCache::ApplyTextureReplacements(SourceKey key, HashType tex_hash,
if (HasVRAMWriteTextureReplacements())
{
const GSVector4i page_rect = GetTextureRect(key.page, key.mode);
// Wrapping around the edge for replacement testing breaks 8/16-bit textures in the rightmost page.
const GSVector4i page_rect = GetTextureRectWithoutWrap(key.page, key.mode);
LoopRectPages(page_rect, [&key, &pal_hash, &subimages, &page_rect](u32 pn) {
const PageEntry& page = s_state.pages[pn];
ListIterate(page.writes, [&key, &pal_hash, &subimages, &page_rect](const VRAMWrite* vrw) {

View File

@ -517,6 +517,15 @@ ALWAYS_INLINE static constexpr GSVector4i GetTextureRect(u32 pn, GPUTextureMode
return GSVector4i::cxpr(left, top, right, bottom);
}
ALWAYS_INLINE static constexpr GSVector4i GetTextureRectWithoutWrap(u32 pn, GPUTextureMode mode)
{
const u32 left = VRAMPageStartX(pn);
const u32 top = VRAMPageStartY(pn);
const u32 right = std::min<u32>(left + TexturePageWidthForMode(mode), VRAM_WIDTH);
const u32 bottom = top + VRAM_PAGE_HEIGHT;
return GSVector4i::cxpr(left, top, right, bottom);
}
/// Returns the maximum index for a paletted texture.
ALWAYS_INLINE static constexpr u32 GetPaletteWidth(GPUTextureMode mode)
{