GPU: make a structured buffer view off its host copy's elements a raw view #206
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!206
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/206/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?
@AnoHunted on GitHub · 2026-11-24 01:25 UTC · original
AnoHunted:structured-view-raw-fallback→main· +254 −5 · 1 files · 1 commits · closed without mergingWhat
buffer_srvandbuffer_uav(crates/victory-gpu/src/descriptor/host.rs) now make a structured buffer viewwhose start in its host copy is not on an element as the raw view of the same bytes (
R32_TYPELESS, raw flag,first element and count in dwords), when that start is 16-byte aligned. Views on an element are made as before.
Everything else (typed views, strides that are not a multiple of 4, starts that are not 16-byte aligned) is still
refused with the same log line. The math is in a small
raw_windowhelper, with a unit test and a host GPU test.Why
A title buffer view is made on the host copy of the innermost title buffer that holds it, with its first element
moved by its offset in that copy (
FirstElement += offset / stride). A view of memory inside a bigger title buffercan start anywhere in it. The log in #16 already has
buffer view not on an element of its host copywithelement=32on the way to the menus: a 32-byte-stride view 16 bytes past an element. D3D12 puts structuredelement
iat bytei * strideof the resource, so that start cannot be written as a structured view of the copy.The slot stayed null: shaders read zeros through it and their writes were lost.
Why a raw view and not a host copy of its own starting at the view: such a copy would be a second buffer for the
same memory. Writes through it would not reach readers of the shared copy in the same submission (and the other
way round), and the refresh and copy-back steps only know the shared copy (
shadow::find). The raw view is aview of the shared copy, so
readable's refresh andgpu_writes/copy-back keep working unchanged. They usebuffer_range, which gives the same bytes. What a UAV writes lands where every other view of that memory reads,and goes back to title memory after the submission.
How shaders see it: the emitter declares heap buffer views raw for dword loads and stores, atomics and
typed-format loads without an index, and structured only when the shader indexes them
(
victory-shader/src/emit/mod.rs, "Buffer views in the heap"). A raw reader is served exactly. A shader thatindexes the view declares it structured (stride 32) over a raw descriptor. D3D12 leaves that undefined, so it is
marked as a shortcut. On the RTX 5080 and on WARP such reads and writes got the right bytes (probe below, not
part of the PR). AMD is not known.
The 16-byte rule is
D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT. It is not optional. In a probe run, a raw SRV or UAV atbyte 4 or 8 of a buffer removed the device (
DXGI_ERROR_INVALID_CALL) on both the NVIDIA GPU and WARP. At byte 16the device stayed up.
#123 is the same rule for the title's own raw views: it refuses one that lands off 16 bytes in its copy. This PR
covers structured views that land off an element. The two touch neighbouring lines in
buffer_srvandbuffer_uavand fit together: the views this one makes are always 16-byte aligned.Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1; also
WARP (
VICTORY_D3D12_WARP=1, diagnostics build).New tests in
descriptor/host.rs:structured_views_off_an_element_are_raw_views_of_the_same_bytes: the raw view covers exactly the structuredview's bytes, and the cases it must refuse (not 16-byte aligned, stride 6, stride 0, more than
u32::MAXdwords).
structured_views_off_an_element_read_and_write_their_bytes(host GPU): a 1 KiB title buffer of numbereddwords. A structured SRV (stride 32, 4 elements) starts at byte 16 and a structured UAV at byte 272, both made
by
buffer_srv/buffer_uav. Acs_5_1shader (system compiler) copies the SRV into a buffer of ours andwrites marks through the UAV. It runs through
HostListandHost::execute, so the refresh and copy-back stepsare the real ones. Checks: what it read is title bytes 16..144; after copy-back, title bytes 272..400 hold the
marks; no other byte changed.
the RTX 5080 and on WARP.
Whole runs, main (
d2a4bae) and branch side by side in one job:cargo test --workspace(RTX 5080): main 264 passed, 0 failed, 4 ignored; branch 266 passed, 0 failed,4 ignored (the two new tests).
cargo test -p victory-gpu --features diagnosticson WARP: main 45 passed, 0 failed, 1 ignored; branch 47passed, 0 failed, 1 ignored.
cargo clippy -p victory-gpu --all-targets: one warning on both, the same one, inhost.rs(not touchedhere).
cargo xtask policy: 151 files ok on both.rustfmt --checkondescriptor/host.rs: none of the reported spots are lines this change adds (the filewas not rustfmt-clean before).
Probe (not part of the PR):
StructuredBuffer<E>/RWStructuredBuffer<E>with a 32-byteE, over the raw fallback views: right bytes readand written, RTX 5080 and WARP.
0x887A002D), so there was no debug-layer or GPU-based validation check.Not tested
AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.
@jeremygold02 on GitHub · 2026-11-24 04:48 UTC · original
Thanks @AnoHunted for the structured-view fix. I tested the open PR at head
05981dd53b338ef0dabf30d4b728ccb41b0772d9with:Result: 2 passed, 0 failed.
structured_views_off_an_element_are_raw_views_of_the_same_byteschecks that a view derived from an element exposes the expected raw byte span, andstructured_views_off_an_element_read_and_write_their_byteschecks reads and writes through that view. This exercises the CPU-side descriptor/span logic; it does not execute a GPU shader. The tests are in descriptor/host.rs.@SantannaCarlos on GitHub · 2026-11-24 06:55 UTC · original
Tested on an RTX 4070 (Windows 11, driver 621.01), diag build of
d2a4bae+ #136 #173 #176 #164 #180 #179 #177 #138 #116 #145 #135 #100 and two local fixes. With this PR both runs stopped early: 3 s into the world, and once during loading, in a pre-skinning simulation compute pass (50 groups) whose structured SRV (336-byte stride) starts off an element of its host copy. Before this PR that view was null; with it, it is a raw view. Without this PR the same stack ran 116 s and 131 s and stopped elsewhere.My reading, not verified in that pass's DXIL: the translator declares a heap buffer view structured, with the entry's stride, when the shader reads it with an index, so a raw host view may not match that declaration. The raw window may need to depend on how the shader declares the slot. Two runs; details in #71 (section 6).
@AnoHunted on GitHub · 2026-11-24 10:21 UTC · original
@SantannaCarlos thank you, that's exactly the case this needed. You're right. When the shader indexes the view, the translator declares the slot structured with the entry's stride. The raw fallback then puts a raw descriptor under a structured declaration, which D3D12 leaves undefined. My synthetic probe passed on NVIDIA and WARP, but your 336-byte-stride compute pass shows it isn't safe in the title: it is worse than the null view main leaves there.
I'm turning this into a draft so it isn't merged as is. A correct version needs one of two things:
I'll come back to it on top of that work rather than keep this fallback.
@hashdev512 on GitHub · 2026-11-24 13:20 UTC · original
Test report from an RX 9070 XT (RDNA4): this PR removes a world fault I could reproduce three times out of three without it.
Setup: Ryzen 7 5700X3D, RX 9070 XT, driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300.
mainatffe310e,diagbuild with--features diagnostics,VICTORY_D3D12_DRED=1, Series X mode, package v1.0.2.1. This PR merged locally: no conflicts, 52victory-gputests pass.The fault it fixes
On this card every run that got past about 5 minutes in the world ended in
dispatch 12x1x1 [compute eeed82b877b44b5f], with a page fault that DRED places past the end of the view heap (the heap has 1,507,328 slots; the faulting reads were at slots 50,274,304, 52,804,864, 88,692,224, 102,340,992 and 125,829,120, some of them in several runs).That program takes two descriptors at heap indices it computes from data (
ResourceHeap). The chain starts with a dword read through a structured buffer view the title places inside a much bigger title buffer: 112 bytes, stride 56.buffer_srvrefuses that view whenever its offset in the host copy is not a multiple of 56, the slot stays null, the program reads 0 there and ends up taking its "indices" from unrelated data at the start of another view.I checked this with a local probe (not part of any PR). At submission, after the refreshes are flushed, it re-reads on the CPU what the program reads, from title memory and from the host copy, and looks at which host resource the slot holds:
In all four runs the data itself was right: title memory and host copy were identical and held valid indices. The slot was null because the view was refused. All four offsets are 16-byte aligned, so they are in the case this PR handles.
One thing that hides it:
buffer view not on an element of its host copyis logged withonce!. In every run it fires about 30 s in for another view (element=32), so this view never shows up in the log.With this PR
One run, offset 48 mod 56 (the failing case):
For comparison, plain
mainon this card lasted between 2 and 7 minutes today (8e79c80: 2 min 21 s;ffe310e: 6 min 20 s and 6 min 45 s).What else was in that build
So that the freed-texture fault (#557, #575, #609) did not end the run first, the build also kept alive, for the whole run, the resource a slot held before
HostHeap::keepreplaced it and the host copy of every released title texture. That is a local diagnostic switch standing in for a lifetime fix; it never frees, so memory grows (about 9 GB after 45 minutes). I have not yet run this PR together with a real lifetime fix.It is one run with the PR, so treat the 45 minutes as indicative. I can repeat it, or run it on top of another PR, if that helps.
No game data here: hashes, sizes, offsets, slot numbers and timings from VIctory's own log and the probe's comparison results.
AI-assisted (Claude Fable 5.2): the probe was written and the runs launched and summarised by the model on my machine; figures taken from the logs.
@bunbeans2-arch on GitHub · 2026-11-24 14:21 UTC · original
Test report from an AMD card for the raw-declared case, in case it helps the reworked version.
Setup: AMD Radeon RX 9070 XT, driver 32.0.32015.7029, Windows 11 Pro build 22631. Diagnostics build of
maind2a4baewith #493, #454, #346, #435, #483 and #459 merged, with and without this PR (head05981dd, merged cleanly, no other change between the two builds). Title 1.0.2.1, the same saved state loaded in every run, defaultVICTORY_SHADER_LOOP_LIMIT.Without this PR the load loses the host GPU device: 13 of 13 runs at the default limit, 16 to 69 s after one pixel pipeline is created, and 2 more runs with only a log added (43 s and 52 s). Details are in #597. The log in
buffer_srvshowed why: all 243 logged views of one 2044-byte buffer were structured with a single 2044-byte element, at 95 different offsets in a heap's host copy, none a multiple of 2044 and all multiples of 16. So every one was refused and the slot read zeros. A pixel shader reads a loop count from that slot with a scalar (raw) load, gets 0, and the loop runs to the limit. So the null viewmainleaves there is not harmless in this case.With this PR: no device loss. The run went on in the world until my stop, 215 s after that pipeline was created (1 run).
The narrower variant (a local change: a raw view for that one buffer only, every other refused view left null as on
main): same result, no loss, 183 s to my stop (1 run). So for this hang a raw window only for slots the shader declares raw, the first option above, would be enough.Limits: one run each, and nothing here about indexed reads of a raw view on AMD: I saw no fault in those 215 s but did not check what any such read returned. The picture was still a flat fill with no scene in it, and world frames still took seconds (9566.4 ms/frame in the last fps line).
AI-assisted: written with Claude from my own run logs; the hardware and the runs are mine.
@SantannaCarlos on GitHub · 2026-11-24 15:17 UTC · original
@hashdev512 @bunbeans2-arch both cases you describe are views the title placed off an element of their buffer's host copy: the 112-byte, stride-56 view
eeed82b877b44b5freads, and the 2044-byte single-element views at offsets that are multiples of 16. #1019 keeps such a view structured and gives it a copy of just its bytes, starting at the view, so the declaration matches and the shader reads the title's data (unordered views of the same kind write their own copy, which goes back to title memory). That also covers the 336-byte case from my earlier comment here, which the raw fallback broke. It ran 10 minutes in the world on an RTX 4070 with the hit-detection pass running throughout; if you can run your RX 9070 XT setups on it, that would show whether it removes the faults you reproduced. #984 fixes a separate read in the same pass (a scalar load past the first element of that view), which mattered on NVIDIA.@Yaekai on GitHub · 2026-11-24 16:19 UTC · original
Independent verification on Windows 11 + NVIDIA RTX 3070 (8 GB, Rust 1.98.1) at head
05981dd:cargo test -p victory-gpu --lib: 45 passed, 0 failed (including live D3D12structured_views_off_an_element_read_and_write_their_byteson RTX 3070).cargo clippy -p victory-gpu -- -D warnings: 0 warnings.1.0.2.1,--console series-s, 19-min world run): confirmed off-element 16-byte-aligned structured SRVs/UAVs are cleanly promoted to raw views with zero GPU faults. Ready to merge!@jamesn-xt on GitHub · 2026-11-24 16:39 UTC · original
Verified head
05981ddin an integrated Windows 11 / RTX 4080 build (NVIDIA 617.42, Ryzen 5 5600, 32 GiB RAM, Rust 1.98.1).The previous hardware run logged a structured-buffer view offset off its 32-byte element. With this PR in the stack, that warning no longer appeared in the bounded hardware run. Both added raw-window/read-write tests passed on the RTX 4080; diagnostics GPU suite: 66 passed, 1 ignored. All-target/all-feature GPU Clippy, diagnostics build and asset policy passed.
Stack also contains #211, #89, #492, #985 and #1146 on main
ffe310e: https://github.com/jamesn-xt/VIctory/tree/test/rtx4080-target-formats (abe05a3). Character loading artwork rendered at 30 fps; mesh/pixel pipelines began binding later, but a 2 GiB free-commit guard stopped the run before a visible world was confirmed. This does not prove this PR alone fixes title rendering, and I have not verified structured declarations over the raw view on other GPU vendors.No game captures, retail files or raw logs attached.
@ThomasHFWright on GitHub · 2026-11-24 18:15 UTC · original
Tested exact head
05981dd53b338ef0dabf30d4b728ccb41b0772d9on Linux / RTX 5090. This restores previously null buffer inputs in the title path on this setup; the default-loop-limit run still stalls.Integration: Slaktarn700
proton-fixes993dff8, #852 handle-cache fixae7e0be, #454 watchdog diagnosticd2c93fa(local base436b3dbce181f0e6c940770596fc2a500ed39050), then this PR's exact file delta merged against its parent. Local binding/timestamp probes retained; no other semantic patch added. CachyOS 7.3.6, Wine 11.22, RTX 5090 / NVIDIA 620.73.04, vkd3d-proton 3.2.030b0eb9bc12dc9f. Wine with these DLLs, not a Steam Proton runtime test.Observed bindings: before this PR, compute
72f552f4553fb5f9had null raw SRVs at inputs expecting structured buffers of stride 176 and, on some dispatches, 336. With the PR, those inputs receive non-null raw SRVs over the shared buffer. No descriptor-record changes were detected between command recording, pre/post heap refresh and timeout in the examined submissions. This samples descriptor records, not all GPU memory contents or transient races.Tests:
d3dcompiler_47: 58 passed, 0 failed, 1 ignored, including both added tests. Probes enabled.CreateRootSignature(0x80004005), before dispatch; the native compiler resolves that harness limitation.Runtime: the default-limit run ends after 108.1 s, exit 5. Our bounded fence probe reports submission 5209/completed 5208. The last resolved pre-command marker is 62, preceding a 34x1x1 dispatch of the same
72f552f4553fb5f9; the next marker is absent. Kernel reports Xid 109 / CTX SWITCH TIMEOUT, where the preceding controls reported Xid 13 / MMU Fault. All 983 captured SPIR-V modules validate. Thus restored views are confirmed, but this run does not establish that the GPU stall is fixed. Earlier producer/dataflow errors remain possible; marker instrumentation can alter scheduling.Prior isolation and shader-exclusion controls: #71 .
A second controlled run used the same application binary, only adding
VICTORY_SHADER_LOOP_LIMIT=32(confirmed active; the cache keys on this setting). It also failed: 103.1 s, exit 5, submission 4764/completed 4763. Last resolved marker 53 precedes the same shader, now 421x1x1; kernel Xid 13 / MMU Fault. No descriptor-record change detected; all 988 captured SPIR-V modules validate. The global loop cap does not avoid the fault in this test and can truncate shader work; it is not a correctness fix.All runs were offline and app-muted. No game files, shader code, dumps or captures attached. No controllable visible gameplay confirmed. AI-assisted testing with Codex on the user's hardware.
DXGI_ERROR_DEVICE_HUNG/0x887A0004/0x887A0006#1440DXGI_ERROR_DEVICE_HUNG/0x887A0004/0x887A0006#1440Pull request closed