Skip to content

Commit 016c08b

Browse files
committed
GPU/HW: Use clamped rect for sprites-as-fills
Fixes VRAM corruption in Tales of Phantasia with the texture cache enabled.
1 parent 0094344 commit 016c08b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/core/gpu_hw.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,16 @@ void GPU_HW::DrawLine(const GPUBackendDrawCommand* cmd, const GSVector4 bounds,
27662766

27672767
void GPU_HW::DrawSprite(const GPUBackendDrawRectangleCommand* cmd)
27682768
{
2769+
const GSVector2i pos = GSVector2i::load<true>(&cmd->x);
2770+
const GSVector2i size = GSVector2i::load<true>(&cmd->width).u16to32();
2771+
const GSVector4i rect = GSVector4i::xyxy(pos, pos.add32(size));
2772+
const GSVector4i clamped_rect = m_clamped_drawing_area.rintersect(rect);
2773+
if (clamped_rect.rempty())
2774+
{
2775+
GL_INS_FMT("Culling off-screen sprite {}", rect);
2776+
return;
2777+
}
2778+
27692779
// Treat non-textured sprite draws as fills, so we don't break the TC on framebuffer clears.
27702780
bool draw_with_software_renderer = m_draw_with_software_renderer;
27712781
if (m_use_texture_cache && !cmd->transparency_enable && !cmd->shading_enable && !cmd->texture_enable &&
@@ -2783,23 +2793,15 @@ void GPU_HW::DrawSprite(const GPUBackendDrawRectangleCommand* cmd)
27832793
}
27842794
else
27852795
{
2786-
GL_INS_FMT("Treating non-textured sprite as VRAM fill at {},{} size {}x{}", cmd->x, cmd->y, cmd->width,
2787-
cmd->height);
2788-
FillVRAM(cmd->x, cmd->y, cmd->width, cmd->height, cmd->color, cmd->interlaced_rendering, cmd->active_line_lsb);
2796+
const GSVector2i clamped_size = clamped_rect.rsize();
2797+
GL_INS_FMT("Treating non-textured sprite as VRAM fill at {},{} size {}x{} (clamped {})", cmd->x, cmd->y,
2798+
cmd->width, cmd->height, clamped_rect);
2799+
FillVRAM(clamped_rect.left, clamped_rect.top, clamped_size.x, clamped_size.y, cmd->color,
2800+
cmd->interlaced_rendering, cmd->active_line_lsb);
27892801
return;
27902802
}
27912803
}
27922804

2793-
const GSVector2i pos = GSVector2i::load<true>(&cmd->x);
2794-
const GSVector2i size = GSVector2i::load<true>(&cmd->width).u16to32();
2795-
const GSVector4i rect = GSVector4i::xyxy(pos, pos.add32(size));
2796-
const GSVector4i clamped_rect = m_clamped_drawing_area.rintersect(rect);
2797-
if (clamped_rect.rempty())
2798-
{
2799-
GL_INS_FMT("Culling off-screen sprite {}", rect);
2800-
return;
2801-
}
2802-
28032805
PrepareDraw(cmd);
28042806
SetBatchDepthBuffer(cmd, false);
28052807
SetBatchSpriteMode(cmd, m_allow_sprite_mode);

0 commit comments

Comments
 (0)