Texture registry: binary search for a registration's and a page mapping's overlap run #56

Manually merged
github merged 2 commits from gh-pr/56/head into gh-pr/56/base 2026-11-27 03:16:02 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-26 06:29 UTC · original
Sr-0w:resources/registry-insert-without-sort → main · +159 −17 · 3 files · 2 commits · merged 2026-11-26 06:49 UTC

What

GpuTextureRegistry no longer scans or re-sorts all its textures:

  • Register copied every registered texture into a list and sorted it again, for each new texture. Registered ranges never overlap, so the textures a new one overlaps form one run of the sorted array. OverlapRun finds that run from LastStartingBefore and walks back. The run is retired as before, and the new array is the prefix, the texture and the suffix: two block copies, no sort.
  • Mark, called for each page the game maps or unmaps (CopyPageMappings), scanned all textures. It now visits only that run.

Why

On a loading screen the registry holds about 15,000 textures and registers thousands more. With --cpu-sample, on a retail game and an RX 7800 XT:

  • Before, the game thread that creates views at addresses (CreateShaderResourceViewAtAddress) was 100 % busy in the sort's comparer (<Register>b__36_0, GpuTexture.Address). The other game threads were blocked behind it, frames took 18 to 37 s, and the game's 30 s hang watchdog (RVA 0x23cf683) ended every boot on current main before the world.
  • With the Register fix only, the same thread was 100 % busy in CopyPageMappings → GpuTextureRegistry.Mark.
  • With both, the registry no longer appears in the samples.

In game

The registry no longer shows in the CPU samples, but on this machine these two changes alone still left the boot ending at the watchdog (1,200 presents). The remaining cost was the texture refresh of submissions, which is handled in a separate PR. With both PRs, the boot passes the loading screen and plays the intro: a night street with car lights, signs and lit windows, at about 1 fps.

Tests

  • New GpuTextureRegistryRunTests:
    • OverlapRun against a scan of every texture, over 2,000 random ranges, including where a range with no overlap belongs;
    • Unmapped and Mapped against a scan;
    • the empty registry.
  • Loader tests: 449 passed.
  • docs/gpu-resources.md is updated.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-26 06:29 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/56) `Sr-0w:resources/registry-insert-without-sort` → `main` · +159 −17 · 3 files · 2 commits · merged 2026-11-26 06:49 UTC ## What `GpuTextureRegistry` no longer scans or re-sorts all its textures: - **`Register`** copied every registered texture into a list and sorted it again, for each new texture. Registered ranges never overlap, so the textures a new one overlaps form one run of the sorted array. `OverlapRun` finds that run from `LastStartingBefore` and walks back. The run is retired as before, and the new array is the prefix, the texture and the suffix: two block copies, no sort. - **`Mark`**, called for each page the game maps or unmaps (`CopyPageMappings`), scanned all textures. It now visits only that run. ## Why On a loading screen the registry holds about 15,000 textures and registers thousands more. With `--cpu-sample`, on a retail game and an RX 7800 XT: - **Before**, the game thread that creates views at addresses (`CreateShaderResourceViewAtAddress`) was 100 % busy in the sort's comparer (`<Register>b__36_0`, `GpuTexture.Address`). The other game threads were blocked behind it, frames took 18 to 37 s, and the game's 30 s hang watchdog (RVA 0x23cf683) ended every boot on current main before the world. - **With the `Register` fix only**, the same thread was 100 % busy in `CopyPageMappings` → `GpuTextureRegistry.Mark`. - **With both**, the registry no longer appears in the samples. ## In game The registry no longer shows in the CPU samples, but on this machine these two changes alone still left the boot ending at the watchdog (1,200 presents). The remaining cost was the texture refresh of submissions, which is handled in a separate PR. With both PRs, the boot passes the loading screen and plays the intro: a night street with car lights, signs and lit windows, at about 1 fps. ## Tests - New `GpuTextureRegistryRunTests`: - `OverlapRun` against a scan of every texture, over 2,000 random ranges, including where a range with no overlap belongs; - `Unmapped` and `Mapped` against a scan; - the empty registry. - Loader tests: 449 passed. - `docs/gpu-resources.md` is updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Register copied every registered texture into a list and sorted it again for each new texture. A loading screen
registers thousands of textures over a registry of about 15,000: the CPU sampler (--cpu-sample) showed the game
thread that creates views at addresses (CreateShaderResourceViewAtAddress) 100 % busy in that sort's comparer
(GpuTexture.Address), the other game threads blocked behind it, frames of 18 to 37 s, and the game's 30 s hang
watchdog ending the boot before the world.

Registered ranges never overlap, so the textures a new one overlaps are one run of the sorted array: OverlapRun finds
it from LastStartingBefore and walks back, the run is retired as before, and the new array is the prefix, the texture
and the suffix (two block copies, no sort).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the sort, the CPU sampler showed the same game thread 100 % busy in CopyPageMappings: each page the game maps
or unmaps went through Mark, which scanned all 15,000 registered textures for the ones over the page. Mark now visits
only the run OverlapRun finds; a test checks Unmapped and Mapped against a scan over 2,000 random ranges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:16:01 +00:00
github manually merged commit 32aec6eef5 into gh-pr/56/base 2026-11-27 03:16:02 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-26 07:30 UTC · original

nice, the full re-sort per register was a silly one to leave in. the run search + tests against a full scan look solid

merged together with #57

**@⁠ThatRecompDev** on GitHub · 2026-11-26 07:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/56#issuecomment-7185525123) nice, the full re-sort per register was a silly one to leave in. the run search + tests against a full scan look solid merged together with #57
This discussion has been locked. Commenting is limited to contributors.
No description provided.