Skip to content

Commit

Permalink
GPU/TextureCache: Prevent wrapping for replacement lookup
Browse files Browse the repository at this point in the history
Fixes replacements for 8 and 16-bit textures placed in the right-most
page of VRAM.
  • Loading branch information
stenzek committed Jan 31, 2025
1 parent 635ae5d commit b01c06b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/gpu_hw_texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/core/gpu_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit b01c06b

Please sign in to comment.