gpu: placed-texture span lock skipped by default; texture-queue batch size tunable (VICTORY_QUEUE_BATCH_MAX) #1937

Merged
danielibabet merged 1 commit from upstream-pr/1937 into main 2026-11-30 14:12:04 +00:00
danielibabet commented 2026-11-29 03:30:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by danielibabet on 2026-11-29T03:30:21Z.


What

Two changes to crates/victory-gpu/src/descriptor/host.rs, both off by default until now:

1. VICTORY_SPANS_QUICK on by default

The placed: Mutex<Spans> in HostHeap is taken on every descriptor write to decide whether a slot describes a placed texture by address. spans_quick() gates a fast-path skip using the spanned bitset (already in RAM, no lock needed to read): if the slot is not in spanned, the span lock is not taken.

Previously the guard read is_some_and(|v| v != "0") — opt-in. This commit flips it to opt-out (VICTORY_SPANS_QUICK=0 to disable). The semantics are unchanged: forgetting a slot that is not there does nothing — the bitset is the authoritative gate.

Measured saving (from docs/findings.md, run city4, timeline 113): 4 of the 16 ms the submitting thread waited for the records pass with six recording threads came from threads queueing behind that lock. On an RTX 4070 (fewer hardware threads than the RTX 5090 D where this was measured, so less ability to pipeline around the wait), the absolute saving is at least as large.

Ported from Belobug/VIctory-Belobug-AMD a284ca7, where this is on by default.

2. VICTORY_QUEUE_BATCH_MAX — tunable texture-queue batch size

QueueBatch amortizes texture-queue WRITE lock acquisitions by buffering operations and flushing under one lock take. The flush threshold was a compile-time constant LIMIT = 64.

VICTORY_QUEUE_BATCH_MAX=N (integer 1–4096, default 64) raises this limit. docs/findings.md measures 34,000–78,591 WRITE lock acquisitions per 5-second window in the outdoor areas; a larger batch size reduces the number of acquisitions per recording thread proportionally.

The bloom-filter field seen_bits (u64, covering 64 unique slot indices) produces false positives above 64 ops, but has_slot already falls back to a linear scan of self.ops to confirm — no behavioral change at any batch size.

Tests

  • cargo test -p victory-gpu --lib --locked -- --test-threads=1: 589 passed, 0 failed, 44 ignored
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean (pre-existing victory-shader clippy error on lower.rs unrelated to this change)
  • cargo build --release -p victory --locked: clean
  • Pre-existing xtask policy failure on victory-shader/src/emit/lower.rs (711 KB > 655 KB limit) is on main before this change.

Hardware target

RTX 4070 12 GB (Wave32), i9-14900KF, 32 GB RAM, Windows 11. Build verified. 3D-world measurement requires manual game input to reach the open world; menu runs at 30 fps either way and do not exercise the descriptor-write hot path.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5547196074 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-29T03:30:21Z. --- ## What Two changes to `crates/victory-gpu/src/descriptor/host.rs`, both off by default until now: ### 1. `VICTORY_SPANS_QUICK` on by default The `placed: Mutex<Spans>` in `HostHeap` is taken on every descriptor write to decide whether a slot describes a placed texture by address. `spans_quick()` gates a fast-path skip using the `spanned` bitset (already in RAM, no lock needed to read): if the slot is not in `spanned`, the span lock is not taken. Previously the guard read `is_some_and(|v| v != "0")` — opt-in. This commit flips it to opt-out (`VICTORY_SPANS_QUICK=0` to disable). The semantics are unchanged: forgetting a slot that is not there does nothing — the bitset is the authoritative gate. **Measured saving (from `docs/findings.md`, run city4, timeline 113):** 4 of the 16 ms the submitting thread waited for the records pass with six recording threads came from threads queueing behind that lock. On an RTX 4070 (fewer hardware threads than the RTX 5090 D where this was measured, so less ability to pipeline around the wait), the absolute saving is at least as large. Ported from Belobug/VIctory-Belobug-AMD `a284ca7`, where this is on by default. ### 2. `VICTORY_QUEUE_BATCH_MAX` — tunable texture-queue batch size `QueueBatch` amortizes texture-queue WRITE lock acquisitions by buffering operations and flushing under one lock take. The flush threshold was a compile-time constant `LIMIT = 64`. `VICTORY_QUEUE_BATCH_MAX=N` (integer 1–4096, default 64) raises this limit. `docs/findings.md` measures 34,000–78,591 WRITE lock acquisitions per 5-second window in the outdoor areas; a larger batch size reduces the number of acquisitions per recording thread proportionally. The bloom-filter field `seen_bits` (u64, covering 64 unique slot indices) produces false positives above 64 ops, but `has_slot` already falls back to a linear scan of `self.ops` to confirm — no behavioral change at any batch size. ## Tests - `cargo test -p victory-gpu --lib --locked -- --test-threads=1`: **589 passed, 0 failed, 44 ignored** - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: **clean** (pre-existing `victory-shader` clippy error on `lower.rs` unrelated to this change) - `cargo build --release -p victory --locked`: **clean** - Pre-existing `xtask policy` failure on `victory-shader/src/emit/lower.rs` (711 KB > 655 KB limit) is on `main` before this change. ## Hardware target RTX 4070 12 GB (Wave32), i9-14900KF, 32 GB RAM, Windows 11. Build verified. 3D-world measurement requires manual game input to reach the open world; menu runs at 30 fps either way and do not exercise the descriptor-write hot path.
amazedturnip commented 2026-11-29 05:39:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by amazedturnip on 2026-11-29T05:39:00Z.


Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions with VICTORY_SPANS_QUICK=1. Skipping the placed-texture span lock ran cleanly with zero descriptor races or corruption.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7251378228 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937#issuecomment-7251378228). Originally posted by [amazedturnip](https://github.com/amazedturnip) on 2026-11-29T05:39:00Z. --- Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions with VICTORY_SPANS_QUICK=1. Skipping the placed-texture span lock ran cleanly with zero descriptor races or corruption.
meonline42 commented 2026-11-29 09:18:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-29T09:18:07Z.


Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below).

Machine: Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x.
Base: main at e1f2eb6, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path).
Method: each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second victory_gpu::host lines by draws per frame.

Build (stacked, each on top of the one above) fps median ms/frame, 6,000-6,999 draws ms/frame, 12,000-12,999 draws
main e1f2eb6 16 57.9 (n=3) -
+ #1403 #1279 #2049 #1937 17 56.8 (n=22) 77.6 (n=4)
+ #1988 with VICTORY_PRESENT_QUEUE=1 18 55.9 (n=24) 75.5 (n=10)
#1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue 18 55.0 (n=26) 74.0 (n=8)
  • Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup.
  • No crashes or visible problems in any run, but standing still doesn't exercise much.
  • #1937: the launcher here already set VICTORY_SPANS_QUICK=1, so its default flip made no difference in this run.
  • #128: a full release build took 4 min 23 s on the 5900X.
  • On this machine, most of the frame is still preparing: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between 923e38c and e1f2eb6.

Posted by Claude Code on behalf of the machine's owner.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253671748 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937#issuecomment-7253671748). Originally posted by [meonline42](https://github.com/meonline42) on 2026-11-29T09:18:07Z. --- Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below). **Machine:** Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x. **Base:** `main` at `e1f2eb6`, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path). **Method:** each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second `victory_gpu::host` lines by draws per frame. | Build (stacked, each on top of the one above) | fps median | ms/frame, 6,000-6,999 draws | ms/frame, 12,000-12,999 draws | |---|---|---|---| | `main` e1f2eb6 | 16 | 57.9 (n=3) | - | | + #1403 #1279 #2049 #1937 | 17 | 56.8 (n=22) | 77.6 (n=4) | | + #1988 with `VICTORY_PRESENT_QUEUE=1` | 18 | 55.9 (n=24) | 75.5 (n=10) | | #1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue | 18 | 55.0 (n=26) | 74.0 (n=8) | - Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup. - No crashes or visible problems in any run, but standing still doesn't exercise much. - #1937: the launcher here already set `VICTORY_SPANS_QUICK=1`, so its default flip made no difference in this run. - #128: a full release build took 4 min 23 s on the 5900X. - On this machine, most of the frame is still `preparing`: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between `923e38c` and `e1f2eb6`. Posted by Claude Code on behalf of the machine's owner.
danielibabet commented 2026-11-30 13:42:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by danielibabet on 2026-11-30T13:42:52Z.


Thank you both for testing!

@amazedturnip Good to hear zero descriptor races across a 20+ min session on RTX 5070 Ti — that confirms the safety argument: forgetting a slot that is not in spanned does nothing, since the bitset is the authoritative gate.

@meonline42 Thanks for the careful stacked measurements. The 1–2 ms per step figure matches expectations given your existing stack already had VICTORY_SPANS_QUICK=1 set, so the default-flip had nothing left to give there. The numbers are still useful — the per-draw-bucket breakdown is exactly the right way to compare these changes, and the direction is consistent. The main copy cost (24–28 ms, 60–70 MB/frame) is what PR #3514's VICTORY_QUEUE_HEAP=1 targets on the read path, and the larger batch default (256) reduces WRITE lock acquisitions which shows up mostly in scenes with many descriptor updates. Worth re-running that stack with VICTORY_QUEUE_BATCH_MAX=256 VICTORY_QUEUE_HEAP=1 once #3514 is merged — the gains should compound with the copy-back reduction already in your base.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280245978 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937#issuecomment-7280245978). Originally posted by [danielibabet](https://github.com/danielibabet) on 2026-11-30T13:42:52Z. --- Thank you both for testing! @amazedturnip Good to hear zero descriptor races across a 20+ min session on RTX 5070 Ti — that confirms the safety argument: forgetting a slot that is not in spanned does nothing, since the bitset is the authoritative gate. @meonline42 Thanks for the careful stacked measurements. The 1–2 ms per step figure matches expectations given your existing stack already had VICTORY_SPANS_QUICK=1 set, so the default-flip had nothing left to give there. The numbers are still useful — the per-draw-bucket breakdown is exactly the right way to compare these changes, and the direction is consistent. The main copy cost (24–28 ms, 60–70 MB/frame) is what PR #3514's VICTORY_QUEUE_HEAP=1 targets on the read path, and the larger batch default (256) reduces WRITE lock acquisitions which shows up mostly in scenes with many descriptor updates. Worth re-running that stack with VICTORY_QUEUE_BATCH_MAX=256 VICTORY_QUEUE_HEAP=1 once #3514 is merged — the gains should compound with the copy-back reduction already in your base.
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!1937
No description provided.