Opt-in copy-pipeline, second-queue and staging experiments for the title-memory path (Radeon) #32

Open
Amaz1ny wants to merge 5 commits from upstream-pr/32 into main
Amaz1ny commented 2026-11-25 19:40:32 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Amaz1ny on 2026-11-25T19:40:32Z.


What

A set of opt-in experiments on the title-memory copy pipeline. The
environment variables are off by default; the baseline path is
unchanged. Plus a fix for typed SRV component types. Developed and measured
on a Ryzen 7 5700X3D + Radeon RX 7800 XT 16 GB (driver 32.0.32029.2010,
Windows 11).

Switch Default Effect
VICTORY_COPY_PLAIN=1 off Copies of title memory made in place by a rep-movsb helper with a first-in-line exception fallback to the kernel copy
VICTORY_QUEUE2=1/2/3 off A second pair of copy-only queues (down/up lanes) so copy work no longer stands behind the title's draws in the one direct queue
VICTORY_MATERIAL_TEXTURE_DEMAND=1 off Scheduling hints for native shaders whose texture indices come straight from the material record
VICTORY_STAGING_POOL=0 on Upload staging buffers pooled by power of two (0 reverts to per-copy allocation)
VICTORY_INDIRECT_CARD_BUDGET=0 on Indirect-draw budget kept on the card (WriteBufferImmediate) instead of a CPU-mapped buffer
VICTORY_FILL_WAIT=1 off Restores waiting on in-flight shader writes before fill/copy reads
VICTORY_TEXTURE_SWEEP=0 on Partially reverts the texture sweep resume and displaced-slot recovery

Also: crates/victory-shader/src/emit/typed_views.rs — host SRV component
types and declared ranges for tracked guest descriptors. The tiled-lighting
UINT view table is kept test-only pending further validation on Navi 32.

Why

  • The submitting thread spent 35 ms a frame inside ZwReadVirtualMemory
    (~100 MB/frame, run 225's profile); the in-place copy moves that to the
    processor's own copy speed.
  • The relay fetch stood behind every flight sent since: 114–157 ms a frame
    of the landing thread's 176–229 (run 118). The second queue pair runs it
    on the card's copy engine beside the engine that draws.
  • Copy refresh and copy-back run single-threaded (46–51 ms and 25–31 ms a
    frame); VICTORY_WIDE_REFRESH / VICTORY_WIDE_MERGE spread both over
    worker threads.
  • Presenting at 1920x1080 instead of 3840x2160 on a ~1080p window removes
    4x the pixels.

Result

  • About 10 FPS in the world (9.7–11), no ray tracing; menus at 30 FPS.
    One measurement on one machine, with the switches above enabled.
  • cargo test --workspace --locked: all suites pass (incl. 212
    victory-shader, 237 victory-gpu; BVH intersection tests run on the GPU,
    bit-exact).
  • cargo build --locked --release -p victory --features diagnostics --bins:
    clean.
    image
<!-- greyfinch-sync:DexNom/VIctory:issue:5497943890 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/32). Originally posted by [Amaz1ny](https://github.com/Amaz1ny) on 2026-11-25T19:40:32Z. --- ## What A set of opt-in experiments on the title-memory copy pipeline. The environment variables are **off by default**; the baseline path is unchanged. Plus a fix for typed SRV component types. Developed and measured on a Ryzen 7 5700X3D + Radeon RX 7800 XT 16 GB (driver 32.0.32029.2010, Windows 11). | Switch | Default | Effect | |--------|---------|--------| | `VICTORY_COPY_PLAIN=1` | off | Copies of title memory made in place by a rep-movsb helper with a first-in-line exception fallback to the kernel copy | | `VICTORY_QUEUE2=1/2/3` | off | A second pair of copy-only queues (down/up lanes) so copy work no longer stands behind the title's draws in the one direct queue | | `VICTORY_MATERIAL_TEXTURE_DEMAND=1` | off | Scheduling hints for native shaders whose texture indices come straight from the material record | | `VICTORY_STAGING_POOL=0` | on | Upload staging buffers pooled by power of two (0 reverts to per-copy allocation) | | `VICTORY_INDIRECT_CARD_BUDGET=0` | on | Indirect-draw budget kept on the card (`WriteBufferImmediate`) instead of a CPU-mapped buffer | | `VICTORY_FILL_WAIT=1` | off | Restores waiting on in-flight shader writes before fill/copy reads | | `VICTORY_TEXTURE_SWEEP=0` | on | Partially reverts the texture sweep resume and displaced-slot recovery | Also: `crates/victory-shader/src/emit/typed_views.rs` — host SRV component types and declared ranges for tracked guest descriptors. The tiled-lighting UINT view table is kept test-only pending further validation on Navi 32. ## Why - The submitting thread spent 35 ms a frame inside `ZwReadVirtualMemory` (~100 MB/frame, run 225's profile); the in-place copy moves that to the processor's own copy speed. - The relay fetch stood behind every flight sent since: 114–157 ms a frame of the landing thread's 176–229 (run 118). The second queue pair runs it on the card's copy engine beside the engine that draws. - Copy refresh and copy-back run single-threaded (46–51 ms and 25–31 ms a frame); `VICTORY_WIDE_REFRESH` / `VICTORY_WIDE_MERGE` spread both over worker threads. - Presenting at 1920x1080 instead of 3840x2160 on a ~1080p window removes 4x the pixels. ## Result - **About 10 FPS in the world** (9.7–11), no ray tracing; menus at 30 FPS. One measurement on one machine, with the switches above enabled. - `cargo test --workspace --locked`: all suites pass (incl. 212 victory-shader, 237 victory-gpu; BVH intersection tests run on the GPU, bit-exact). - `cargo build --locked --release -p victory --features diagnostics --bins`: clean. <img width="1818" height="1020" alt="image" src="https://github.com/user-attachments/assets/7c4cd0e8-4539-4493-b420-8fbd28e37798" />
j-fuxa commented 2026-11-26 01:41:16 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by j-fuxa on 2026-11-26T01:41:16Z.


Hardware-driver data for opening title memory as a host heap in place

The header of inplace.rs says its figures come from the software adapter and that what the card's driver adds is what the probe is for. These are measurements from a hardware driver: an RTX 4060 Laptop 8 GB, Windows 11, 32 GB RAM, in our own fork's in-place path. They are NVIDIA numbers from a different code base.

  • Consistent with the header: OpenExistingHeapFromFileMapping returns E_INVALIDARG for SEC_RESERVE sections. ID3D12Device13::OpenExistingHeapFromAddress1(addr, size) opens committed, 64 KiB-aligned sub-ranges as custom write-back L0 heaps. Placed resources need D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER, and textures only row-major. While a heap is open, VirtualProtect, VirtualFree and UnmapViewOfFile on its pages fail with error 87.
  • Added: opening costs 2.4-5 ms per heap whatever its size, and it makes every page resident (+256 MiB working set for an untouched 256 MiB range). Many small heaps cost milliseconds each, and one large heap costs its memory up front.
  • One A/B in the title's world, copy vs in place, a single run each, so indicative only: fps 0.8 / 0.8, "preparing" 597 / 406 ms, GPU time 304 / 505 ms (not explained), working set 14.31 / 13.52 GiB.

A pitfall, in case a read-modify-write is ever used to dirty pages for GetWriteWatch. AtomicU8::fetch_add(0) is idempotent, and release builds lower it to a plain load. The page then stays clean, and dev-profile tests pass while release fails. lock add byte ptr [p], 0 does dirty it. watch.rs in this repo uses write_volatile, so it is not affected today.

Caveats. One GPU, one A/B run, and the GPU-time increase was not isolated. We have not measured Radeon.

<!-- greyfinch-sync:DexNom/VIctory:comment:7180024673 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/32#issuecomment-7180024673). Originally posted by [j-fuxa](https://github.com/j-fuxa) on 2026-11-26T01:41:16Z. --- **Hardware-driver data for opening title memory as a host heap in place** The header of `inplace.rs` says its figures come from the software adapter and that what the card's driver adds is what the probe is for. These are measurements from a hardware driver: an RTX 4060 Laptop 8 GB, Windows 11, 32 GB RAM, in our own fork's in-place path. They are NVIDIA numbers from a different code base. - Consistent with the header: `OpenExistingHeapFromFileMapping` returns `E_INVALIDARG` for `SEC_RESERVE` sections. `ID3D12Device13::OpenExistingHeapFromAddress1(addr, size)` opens committed, 64 KiB-aligned sub-ranges as custom write-back L0 heaps. Placed resources need `D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER`, and textures only row-major. While a heap is open, `VirtualProtect`, `VirtualFree` and `UnmapViewOfFile` on its pages fail with error 87. - Added: opening costs 2.4-5 ms per heap whatever its size, and it makes every page resident (+256 MiB working set for an untouched 256 MiB range). Many small heaps cost milliseconds each, and one large heap costs its memory up front. - One A/B in the title's world, copy vs in place, a single run each, so indicative only: fps 0.8 / 0.8, "preparing" 597 / 406 ms, GPU time 304 / 505 ms (not explained), working set 14.31 / 13.52 GiB. **A pitfall, in case a read-modify-write is ever used to dirty pages for `GetWriteWatch`.** `AtomicU8::fetch_add(0)` is idempotent, and release builds lower it to a plain load. The page then stays clean, and dev-profile tests pass while release fails. `lock add byte ptr [p], 0` does dirty it. `watch.rs` in this repo uses `write_volatile`, so it is not affected today. **Caveats.** One GPU, one A/B run, and the GPU-time increase was not isolated. We have not measured Radeon.
andrewDoing commented 2026-11-26 23:06:20 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T23:06:20Z.


Independent physical RTX 5070 check at 44cf836: I switched only the fixture's WARP selection to the NVIDIA adapter and made the fixture fail instead of silently skipping. Four of five secondary-queue tests passed. In the landing-buffer test, queue2.rs:988 reads card as COPY_SOURCE on the same direct list immediately after writing it as COPY_DEST; all 12 direct readbacks returned the old 0xDEAD0000+k values rather than 0xC000+k. In a scratch control, adding a COPY_DEST → COPY_SOURCE transition between those copies made all five tests pass, including both direct and down-readback assertions. This identifies a fixture issue; the game path was not tested.

A coverage caveat: value + (h & 0u) in the slow shader at queue2.rs:629 lets FXC eliminate the loop. SDK cs_5_1 disassembly contains only store_raw and ret regardless of the spin count, so the conditional in-flight-list test may never exercise contention. An initially unsignaled fence could enforce it.

Verification was AI-assisted with GPT-6.2 Astra.

<!-- greyfinch-sync:DexNom/VIctory:comment:7205257915 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/32#issuecomment-7205257915). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T23:06:20Z. --- Independent physical RTX 5070 check at `44cf836`: I switched only the fixture's WARP selection to the NVIDIA adapter and made the fixture fail instead of silently skipping. Four of five secondary-queue tests passed. In the landing-buffer test, `queue2.rs:988` reads `card` as `COPY_SOURCE` on the same direct list immediately after writing it as `COPY_DEST`; all 12 direct readbacks returned the old `0xDEAD0000+k` values rather than `0xC000+k`. In a scratch control, adding a `COPY_DEST` → `COPY_SOURCE` transition between those copies made all five tests pass, including both direct and down-readback assertions. This identifies a fixture issue; the game path was not tested. A coverage caveat: `value + (h & 0u)` in the slow shader at `queue2.rs:629` lets FXC eliminate the loop. SDK `cs_5_1` disassembly contains only `store_raw` and `ret` regardless of the spin count, so the conditional in-flight-list test may never exercise contention. An initially unsignaled fence could enforce it. Verification was AI-assisted with GPT-6.2 Astra.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/32:upstream-pr/32'
git switch 'upstream-pr/32'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/32'
git switch 'upstream-pr/32'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/32'
git switch 'upstream-pr/32'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/32'
git switch 'main'
git merge --squash 'upstream-pr/32'
git switch 'main'
git merge --ff-only 'upstream-pr/32'
git switch 'main'
git merge 'upstream-pr/32'
git push origin 'main'
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
DexNom/VIctory!32
No description provided.