sweep: plan the look under pressure on a thread of its own #495

Closed
github-bot wants to merge 1 commit from github-bot/gh-495 into main AGit
Owner

@⁠arutkowski00 on GitHub · 2026-12-04 18:32 UTC · original
arutkowski00:pr/sweep-thread → main · +168 −39 · 2 files · 1 commits · closed without merging

Problem

Under VRAM pressure the texture sweep walked every host copy of a texture the title fills (over 70,000 in one play) on the submitting thread, with the table of textures held throughout. That cost 8.9 ms a look on average and up to 175 ms, once a second, and making and dropping textures on the title's threads waited for the same lock.

Change

A thread of its own now makes the look (idle copies, coldest first), a slice of 4,096 members at a time so the table is held briefly. The look before a submission takes the last plan, drops entries no longer in the table, and lets go only what take_idle finds idle again, so the moment and the checks under which copies are let go are unchanged. Copies whose lock another thread holds are in use and are skipped rather than waited for. The memory line reports the planner's looks and their cost.

Touches resource.rs and a few lines of host.rs. No new switch.

Evidence

The look cost (8.9 ms average, 175 ms maximum, over 70,000 members) was measured from the memory line in a play session on an RX 7900 XTX (RADV, stock Mesa, VICTORY_PAGES=0). The commit was then used in every play session after that. I have not run a controlled before and after of frame times for this change alone.

Not tested

  • Hardware other than the 7900 XTX.
  • A run with the planner thread under heavy contention (fewer than 4 CPU cores).
  • The unit tests that need a GPU return early under Wine in my setup, so the planner's selection logic was not exercised by them.
**@⁠arutkowski00** on GitHub · 2026-12-04 18:32 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/495) `arutkowski00:pr/sweep-thread` → `main` · +168 −39 · 2 files · 1 commits · closed without merging ## Problem Under VRAM pressure the texture sweep walked every host copy of a texture the title fills (over 70,000 in one play) on the submitting thread, with the table of textures held throughout. That cost 8.9 ms a look on average and up to 175 ms, once a second, and making and dropping textures on the title's threads waited for the same lock. ## Change A thread of its own now makes the look (idle copies, coldest first), a slice of 4,096 members at a time so the table is held briefly. The look before a submission takes the last plan, drops entries no longer in the table, and lets go only what `take_idle` finds idle again, so the moment and the checks under which copies are let go are unchanged. Copies whose lock another thread holds are in use and are skipped rather than waited for. The memory line reports the planner's looks and their cost. Touches `resource.rs` and a few lines of `host.rs`. No new switch. ## Evidence The look cost (8.9 ms average, 175 ms maximum, over 70,000 members) was measured from the memory line in a play session on an RX 7900 XTX (RADV, stock Mesa, `VICTORY_PAGES=0`). The commit was then used in every play session after that. I have not run a controlled before and after of frame times for this change alone. ## Not tested - Hardware other than the 7900 XTX. - A run with the planner thread under heavy contention (fewer than 4 CPU cores). - The unit tests that need a GPU return early under Wine in my setup, so the planner's selection logic was not exercised by them.
Under VRAM pressure the texture sweep walked every host copy of a texture
the title fills (over 70,000 in a play) on the submitting thread, with the
table of textures held throughout: 8.9 ms a look on average and up to
175 ms, once a second, while making and dropping textures on the title's
threads waited for the same lock.

A thread of its own now makes the look (idle copies, coldest first), a
slice of 4,096 members at a time so the table is held briefly. The look
before a submission takes the last plan, drops entries no longer in the
table, and lets go only what take_idle finds idle again, so the moment
and the checks under which copies are let go are unchanged. Copies whose
lock another thread holds are in use and are skipped rather than waited
for. The memory line reports the planner's looks and their cost.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 18:36:28 +00:00
github-bot closed this pull request 2026-12-04 18:48:02 +00:00
Author
Owner

@⁠arutkowski00 on GitHub · 2026-12-04 18:44 UTC · original

Closing: #355 addresses the same sweep stall (and the placed-textures lock) and is ahead in the queue; the two conflict in resource.rs. I'll re-measure with #355 applied instead.

**@⁠arutkowski00** on GitHub · 2026-12-04 18:44 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/495#issuecomment-7420854390) Closing: #355 addresses the same sweep stall (and the placed-textures lock) and is ahead in the queue; the two conflict in resource.rs. I'll re-measure with #355 applied instead.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.