Shaders: bound root view accesses by the size the host binds #650
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!650
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/650/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wbkepler on GitHub · 2026-11-24 06:12 UTC · original
wbkepler:shader/root-view-bounds→main· +336 −6 · 4 files · 1 commits · closed without mergingWhat
A root SRV or CBV has no bounds on the host. Any shader access past the memory the host mapped there is a GPU page fault. The console's buffer views have record counts, so a console program never faults on these. But the offsets come from title data, and when the host has not mirrored that data (zeros, stale memory) the reads land far outside the view.
Lower::root_view_sizereads the view's byte size from the user-data dword of the view's address. That dword is otherwise unused, because the view itself is bound as a root argument. The lowering records it as a newUserDataentry withroot: Descriptor. Every access through a root view checks the bytes it touches against that size: rawbuffer_*loads, stores and atomics, the raw loads behindtbuffer_load_format_*andbuffer_load_format_*,global_load_*, per-lane constant-buffer reads and scalars_buffer_load_*. Past the size, reads give 0 and writes are dropped, as for a console view past its records. An out-of-range access goes to offset 0 instead, so the hardware never touches memory past the view.State::root_view_bytesfills that dword with whatroot_viewbinds there: up to 1 MiB for SRVs and 64 KiB for CBVs (the newroot_view_len), or 0 when the title set no view.Why
Translated programs were replayed on an RTX 5090 with synthetic data (hardware probe, not part of this PR):
tbuffer_load_format_*, given nonzero data, removed the device as hung (DXGI_ERROR_DEVICE_HUNG) after 3.7 s, every time.In the world, these are the mesh hangs that #578 currently avoids by refusing wave64 mesh programs on 32-lane hosts. They are not about the wave size.
Tests
root_view_reads_stop_at_the_bound_size. A program builds a buffer descriptor around a root SRV address and reads at offsets inside, at and past the bound size. The test checks the reads past it give 0 even where the bound buffer holds data, and that the size is aDescriptoruser-data entry. Passes on an RTX 5090 and on WARP.cargo clippy --workspace --all-targets,cargo clippy -p victory --features diagnostics --all-targets,cargo test --workspace,cargo xtask policy: pass. The remaining clippy warnings are already onmain.Not covered: root UAVs, which
maindoes not bind yet. Open PR #294 adds them, and its root UAV accesses take the same check once both land.🤖 Generated with Claude Code
@ghost on GitHub · 2026-11-24 11:27 UTC · original
In-game AMD data point (RX 9060 XT): with this PR, #294's root-UAV programs run without the device hang it otherwise causes 25–31 s into the world (2 runs each, with and without this merge in MichaelSmithAI's
afa5bdc). Details: #294AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@banbanzhige on GitHub · 2026-11-24 11:51 UTC · original
Great root-cause work on the root-view page-fault hangs! I merged
06657a8locally onto currentmain(ffe310e) on Windows 11 (Rust 1.98.1, SDK10.0.26100.0dxil.dll, 32-lane SM 6.6 hardware GPU + WARP) and did a line-by-line review of the bounds logic.Verification on
ffe310e+#650cargo clippy --workspace --all-targets --locked -- -D warnings: passcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passcargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored (includingroot_view_reads_stop_at_the_bound_sizeon both hardware and WARP)cargo test -p victory-gpu --locked -- --test-threads=1: 50 passed, 0 failed, 1 ignoredcargo xtask policy: 154 files okvictory translate --validate --pipelines, 26,599 containers / 26,148 programs) vs cleanmain(ffe310e): 0 regressions (VS/PS12,243 / 12,167 / 12,243, CS1,441 / 1,417 / 1,121, MS8,214 / 8,152 / 8,214— identical toffe310e).Technical findings in the current patch
tbuffer_load_format_*hardcodingbytes = 16silently zeroes valid tail elements (lower.rs,buffer()):let bytes = if format.is_some() { 16 } else { 4 * count };assumes every formatted load reads 16 bytes, but 13 of the 14 GFX10 families inbuffer_format()are narrower (4, 8, or 12 bytes, plus sub-dword formats thatformat_load()reads as 4 bytes atoff & !3).16 - actual_bytesbytes of a root SRV (e.g. the last element of a32_32_32/16_16_16_16/8_8_8_8stream) failsin_root_view(size, off, 16)and gets replaced with0.buffer_format(f)to compute the actual span ((off & !3, 4)whentotal < 32, else(off, total / 8)) matches whatformat_loadactually loads.Load paths still unconditionally execute at offset
0whensize == 0or0 < size < bytes(lower.rs):begin_guarded(self.narrow(guard, root_ok)), but all load paths (flat,smem,bufferCBV / formatted / raw) rewrite out-of-range offsets to0and still issuerawBufferLoad/cbufferLoadLegacybeforezero_unless(ok, x).size == 0(State::root_view_bytesexplicitly returns0for an unset/unshadowed root view, andState::bindskipsSet*Root*View), offset0still dereferences an unbound/stale root descriptor.0 < size < bytes(e.g. an 8-byte tail with a 16-bytedwordx4load, or< 16bytes withcbufferLoadLegacyfetching a 16-byte row),okis false soat = 0, and the hardware still issues abytes-wide read past the end of the buffer.begin_guarded(yielding0fromend_guarded) avoids touching the descriptor in both cases.Constant-offset
s_buffer_load_dword*on root CBVs is unchecked (lower.rs,smem()):None =>(dynamic offset) arm checkssize, but theSome(base) =>(constant offset) arm was left unchecked — so static-offset scalar reads from an unset or smaller-than-expected root CBV bypass bounds checking.32-bit offset wraparound in multi-dword per-dword loops (
lower.rs,smem()SRV/CBV dynamic &buffer()CBV):a = addr + 4 * kper iteration and checkingin_root_view(size, a, 4)wraps on high offsets: e.g. foraddr = u32::MAX - 3(0xFFFF_FFFC) andcount >= 2,k = 0yields0, butk = 1wraps toa = 0, passingin_root_view(size, 0, 4)and returning dword 0 of the buffer instead of0.Minor host-side & rebase notes against
main(ffe310e):draw.rs,State::bindfillsroot_view_bytesbefore callingroot_view; for an unaligned root CBV (!srv && gpu % 256 != 0), iflist.scratch(len)returnsNoneand binding is skipped, the shader still receives a non-zero size.ffe310e:valu_tests.rshas a tail conflict,resource::tracknow takes 4 arguments (Some(&st)from#566), androot_view_reads_stop_at_the_bound_sizeshould lockONE_AT_A_TIMEbefore creatingHost::newso it doesn't race with parallel GPU tests.AI-assisted review; all tests and corpus checks run locally on my machine, no game data included.
@erLCoder on GitHub · 2026-11-24 13:06 UTC · original
Independent synthetic A/B on GTX 1660 Ti (6 GB), NVIDIA 581.42, Windows 10 22H2 build 19045.6466, Ryzen 5 3600, Rust 1.98.1 and Agility SDK 1.620.2. Both test processes confirmed NVIDIA LUID 00000000:00017c52.
A: parent
d2a4baewith a port of the fixture. B: PR06657a8with its fixture. Both use the same 256-byte backing buffer and hardware-only adapter assertion. B receives a 64-byte logical view size. The readbacks at byte offsets 0 and 60 were 0x100 and 0x10f in both; at offsets 64 and 128, A returned 0x110 and 0x120, while B returned zero. B also returned zero at the near-maximum offset; A did not attempt that offset. Each filtered test passed 1/1, 0 failed, 0 ignored, 69 filtered out. WARP excluded.cargo test --offline --locked -p victory-shader --features host --lib root_view_reads_stop_at_the_bound_size -- --nocapture --test-threads=1This tests synthetic compute raw-SRV loads and GPU readback. Stores, atomics, in-game host size calculation, DispatchMesh hangs and image quality remain untested. Codex prepared the worktrees and fixtures, ran the tests and drafted this report.
@Ilokaxt on GitHub · 2026-11-24 14:27 UTC · original
On an RTX 3070 Ti Laptop (wave lanes 32..32, NVIDIA driver 610.88, Windows 11 build 26300), this PR removes the mesh-shader hangs in the world that #587 alone did not (see my correction on #587).
Tree:
mainffe310e+ #439 + #431 + #579 + #587 + this PR, plus a local fix that creates the device on the high-performance adapter. Diagnostics build,VICTORY_SHADER_LOOP_LIMIT=1000, DRED on, scripted Enter presses, two runs of up to 900 s.DispatchMeshof mesh4adfa13bea1c556a(MSR_VS_CascadeShadows_drawskinned) or mesh18bbb989c875c8fb(MS_VS_TransformSkinD_NoDeform).eeed82b877b44b5f(vfx_proj_decal_hit_detection:CS_ComputeHitDetectionSkinnedResults,Dispatch(12, 1, 1)). It reads the same skinned-geometry buffers (42,991,392 and 182,452,224 bytes) through table SRVs, not root views, so it is likely the same kind of out-of-range read in a path this PR does not cover. That last part is a guess, not verified.@contatopablow-spec on GitHub · 2026-11-24 18:54 UTC · original
Independent synthetic validation on desktop RTX 3050 6 GB (Ampere), NVIDIA driver 610.88, PCI ID
10de:2584, Windows 11 Pro build 26300, i5-8400, 24 GB RAM, Rust 1.98.1.Tested PR head
06657a8bebe86f562cf1d55796de565b9a9d329bin a separate worktree; the sole local change was non-fatal test-only adapter logging using the D3D12 device LUID.The existing fixture completed on both adapters, including expected zero reads at offsets 64, 128 and
u32::MAX - 3. Exit code 0. No game data used.Scope: synthetic raw-SRV reads only; not proof of a fix for mesh dispatch hangs, stores/atomics, table SRVs or gameplay. PR head tested as-is apart from adapter logging, not merged onto current main. AI-assisted instrumentation, test execution and reporting (ChatGPT and Codex).
@Impre-visible on GitHub · 2026-11-25 00:11 UTC · original
Test report for this PR's idea on Linux/NVIDIA, where it seems to remove the driver-level faults (not a code review).
Setup: Arch Linux, Wine (GE-Proton11-6) + vkd3d-proton, GTX 1660 6 GB, NVIDIA 620.73.04 open modules, Series X mode. On this host a GPU fault shows as
NVRM: Xid 13in the kernel log (Graphics SM Warp Exception ...: MMU Fault,Multiple Warp Errors), after which the channel is dead and VIctory waits on its fence forever (see my note on #1581).Tree: #1433 with #1492 merged by hand plus #1077 #1175 #523 #530 #1040 #1406 #542 #1056 #1392 #1516 #1388 #1189 #1523 #635 #988, and #1769. This branch does not merge there (8 conflicts with #542's 2 GiB guards in
emit/lower.rs), so I ported it by hand, keeping both checks. Two differences from the PR as written: the size given for a root SRV is the whole host copy from its address (not the refreshed megabyte), and a root view the title never set, or one with no host copy, is bound to 256 bytes of list scratch with size 0 instead of being left unset.cargo test -p victory-shader --liband-p victory-gpu --libgive the same results as before the port.Runs that reached the world, same tree with and without the port:
Before that tree existed, Xid 13 also ended runs during loading, before the world (about 7 of some 50 runs this evening, always a few hundredths of a second after the first bind of the same group of loading-phase pipelines, one of which is a mesh pipeline reading through a root SRV); none of the 5 runs with the bound did.
The sample is small and the 5 runs also carried a lower cap on a wave64 wait loop, so the Xid 109 column is not attributable to this PR. The Xid 13 column is the one this PR is about. The runs with the bound still end for other reasons (the title's own stop after a render iteration longer than 30 s, or a title assert while streaming).
Reads that legitimately reach past the host copy now return 0 where the console would read real memory, so this trades a fault for possibly missing geometry; I cannot judge the picture yet (the world is still dark here).
@Marvisak on GitHub · 2026-11-25 00:26 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Root SRV/UAV accesses are bounded in main another way (
d71c3889: root views read through heap views of the host copy, offset from user data; Lower::root_view).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