descriptor: write-back strides/view-addresses table and lock-free placed address lookup in sync_heaps #2174

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

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T10:14:21Z.


What it changes

Fixes a major sync_heaps CPU regression introduced by 920e4eef ("Translate bindless buffer address reads in ray-tracing shaders"), where sync_heaps() calls HostHeap::copied_view_address ~23,000–35,000 times per frame across 6 concurrent victory-records threads:

  1. Write-back HostHeap::strides / VIEW_ADDRESSES buffer (crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/host.rs): Allocates the ~8 MiB strides + VIEW_ADDRESSES metadata buffer via host.upload_buffer_maybe_wb(bytes, crate::host::scratch_wb(host)) (falling back automatically to upload_buffer where unsupported or when VICTORY_SCRATCH_WB=0). Previously it used a write-combined D3D12_HEAP_TYPE_UPLOAD heap, so tens of thousands of scattered 8-byte write_volatile updates per frame — each followed by self.made.lock(index) unlock — forced partial write-combining buffer flushes across 6 threads. When write-back (strides_wb == true), write_view_address uses paired AtomicU64::store(Release) and copied_view_address_sync can also skip the slot lock when the cached entry already matches.
  2. Lock-free PLACED shape address side table (crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/descriptor/host.rs): Populates an append-only paged AtomicU64 table (SHAPE_ADDR_CACHE) when ViewShapes::shape() inserts a new placed shape, encoding non-addressable shapes (placed textures), buffer byte offsets, or STRUCTURE fallback. view_address_at(i, generation) resolves CONSTANT and 99.9%+ of PLACED views without taking shapes_read() or constructing a temporary View::Placed.
  3. Zero-lock fast path & direct safecopy::copy in copied_view_address_sync: Uses the already-read [VIEW_TAG, word(1), word(2)] record from sync_heaps to skip locking made and re-reading title memory when the view is non-addressable (e.g. placed textures) with no stale quick key and no prior published address; uses leaf safecopy::copy instead of host::read_into (soft_read bypass) on the in_place path; skips redundant quick.store(0) when already 0 and skips Slots::put fetch_or when the bit is already set.
  4. Unit test: Adds copied_view_address_sync_matches_view_address_across_placed_and_constant_views verifying placed SRV/UAV buffers, placed textures, placed acceleration structures, constant views, addressed clearing, and quick key invalidation.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 4070 Ti 12 GB + Ryzen 7 5700X (64 GB RAM), Series X, 2560×1440 native, DLSS Balanced, NoFG (VICTORY_PORT_CONSTANTS=1, VICTORY_WAIT_RESIDENT=textures), clean 90s A/B gameplay runs on 829188e9 (0 WARNs / 0 ERRORs in both runs):
  • Before (origin/main 829188e9, victory-nvidia-20261129-120600.log):
    • FPS median 16.80 (mean 17.76), frame time median 59.65 ms (frame_times: med 56.4 ms, p95 91.3, p99 103.8, >50ms 55.5%)
    • sync_heaps: total med 16.92 ms (mean 15.28), read+cmp med 7.50 ms (mean 6.74), make med 3.59 ms, waited med 1.83 ms
    • VICTORY_THIN: 224.45 ms
  • After (this PR on 829188e9, victory-nvidia-20261129-123819.log):
    • FPS median 18.90 (+2.10 FPS / +12.5%; mean 18.03), frame time median 52.80 ms (-6.85 ms; frame_times: med 54.2, p95 84.8 -6.5 ms, p99 98.3 -5.5 ms, >50ms 46.7% -8.8%)
    • sync_heaps: total med 12.89 ms (-4.03 ms / -24%; mean 11.52), read+cmp med 4.58 ms (-2.92 ms / -39%; mean 4.22), make med 2.73 ms (-0.86 ms), waited med 0.96 ms (-48%)
    • VICTORY_THIN: 206.40 ms (-18.05 ms)
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes).
  • cargo test passed for the crates it touches: yes (cargo test -p victory-gpu --lib --locked -- --test-threads=1 — 916 passed, 0 failed; cargo clippy -p victory-gpu --lib --tests --locked — exit 0, 0 new warnings).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none touching copied_view_address, ViewShapes, or HostHeap::strides allocation.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549733712 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2174). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T10:14:21Z. --- ## What it changes Fixes a major `sync_heaps` CPU regression introduced by `920e4eef` (*"Translate bindless buffer address reads in ray-tracing shaders"*), where `sync_heaps()` calls `HostHeap::copied_view_address` ~23,000–35,000 times per frame across 6 concurrent `victory-records` threads: 1. **Write-back `HostHeap::strides` / `VIEW_ADDRESSES` buffer (`crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/host.rs`):** Allocates the ~8 MiB `strides` + `VIEW_ADDRESSES` metadata buffer via `host.upload_buffer_maybe_wb(bytes, crate::host::scratch_wb(host))` (falling back automatically to `upload_buffer` where unsupported or when `VICTORY_SCRATCH_WB=0`). Previously it used a write-combined `D3D12_HEAP_TYPE_UPLOAD` heap, so tens of thousands of scattered 8-byte `write_volatile` updates per frame — each followed by `self.made.lock(index)` unlock — forced partial write-combining buffer flushes across 6 threads. When write-back (`strides_wb == true`), `write_view_address` uses paired `AtomicU64::store(Release)` and `copied_view_address_sync` can also skip the slot lock when the cached entry already matches. 2. **Lock-free `PLACED` shape address side table (`crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/descriptor/host.rs`):** Populates an append-only paged `AtomicU64` table (`SHAPE_ADDR_CACHE`) when `ViewShapes::shape()` inserts a new placed shape, encoding non-addressable shapes (placed textures), buffer byte offsets, or `STRUCTURE` fallback. `view_address_at(i, generation)` resolves `CONSTANT` and 99.9%+ of `PLACED` views without taking `shapes_read()` or constructing a temporary `View::Placed`. 3. **Zero-lock fast path & direct `safecopy::copy` in `copied_view_address_sync`:** Uses the already-read `[VIEW_TAG, word(1), word(2)]` record from `sync_heaps` to skip locking `made` and re-reading title memory when the view is non-addressable (e.g. placed textures) with no stale `quick` key and no prior published address; uses leaf `safecopy::copy` instead of `host::read_into` (`soft_read` bypass) on the `in_place` path; skips redundant `quick.store(0)` when already `0` and skips `Slots::put` `fetch_or` when the bit is already set. 4. **Unit test:** Adds `copied_view_address_sync_matches_view_address_across_placed_and_constant_views` verifying placed SRV/UAV buffers, placed textures, placed acceleration structures, constant views, `addressed` clearing, and `quick` key invalidation. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 4070 Ti 12 GB + Ryzen 7 5700X (64 GB RAM), Series X, 2560×1440 native, DLSS Balanced, NoFG (`VICTORY_PORT_CONSTANTS=1`, `VICTORY_WAIT_RESIDENT=textures`), clean 90s A/B gameplay runs on `829188e9` (`0 WARNs / 0 ERRORs` in both runs): - Before (`origin/main` `829188e9`, `victory-nvidia-20261129-120600.log`): - FPS median `16.80` (mean `17.76`), frame time median `59.65 ms` (`frame_times`: med `56.4 ms`, p95 `91.3`, p99 `103.8`, `>50ms` `55.5%`) - `sync_heaps`: total med `16.92 ms` (mean `15.28`), `read+cmp` med `7.50 ms` (mean `6.74`), `make` med `3.59 ms`, `waited` med `1.83 ms` - `VICTORY_THIN`: `224.45 ms` - After (this PR on `829188e9`, `victory-nvidia-20261129-123819.log`): - FPS median **`18.90`** (**`+2.10 FPS` / `+12.5%`**; mean `18.03`), frame time median **`52.80 ms`** (**`-6.85 ms`**; `frame_times`: med `54.2`, p95 `84.8` `-6.5 ms`, p99 `98.3` `-5.5 ms`, `>50ms` `46.7%` `-8.8%`) - `sync_heaps`: total med **`12.89 ms`** (**`-4.03 ms` / `-24%`**; mean `11.52`), `read+cmp` med **`4.58 ms`** (**`-2.92 ms` / `-39%`**; mean `4.22`), `make` med **`2.73 ms`** (`-0.86 ms`), `waited` med **`0.96 ms`** (**`-48%`**) - `VICTORY_THIN`: **`206.40 ms`** (**`-18.05 ms`**) - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes). - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-gpu --lib --locked -- --test-threads=1` — 916 passed, 0 failed; `cargo clippy -p victory-gpu --lib --tests --locked` — exit 0, 0 new warnings). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none touching `copied_view_address`, `ViewShapes`, or `HostHeap::strides` allocation.
DoubleD17 commented 2026-11-30 03:37:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T03:37:07Z.


We ran a test of this PR on a CPU-bound machine (about 66 ms of CPU preparation per frame), a setup close to yours (Ryzen 7, 12 GB card, Series X 1440p, frame generation off).

CPU prep (ms/frame) controls at that point fps (mean) controls at that point
round 1 70.8 68.1 11.76 12.01
round 2 65.4 65.2 13.24 12.40
mean difference +1.5 ms +2.3 %

No gain we can measure on top of current main: the controls alone spread over 9 ms. The picture was clean (0 defects in 160 frames).

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off;
  • the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with four control runs of 41adb551 spread through the session;
  • every run starts from the same save, restored before each run;
  • figures are medians of the 5 s host lines. The four controls measured 60.4–69.4 ms of CPU preparation per frame and drifted during the session, so each run is compared with the controls interpolated to its own start.

Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.

AI Assisted

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7268047463 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2174#issuecomment-7268047463). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T03:37:07Z. --- We ran a test of this PR on a CPU-bound machine (about 66 ms of CPU preparation per frame), a setup close to yours (Ryzen 7, 12 GB card, Series X 1440p, frame generation off). | | CPU prep (ms/frame) | controls at that point | fps (mean) | controls at that point | |---|---|---|---|---| | round 1 | 70.8 | 68.1 | 11.76 | 12.01 | | round 2 | 65.4 | 65.2 | 13.24 | 12.40 | | **mean difference** | **+1.5 ms** | | **+2.3 %** | | No gain we can measure on top of current main: the controls alone spread over 9 ms. The picture was clean (0 defects in 160 frames). **Setup:** - Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11; - Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off; - the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself; - a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with four control runs of 41adb551 spread through the session; - every run starts from the same save, restored before each run; - figures are medians of the 5 s host lines. The four controls measured 60.4–69.4 ms of CPU preparation per frame and drifted during the session, so each run is compared with the controls interpolated to its own start. Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame. AI Assisted
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!2174
No description provided.