GPU: buffer views off their host copy's elements use a copy of just their bytes #1019

Closed
github-bot wants to merge 4 commits from gh-pr/1019/head into gh-pr/1019/base
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 15:06 UTC · original
SantannaCarlos:fix/view-off-element → main · +679 −118 · 3 files · 4 commits · closed without merging

What

A view of memory the title placed itself (methods 0x230 and 0x238) names its own start, which need not be a multiple of its stride from the start of its buffer's host copy. Such slots were left null: shader views read zeros, and unordered views lost what shaders wrote. CS_ComputeHitDetectionSkinnedResults (eeed82b877b44b5f) reads one of these shader views (stride 56) and took down both GPUs right after its first use in the world (#71). This was filed as #981; this PR is that branch.

  1. A shader view off an element reads a copy of just its bytes that starts at the view: made on first use, keyed by (start, length), held by the slot. It is a host copy like the others, so its own refresh copies only the 64 KiB pages the title wrote, from title memory.
  2. An unordered view off an element writes that same copy (one per range, shared with a shader view of the same bytes). readable declares the range on it, so the copy-back puts what the GPU wrote into title memory after the submission, and the other copies of that memory pick it up at their next refresh. Which copy a view uses is decided as its slot decided it, not by the range alone.
  3. From @⁠andrewpozdnakov7-jpg (reported on #981): two recording threads making the copy of the same range at once publish one of them, so every slot holds the copy that is refreshed.
  4. With @⁠aycow (reported here, with his fix): a slot keeps the copy it views, its buffer's or the view's own, and its draws bring up to date and copy back that one. readable used to find a copy again from the view's range, which with a title buffer registered inside another is the inner buffer's: stale reads and lost writes even for views on an element.

Known limit, commented as a shortcut: within one submission, a view's copy and its buffer's copy do not see each other's writes. Getting that right needs host buffer states tracked across the submission (#334).

Also: buffer_range and the slots share one reading of the descriptor; the warning for a null buffer view names its kind (placed or registered), stride and range; a diagnostics build leaves the views of the strides in VICTORY_NULL_VIEW_STRIDES null.

#986 fixes the same shader view by copying the view's bytes into the list's scratch memory at each submission. This keeps one copy per view range, refreshed only where the title wrote, and also covers the unordered views of the same kind (44-byte elements, below), which #986 leaves for a follow-up. #912 adds a zero-element check at the top of buffer_srv; the two conflict there only textually. With #493, its raw_at/null_raw_at call keep with two arguments and need None for the new one (a root SRV view reads the buffer's copy, never one of its own). #984 fixes a separate read in the same hit-detection pass; on NVIDIA that pass also hung without it (see below).

Tested

  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features; cargo test --workspace; cargo xtask policy. New tests: on the host device, an unordered view off an element gets its own copy, shared with a shader view of the same bytes, and one on an element keeps the buffer's copy; bytes the GPU writes in a view's own copy (which starts off a page and off its elements) go back to title memory, and a byte the title wrote meanwhile is kept.
  • In the world on an RTX 4070 and the Radeon RDNA2 iGPU (0x164E) in the same PC, with the diag tree from my comments on #71 (loop limit 64, DRED on, Enter-only input), runs of up to 10 minutes:
GPU, setup Before After
4070, mesh off TDR 3.4–11.8 s after the pass's first use no stop: 622 s (first two commits), 623 s (first commit)
4070, mesh on TDR 4.2 s after first use no stop; 496 s in the world, the pass ran 285 s (earlier revision of the first commit)
iGPU, compute only page fault 1.3–1.4 s after first use (3/3) no stop: 622 s, the pass ran 6 min 41 s (all three commits)
  • Unordered views off an element are written by CS_GenerateAccessories0 and CS_GenerateAccessories1 (1,672-byte ranges of 44-byte elements) and CS_DistanceWindowEmissivesCulling (a 40-byte range); on main their writes through these slots were dropped. The 10-minute runs gave 315 such ranges their own copy on the 4070 and 2,779 on the iGPU. Frame cost did not grow on the 4070: medians over the run of 1.1 s a frame in both, copies 189 → 177 ms and copy-back 429 → 381 ms (first commit → first two).

  • On a 4070 tree of main + #493 + #439 + #116 (+ #876 in some runs), the pass hung 3–7 s after its first bind in 2 of 2 runs with this PR's first commit alone, and ran to the 10-minute limit in 3 of 3 runs with this PR and #984 (5–6 min after its first bind each); details on #984.

Two alternatives for the first commit were measured and dropped. Leaving the view null when its submission writes its range brought the stop back: the range covering these views is the whole 174 MB buffer that holds them, declared written in every submission, so 470–1,340 views a frame were nulled. Copying the bytes on the GPU inside the list kept both cards running, but its barriers had the wrong before state in about 28% of the copies (the buffer was already promoted earlier in the same list) and it copied ~3 GB a frame.

Not tested: a shader writing a view's range in the same submission before another view of it reads it (the shortcut above).

**@⁠SantannaCarlos** on GitHub · 2026-11-24 15:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019) `SantannaCarlos:fix/view-off-element` → `main` · +679 −118 · 3 files · 4 commits · closed without merging ## What A view of memory the title placed itself (methods 0x230 and 0x238) names its own start, which need not be a multiple of its stride from the start of its buffer's host copy. Such slots were left null: shader views read zeros, and unordered views lost what shaders wrote. `CS_ComputeHitDetectionSkinnedResults` (`eeed82b877b44b5f`) reads one of these shader views (stride 56) and took down both GPUs right after its first use in the world (#71). This was filed as #981; this PR is that branch. 1. A shader view off an element reads a copy of just its bytes that starts at the view: made on first use, keyed by (start, length), held by the slot. It is a host copy like the others, so its own refresh copies only the 64 KiB pages the title wrote, from title memory. 2. An unordered view off an element writes that same copy (one per range, shared with a shader view of the same bytes). `readable` declares the range on it, so the copy-back puts what the GPU wrote into title memory after the submission, and the other copies of that memory pick it up at their next refresh. Which copy a view uses is decided as its slot decided it, not by the range alone. 3. From @⁠andrewpozdnakov7-jpg (reported on #981): two recording threads making the copy of the same range at once publish one of them, so every slot holds the copy that is refreshed. 4. With @⁠aycow (reported here, with his fix): a slot keeps the copy it views, its buffer's or the view's own, and its draws bring up to date and copy back that one. `readable` used to find a copy again from the view's range, which with a title buffer registered inside another is the inner buffer's: stale reads and lost writes even for views on an element. Known limit, commented as a shortcut: within one submission, a view's copy and its buffer's copy do not see each other's writes. Getting that right needs host buffer states tracked across the submission (#334). Also: `buffer_range` and the slots share one reading of the descriptor; the warning for a null buffer view names its kind (placed or registered), stride and range; a diagnostics build leaves the views of the strides in `VICTORY_NULL_VIEW_STRIDES` null. #986 fixes the same shader view by copying the view's bytes into the list's scratch memory at each submission. This keeps one copy per view range, refreshed only where the title wrote, and also covers the unordered views of the same kind (44-byte elements, below), which #986 leaves for a follow-up. #912 adds a zero-element check at the top of `buffer_srv`; the two conflict there only textually. With #493, its `raw_at`/`null_raw_at` call `keep` with two arguments and need `None` for the new one (a root SRV view reads the buffer's copy, never one of its own). #984 fixes a separate read in the same hit-detection pass; on NVIDIA that pass also hung without it (see below). ## Tested - `cargo clippy --workspace --all-targets -- -D warnings`, with and without `--all-features`; `cargo test --workspace`; `cargo xtask policy`. New tests: on the host device, an unordered view off an element gets its own copy, shared with a shader view of the same bytes, and one on an element keeps the buffer's copy; bytes the GPU writes in a view's own copy (which starts off a page and off its elements) go back to title memory, and a byte the title wrote meanwhile is kept. - In the world on an RTX 4070 and the Radeon RDNA2 iGPU (`0x164E`) in the same PC, with the diag tree from my comments on #71 (loop limit 64, DRED on, Enter-only input), runs of up to 10 minutes: | GPU, setup | Before | After | |---|---|---| | 4070, mesh off | TDR 3.4–11.8 s after the pass's first use | no stop: 622 s (first two commits), 623 s (first commit) | | 4070, mesh on | TDR 4.2 s after first use | no stop; 496 s in the world, the pass ran 285 s (earlier revision of the first commit) | | iGPU, compute only | page fault 1.3–1.4 s after first use (3/3) | no stop: 622 s, the pass ran 6 min 41 s (all three commits) | - Unordered views off an element are written by `CS_GenerateAccessories0` and `CS_GenerateAccessories1` (1,672-byte ranges of 44-byte elements) and `CS_DistanceWindowEmissivesCulling` (a 40-byte range); on `main` their writes through these slots were dropped. The 10-minute runs gave 315 such ranges their own copy on the 4070 and 2,779 on the iGPU. Frame cost did not grow on the 4070: medians over the run of 1.1 s a frame in both, copies 189 → 177 ms and copy-back 429 → 381 ms (first commit → first two). - On a 4070 tree of `main` + #493 + #439 + #116 (+ #876 in some runs), the pass hung 3–7 s after its first bind in 2 of 2 runs with this PR's first commit alone, and ran to the 10-minute limit in 3 of 3 runs with this PR and #984 (5–6 min after its first bind each); details on #984. Two alternatives for the first commit were measured and dropped. Leaving the view null when its submission writes its range brought the stop back: the range covering these views is the whole 174 MB buffer that holds them, declared written in every submission, so 470–1,340 views a frame were nulled. Copying the bytes on the GPU inside the list kept both cards running, but its barriers had the wrong before state in about 28% of the copies (the buffer was already promoted earlier in the same list) and it copied ~3 GB a frame. Not tested: a shader writing a view's range in the same submission before another view of it reads it (the shortcut above).
A view of memory the title placed itself (methods 0x230 and 0x238) names
its own start, which need not be a multiple of the view's stride, so its
slot was left null and shaders read zeros through it. Such a view now
reads a copy of just its bytes that starts at the view, made on first use
and keyed by (start, length); the slot holds it, the map holds a weak
reference.

The copy is a host copy like any other, so its own refresh brings it up to
date from title memory, copying only the pages the title wrote. That is
sound because a submission's copy-back runs before the next submission is
prepared (Host::execute waits for the GPU before copying back), so title
memory holds what the GPU wrote by then. Nothing copies from the buffer's
copy: that would copy the view's whole range again on every submission,
and in the world these views sum to hundreds of megabytes.

Known limit, commented where the copy is made: being prepared from title
memory, the copy does not see what a shader of the same submission wrote
in that range before the read. Correcting that needs every host buffer's
state tracked across the submission (PR #334), so the bytes can be copied
on the GPU inside the list instead. Measured in the world, this version
keeps the collision-detection compute running to the time limit on both
cards, where a per-submission null rule of the same copy caused the
device to go 1 to 12 s after first use.

The step also unifies the view's range: buffer_srv chose its copy from the
resource and readable refreshed from the view, and the title's nested
174 MB heaps made the two differ. One view_range_of now feeds both.

The warning a buffer shader view left null names its kind (placed or
registered), its stride and its range, which is what the logs need to
confirm that only placed views misalign. A diagnostics build leaves the
views of the strides in VICTORY_NULL_VIEW_STRIDES null, to confirm in the
game which ones a pass needs.
An unordered access view of memory the title placed itself starts where
the title put it, which need not be a multiple of its stride from the
start of its buffer's host copy. Such a slot was left null, so what the
shader wrote through it was lost. It now writes the view's own copy, the
one a shader view off an element already reads (one copy per range, so a
shader view and an unordered view of the same bytes share it).

readable declares the view's range on that copy, so the copy-back puts
the bytes the GPU wrote there into title memory after the submission, and
every other copy of that memory picks them up at its next refresh. A view
with its own copy is now brought up to date in that copy only: the
buffer's copy was refreshed for it too, which nothing read. Which copy a
view uses is decided as the slot decided it (off_element), not by the
range alone: an on-element view of the same bytes with another stride
writes the buffer's copy, and its writes must go back from there.

buffer_range, the views' copies and the new check share one reading of
the descriptor (buffer_parts, extent), so the range a slot's copy is keyed
by and the one readable declares cannot differ.

Known limit, as for shader views: within one submission the copy and the
buffer's copy do not see each other's writes (PR #334).
Two recording threads can allocate separate aligned buffers for the
same range. The last cache insert wins, leaving a descriptor that
points at a different buffer from the one refreshed at submission.

Reuse any live copy published while allocation was in progress.
Exercise concurrent publication and verify that each caller holds the
copy that receives the refreshed bytes.
A slot finds its buffer's copy from the resource it views (make), while
readable looked a copy up again from the view's range. With a title
buffer registered inside another, that finds the inner buffer's copy: the
copy the descriptor reads was not brought up to date, and what shaders
wrote was copied back from a copy they never wrote. aycow reported it on
#1019, with a fix and fixtures on AMD, NVIDIA and WARP.

As in that fix, the slot now keeps the copy it views, its buffer's or a
view's own, and hands that one to readable (make_at, mirror, copy_at).
That also replaces the separate list of own copies and the off-element
recheck readable needed: the slot already knows which copy it is of.

Co-authored-by: asc <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:17:19 +00:00
github-bot closed this pull request 2026-11-26 04:17:19 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:10 UTC · original

We checked copyback through a real guest compute dispatch on an RTX 4090 under Wine/vkd3d-proton 3.2. The placed UAV began 48 bytes into the registered buffer and held two 56-byte records. The shader updated the last dword of each record. On ordinary memory at 617aba9, both fields reached guest memory and the surrounding bytes were preserved.

With MEM_WRITE_WATCH, the same two fields retained their CPU values after submission. Adding #322 as the only production change made both memory modes pass the same byte-for-byte check. The combined GPU suite had 61 passes, one ignored test, and the known Wine empty-pipeline-library failure. This covers copyback after a submission. Same-submission visibility between different backing copies and the title’s reported 44-byte UAVs remain separate cases.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7135584668) We checked copyback through a real guest compute dispatch on an RTX 4090 under Wine/vkd3d-proton 3.2. The placed UAV began 48 bytes into the registered buffer and held two 56-byte records. The shader updated the last dword of each record. On ordinary memory at 617aba9, both fields reached guest memory and the surrounding bytes were preserved. With MEM_WRITE_WATCH, the same two fields retained their CPU values after submission. Adding #322 as the only production change made both memory modes pass the same byte-for-byte check. The combined GPU suite had 61 passes, one ignored test, and the known Wine empty-pipeline-library failure. This covers copyback after a submission. Same-submission visibility between different backing copies and the title’s reported 44-byte UAVs remain separate cases.
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 15:17 UTC · original

Thanks to both of you.

@⁠andrewpozdnakov7-jpg the race is real, and with the second commit it matters more: a slot holding the copy the map lost would have its writes declared on the other one. Your commit is now on this branch as it was (85d813c, your authorship), on top of the unordered-view commit; it applied cleanly. cargo test -p victory-gpu (56 passed, 1 ignored, your test included), clippy with and without --all-features, and the asset policy pass.

@⁠MichaelSmithAI I ran your write-watch case on Windows (RTX 4070, as a local test, not in the branch): title memory from VirtualAlloc with MEM_WRITE_WATCH, a view copy 48 bytes into a 64 KiB page, refreshed with update as at submission, the GPU's bytes put in one element, a title byte written meanwhile. copy_back wrote the element into title memory and kept the title's byte, and the next update left the element in the copy (the page is marked current, so our own write is not taken for the title's). So on Windows WriteProcessMemory reaches write-watched pages. What you saw looks like Wine's WriteProcessMemory on such pages, which every copy-back goes through, not only this one; #322 replaces that call for all of them, which fits with it fixing your run.

On the 44-byte unordered views in the title: what I have is the world run in the description (315 ranges, no stop on the 4070 for 10 minutes); I have not checked what the passes that write them produce.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7135764590) Thanks to both of you. @⁠andrewpozdnakov7-jpg the race is real, and with the second commit it matters more: a slot holding the copy the map lost would have its writes declared on the other one. Your commit is now on this branch as it was (85d813c, your authorship), on top of the unordered-view commit; it applied cleanly. `cargo test -p victory-gpu` (56 passed, 1 ignored, your test included), clippy with and without `--all-features`, and the asset policy pass. @⁠MichaelSmithAI I ran your write-watch case on Windows (RTX 4070, as a local test, not in the branch): title memory from `VirtualAlloc` with `MEM_WRITE_WATCH`, a view copy 48 bytes into a 64 KiB page, refreshed with `update` as at submission, the GPU's bytes put in one element, a title byte written meanwhile. `copy_back` wrote the element into title memory and kept the title's byte, and the next `update` left the element in the copy (the page is marked current, so our own write is not taken for the title's). So on Windows `WriteProcessMemory` reaches write-watched pages. What you saw looks like Wine's `WriteProcessMemory` on such pages, which every copy-back goes through, not only this one; #322 replaces that call for all of them, which fits with it fixing your run. On the 44-byte unordered views in the title: what I have is the world run in the description (315 ranges, no stop on the 4070 for 10 minutes); I have not checked what the passes that write them produce.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 85d813c: cargo test -p victory-gpu passes, 56 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7136418474) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 85d813c: `cargo test -p victory-gpu` passes, 56 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠hashdev512 on GitHub · 2026-11-24 16:06 UTC · original

Ran this on the RX 9070 XT setup from my report on #206, as asked there. It removes the fault, and the view's own copy holds the title's bytes.

Setup: Ryzen 7 5700X3D, RX 9070 XT (RDNA4), driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300. main at ffe310e with this PR (head 85d813c) merged locally, diag build with --features diagnostics, VICTORY_D3D12_DRED=1, Series X mode, package v1.0.2.1. 56 victory-gpu tests pass. The only merge conflict was with my own local diagnostics.

Same method as on #206: a local probe (not part of any PR) that, at submission and after the refreshes are flushed, re-reads on the CPU what eeed82b877b44b5f reads, from title memory and from the host side, and looks at what the slot of the stride-56 view holds. For this PR it also reads the slot's own copy.

Build View offset in the shared host copy, mod 56 Slot of the stride-56 view The compute
ffe310e (3 runs) 48, 32, 16 null page fault past the end of the view heap in the first submission that has it
ffe310e + #206 (1 run) 48 the shared copy, raw view 42 min without a fault; run ended by hand at 45 min 46 s
ffe310e + this PR (1 run) 16 its own copy 26 min without a fault; run ended by hand at 36 min 21 s

In the run with this PR:

  • the offset was 16 mod 56 (and a multiple of 16), so it is the failing case;
  • the slot holds a resource that is not the shared copy, and the 56 bytes of the record the program reads are identical in the slot's own copy and in title memory, on the first two dispatches;
  • the record and the 12 entries the program then reads from the big view are also identical in title memory and in the shared copy, and hold valid heap indices;
  • the compute is first dispatched 10 min 8 s in. Over 8,192 frames presented, no device removal. The picture is unchanged (still almost all black), as expected for a fix that unlocks no shader.

As in my #206 test, the build also kept alive, for the whole run, the resource a slot held before HostHeap::keep replaced it and the host copy of every released title texture, so that the freed-texture fault (#557) did not end the run first. That is a local diagnostic switch, not a lifetime fix.

One thing I noticed while merging, which I have not tested: keep replaces the slot's previous own copy in place (*slot = copy), so the previous Arc<Shadow> is dropped right there. If the late release #575 does for the slot's resource matters, the same may apply to that copy. In my run the switch above kept the buffer alive through the slot's resource, so the run says nothing either way.

It is one run, so treat the time as indicative. I can rerun it, with #984 or with a lifetime PR on top, if that is useful.

No game data here: hashes, sizes, offsets and timings from VIctory's own log and the probe's comparison results (equal or not equal), no memory contents.

AI-assisted (Claude Fable 5.2): the probe was written and the run launched and summarised by the model on my machine; figures taken from the logs.

**@⁠hashdev512** on GitHub · 2026-11-24 16:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7137137096) Ran this on the RX 9070 XT setup from my report on #206, as asked there. It removes the fault, and the view's own copy holds the title's bytes. **Setup:** Ryzen 7 5700X3D, RX 9070 XT (RDNA4), driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300. `main` at `ffe310e` with this PR (head `85d813c`) merged locally, `diag` build with `--features diagnostics`, `VICTORY_D3D12_DRED=1`, Series X mode, package v1.0.2.1. 56 `victory-gpu` tests pass. The only merge conflict was with my own local diagnostics. Same method as on #206: a local probe (not part of any PR) that, at submission and after the refreshes are flushed, re-reads on the CPU what `eeed82b877b44b5f` reads, from title memory and from the host side, and looks at what the slot of the stride-56 view holds. For this PR it also reads the slot's own copy. | Build | View offset in the shared host copy, mod 56 | Slot of the stride-56 view | The compute | |---|---|---|---| | `ffe310e` (3 runs) | 48, 32, 16 | null | page fault past the end of the view heap in the first submission that has it | | `ffe310e` + #206 (1 run) | 48 | the shared copy, raw view | 42 min without a fault; run ended by hand at 45 min 46 s | | `ffe310e` + **this PR** (1 run) | **16** | **its own copy** | **26 min without a fault; run ended by hand at 36 min 21 s** | In the run with this PR: - the offset was 16 mod 56 (and a multiple of 16), so it is the failing case; - the slot holds a resource that is not the shared copy, and the 56 bytes of the record the program reads are **identical in the slot's own copy and in title memory**, on the first two dispatches; - the record and the 12 entries the program then reads from the big view are also identical in title memory and in the shared copy, and hold valid heap indices; - the compute is first dispatched 10 min 8 s in. Over 8,192 frames presented, no device removal. The picture is unchanged (still almost all black), as expected for a fix that unlocks no shader. As in my #206 test, the build also kept alive, for the whole run, the resource a slot held before `HostHeap::keep` replaced it and the host copy of every released title texture, so that the freed-texture fault (#557) did not end the run first. That is a local diagnostic switch, not a lifetime fix. One thing I noticed while merging, which I have **not** tested: `keep` replaces the slot's previous own copy in place (`*slot = copy`), so the previous `Arc<Shadow>` is dropped right there. If the late release #575 does for the slot's resource matters, the same may apply to that copy. In my run the switch above kept the buffer alive through the slot's resource, so the run says nothing either way. It is one run, so treat the time as indicative. I can rerun it, with #984 or with a lifetime PR on top, if that is useful. No game data here: hashes, sizes, offsets and timings from VIctory's own log and the probe's comparison results (equal or not equal), no memory contents. _AI-assisted (Claude Fable 5.2): the probe was written and the run launched and summarised by the model on my machine; figures taken from the logs._
Author
Owner

@⁠FrancescoGelosoEterea on GitHub · 2026-11-24 16:08 UTC · original

Tested on an RTX 5070 Ti (driver 621.24, Windows 11 Pro 26300, Ryzen 7 9800X3D, title 1.0.2.1, Series X mode). With this PR the world runs 14.5 min with no device removal and no slow submission at all. compute eeed82b877b44b5f no longer shows up.

Build: diag (--profile diag --features diagnostics) of main ffe310e + #493 + #454 + this PR + #984. I left #206 out, because it conflicts with this PR in buffer_srv/buffer_uav and covers the same views. Settings: VICTORY_SHADER_LOOP_LIMIT=1024, VICTORY_D3D12_DRED=1, VICTORY_NO_WATCHDOG=1, stock TDR, Enter every 5 s through VICTORY_KEYS, target dumps at frames 1600/2000/2400. Same input and settings as my #71 run with #206 in this PR's place.

#493 + #206 #493 + this PR + #984
Time in the world 7.5 min, then device removed, 5,334 ms submission 14.5 min, stopped by hand, no removal
slow host submission 249, median 320 ms, max 670 ms 0
GPU time per world frame 300–650 ms ~90–105 ms
Draws per frame ~1,950 ~3,400
Dropped for a missing host pipeline ~1,300–1,450 ~1,500–1,750
fps ~1.1 ~1.1 (now ~420 MB of copies per frame on the CPU side)

In the #206 run, DRED's in-flight lists had dispatch 12x1x1 [compute eeed82b877b44b5f] with SRVs 42991392x1 and 182452224x1. With this PR it is in no slow submission.

Merge note: this PR and #493 merge without textual conflicts but don't build together. #493's HostHeap::raw_at and null_raw_at call self.keep(index, …) with two arguments, and this PR gives keep a third (copy). I passed None in both places, since those slots view a list's buffer and not a copy of a view's bytes:

// raw_at
self.keep(index, Some(buffer.clone()), None);
// null_raw_at
self.keep(index, None, None);

The image is still black. At frame 1600 the scene is no longer whole in f62, where the #206 run had all of it. Only the tyres are there now. The 2560x1440 f28 G-buffer target shows a fine diagonal hatching over a larger area instead of a few spiky triangles. 520 shaders are still refused at translation (447 compute, 43 pixel, 25 mesh, 5 vertex), and 130 compute pipelines are refused by D3D12 with E_INVALIDARG. So on this card the hang looks fixed by this PR, and the black scene is a separate problem.

From a tester working with Claude (AI-assisted); measured on my own machine.

**@⁠FrancescoGelosoEterea** on GitHub · 2026-11-24 16:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7137187745) Tested on an RTX 5070 Ti (driver 621.24, Windows 11 Pro 26300, Ryzen 7 9800X3D, title 1.0.2.1, Series X mode). **With this PR the world runs 14.5 min with no device removal and no slow submission at all. `compute eeed82b877b44b5f` no longer shows up.** Build: diag (`--profile diag --features diagnostics`) of `main` `ffe310e` + #493 + #454 + this PR + #984. I left #206 out, because it conflicts with this PR in `buffer_srv`/`buffer_uav` and covers the same views. Settings: `VICTORY_SHADER_LOOP_LIMIT=1024`, `VICTORY_D3D12_DRED=1`, `VICTORY_NO_WATCHDOG=1`, stock TDR, Enter every 5 s through `VICTORY_KEYS`, target dumps at frames 1600/2000/2400. Same input and settings as my [#71 run](https://git.gtahub.st/github/Marvisak--VIctory/issues/71) with #206 in this PR's place. | | #493 + #206 | #493 + this PR + #984 | |---|---|---| | Time in the world | 7.5 min, then `device removed`, 5,334 ms submission | **14.5 min**, stopped by hand, no removal | | `slow host submission` | 249, median 320 ms, max 670 ms | **0** | | GPU time per world frame | 300–650 ms | **~90–105 ms** | | Draws per frame | ~1,950 | **~3,400** | | Dropped for a missing host pipeline | ~1,300–1,450 | ~1,500–1,750 | | fps | ~1.1 | ~1.1 (now ~420 MB of copies per frame on the CPU side) | In the #206 run, DRED's in-flight lists had `dispatch 12x1x1 [compute eeed82b877b44b5f]` with SRVs `42991392x1` and `182452224x1`. With this PR it is in no slow submission. **Merge note:** this PR and #493 merge without textual conflicts but don't build together. #493's `HostHeap::raw_at` and `null_raw_at` call `self.keep(index, …)` with two arguments, and this PR gives `keep` a third (`copy`). I passed `None` in both places, since those slots view a list's buffer and not a copy of a view's bytes: ```rust // raw_at self.keep(index, Some(buffer.clone()), None); // null_raw_at self.keep(index, None, None); ``` **The image is still black.** At frame 1600 the scene is no longer whole in `f62`, where the #206 run had all of it. Only the tyres are there now. The 2560x1440 `f28` G-buffer target shows a fine diagonal hatching over a larger area instead of a few spiky triangles. 520 shaders are still refused at translation (447 compute, 43 pixel, 25 mesh, 5 vertex), and 130 compute pipelines are refused by D3D12 with `E_INVALIDARG`. So on this card the hang looks fixed by this PR, and the black scene is a separate problem. *From a tester working with Claude (AI-assisted); measured on my own machine.*
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 16:19 UTC · original

Thank you both, that is the confirmation this needed on RDNA4 and Blackwell.

@⁠hashdev512 on the release: the view's copy has no teardown of its own (no Drop on Shadow); dropping the last Arc releases its ID3D12Resource, and that is the same COM object the slot's kept entry holds (Kept::Resource { resource: shadow.buffer.clone(), .. }). So with #575, whose keep hands the slot's previous resource to release_late, the copy's buffer also stays alive behind the queue, with no change here. On main today it goes when the slot is remade, as every slot's resource does.

@⁠FrancescoGelosoEterea the merge note with #493 is the one in the description (None in raw_at/null_raw_at). On f62 at frame 1600 holding only the tyres where the #206 run had the whole scene: one difference between the two is the limit noted in the description. A view's own copy is brought up to date from title memory when the submission is prepared, so it does not see what a shader wrote in that range earlier in the same submission, while #206's raw view of the shared copy does. If a culling pass writes what a draw then reads through such a view, that would drop geometry. Your two runs also differ by #984, so it is not settled; I'll compare f62 with and without the copy on the 4070 and report here.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 16:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7137486537) Thank you both, that is the confirmation this needed on RDNA4 and Blackwell. @⁠hashdev512 on the release: the view's copy has no teardown of its own (no `Drop` on `Shadow`); dropping the last `Arc` releases its `ID3D12Resource`, and that is the same COM object the slot's `kept` entry holds (`Kept::Resource { resource: shadow.buffer.clone(), .. }`). So with #575, whose `keep` hands the slot's previous resource to `release_late`, the copy's buffer also stays alive behind the queue, with no change here. On `main` today it goes when the slot is remade, as every slot's resource does. @⁠FrancescoGelosoEterea the merge note with #493 is the one in the description (`None` in `raw_at`/`null_raw_at`). On `f62` at frame 1600 holding only the tyres where the #206 run had the whole scene: one difference between the two is the limit noted in the description. A view's own copy is brought up to date from title memory when the submission is prepared, so it does not see what a shader wrote in that range earlier in the same submission, while #206's raw view of the shared copy does. If a culling pass writes what a draw then reads through such a view, that would drop geometry. Your two runs also differ by #984, so it is not settled; I'll compare `f62` with and without the copy on the 4070 and report here.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 16:34 UTC · original

@⁠SantannaCarlos I found a separate case with an ordinary, aligned raw descriptor. The descriptor resolves from the full backing buffer, while refresh/copyback can reselect an inner overlapping shadow from the view slice. On exact ffe310e this produced stale SRV data and lost UAV writes in the synthetic tests. Retaining the shadow selected by the native slot passed all six ordinary/rebuilt table cases on AMD, NVIDIA, and WARP with full GPU-based validation. Synthetic fixture and focused fix. This test establishes the aligned case. The reported pixel hang remains unassigned. Would you be interested in reviewing the interaction with your per-slot off-element backing?

**@⁠aycow** on GitHub · 2026-11-24 16:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7137879838) @⁠SantannaCarlos I found a separate case with an ordinary, aligned raw descriptor. The descriptor resolves from the full backing buffer, while refresh/copyback can reselect an inner overlapping shadow from the view slice. On exact `ffe310e` this produced stale SRV data and lost UAV writes in the synthetic tests. Retaining the shadow selected by the native slot passed all six ordinary/rebuilt table cases on AMD, NVIDIA, and WARP with full GPU-based validation. [Synthetic fixture and focused fix](https://github.com/aycow/VIctory/commit/9bc5f483244e7f0765760d81db9a2c2c6a57cf07). This test establishes the aligned case. The reported pixel hang remains unassigned. Would you be interested in reviewing the interaction with your per-slot off-element backing?
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 16:52 UTC · original

@⁠aycow yes, thank you. That is a mismatch I noticed while writing this and left out: the slot finds its copy from the resource, readable finds one again from the view's range, and nested registered buffers make the two differ. Keeping the copy in the slot and handing that one to readable is the right fix, and it fits this PR: the slot can hold a view's own copy the same way (your Backing::Buffer), which removes this PR's kept_copy and the off_element recheck in readable, since the slot already knows which copy it views.

I'll put your fix on this branch with your authorship, fold the own copy into Backing::Buffer, take your fixture if it fits the tests here, and report the tests and a world run on this thread.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 16:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7138348625) @⁠aycow yes, thank you. That is a mismatch I noticed while writing this and left out: the slot finds its copy from the resource, `readable` finds one again from the view's range, and nested registered buffers make the two differ. Keeping the copy in the slot and handing that one to `readable` is the right fix, and it fits this PR: the slot can hold a view's own copy the same way (your `Backing::Buffer`), which removes this PR's `kept_copy` and the `off_element` recheck in `readable`, since the slot already knows which copy it views. I'll put your fix on this branch with your authorship, fold the own copy into `Backing::Buffer`, take your fixture if it fits the tests here, and report the tests and a world run on this thread.
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 17:12 UTC · original

@⁠aycow done, as 461d12a on this branch. The slot keeps the copy it views, its buffer's or the view's own, as your Backing::Buffer does, and make_at, mirror and a new copy_at hand that one to readable. That replaced this PR's separate list of own copies and the off-element recheck in readable. I wrote it on top of the PR's commits rather than cherry-picking yours, since both change what a slot keeps; you are co-author on the commit.

I left the fixture out: it changes device creation and needs a local Agility SDK with GPU-based validation, which not every machine running cargo test has. A unit test covers the case instead: a raw view of an outer registered buffer whose bytes lie in an inner registered one, checking that the slot hands out the outer buffer's copy and not the one a lookup by the view's range finds.

Tested: cargo test --workspace (victory-gpu 57 passed, 1 ignored), clippy with and without --all-features, the asset policy. In the world on the 4070 (same setup as the description): 623 s with no stop, the hit-detection pass ran 6 min 47 s from its first bind, and frames got slightly cheaper (medians 1.07 → 0.97 s a frame, copies 168 → 139 ms), since a view now refreshes only the copy it reads.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 17:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7138837708) @⁠aycow done, as 461d12a on this branch. The slot keeps the copy it views, its buffer's or the view's own, as your `Backing::Buffer` does, and `make_at`, `mirror` and a new `copy_at` hand that one to `readable`. That replaced this PR's separate list of own copies and the off-element recheck in `readable`. I wrote it on top of the PR's commits rather than cherry-picking yours, since both change what a slot keeps; you are co-author on the commit. I left the fixture out: it changes device creation and needs a local Agility SDK with GPU-based validation, which not every machine running `cargo test` has. A unit test covers the case instead: a raw view of an outer registered buffer whose bytes lie in an inner registered one, checking that the slot hands out the outer buffer's copy and not the one a lookup by the view's range finds. Tested: `cargo test --workspace` (`victory-gpu` 57 passed, 1 ignored), clippy with and without `--all-features`, the asset policy. In the world on the 4070 (same setup as the description): 623 s with no stop, the hit-detection pass ran 6 min 47 s from its first bind, and frames got slightly cheaper (medians 1.07 → 0.97 s a frame, copies 168 → 139 ms), since a view now refreshes only the copy it reads.
Author
Owner

@⁠465d6a0eac on GitHub · 2026-11-24 17:02 UTC · original · edited 2026-11-24 17:20 UTC

Thank you for this, @⁠SantannaCarlos! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/34. You're credited as the author there. This pull request stays the original.

Test results

  • Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with #320/#439, #265 and #492, cargo clippy (both variants) and cargo test --workspace pass (407 passed, 0 failed).
  • Running the title through the same menus with and without it: without it the log shows buffer view not on an element of its host copy offset=9171600 element=32; with it that warning is gone.
  • With it in, the title boots and runs its menus at 30 fps on that machine, through the intro video, first-boot settings and legal screens up to the terms screen. I haven't reached the world yet.
**@⁠465d6a0eac** on GitHub · 2026-11-24 17:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7138599468) · edited 2026-11-24 17:20 UTC Thank you for this, @⁠SantannaCarlos! Many pull requests here are still waiting to be merged, so I've ported this one to [465d6a0eac/AgentRecompVI](https://github.com/465d6a0eac/AgentRecompVI), a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/34. You're credited as the author there. This pull request stays the original. **Test results** - Windows 11, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088, 32-lane waves): together with #320/#439, #265 and #492, `cargo clippy` (both variants) and `cargo test --workspace` pass (407 passed, 0 failed). - Running the title through the same menus with and without it: without it the log shows `buffer view not on an element of its host copy offset=9171600 element=32`; with it that warning is gone. - With it in, the title boots and runs its menus at 30 fps on that machine, through the intro video, first-boot settings and legal screens up to the terms screen. I haven't reached the world yet.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 17:24 UTC · original

@⁠SantannaCarlos Thanks for adopting the slot-backing fix at 461d12a. The #1019/#185/#387 composition passed four focused cases on AMD, NVIDIA and WARP with full GPU validation. Translated off-element stride-56 producer/consumer passed across submissions. Distinct-shadow visibility within one native submission remains open.

**@⁠aycow** on GitHub · 2026-11-24 17:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7139156063) @⁠SantannaCarlos Thanks for adopting the slot-backing fix at `461d12a`. The [#1019/#185/#387 composition](https://github.com/aycow/VIctory/commit/696fcf14d451ca26f76adfa024db35d1cfc63683) passed four focused cases on AMD, NVIDIA and WARP with full GPU validation. Translated off-element stride-56 producer/consumer passed across submissions. Distinct-shadow visibility within one native submission remains open.
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 17:32 UTC · original

@⁠aycow thanks for running the composition. I'm on the within-submission case: on top of #334, a view's own copy whose range shaders write in its buffer's copy (found by that copy's copy-back) gets those bytes copied in on the GPU right before each read, inside the list. In a 10-minute 4070 run about 1,900 such ranges showed up, roughly ten a frame. It is in a world run now; I'll post it as a separate PR stacked on #334 and this one, with the results.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7139351887) @⁠aycow thanks for running the composition. I'm on the within-submission case: on top of #334, a view's own copy whose range shaders write in its buffer's copy (found by that copy's copy-back) gets those bytes copied in on the GPU right before each read, inside the list. In a 10-minute 4070 run about 1,900 such ranges showed up, roughly ten a frame. It is in a world run now; I'll post it as a separate PR stacked on #334 and this one, with the results.
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 17:47 UTC · original

The within-submission case is now #1405, stacked on #334 and this PR.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 17:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7139700319) The within-submission case is now #1405, stacked on #334 and this PR.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:30 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1019#issuecomment-7148577232) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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/Marvisak--VIctory!1019
No description provided.