Skip to content

texture: SEEDS and HOST_WRITTEN behind a RwLock — asked of every texture read on every recording thread (3–5× cheaper under contention) - #2226

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
birdneststream:seeds-host-written-rwlock
Nov 30, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
birdneststream:seeds-host-written-rwlock

Conversation

@birdneststream

Copy link
Copy Markdown

SEEDS and HOST_WRITTEN in texture.rs are asked of every texture read on every recording thread (seed_pending per SRV, upload_from, host_wrote, is_host_written), and written only when a view is seeded, a texture is written by the host, or a resource is forgotten. Behind a Mutex, every one of those reads serialises against every other thread's read.

Measured under Wine (wine-staging 11.22, i9-13900KF), eight threads hashing a key in a 32-element set behind each lock, 200k lookups a thread, three runs:

Mutex: 8 threads x 200000 lookups in 543 ms: 340 ns a lookup   / 812 ms: 508 ns   / 857 ms: 536 ns
RwLock: 8 threads x 200000 lookups in 157 ms:  99 ns a lookup   / 207 ms: 130 ns   / 170 ms: 107 ns

Three to five times cheaper per lookup under contention, the same answers (writers still exclusive). seed_pending takes the read first and only the write when the view really waits, so the usual "not waiting" costs one read.

This lock per texture read came in with e530c00 (11-28, UPLOAD_GUARD on by default), which is why I am pointing at it in #2129 as a candidate for the per-draw cost: with thousands of texture reads a frame across the recording threads, a global Mutex there is on the per-draw path. No behaviour change; the GPU suite under Wine is at its usual baseline with it (913/6, the six known Wine/vkd3d ones).

…n every recording thread, written only when a view is seeded, a texture is written by the host, or forgotten
sethwololo pushed a commit to sethwololo/tempo-launcher that referenced this pull request Nov 29, 2026
SEEDS and HOST_WRITTEN behind a RwLock: asked of every texture read on every recording thread, written only when a view is seeded, a texture is written by the host, or forgotten

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moritz-eckhard-nickel added a commit to moritz-eckhard-nickel/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…N behind a RwLock — asked of every texture read on every recording thread (3–5× cheaper under contention)

trustno1-coder#2226 by birdneststream, head ad26de6.
@Lyrnc

Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Measured this on an RTX 5080 + 9800X3D with a CPU micro-benchmark of the texture-read path (per_read_lookups_bench, now in #3739). Values are ns per read, for main 41adb55, this PR, and #3739, which builds on this PR:

main this PR #3739
1 thread 36.5 36.3 7.7
8 threads, back to back 1,235 1,334 34
8 threads, ~0.94 µs of work between reads 88–109 76–115 10.7–13.5

With realistic spacing, the RwLock alone lands within noise of main. There are two reasons: HOST_WRITTEN_AT stays a mutex, and a read lock still writes the shared lock word. In 9 game runs SEEDS held 0–1 views, so almost every lookup is a miss. #3739 keeps your commit as it is (author kept) and adds an atomic bit filter in front of the three tables, so a miss takes no lock. It also turns HOST_WRITTEN_AT into an RwLock.

On the "2× slower per draw since .01" reports: in our logs that came from the compile-memory guard, not from these tables. Recording threads measured 3.6–4.5 µs a list call on .28.03, 15–128 µs on .29.01 with the guard on, and 3.7–4.8 µs with it off (#3347). These tables are worth about 1–5 % of recording time per draw.

AI use: Claude Code (Claude Opus 5.5).

PranThow added a commit to PranThow/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…a RwLock — asked of every texture read on every recording thread (3–5× cheaper under contention)
@trustno1-coder
trustno1-coder merged commit c1b845b into trustno1-coder:main Nov 30, 2026
1 check passed
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.

3 participants