Skip to content

GS/TC: Refactor/cleanup preload function.#14300

Draft
TJnotJT wants to merge 1 commit intoPCSX2:masterfrom
TJnotJT:gs-preload-wrapping
Draft

GS/TC: Refactor/cleanup preload function.#14300
TJnotJT wants to merge 1 commit intoPCSX2:masterfrom
TJnotJT:gs-preload-wrapping

Conversation

@TJnotJT
Copy link
Copy Markdown
Contributor

@TJnotJT TJnotJT commented Apr 14, 2026

Description of Changes

Does some light refactoing/cleanup to GSTextureCache::PreloadTarget().

Rationale behind Changes

Fixes the long dump in #13308. Should be checked in game since it's multiframe.

The main effective change in the code is changing the following condition that determines whether to nuke an old targets in preload (pseudocode):

if (dst->m_TEX0.TBW, dst->m_TEX0.PSM, dst_valid) &&
((std::abs(static_cast<int>(old_dst->m_TEX0.TBP0 - dst->m_TEX0.TBP0)) >> 5) % std::max(static_cast<int>(dst->m_TEX0.TBW), 1)) <= std::max(0, static_cast<int>(dst->m_TEX0.TBW - old_dst->m_TEX0.TBW)))
{
// Possibly nuke.
}

to

// Make sure roughly that the first row of pages of the old target fit within the buffer width
// of the new target.
const int page_diff = std::abs(static_cast<int>(old_dst->m_TEX0.TBP0 - dst->m_TEX0.TBP0)) >> 5;
const int page_left = page_diff % dst->m_TEX0.TBW;
const int page_right = page_left + old_dst->m_TEX0.TBW;
const bool old_width_fits_in_new_width = page_right <= dst->m_TEX0.TBW;
if (old_width_fits_in_new_width)
{
// Possibly nuke.
}

Previously, the code allowing nuking the old target even the new target had a smaller buffer width, which seemed to have caused the clock tower issue.

Suggested Testing Steps

Test any game with any HW renderer.

Tested so far with a dump run at native resolution.

Did you use AI to help find, test, or implement this issue or feature?

No.

@refractionpcsx2
Copy link
Copy Markdown
Member

The condition for nuking should also depend on if the old target height is more than one page if the widths don't match.

So if the old width is > new width, or the old width is < new width but height is > 1 page, then it's not going to neatly fit. So you'll need to make sure these conditions are met, else pages will need copying in a rearranged format (which is also a possible solution, but requires more work, maybe leveraging thre "merge target" function).

Just something to keep in mind :)

@TJnotJT
Copy link
Copy Markdown
Contributor Author

TJnotJT commented Apr 14, 2026

I see, thanks for explaining that. In this case the draw is overwriting exactly the bottom 64 pixel strip of the old target. The old/new will be misaligned since it’s 2 rows of pages. Maybe we could just crop the old target in this case?

@TJnotJT TJnotJT marked this pull request as draft April 14, 2026 13:20
@refractionpcsx2
Copy link
Copy Markdown
Member

so it's an inside target but a width aligned offset? Hmm why is it preloading, then, and not doing RT in RT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants