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

Merged
birdneststream merged 1 commit from upstream-pr/2226 into main 2026-11-30 14:12:03 +00:00
birdneststream commented 2026-11-29 10:44:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by birdneststream on 2026-11-29T10:44:09Z.


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 e530c0034 (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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549942647 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2226). Originally posted by [birdneststream](https://github.com/birdneststream) on 2026-11-29T10:44:09Z. --- `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 e530c0034 (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).
Lyrnc commented 2026-11-30 05:45:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T05:45:47Z.


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 41adb551, 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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7269980199 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2226#issuecomment-7269980199). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T05:45:47Z. --- 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 41adb551, 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!2226
No description provided.