Shaders, GPU: add runtime stride table for structured buffers #193
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!193
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/193/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?
@n-romanovich on GitHub · 2026-11-24 01:17 UTC · original
n-romanovich:feat/runtime-stride-channel→main· +596 −76 · 10 files · 2 commits · closed without mergingImplements the runtime stride channel described in #155 so structured-buffer accesses whose element stride is not recovered statically fall back to a host-maintained per-slot stride table instead of failing translation (
a structured buffer of unknown stride).Changes
victory-shader:STRIDE_SPACE = 2(t0),Shader::stride_table_handle(), andHostShader::stride_table: bool.Lower::runtime_stride_offsetforLoadedandPhiheap descriptors, readingstridefromt0(STRIDE_SPACE) atslot * 4and emittingindex * stride + offat all three structured-bufferidxensites (load, store, atomic).Host::root_signature_forso standalone shader tests can bind the stride table.victory-gpu:stride_tableserialization toshader_cache(bumpedMAGICtoVSH2).STRIDE_SPACEroot SRV inpipeline/host.rswhent.stride_tableis set and bound it indraw.rs.UPLOADStrideTablebuffer (4 bytes per view-heap slot) toHostHeapindescriptor/host.rs, kept in sync acrossmake_at,make_null,constant_at, andmirror.Testing & Hardware Note
emit::tests::structured_buffer_unknown_stride_uses_runtime_stride_tablecoveringbuffer_load_dword ... idxen,buffer_store_dword ... idxen, andbuffer_atomic_add ... idxenwithstride = 0inUsedResource.dxil.dlland ran on D3D12:VICTORY_WARP=1): passes with bothStructured(12)andRawdescriptors.Rawdescriptors (107,20), whereasdxil_kind = 11(ByteAddressBuffer) reading aStructured(12)descriptor returns0on NVIDIA D3D12 (unlike WARP/AMD).cargo clippy -p victory-shader -p victory-gpu --lib -- -D warnings: passed (0 warnings).cargo xtask policy: passed (asset policy: 151 files ok).cargo test -p victory-shader: 70 passed, 0 failed.@DaviTostes on GitHub · 2026-11-24 01:30 UTC · original
Tested
4322b61on Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the {adds} test{'s' if adds != 1 else ''} this PR adds.victory-gpuE0425.No game data used.
@DaviTostes on GitHub · 2026-11-24 01:31 UTC · original
Follow-up on the GPU half: the test build does not compile, so the host-GPU side cannot be validated yet.
The shader crate is green (57 passed, 1 new test — see above), but the
victory-gputest target fails on every platform until the new test module is merged into the existing one inhost.rs. This is the same rebase issue as #134/#135/#161/#175.No game data used.
@Mesrine67 on GitHub · 2026-11-24 02:03 UTC · original
I reviewed the current PR and agree this is a useful path for the unknown-stride failures. One failure path should be handled before dispatch: in
crates/victory-gpu/src/draw.rs, whenstage.stride_tableis set but there is no host view heap orstride_table_gpu()returnsNone, the code logs and continues. The root SRV is then left unbound while the shader reads it; please makeState::bindreport failure and skip the draw/dispatch in that case.I also ran an equivalent synthetic D3D12 implementation on PC-MIKE (Windows 11, Radeon RX 6750 XT) and WARP: an
idxenstore to element 1 of a structured UAV with stride 8 wrote to byte offset 8 on both. This was my local implementation based ond2a4bae, not a run of this PR's branch. The targeted test and workspace suite passed (265 passed, 0 failed, 4 ignored); the release build and strict library Clippy also passed. This confirms the offset logic on AMD/WARP but does not validate the game's rendered output or this exact diff.@gw1337x on GitHub · 2026-11-24 02:21 UTC · original
In-game test on an RX 7800 XT (Windows 11 26200),
diagbuild withVICTORY_D3D12_DRED=1. Build:maind2a4bae+ #135 + #242 + #230 + #124 + #130 + this PR. The merge conflicts were formatting only, plus the newstridesfield inHostHeap::newnext to #135'sdynamic: extra.Result: the host device is removed with
0x887A0001(invalid call) at the first world frame, about 40 s after start. The same build without this PR reaches the opening cutscene and runs about 177 s; on this PC it has never ended in an invalid call.An invalid call (rather than a hang or page fault) suggests a view description the host refuses, possibly one of the structured views this PR now makes. I don't have the D3D12 debug layer installed, so I can't name the call. I can rerun with a diagnostics switch if you add one.
@r4tedx on GitHub · 2026-11-24 03:08 UTC · original
Review question on the fallback path. When the stride is not known statically, the three
idxensites now take a raw handle and compute the byte offset themselves:The heap slot that handle resolves to still holds the view the title created, which for a structured buffer is a structured view (
descriptor/host.rsmirrors the title's view as given). The description says of exactly that combination:So as far as I can read it, on NVIDIA these accesses would now read zeros where they were refused before, which is harder to notice than a dropped draw. Is there a place where the host makes a raw view for slots that are read through this path (I did not find one in the diff), or could the fallback be limited to slots known to hold raw views?
a structured buffer of unknown strideis the third row of #293 (about 276 draws per frame), so a before/after from a tester on both an NVIDIA and an AMD card would settle it. From reading only; I have no copy of the title.@EduAzevedo on GitHub · 2026-11-24 03:52 UTC · original
Measured
4322b61on the retail shaders (v1.0.2.1, Series X package), offline withvictory translate --jobs 8 --listagainstmaind2a4bae, same 26,148 programs:a structured buffer of unknown stride: 117 → 0.a lane-mask join of an untracked mask(22),a lane mask read as data(18),a descriptor read only as data(4) anda lane mask holding lanes elsewhere read as data(2).mainstopped translating.This is translation only; it does not exercise the runtime stride table in a game run.
AI-assisted.
@AnoHunted on GitHub · 2026-11-24 04:35 UTC · original
Tested
4322b61merged ontomaind2a4baeon NVIDIA GeForce RTX 5080, Windows 11, Rust 1.98.1, withdxil.dllvalidation on: pass.cargo test -p victory-shader -- --test-threads=1: main 69 passed / 0 failed; this PR 70 passed / 0 failed (new tests:emit::tests::structured_buffer_unknown_stride_uses_runtime_stride_table).cargo test --workspace -- --test-threads=1: main 264 passed / 0 failed / 4 ignored; this PR 265 passed / 0 failed / 4 ignored.Stride::Raw/RawUav) to the slots read through the fallback. The PR description says the same combination with aStructured(12)descriptor read asByteAddressBuffer(dxil_kind = 11) returns0on NVIDIA. In the game the slot holds the structured view the title built (descriptor/host.rsmirrors it as given), so the fallback would read zeros on NVIDIA rather than being refused. This matches the question above; the test does not catch it because it never uses a structured view. (From reading the diff; I did not run a structured-view variant.)HostHeap::make_at/mirror, for a structured buffer view in sloti, also write a RAW view of the same bytes (DXGI_FORMAT_R32_TYPELESS,Flags = RAW,FirstElement = first * stride / 4,NumElements = count * stride / 4) into sloti + N(N= view heap size, heap allocated at2 * N). Inruntime_stride_offset's callers useheap_slot + Nfor thedxil_kind = 11handle, whilestrideis still read fromtable[slot]. Then add aStructured(12)case to the test, so it covers what the game does.stage.stride_tableis set butstride_table_gpu()returnsNone,draw.rslogs and continues with the root SRV unbound; skipping the draw would be safer than reading garbage.No game files used.
@Mesrine67 on GitHub · 2026-11-24 04:50 UTC · original
AMD validation on PC-MIKE (PR head
4322b61)Hardware: AMD Radeon RX 6750 XT, driver 32.0.21045.29003.
VICTORY_WARPandVICTORY_D3D12_WARPwere unset.cargo test --locked -p victory-shader structured_buffer_unknown_stride_uses_runtime_stride_table -- --nocapture --test-threads=1passed. I confirmed the test created a D3D12 device with shader model 6.6, then ran the dispatch and assertion on the default hardware adapter.cargo test --locked -p victory-shader -- --test-threads=1passed: 70 passed.cargo test --locked -p victory-gpu --lib -- --test-threads=1fails to compile:crates/victory-gpu/src/host.rsdefinesmod testsat lines 252 and 1974. This commit renames the existingmod batchat the latter location tomod tests. Renaming that second module back tobatchlocally allowed the suite to build and pass: 43 passed, 1 ignored.Please restore a unique module name for the latter block before merge. These are synthetic D3D12 tests; they do not yet verify the in-game world render.
@marquezinii on GitHub · 2026-11-24 04:51 UTC · original
Ran
4322b61merged withmain(d2a4bae) on an NVIDIA RTX 5070 (driver 621.24), Windows 11, the SDK'sdxil.dllvalidating:cargo test -p victory-shader70 passed,cargo test -p victory-gpu43 passed. Then a probe through the runtime-stride path: a compute program that loads[index, offset]from slot 0 and writes the loaded dword to a raw UAV, over data dwords 100..111, with the table entry and the bound view varied. Every module validates.main0x00670000So the hardware confirms the concern raised above about the raw handle: the fallback's
handle(..., (11|u, 0))is a raw handle over whatever view the title put in the slot, and over a structured view NVIDIA returns 0 (WARP happens to return the data), over a typed view both return 0. The programs this lets translate would read zeros on NVIDIA instead of being refused. Limiting the fallback to slots that hold raw views, or a raw alias slot as suggested above, would avoid it. Stores and atomics through a structured UAV take the same handle; the test harness has no structured UAV, so I could not run that.A second case, not raised yet: the condition now also lets a known stride that is not a multiple of 4 (2, 6, ...) take the runtime path, where it used to be refused. The runtime path issues a
rawBufferLoadwith alignment 4, which drops the low address bits, so stride 6, index 1, offset 4 reads dword 2 (102) instead of bytes 10..13. The table can hold such strides:view_stridefalls back to the format size for typed views. Keeping the refusal for a nonzero static stride that is not a multiple of 4 would be safer.Also:
StrideTable::newreturnsNonewithout a log line when it fails, which would make an unbound table (the point raised above aboutdraw.rs) hard to see in a report.An index whose
index * stridepasses 2^32 wraps on both GPUs, but the existing static structured path wraps the same way, so that is not new here.Not covered: the title (no game data here).
@upipibi on GitHub · 2026-11-24 05:51 UTC · original
Independent check of head
4322b61merged ontomaind2a4bae. I read the comments above first. The main problem is already stated (the fallback takes a raw handle over whatever view the title put in the slot); I can confirm it on a third NVIDIA card, and I have one correction and two smaller points that are not above.Confirmed on an RTX 3070 (driver 616.56): the PR's own test
structured_buffer_unknown_stride_uses_runtime_stride_table, with only the SRV in slot 0 changed:So on this card too the programs this lets translate would read zeros from the structured views the title creates. The test binds only raw views, so no run of it shows this; and per the table posted above WARP returns the data through a structured view anyway, so a WARP-only runner would not show it even with a structured case.
A correction on the stride-6 case raised above (stride 6, index 1, offset 4, where the runtime path reads dword 2). By the RDNA2 ISA (30-November-2020), 8.1, p. 64, that is what the hardware does in its default mode: "For Dword or larger reads or writes of non-formatted ops (such as BUFFER_LOAD_DWORD), the two LSBs of the byte-address are ignored, thus forcing Dword alignment." (It is configurable:
SH_MEM_CONFIG.alignment_modeDWORD / DWORD_STRICT / STRICT / UNALIGNED, same page.) SorawBufferLoadat byte 10 reading dword 2 agrees with the ISA unless the console runs in UNALIGNED mode, which I cannot tell. I would not refuse strides that are not multiples of 4 on that ground alone.Against the ISA otherwise
index * stride + off.OOB = (index >= NumRecords() || (offset+payload > stride))when the stride is not 0, and "Reads that go out-of-range return zero ... Writes that are out-of-range do not write anything." Through a raw handle anoffat or past the stride reads or writes the next element instead. Only programs that address past their element hit it; worth ashortcut:comment.index * 0 + off: every index reads element 0, silently.Smaller points not raised above
Source::Phiis handled byheap_slotbut no test reaches it; the three sites in the test all use aLoadeddescriptor.maindoes not keep rustfmt-clean (cargo fmt --all --checkonmainreports diffs in them): most of the 43 lines removed fromdescriptor/host.rs,draw.rsandpipeline/host.rsare line wraps unrelated to the change. That is what made the merges reported above conflict; leaving those lines alone would make this much easier to stack.main,cargo check -p victory-gpu --testscompiles here, so the duplicatemod testsreported above is a matter of rebasing ontod2a4bae.Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1,
dxil.dllfrom the Windows SDK 10.0.26100 validating;cargo test -p victory-shader -- --test-threads=1: 70 passed, 0 failed (main: 69). The two extra view kinds in the table above are a local change to the PR's test, run once each.Verdict from here: the stride table and the offset are right; the handle is the problem. As it stands this turns a refusal into zeros on NVIDIA, so it should not go in without the raw alias (or a fallback limited to raw slots) suggested above, and a structured-view case in the test.
Not checked: the title (no game files here), AMD hardware, stores and atomics through a structured UAV.
AI-assisted (Claude Code).
@aycow on GitHub · 2026-11-24 06:34 UTC · original
@n-romanovich I’m independently checking the descriptor-kind issue reported by @marquezinii on AMD, NVIDIA and WARP. The original synthetic matrix will cover typed and structured SRVs, UAV stores and atomics, differing strides and bounds, and descriptor and stride-metadata lifetime across a fence. Are you already implementing a raw-view alias or versioned stride metadata? I’ll bring the results back here so the fixture or fix can support your PR.
@aycow on GitHub · 2026-11-24 06:46 UTC · original
I ran an original fixture using DXIL generated by
4322b61. AMD Radeon Graphics, RTX 5070 Laptop and WARP matched the complete CPU readback with the debug layer and full GPU-based validation using both native structured views and separate view-bounded raw aliases. This covered 8/12/16/20/32-byte strides, mixed strides, a typed RGBA32F SRV, structured UAV stores and atomics, and unchanged sentinel words.In a separate characterization of the original descriptor-kind mismatch, NVIDIA read zero through both structured and typed SRVs. WARP read the structured data and returned zero for the typed view. The fixture also showed that flat address calculation can cross an element boundary within the view. The stride-6 control dword-aligned the address on all three adapters, so the console reference depends on the instruction's alignment rule. A fence-gated run returned the right results with immutable descriptor and metadata pairs. A dispatch using mutable shared stride storage observed the replacement value.
The test-only branch is based on your head. Compile with
cargo test --locked -p victory-shader --no-run, stage the Agility SDK 1.620.2 DLLs under the test executable'sD3D12directory, then run the ignored testsstructured_stride_alias_matrix,structured_stride_boundsandstructured_stride_fence_lifetimeseparately with--nocapture. Exact fixture@r4tedx on GitHub · 2026-11-24 07:08 UTC · original
@n-romanovich @aycow a fix for the view-kind problem discussed above is up as #704, stacked on this PR's head
4322b61(merged withmain). @n-romanovich, you are welcome to take its three commits into this PR instead; it only makes sense on top of yours.It is the raw-alias route aycow asked about: each table entry gains the heap slot of a raw view of the same bytes, the GPU side makes that view whenever it makes a structured or typed buffer view, and the shader makes its raw handle from the slot the entry names. The handle's kind then always matches the view.
Two things from the work that bear on the discussion here, measured on an RTX 5070, a Radeon integrated GPU and WARP with hand-assembled programs:
What #704 does not fix, and it matters for the programs this is wanted for: a buffer view in a slot that a shader reaches only through an index loaded at run time is still a null view on the host (
HostHeap::mirrormakes buffer views only for the slots a dispatch names), so those reads still return zeros.@aycow your fixture covers more than my tests do (the debug layer, GPU-based validation, 8- and 32-byte strides, lifetime across a fence). If you run it against #704's head
30a93f9, the result belongs on that PR.The title was not used in these tests. AI-assisted.
@Mesrine67 on GitHub · 2026-11-24 07:18 UTC · original
AMD and WARP reproduction of the stride fixture
I ran the three ignored D3D12 validation tests from
aycow/VIctorycommit19d5efb591b5840142debcd0451827b580d03894, whose parent is this PR's current head4322b61328e158b4f7619333a163148a92de22c8. The fixture used D3D12 Agility SDK 1.620.2 with the debug layer and GPU-based validation enabled on Windows 11, an AMD Radeon RX 6750 XT, and WARP (Microsoft Basic Render Driver). I narrowed the local adapter list to AMD and WARP. All three tests passed on both adapters.structured_stride_alias_matrix: strides 8, 12, 16, 20, and 32, typed aliases, and mixed source/destination strides matched the expected output.structured_stride_fence_lifetime: old and new descriptor/metadata generations produced the expected results; overwriting the shared mapped stride table before the queue fence released exposed the replacement stride, reproducing the lifetime race.structured_stride_bounds: reproduced cross-record and zero-stride alias behavior; the descriptor extent remained enforced.I did not run
structured_stride_incompatible_descriptor_characterization; it disables validation and intentionally binds incompatible descriptor kinds. These are synthetic GPU tests only: they do not execute GTA VI or verify its in-game rendering.@aycow on GitHub · 2026-11-24 07:29 UTC · original
@n-romanovich I have a working opt-in production binder on
4322b61, withVICTORY_RUNTIME_STRIDE_ALIASES=1. It keeps the original view and binds a separate raw alias plus immutable alias-index, stride, and record-count metadata per dispatch. The emitter guards record boundaries for loads, stores and atomics. With the flag unset, the pipeline refuses the runtime-stride path.AMD, RTX 5070 Laptop and WARP each passed 12 actual translated dispatches through
State::bindand title-buffer copyback with DXIL validation and full GBV. The fixture replaces descriptors and releases the title heap before submitting both recorded lists. The focused scope covers exact compute table entries, structured views, and aligned dword accesses. Typed, counter, computed-offset, and #206's off-element cases still need separate coverage. #185 and #562 can reuse the backing and lease invariants when composed; those compositions require their own validation. I'd like to contribute this as a follow-up to your PR. Exact implementation and reproduction@n-romanovich on GitHub · 2026-11-24 08:45 UTC · original
Thanks for the review! Addressed the feedback and resolved the compilation issue in the latest commit. All tests pass cleanly.
@upipibi on GitHub · 2026-11-24 10:25 UTC · original
Re-check of the new head
f99b792, merged ontomainffe310e, same card as before (RTX 3070, driver 616.56, SDK 10.0.26100dxil.dllvalidating).The main problem is unchanged. The PR's own test with only the SRV in slot 0 changed:
These are the numbers I had on
4322b61.f99b792does not touch how the handle is made, so the runtime path still takes a raw handle over whatever view the title put in the slot, and on NVIDIA that reads zeros from a structured or typed view. The test still binds only raw views. @aycow's raw-alias binder above is the kind of change that would move this row.My three smaller points
f99b792Source::Phireachingheap_slotWhat the new commit does fix (points others raised, read in the diff, not run by me): a dispatch or draw whose shader reads the stride table without a host view heap is now dropped instead of run;
NumElementsis clamped to what is left of the buffer; the duplicatemod testsinvictory-gpu/src/host.rsis renamed as onmain. It also refuses static strides that are not a multiple of 4. As in my first note, the ISA's default mode ignores the two low address bits, so that refusal is cautious rather than required; it costs nothing wrong.It does not merge or build on
mainas it is.emit/lower.rs(mainhas a newlane_heap_indexwhere this addsheap_slot; both functions are wanted),victory-gpu/src/descriptor/host.rs,draw.rsandhost.rs(mainalready hasbindreturningboolandmod batch).resource::trackwith three arguments (maintakes the structure as a fourth), andwaterfall_tests.rsonmainbuilds aHostShaderwithoutstride_table.With those resolved locally,
cargo test -p victory-shader -- --test-threads=1: 121 passed, 0 failed, 1 ignored (main: 120), andcargo check -p victory-gpu --testscompiles.Verdict unchanged: the table and the offset arithmetic are right and the phi path works, but this still turns a refusal into zeros for structured and typed views on NVIDIA. It needs the raw alias (or a fallback limited to slots known to hold raw views) and a structured-view case in its test before it goes in.
Not checked: the title (no game files here), AMD hardware, the
victory-gpuchanges at run time.AI-assisted (Claude Code).
@EduAzevedo on GitHub · 2026-11-24 13:06 UTC · original
Some in-game evidence for this PR, and a request.
On an RTX 2070 SUPER (Turing) I ran
integration/testers(92bc27b) plus #638's diagnostics into the first playable section (VICTORY_SHOW_TARGET=busiestshows the G-buffer with people and objects; the final picture stays black). WithVICTORY_PRODUCERS=1, 292 dropped programs had outputs that running draws then read (5,597 reader/producer pairs logged). The largest group with a known refusal isa structured buffer of unknown stride: 18 compute producers, 1,840 of those reads (about a third), among them the 7 most-read producers of the whole run. Offline this PR takes that refusal from 117 to 0 (my counts earlier in this thread).The request: this branch's merge base is still
9aef3d9. Merging it here conflicts in 22 hunks with the integration tree (descriptor/host.rs,draw.rs,host.rs,pipeline/host.rs,emit/lower.rs) and in 8 with8e79c80+ #493 + #189 + #206, so I can't test it in game without rewriting your code. A rebase on currentmainwould let me run it into the world with those producers and report what changes.AI-assisted.
@justlovett0 on GitHub · 2026-11-24 17:32 UTC · original
Runtime verification, Win10/RTX 3080 (driver 621.24), with #704 stacked: the "a structured buffer of unknown stride" class is gone at runtime (it was the dominant failure in our world computes before this). #704's raw-alias slots are what make it work on NVIDIA — without them the runtime-stride
ByteAddressBufferreads return 0 against the structured host views (the quirk noted here).Build: main
ffe310e+ #175/#994/#302 + this + #704 + #309/#1067/#953 + copy fixes. The stride-table binding plus raw aliases let the culling/world computes run; combined with #1067 the in-game untranslated count fell 444 → 100.One integration note: the capped-heap split interacts with #747 — with #704's alias region (2^16) and a full 2^18 dynamic pool, the mirrored title range is 1,000,000 − 262,144 − 65,536 = 672,320 slots, matching the #747 author's measured setup. The title writes ~1.1M slots, so high bindless indices still read the guard slot (the #747-part-2 / clamping work).
AI use: Qwen Code (underlying model name not disclosed by the tool); counts from run logs and a
victory translatecensus of captured runtime containers.Pull request closed