memory: keep a packed structure's pages when another one replaces it at the same address #1878

Merged
xteral67 merged 1 commit from upstream-pr/1878 into main 2026-11-29 08:16:53 +00:00
xteral67 commented 2026-11-29 01:22:51 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xteral67 on 2026-11-29T01:22:51Z.


No issue filed: found while profiling city driving with ray tracing on.

What it changes

What was wrong. With ray tracing on, driving fast through a city made the game drop to 0.3-2 fps for 5-60 s at a time. Often it did not recover even when standing still, and on the release build it often ended in a device removal (0x887A0005, the card hung past the TDR delay). GPU timing showed the ray walk shaders (indirect-walk) going from 2-15 ms to 340-670 ms a frame. The builder itself stayed cheap.

Memory dumps (VICTORY_MEMORY_DUMP) taken during the slowdown showed 23-36 instances of the walked top level structures pointing at bottom level structures whose arena pages still held the packed header (0x...81020006). Rays walked packed bytes as nodes until their iteration limit.

A per-structure history of Memory::land showed the same sequence for every one of them:

  1. Structure A streams in at an address, lands, is unpacked, and works.
  2. Structure B streams in at the same address. land sees another header and calls gone(A): A's pages go back to the free list and their directory entries become 0.
  3. The re-insert places B's pages again. The free list hands them out last-in first, so they come back at other places in the arenas.
  4. That submission has already asked the write watch, so the card's directory still names the old places when the builder unpacks B. B's packed bytes go up to the new places, and nothing unpacks them again.

Structures landing at a fresh address never broke. Only replacements at the same address did. That happens a lot when streaming in fast.

What this does. When a known packed structure gives way to another one at the same address, the new Memory::replaced drops it like gone does, but keeps its pages where they are. The new structure takes the same places, so the directory does not change and the builder unpacks where the rays later read.

Works together with #1161 (merged, off by default). This fix only shows when the compacted sizes reach the title's copies (VICTORY_BVH_SIZE_COPY=1). Without that, the copies of compacted structures are still wrong and the slowdown stays, with or without this change. Neither of the two alone stops it; together they do (numbers below).

Trade-off. If the new structure is shorter than the old one, the old one's tail pages stay held with no owner until the address is reused. This is a small, bounded leak, traded for not touching the directory in the middle of a submission.

How it was tested

  • GPU and profile: RTX 3080 Ti, Windows 11, Series X profile, 1440p, DLSS Quality, FSR 3 frame generation, the title's ray tracing on (VICTORY_BVH_BUILDER=1, VICTORY_AMBIENT=0). The same city route at high speed by car in every run. Numbers are fps per 5 s interval, in game only.

v2026.11.28.03 + #1161 cherry-picked (VICTORY_BVH_SIZE_COPY=1):

fps per 5 s interval End
Before (no fix) 9 10 2 11 10 8 9 8 8 8 7 9 8 9 7 9 8 9 7 1 6 6 device removed (0x887A0005)
After 16 12 13 11 9 9 9 8 8 7 8 5 6 6 6 8 8 6 11 7 no crash, no interval under 5 fps

v2026.11.28.03 alone (no #1161): with or without this fix, the slowdown to 0-3 fps and a device removal at speed.

A build close to v2026.11.27.9 that already has the compacted size copies, switching one thing at a time:

fps per 5 s interval
Fix off 10 12 10 11 9 8 9 3 6 1 1 0 2 1 (did not recover)
Fix on (an earlier run, the same kind of driving) steady 10-11, lowest 4.5 at a loading moment
Fix on, size copies off 14 14 7 5 4 6 ... 1 ... 1 ... 2 1

Diagnostics build, same place and route:

Before After
Broken (packed) structures in the dump 23-36 0 (560 replacements in that run)
Mean frame over 5 s intervals ~1,020 ms ~124 ms
Intervals slower than 300 ms 19 2
  • Rebased onto d585f88. There memory.rs gained #1062 and #722 (gone now tells the write watch about the directory entries it clears, and faulted pages are kept under a budget); the only conflict was the two new functions sitting next to each other. The driving runs above are on v2026.11.28.03 and on a build close to v2026.11.27.9, cargo test on d4b5d51; this exact rebased commit was not driven again.
  • For shader changes, the wave sizes tested: no shader changes.
  • cargo test passed for the crates it touches: yes, cargo test --release -p victory-gpu on main at d4b5d51 with this change: 550 passed, 0 failed. In one earlier run descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes failed once (view width 6291456 instead of 65536) and passed on the next run with no change; it does not touch title memory by address, so it looks flaky (tests sharing a pool while running in parallel?).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1161 (merged; needed together with this one), #718 (compacted sizes answered at the builder call, another way to the same end as #1161), #1062 and #1468 (also in title memory by address, not the same change). None of them changes how land drops a replaced packed structure.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5546397627 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1878). Originally posted by [xteral67](https://github.com/xteral67) on 2026-11-29T01:22:51Z. --- No issue filed: found while profiling city driving with ray tracing on. ## What it changes **What was wrong.** With ray tracing on, driving fast through a city made the game drop to 0.3-2 fps for 5-60 s at a time. Often it did not recover even when standing still, and on the release build it often ended in a device removal (`0x887A0005`, the card hung past the TDR delay). GPU timing showed the ray walk shaders (`indirect-walk`) going from 2-15 ms to 340-670 ms a frame. The builder itself stayed cheap. Memory dumps (`VICTORY_MEMORY_DUMP`) taken during the slowdown showed 23-36 instances of the walked top level structures pointing at bottom level structures whose arena pages still held the **packed** header (`0x...81020006`). Rays walked packed bytes as nodes until their iteration limit. A per-structure history of `Memory::land` showed the same sequence for every one of them: 1. Structure A streams in at an address, lands, is unpacked, and works. 2. Structure B streams in at the same address. `land` sees another header and calls `gone(A)`: A's pages go back to the free list and their directory entries become 0. 3. The re-insert places B's pages again. The free list hands them out last-in first, so they come back at other places in the arenas. 4. That submission has already asked the write watch, so the card's directory still names the old places when the builder unpacks B. B's packed bytes go up to the new places, and nothing unpacks them again. Structures landing at a fresh address never broke. Only replacements at the same address did. That happens a lot when streaming in fast. **What this does.** When a known packed structure gives way to another one at the same address, the new `Memory::replaced` drops it like `gone` does, but keeps its pages where they are. The new structure takes the same places, so the directory does not change and the builder unpacks where the rays later read. **Works together with #1161** (merged, off by default). This fix only shows when the compacted sizes reach the title's copies (`VICTORY_BVH_SIZE_COPY=1`). Without that, the copies of compacted structures are still wrong and the slowdown stays, with or without this change. Neither of the two alone stops it; together they do (numbers below). **Trade-off.** If the new structure is shorter than the old one, the old one's tail pages stay held with no owner until the address is reused. This is a small, bounded leak, traded for not touching the directory in the middle of a submission. ## How it was tested - GPU and profile: RTX 3080 Ti, Windows 11, Series X profile, 1440p, DLSS Quality, FSR 3 frame generation, the title's ray tracing on (`VICTORY_BVH_BUILDER=1`, `VICTORY_AMBIENT=0`). The same city route at high speed by car in every run. Numbers are fps per 5 s interval, in game only. **v2026.11.28.03 + #1161 cherry-picked** (`VICTORY_BVH_SIZE_COPY=1`): | | fps per 5 s interval | End | |---|---|---| | Before (no fix) | 9 10 2 11 10 8 9 8 8 8 7 9 8 9 7 9 8 9 7 **1** 6 6 | device removed (`0x887A0005`) | | After | 16 12 13 11 9 9 9 8 8 7 8 5 6 6 6 8 8 6 11 7 | no crash, no interval under 5 fps | **v2026.11.28.03 alone** (no #1161): with or without this fix, the slowdown to 0-3 fps and a device removal at speed. **A build close to v2026.11.27.9** that already has the compacted size copies, switching one thing at a time: | | fps per 5 s interval | |---|---| | Fix off | 10 12 10 11 9 8 9 3 6 **1 1 0 2 1** (did not recover) | | Fix on (an earlier run, the same kind of driving) | steady 10-11, lowest 4.5 at a loading moment | | Fix on, size copies off | 14 14 7 5 4 6 ... **1** ... **1** ... 2 **1** | Diagnostics build, same place and route: | | Before | After | |---|---|---| | Broken (packed) structures in the dump | 23-36 | 0 (560 replacements in that run) | | Mean frame over 5 s intervals | ~1,020 ms | ~124 ms | | Intervals slower than 300 ms | 19 | 2 | - Rebased onto d585f88. There `memory.rs` gained #1062 and #722 (`gone` now tells the write watch about the directory entries it clears, and faulted pages are kept under a budget); the only conflict was the two new functions sitting next to each other. The driving runs above are on v2026.11.28.03 and on a build close to v2026.11.27.9, `cargo test` on d4b5d51; this exact rebased commit was not driven again. - For shader changes, the wave sizes tested: no shader changes. - `cargo test` passed for the crates it touches: yes, `cargo test --release -p victory-gpu` on main at d4b5d51 with this change: 550 passed, 0 failed. In one earlier run `descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes` failed once (view width 6291456 instead of 65536) and passed on the next run with no change; it does not touch title memory by address, so it looks flaky (tests sharing a pool while running in parallel?). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1161 (merged; needed together with this one), #718 (compacted sizes answered at the builder call, another way to the same end as #1161), #1062 and #1468 (also in title memory by address, not the same change). None of them changes how `land` drops a replaced packed structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xteral67 commented 2026-11-29 01:31:51 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xteral67 on 2026-11-29T01:31:51Z.


A note on #1161, since it is merged but off by default (VICTORY_BVH_SIZE_COPY):

With the title's ray tracing on (VICTORY_BVH_BUILDER=1), the size copies look required rather than optional. In the runs above, city at speed on an RTX 3080 Ti:

  • without the size copies, rays degrade to 4-6 fps with drops to 1 fps, and on v2026.11.28.03 the card is removed (0x887A0005), with or without this PR;
  • with the size copies but without this PR: the freeze to 0-1 fps and a device removal;
  • with both: no freeze, no interval under 5 fps.

So it may be worth turning VICTORY_BVH_SIZE_COPY on whenever the builder is on, or by default.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7248842556 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1878#issuecomment-7248842556). Originally posted by [xteral67](https://github.com/xteral67) on 2026-11-29T01:31:51Z. --- A note on #1161, since it is merged but off by default (`VICTORY_BVH_SIZE_COPY`): With the title's ray tracing on (`VICTORY_BVH_BUILDER=1`), the size copies look required rather than optional. In the runs above, city at speed on an RTX 3080 Ti: - without the size copies, rays degrade to 4-6 fps with drops to 1 fps, and on v2026.11.28.03 the card is removed (`0x887A0005`), with or without this PR; - with the size copies but without this PR: the freeze to 0-1 fps and a device removal; - with both: no freeze, no interval under 5 fps. So it may be worth turning `VICTORY_BVH_SIZE_COPY` on whenever the builder is on, or by default.
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!1878
No description provided.