Skip to content

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

Merged
ThatRecompDev merged 2 commits into
ThatRecompDev:mainfrom
Sr-0w:resources/registry-insert-without-sort
Nov 26, 2026
Merged

ThatRecompDev merged 2 commits into
ThatRecompDev:mainfrom
Sr-0w:resources/registry-insert-without-sort

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 and others added 2 commits November 26, 2026 07:03
…ch instead of sorting

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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@ThatRecompDev
ThatRecompDev merged commit 23b8d2a into ThatRecompDev:main Nov 26, 2026
2 checks passed
@ThatRecompDev

Copy link
Copy Markdown
Owner

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants