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

Manually merged
github merged 1 commit from github-bot/gh-1937 into main 2026-11-30 14:14:27 +00:00 AGit
Owner

@⁠danielibabet on GitHub · 2026-11-29 03:30 UTC · original
danielibabet:perf/spans-quick-default → main · +21 −12 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

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.

**@⁠danielibabet** on GitHub · 2026-11-29 03:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937) `danielibabet:perf/spans-quick-default` → `main` · +21 −12 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## 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.
VICTORY_SPANS_QUICK flips to on by default (VICTORY_SPANS_QUICK=0 turns it
off): a slot write of no placed texture view leaves 'placed' alone when the
slot is not in it, so the span lock is not taken for every write. Ported
from Belobug/VIctory-Belobug-AMD a284ca7, on by default there; their city4
timeline measured 4 of the 16 ms a frame the submitting thread waited for
the records pass spent by recording threads waiting on that lock.

VICTORY_QUEUE_BATCH_MAX (1-4096, default 64) raises the ops accumulated
before the texture queue's WRITE lock is taken, for descriptor-mirror loops
that note thousands of slots a frame; findings.md counts 34,000-78,591 lock
acquisitions per 5 s window on an RTX 5090 D. The bloom-filter fallback of
has_slot stays correct at any size.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 03:33:34 +00:00
Author
Owner

@⁠amazedturnip on GitHub · 2026-11-29 05:39 UTC · original

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.

**@⁠amazedturnip** on GitHub · 2026-11-29 05:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937#issuecomment-7251378228) 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.
Author
Owner

@⁠meonline42 on GitHub · 2026-11-29 09:18 UTC · original

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.

**@⁠meonline42** on GitHub · 2026-11-29 09:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1937#issuecomment-7253671748) 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.
github manually merged commit 9f4d405bb9 into main 2026-11-30 14:14:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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