diff --git a/src/core/gpu_hw_texture_cache.cpp b/src/core/gpu_hw_texture_cache.cpp index 3eb716f5e3..357a5ab882 100644 --- a/src/core/gpu_hw_texture_cache.cpp +++ b/src/core/gpu_hw_texture_cache.cpp @@ -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) { diff --git a/src/core/gpu_types.h b/src/core/gpu_types.h index 571079a041..e0982b990e 100644 --- a/src/core/gpu_types.h +++ b/src/core/gpu_types.h @@ -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(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) {