Skip to content

GPU & shader: full Root SRV extent refresh, safe fallback VAs, and Root UAVs - #294

Closed
wbkepler wants to merge 4 commits into
Marvisak:mainfrom
wbkepler:gpu/root-srv-bounds-and-uav
Closed

wbkepler wants to merge 4 commits into
Marvisak:mainfrom
wbkepler:gpu/root-srv-bounds-and-uav

Conversation

@wbkepler

Copy link
Copy Markdown

Summary

Fixes Root SRV truncation past 1 MiB, null/unmapped root view faults, and adds full Root UAV support end-to-end:

  • Full Root SRV / Root UAV extent refresh (draw.rs):
    • Refreshes the full remaining Shadow buffer extent (shadow.left(address)) for Root SRVs and Root UAVs while keeping Root CBVs at the 64 KiB D3D12 limit.
  • Safe fallback VAs (shadow.rs, draw.rs):
    • Guards shadow::find/loose against low (< 0x10000), overflowing top-of-u64, and uncommitted addresses, and binds permanently-alive 4 MiB zeroed/sink fallback GPU VAs instead of skipping Set*Root*View.
  • End-to-end Root UAVs (victory-shader, victory-gpu):
    • Implements Root UAVs (u<slot>, space1 RWByteAddressBuffer) across victory-shader (descriptor handle, global_store_dword*, s_load_dword* on root descriptors, PSV0/dx.resources metadata, SFI0/ShaderFlags UAVsAtEveryStage), shader_cache (VSH2), pipeline::host (deduplicating shared (kind, slot) root views across stages), and draw.rs (binding, gpu_writes write-back, and post-draw/dispatch/ExecuteIndirect UAV barriers).

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (victory-gpu: 47 passed, 1 ignored; victory-shader: 71 passed including dxil.dll validation, WARP, and host GPU tests)
  • cargo xtask policy — passed (151 files ok)

zebraso added a commit to zebraso/VIctory that referenced this pull request Nov 24, 2026
`root_view` cut a root SRV at 1 MiB (a root CBV at D3D12's 64 KiB), so the
title's vertex and index data past that read from a host copy that was
never brought up to date: the world's geometry read zeros while its
constants and small buffers were fine. The refresh copies only the pages
the title wrote since they were last copied, so naming the whole remaining
extent costs nothing when nothing changed.

Same finding as upstream Marvisak#294 (full root SRV extent), kept to this tree.
AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
On top of integrate/shaders2. Conflicts:
- lower.rs: Marvisak#265's scratch() stays; flat() takes Marvisak#294's root SRV/UAV doc.
- valu_tests.rs: the shader side's test helpers (emit with a Target) stay;
  Marvisak#294's two root UAV tests are appended.
- shader_cache.rs: both new tests kept (Marvisak#320 wave-size key, Marvisak#358 cache
  that cannot keep an entry).
- HostShader initialisers in scratch_tests.rs and valu_tests.rs get
  root_uavs; emit() calls in tests get Target::ANY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review question on cost (built on main d2a4bae; cargo test -p victory-gpu and -p victory-shader pass on an RTX 5070). In root_view, a root SRV and a root UAV now take the whole rest of the backing copy:

RootView::Uav => {
    let len = shadow.left(address);
    shadow.refresh(list, address, len);
    shadow.gpu_writes(list, address, len);

main capped root SRVs at 1 MiB. Testers report one host copy of about 174 MiB behind most of the title's buffers (#199: title buffer 0x19b10000+0xae00000). For a root UAV into it, gpu_writes keeps the range's bytes before the submission and the copy-back compares the range afterwards, so a root UAV near the start of that heap means on the order of 174 MiB kept and compared per submission. A direct-SRV refresh of similar size (#185) took an RX 7800 XT from about 1 s to about 6 s per frame, and long submissions are what ends in the device removal.

Has this been measured on a large buffer? If the view's real extent cannot be known, a cap with a logged warning when it is hit (as main does for SRVs) would keep the worst case bounded.

From reading and synthetic tests only; I have no copy of the title.

@miniongk

Copy link
Copy Markdown

Tested bffaefd on an RTX 5080, driver 621.24, Windows 11 26300, with a local Xbox Series 1.0.2.1 copy.

  • cargo test --workspace: 270 passed, 0 failed, 4 ignored.
  • WARP with DRED still reaches the known menu compute failure described in Host GPU device removed on RTX 4070 (diag build, DRED) - many shaders fail to translate #97; there were no null or unmapped root-view fallback warnings.
  • The native hardware path reached the world (1,283 host pipelines), but still ended in DXGI_ERROR_DEVICE_HUNG at a compute dispatch. There were again no null or unmapped root-view fallback warnings.

So this does not resolve #97 on my machine; that is not evidence against the root-UAV functionality itself. Only aggregate counts and error classes shared, no game data or raw game logs. AI-assisted (Kimi Code).

@wbkepler

Copy link
Copy Markdown
Author

Thanks @r4tedx, good catch: it had not been measured on a large buffer, and the UAV snapshot/compare is the expensive part. Pushed 0050ce5:

  • New root_len bounds every root view instead of using shadow.left(address): CBVs stay at the 64 KiB D3D12 maximum, root SRVs refresh at most 4 MiB, root UAVs refresh, snapshot and copy back at most 2 MiB (smaller because that range is kept and compared on every submission).
  • When a cap cuts the remaining extent, a one-time warning is logged per view kind (with the remaining length and the cap), like main does.
  • It is marked // shortcut:. The translated shader does not report the range a root view reads or writes yet. Once it does, that range should replace the caps.
  • SRVs keep a 4 MiB cap rather than main's 1 MiB, so the >1 MiB geometry reads this PR fixed still work. The existing +1.5 MiB SRV/UAV tests still pass, and a unit test checks the caps and that shorter extents are taken whole.

The fallback VAs and root UAV support are unchanged. Gate: clippy (both configs), cargo test --workspace and cargo xtask policy are clean.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
Build D3 page-faulted the GPU 47 s into the world on an RX 7600, at a
compute dispatch about 1.4 GB past the nearest title copy. Root views
have no bounds checks on the host, and root UAVs (Marvisak#294) are the newest
way a shader reaches unchecked memory. Until that is understood, a
shader that needs a root UAV stops at "a typed root view" again and its
dispatch is dropped, as before Marvisak#294; VICTORY_ROOT_UAVS=1 turns them back
on. The shader cache keys on the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
Build D3 page-faulted the GPU 47 s into the world on an RX 7600, at a
compute dispatch about 1.4 GB past the nearest title copy. Root views
have no bounds checks on the host, and root UAVs (Marvisak#294) are the newest
way a shader reaches unchecked memory. Until that is understood, a
shader that needs a root UAV stops at "a typed root view" again and its
dispatch is dropped, as before Marvisak#294; VICTORY_ROOT_UAVS=1 turns them back
on. The shader cache keys on the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
(cherry picked from commit ea38011)
@jeremygold02

jeremygold02 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Tested this PR at 0050ce50 together with #489 at 279eac1 (which includes #302) on Windows 11 and a physical RTX 5070. Five previously refused compute shaders reached fence-complete direct dispatches during mission loading.

Same 31 compute inputs Windows SDK-valid DXIL
Main d2a4bae 0
#302 0
#489 0
#489 + this PR 6

All six previously stopped on root UAV / typed root view handling with #489. The SDK preserved all six emitted DXIL hashes. For the live comparison I kept the previous mission build, including #457 and the same readback instrumentation, and added #489 and this PR. The startup logs show 682 early pipeline keys for the previous build and 683 for the combined build. I staged identical 682-key seeds, but the harness set only the data directory and both launchers used the shared pipeline cache. The runs therefore do not give a controlled cache or frame-time comparison. A diagnostic observer matched nonempty direct dispatches for five distinct shaders to their submitted command lists. The native queue fence completed at the submitted value for both batches. The mission screen remained near black. This run establishes dispatch progress, with visible rendering and frame-time impact still unresolved.

I also isolated why the sixth shader fails pipeline creation on this adapter. Its validated DXIL requires a 64-lane wave, and DXC accepts the production root signature for it. The RTX 5070 reports WaveOps support with both the minimum and maximum wave size at 32. I compared two ordinary 512-thread compute shaders with 1,024 bytes of group-shared memory and the same root signature. Both passed SDK and root-signature validation. Changing only [WaveSize(32)] to [WaveSize(64)] changed native pipeline creation from S_OK to E_INVALIDARG (0x80070057), the same refusal as the sixth shader. This is a sufficient reason for that PSO refusal. The test created no command list or queue. Related wave-size handling in #223.

Separately, the production root-binding and guest copy-back path passed a bounded synthetic check on the same GPU. A direct dispatch and a one-group indirect dispatch both wrote the expected guest dword. An unmapped UAV wrote to the designated sink, the separate zero buffer stayed zero, and surrounding guest bytes stayed intact. Each submission completed its fence with the device reporting S_OK.

@ghost

ghost commented Nov 24, 2026 •

Copy link
Copy Markdown

In game on AMD RDNA4 (RX 9060 XT, Windows 11), opening cutscene: d2a4bae + #135 + #365 + #318 + #385 + #346 + #305 + #500 + #489 (279eac1), diag + a local logging patch; this PR's draw.rs conflict resolved to its side.

With 0050ce5, 3b90165a77d95cdf (the largest compute dropper) and 4ddd6f9702fab2a7 run: 3,003 and 120 dispatches in 5 traced frames, none dropped.

But the device hangs (0x887A0006) 16–23 s after the world starts in every run I didn't stop first: 4 runs (3 at 0050ce5, 1 at bffaefd, so not the new caps). Two short runs I stopped at 20–21 s hadn't hung yet, and one bffaefd run ended at 12 s in a title access violation instead. Each time 3b90…, 4ddd… and 969c1cef8b783b39 dispatches are in flight, and the fault is in no title memory copy. Without this PR: 79 and 219 s, the known inside freed texture fault with mesh draws. 969c… runs without this PR too.

With VICTORY_SKIP_PIPELINES for 3b90… and 4ddd…, 1 of 2 runs still hung (28 s), with three other programs this PR enables in flight (14394a322f6dd5c2, f94e5d8bf4e1cf05, 5c09eb42b7a3c362). So it looks like the root-UAV programs as a group.

Not checked: which dispatch faults; GBV.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

@Raxstreams

Copy link
Copy Markdown

I checked the root-SRV extent change on Windows in a local integration that also uses the bounded root-SRV tables from #493. The synthetic root_srv_refreshes_dirty_data_past_one_mib regression passed.

I also replayed six dropped world compute shaders offline on that integration. All six reached the program IR, but none produced a host compute pipeline. Four stopped during resource tracking with “an address in an SGPR that is no root parameter” and the two meshlet-culling variants stopped in emission with “a hardware SGPR input”. In this configuration the translator stops before these programs can exercise the runtime root-UAV binding. This check verifies the SRV refresh separately from the title’s lighting.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. cargo test -p victory-shader passed (71 passed) and cargo test -p victory-gpu passed (48 passed, 1 benchmark ignored). End-to-end Root UAV support (shader lowering, VSH2 cache format, root signature deduplication, write-back, and UAV barriers) along with safe fallback VAs resolves Part 1 of #614 and prevents unmapped root view GPU hangs.

@wbkepler

Copy link
Copy Markdown
Author

Thanks @nullmarsh and @miniongk for the live hardware reports!

Re: the 16–28 s 0x887A0006 hangs across the root-UAV compute group (3b90165a77d95cdf, 4ddd6f9702fab2a7, 14394a322f6dd5c2, f94e5d8bf4e1cf05, 5c09eb42b7a3c362) with the fault outside any title memory copy:

jlefebure added a commit to jlefebure/VIctory that referenced this pull request Nov 24, 2026
# Conflicts:
#	crates/victory-gpu/src/draw.rs
#	crates/victory-gpu/src/pipeline/host.rs
#	crates/victory-gpu/src/shader_cache.rs
#	crates/victory-shader/src/emit/host.rs
#	crates/victory-shader/src/emit/lower.rs
#	crates/victory-shader/src/emit/mod.rs
#	crates/victory-shader/src/emit/shader.rs
#	crates/victory-shader/src/emit/valu_tests.rs
Callimann8 added a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jlefebure added a commit to jlefebure/VIctory that referenced this pull request Nov 24, 2026
…fer accesses

Brings byte and half loads/stores on buffers, flat and global memory,
sub-word cbuffer reads, and structured UAVs for 64-bit atomics.

Resolutions against the branch:
- scalar loads through root descriptors keep Marvisak#294's built-source path;
- root view bounds (Marvisak#650) gate the sub-dword and atomic paths too
  (atomics narrow their active lanes by the bound);
- the Marvisak#383 LDS byte path uses lds_ptr and refuses 64-bit LDS atomics;
- memory_tests fill root view sizes in user data, as Marvisak#650 requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dieharddillon1 pushed a commit to dieharddillon1/VIctory that referenced this pull request Nov 24, 2026
… into integ4

(cherry picked from commit f862329)
(cherry picked from commit 92bbf8860e34da76c3455bb813848252656ffeac)
@dpalacios69

Copy link
Copy Markdown
Contributor

Read of head c00c1bc against current main (ffe310e; this PR's base is d2a4bae). It merges without a text conflict, but the Windows test build should stop compiling:

  • The PR adds a required field pub root_uavs: Vec<u8> to HostShader (emit/mod.rs:159, no Default).
  • emit/waterfall_tests.rs exists on main but not in this PR's base, and its build() makes a HostShader { stage, dxil, user_data, samplers, static_samplers, root_cbvs, root_srvs } literal (line 77, no ..). After the merge that literal has no root_uavs, so cargo test -p victory-shader on Windows should fail with E0063: missing field root_uavs.

Adding root_uavs: lowered.root_uavs, next to root_srvs: lowered.root_srvs, there should be enough (Lowered carries root_uavs in this PR, lower.rs:38). The module is #[cfg(all(test, windows))], so I could not compile it on Linux; this is from reading both files. It is the same kind of base drift as the resource::track arity change tracked in #801. AI-assisted; no game data.

suirentakamura pushed a commit to suirentakamura/VIctory that referenced this pull request Nov 24, 2026
The ray-tracing builder passes buffer addresses as a pair of root
constants rather than as root views, so its programs failed with
"an address from a root parameter that is no address".

The tracker now takes a root constant as an address's low half when the
next dword of the same parameter is its high half, and records which
dword (`Address::dword`). The emitter binds such an address as a root CBV
or raw SRV, as it does for root descriptors, at a register that names the
parameter and the dword (`RootView`, `(dword + 1) << 8 | slot`); root
view registers are 16 bits now. The GPU side reads the address from the
two constants the title set and binds it as it does a root view.

The shader cache format is VSH2 (16-bit registers).

Root UAVs (Marvisak#294) and the spill table (Marvisak#302) are still needed for the
builder's programs to translate in the title; tested with synthetic
programs only (tracking, lowering, dxil.dll validation, pipeline
creation on an RTX 5080), no game data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 995f7f3)
wbkepler and others added 4 commits November 24, 2026 21:29
…ot UAVs

- Refresh the full remaining Shadow buffer extent for Root SRVs and Root UAVs instead of truncating at 1 MiB (keeping Root CBVs at the 64 KiB D3D12 limit).

- Guard shadow::find/loose against low (<0x10000) and uncommitted addresses, and bind permanently-alive 4 MiB zeroed/sink fallback GPU VAs instead of skipping Set*Root*View when a root view is unset, null, or unmapped.

- Support Root UAVs (u<slot>, space1 RWByteAddressBuffer) end-to-end across victory-shader (descriptor handle, global_store_dword*, s_load_dword* on root descriptors, PSV0/dx.resources metadata, SFI0/ShaderFlags UAVsAtEveryStage=1<<16), shader_cache (VSH2), pipeline::host (deduplicating shared (kind, slot) root views across stages), and draw (binding, gpu_writes write-back, and post-draw/dispatch UAV barriers).

- Add unit, dxil.dll validation, WARP, and host GPU tests covering >1 MiB Root SRV dirty-page refresh, null/unmapped fallback VAs, cross-stage root view deduplication, and Root UAV execution/write-back.
Root SRVs and UAVs took the whole rest of their buffer's host copy, so a
root UAV near the start of a very large backing copy kept and compared
that whole range on every submission. A root view has no size and the
translated shader does not report its range yet, so bound them: root
SRVs refresh at most 4 MiB, root UAVs refresh, snapshot and copy back at
most 2 MiB, constant buffers keep the 64 KiB D3D12 maximum. A cut is
logged once per view kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prevent RootView::Uav in draw::root_view from falling back to
shadow::loose() copies of arbitrary committed title memory. Because
RootView::Uav schedules Shadow::gpu_writes copy-back after submission,
binding a loose window for an unregistered or bogus root UAV address
allowed GPU shader stores to overwrite unrelated title CPU objects
(reported as 0xc0000005 access violations by Vaximous and nullmarsh).

- Split shadow::find_buffer() out of shadow::find() to look up only
  registered title buffers (never LOOSE windows).
- Route RootView::Uav through shadow::find_buffer() so misses bind the
  writable sink fallback VA without registering copy-back; RootView::Cbv
  and RootView::Srv continue to allow read-only loose lookups.
- Add draw::tests::root_uav_on_unregistered_loose_memory_uses_fallback_without_copy_back
  verifying that an unregistered committed address (even with an active
  loose shadow from CBV/SRV) misses RootView::Uav and is never modified
  by GPU compute stores.
Add root_uavs to the waterfall test HostShader literal and pass the structured
lane info to resource::track in the new Root UAV tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wbkepler

Copy link
Copy Markdown
Author

Thanks @dpalacios69 for the catch. The branch is now rebased onto upstream ffe310e (head a4e0feb), and root_uavs is added to the HostShader literal in waterfall_tests.rs (plus the resource::track signature change in the new Root UAV tests). Clippy, cargo test -p victory-shader -p victory-gpu and the asset policy check are clean.

For the earlier in-world reports of a device hang at a compute program with two raw root UAVs (@nullmarsh, @itsRevela, @erickbobd): your own data shows the hang goes away once #650 (bounding root view accesses by the host-bound size) is stacked on this PR, so #650 should land with or before this one.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

@wbkepler
wbkepler force-pushed the gpu/root-srv-bounds-and-uav branch from c00c1bc to a4e0feb Compare November 24, 2026 20:34
This was referenced Nov 24, 2026
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…sak#709 on Marvisak#1077's root UAVs

Marvisak#709's test used Marvisak#294's Root::Uav; this host binds a zeroed root UAV
(SetComputeRootUnorderedAccessView) and reads it back after the views' UAVs.
Also the fork's track() signature, and stride-0 structured accesses keep the
fork's runtime stride-table view (Marvisak#193/Marvisak#704) after Marvisak#709's structured().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak Marvisak closed this Nov 24, 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.