Skip to content

GPU: bind root SRVs as one-view tables bounded to their host copy - #493

Closed
hophaver wants to merge 3 commits into
Marvisak:mainfrom
hophaver:fix/bounded-root-srvs
Closed

hophaver wants to merge 3 commits into
Marvisak:mainfrom
hophaver:fix/bounded-root-srvs

Conversation

@hophaver

Copy link
Copy Markdown
Contributor

Builds on #336 (it uses that PR's bind returning false); the diff against main shows #336's two commits until that one is merged. The change here is c48b240.

Problem

With #336, the world on an RX 9070 XT runs past the 60 s descriptor exhaustion, then is removed at about 134–145 s with a different signature, seen on three machines (#336 comments):

page fault at 0x408da3000; inside freed ["texture 2048x512 f98 …", "texture 1024x1024 f98 …", …];
the nearest title memory copy below it: 0xb92400000+0x400000 at host 0x408900000, offset 0x4a3000
a list stopped at … mesh 1 [mesh 38ad582f523fd7cf, …] | … root3=0xb925e6000 host Some((0x408ae6000, 0x21a000))

As @GamingRipperDoc worked out there: the mesh shader reads its vertex stream through root SRV root3, whose host copy ends exactly at the end of that 4 MB title memory copy, and the fault lies just past it. A root SRV is a bare address, and vertex fetch reads it with no record limit, so a read past the copied range lands in whatever the host placed there, here memory that had held since-freed textures.

Change

  • A root SRV becomes a one-descriptor table holding a raw view of the buffer's host copy from the root address to the copy's end (raw_at). Reads past the end return zero, as for any bounded view, instead of reaching other host memory.
  • One dynamic slot per (heap, address) per list, from the heap's dynamic range, given back with the list's other dynamic slots.
  • A root SRV the title did not set, or with no host copy, gets a null raw view: an unset table is undefined. If no slot can be had, the draw or dispatch is dropped, as GPU: drop draws whose fresh tables cannot be made; 2^18 dynamic slots #336 does for tables.
  • Raw views must start on 16 bytes. A root address that does not reads zeros and is logged once (not seen in the world runs here).
  • VICTORY_ROOT_SRV_DIRECT=1 goes back to root descriptors.

Root CBVs are unchanged.

Tested

Windows 11, RX 9070 XT, v1.0.2.1, diag build, VICTORY_D3D12_DRED=1, this branch alone on main d2a4bae (+ #336):

One run with the change; more runs, and NVIDIA / Intel, are untested.

hophaver and others added 3 commits November 24, 2026 04:22
When HostHeap::dynamic ran out, State::tables skipped the fresh table and
the stage's user data fell back to the title's table offset. Constant
buffer tables are always made fresh and never mirrored, so the shader read
whatever host descriptor sat at those slots as a constant buffer; on AMD a
texture or null descriptor read as a buffer gives a wild base address and
the device is removed (Marvisak#59: faults at 0x7000037xxxxx, 0x8000037xxxxx,
0x33c4000, a different pipeline every run, about 60 s in).

bind now reports that a table could not be made, and the draw, mesh
dispatch, dispatch or indirect execution is dropped. The dynamic range grows
from 2^16 to 2^18 slots, which the world did not exhaust on an RX 9070 XT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host that refuses the title's slots plus 2^18 dynamic ones (NVIDIA's
1,000,000-view cap) now gets 2^16 dynamic slots, as before, instead of
losing mirrored title slots to the larger range: at the cap, 2^18 left
737,856 title slots against 934,464, and titles were seen to index slots
up to 917,140. The cap itself is unchanged. Hosts that take the larger
heap (RX 9070 XT) keep 2^18.
A root SRV is a bare GPU address: nothing bounds what a shader reads
through it. Vertex fetch reads its stream through a root SRV with no
record limit, and a mesh shader read past the end of the buffer's host
copy into memory the host had already freed (the "inside freed texture"
device removal after the fix for Marvisak#59: the fault lay just past the copy's
end, in the gap where released textures had been).

Each root SRV is now a one-descriptor table holding a raw view of the
host copy from the root address to the copy's end, made once per address
per list in the heap's dynamic slots; reads past the end return zero, as
for any bounded view. A root SRV the title did not set, or one with no
host copy, gets a null raw view (an unset table is undefined). Addresses
not on 16 bytes, which a raw view cannot start at, read zeros and are
logged once. VICTORY_ROOT_SRV_DIRECT=1 restores root descriptors.
@desplmfao

desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA / Linux data point, since NVIDIA was untested here.

Setup: RTX 5080, driver 615.71.09, CachyOS, proton-cachyos (vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of main d2a4bae + #336 + this PR, plus #185, #440, #436, #462, #259, #177, #151 (the last three needed to reach the world here). Story mode entered by VICTORY_KEYS at about 35 s, no other input.

Before (same stack without #336 / #493): 4 of 5 runs ended in a GPU hang, NVRM: Xid 109 ... CTX SWITCH TIMEOUT from title-main, 3.5–5.3 min after start (about 2–4 min into the world), followed about 20 s later by the title's crash at +0x23cf683. The fifth was stopped at 4.5 min. Earlier the same day, with fewer PRs, the same hang came at 1.5–3 min.

With #336 + #493: 4 of 4 runs without a hang: 8, 10 and 9 min after start, through to the timer, and 7.5 min (stopped by hand), about 6–8.5 min in the world. The last one also had #431. No Xid, nothing in crashes.log, no root SRV not on 16 bytes line, no exhaustion warning.

Four runs, so not conclusive, but it fits @matheushagedorn's finding on #71 (an Xid 13 MMU fault in compute from reads past the end, which turns into this CTX SWITCH TIMEOUT with robustness on). Frame times were unchanged (several seconds per world frame here; that is the copy path, not this PR).

AI-assisted (Claude Code); the numbers come from the logs of these runs.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Heads-up: this PR and #458 both add pub(crate) fn is_sampler(&self) -> bool to crates/victory-gpu/src/descriptor/host.rs. They merge without textual conflicts, but the result does not compile:

error[E0592]: duplicate definitions with name `is_sampler`
   --> crates\victory-gpu\src\descriptor\host.rs:371:5

Whichever lands second will need to drop or rename its copy.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

NVIDIA data point: RTX 4070 (driver 32.0.16.2101, Windows 11), diag builds, entering the world (first mission intro), 300 s runs.

Still seen on NVIDIA with both applied: the 65,536 dynamic descriptor slots run out (dropped=65536), and one run had a 1.84 s GPU frame from two mesh+pixel pipelines, close to the TDR limit.

cargo test -p victory-shader and -p victory-gpu pass on the combination (--test-threads=1). Not tested: #483 alone in game, runs longer than 300 s.

@Nixitov

Nixitov commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

RTX 5070, native Windows D3D12: this plus #483 keeps the world alive, where main loses the device within 1-2.5 min.

Setup: Windows 11 Pro 26200.9974, NVIDIA RTX 5070, driver 617.14, in-box D3D12 10.0.26100.9818, Rust 1.98.1, release build.

build world
d2a4bae + #581 11-list submission takes 10.97 s, device removed (0x887A0006 after 0x887A0004)
d2a4bae + #581 + #578 1-list submission of 12 wave32 compute programs takes 11.34 s, device removed
d2a4bae + this PR + #483 still running after 300 s in the world, 0 device removals

With this PR + #483 the slow-submission lines settle at 265-284 ms for the same 11-list submissions that took 11 s before (10-40x), and the frame log goes 2 fps / 455-570 ms per frame, 500-1113 draws per frame. Stopped by the run, not by a fault.

One integration note for landing both: #493 and #483 conflict in crates/victory-gpu/src/descriptor/host.rs. What I merged for the test above:

  • keep this PR's DYNAMIC / MIN_DYNAMIC selection and add Shaders, GPU: a heap index computed from data stays inside the heap #483's guard slot as one more (let guard = u32::from(!sampler); ... make(count + DYNAMIC + guard), and the capped branch PORTABLE_VIEWS - (MIN_DYNAMIC + guard));
  • guard_slot() returns count + self.dynamic for view heaps instead of count + DYNAMIC, so it is the last slot whichever dynamic range the heap got.

That build runs cargo build --release -p victory clean. Whichever lands second needs that small adaptation.

No game files; only timings, frame counts and the two error names.

AI-assisted (DeepSeek V4.1 Flash coding agent).

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
hophaver's Marvisak#493: each root SRV becomes a one-descriptor table holding a
raw view of the buffer's host copy from the root address to the copy's
end, in a dynamic slot, so reads past the copy return zeros.
VICTORY_ROOT_SRV_DIRECT=1 restores root descriptors. The branch carries
Marvisak#336, which this tree had at 3c81420, and with it Marvisak#336's second commit
e8d3b64.

Conflict resolution, crates/victory-gpu/src/descriptor/host.rs: this
tree's side is kept whole (the `spare` field, the capped sampler heap
with its dynamic slots, `with`, `free_table`), and only c48b240's own
additions are taken (raw_at, null_raw_at, is_sampler, gpu_handle).
e8d3b64's sizing is not taken: it gives a heap the host caps 2^16
dynamic slots in place of 2^18 (MIN_DYNAMIC), so that more of the
title's slots are mirrored. A tester measured that tradeoff in the title
on an RTX 5080 (Zignixx, upstream issue Marvisak#71, comment 7123097017, one run
per row): with 65,536 dynamic slots 22-30% of the requests for slots
were refused and about 1,680 mesh dispatches per frame were dropped;
with 262,144 none were, the peak in use was 132,014, and "title slot
past the host heap" never fired in a 7-minute run. A capped view heap
therefore keeps 2^18 dynamic slots, as this tree had. New test
a_capped_view_heap_keeps_its_dynamic_slots (on the integration
machine's RTX 5070 the heap of 1,310,720 title slots is capped: 737,856
title slots and 262,144 dynamic ones).

Change beyond the PR, crates/victory-gpu/src/draw.rs, root_srv_table:
the host copy is moved to its read state (list.buffer_state with
BUFFER_READ), as root_view does since Marvisak#334. Marvisak#493 was written without
Marvisak#334's buffer-state tracker; without this a copy a shader wrote earlier
would be read through the table in its unordered-access state.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
Seven more upstream PRs are in (Marvisak#493, Marvisak#483, Marvisak#206, Marvisak#469, Marvisak#459, Marvisak#454,
Marvisak#579) and the wave64 stack is at Marvisak#439's head 965ce30. Records how each
was combined with what the tree had, that a capped view heap keeps
2^18 dynamic slots and why, Marvisak#189 and Marvisak#578 as left out, and a new
section with testers' reports from the title: the set without the
world-entry hang on three NVIDIA cards and how this tree differs from
it, VICTORY_SKIP_WAVE64 as the switch to try, and Marvisak#136 bisected as
making every frame black.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 24, 2026
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…+ Marvisak#1418) + shader stack

No textual conflict; checked with cargo check --workspace --all-targets and the full
test suite (RTX, WARP, all features) when first merged on the previous Marvisak#1511
head (289f241); this replay with cargo check --workspace --all-targets
--all-features, and the full suite at the end of the line.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…shader writes and reads) onto integ/next

Conflicts:
1. crates/victory-gpu/src/draw.rs, `State::bind`: the stack (Marvisak#1439's depth
   sampling) resets `self.depth_sampled`, Marvisak#334 starts a buffer-state command
   (`list.begin_command()`). Independent; both kept, reset first.
2. crates/victory-gpu/src/host.rs tests: the stack adds
   `warp_device_creation_and_caps_probe`, Marvisak#334 adds
   `buffer_states_transition_between_writes_and_reads`,
   `buffer_states_keep_a_command_writing` and
   `debug_layer_accepts_buffers_written_then_read_as_vertices` (with its
   helpers) at the same place. The shared text holds the `#[test]` before
   and the closing brace after, so neither side's body closes inside the
   hunk: the stack's test is closed and Marvisak#334's follow as separate items
   (not nested).

Non-textual fixes:
- draw.rs `root_srv_table` (Marvisak#493, bounded root SRVs as one-view tables)
  reads a host copy without going through `root_view`, so it never asked
  Marvisak#334's tracker for the read state. It now calls
  `list.buffer_state(&s.buffer, BUFFER_READ)` after its refresh, on cache
  hits too, as Marvisak#334's author and Hiiva noted on Marvisak#334
  (Marvisak#334 (comment),
  Marvisak#334 (comment)).
- indirect.rs test `clamp_preserves_record_offsets_and_shared_budget`
  (Marvisak#1279, via Marvisak#1439) called `indirect::done`, which Marvisak#334 removes (the clamp
  now asks the tracker for the write state and `close` returns the copy to
  COMMON). The call is dropped; the next `bound` asks for the write state
  again, so no transition is missing.
@Marvisak Marvisak closed this Nov 24, 2026
PastiiJay pushed a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.