Repository navigation
Shaders, GPU: add runtime stride table for structured buffers - #193
n-romanovich wants to merge 2 commits into
Conversation
|
Tested
No game data used. |
|
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 No game data used. |
|
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 I also ran an equivalent synthetic D3D12 implementation on PC-MIKE (Windows 11, Radeon RX 6750 XT) and WARP: an |
…uctured buffers (Marvisak#155)) into the integration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Shader PRs 136, 163, 164, 160, 176, 193, 177, 180, 138, 139, 145, 154, 156, 157, 162, 166, 168, 169, 179, 200, 226 and 25. Marvisak#193's runtime stride table is combined with the runtime PRs: - descriptor/host.rs keeps Marvisak#135's retire-on-keep, dynamic pool and sampler cap, Marvisak#185's Slots (made + directly indexed SRVs) and Marvisak#206's raw fallback for structured views off their host copy's elements. The stride table still holds the title view's element stride: a raw view made by Marvisak#206 starts at the same byte (raw_window never rounds), so the shader's index * stride + offset reads the same bytes. - Slots Marvisak#193 did not know about now write their stride: a directly indexed SRV (Marvisak#185) when its record changes, and make_null_kind's typed null views (0). - draw.rs keeps bind() returning whether it bound (with the stride table root SRV set inside it) and the bounded indirect argument copy. - pipeline/host.rs keeps the per-stage subobject stream; the stride table root parameter merges cleanly. - depth_bounds_test's HostShader gains stride_table: false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
In-game test on an RX 7800 XT (Windows 11 26200), Result: the host device is removed with 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. |
|
Review question on the fallback path. When the stride is not known statically, the three let byte = self.runtime_stride_offset(src, index, off)?;
(self.handle(site, src, false, (11 | u, 0))?, [byte, iu, iu])The heap slot that handle resolves to still holds the view the title created, which for a structured buffer is a structured view (
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?
|
|
Measured
This is translation only; it does not exercise the runtime stride table in a game run. AI-assisted. |
|
Tested
No game files used. |
AMD validation on PC-MIKE (PR head 4322b61)Hardware: AMD Radeon RX 6750 XT, driver 32.0.21045.29003.
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. |
|
Ran
So the hardware confirms the concern raised above about the raw handle: the fallback's 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 Also: An index whose Not covered: the title (no game data here). |
|
Independent check of head Confirmed on an RTX 3070 (driver 616.56): the PR's own test
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: Against the ISA otherwise
Smaller points not raised above
Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, 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). |
|
@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. |
|
I ran an original fixture using DXIL generated by 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 |
…stride Structured buffers whose element stride shader analysis cannot recover now read it from a runtime stride table (a GPU buffer of u32 strides indexed by view-heap slot) instead of failing translation. The GPU layer allocates and binds that table and fills each slot when it makes a view. Ported from Marvisak/VIctory Marvisak#193. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
main moved under #193 and this branch. One conflict, in HostHeap::new (descriptor/host.rs): #336 tries the heap with DYNAMIC dynamic slots, then with MIN_DYNAMIC, then capped, and records the range it got in `dynamic`; this branch puts ALIASES raw-view slots after the dynamic ones. Both kept: each attempt asks for the alias slots too, the capped count leaves room for them, the lease bitmap has `extra` entries as on main, and `alias_base` stays `count + extra`. A merge rather than a rebase so #193's commits keep their ids. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
#193 moved: buffer views are clamped to what is left of the host copy, a shader that reads the stride table without a host view heap is not run, and a known stride that is no multiple of four is refused. Conflicts were with main, not with this branch's change: `bind` already returns whether the draw may run (#336), with its doc comment and the dropped counter, and main already renamed the second test module in host.rs. main's side kept in all three; #193's `return false` in the stride-table branch is in. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-together merge Three hunks needed a choice: the dynamic-slot warning in descriptor/host.rs and the blend/mask subobjects in pipeline/host.rs keep the all-together side (free-space diagnostic, host_blend); buffer_srv keeps both the raw-start check and the NumElements clamp of Marvisak#704. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…guard slot and the console-flow rule
…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>
…, bounded (VIctory #193, #704)
A program that reads a buffer by element (idxen) without a stride known
at translation was refused ("a structured buffer of unknown stride",
three sites in emit/lower/buffer.rs): 179 programs of the pack (177
compute, 2 pixel), 210 draws and dispatches a frame in the Series S
world. With XTP_STRIDE_TABLE=1 they translate and read the view the
title binds at run time.
Shader side: Target.stride_table (off in Target::ANY, in Target::key);
the host's table at t0/space2 (STRIDE_SPACE), one StrideEntry of 8 bytes
per view-heap slot; RawWindow::covering; stride_entry and runtime_view
in descriptor.rs; loads, stores and atomics by element read the entry of
the slot they compute and access the raw view it names.
GPU side: each view heap keeps the table (upload memory) and 2^16 more
slots for raw views, counted in NVIDIA's 1,000,000 (taken from the
title's part of a capped heap); every descriptor write writes the
slot's entry with it, a structured or typed buffer view gets a raw view
of the same bytes; a root SRV at t0/space2 in each stage that reads it;
draw.rs binds it at each bind and drops the draw or dispatch when the
view heap has no table; shader cache VSH2 with the field.
Critical review (what was changed, not ported as is):
- An entry of zeros meant "the slot itself" upstream: a null, texture or
constant slot (and every slot of a table of zeros) was read through a
raw handle, a kind mismatch the hardware does not survive in general.
Here zeros hold no view: the access is not made (loads 0, stores and
atomics dropped). Raw views name their own slot.
- Bounds (producers' item 1, watch.md item 84): upstream accessed
index*stride + off + bias unchecked, so an index whose product wraps,
or off + width > stride, reached the bytes the raw view holds before
the view (up to 12) or the next element. The entry now carries the
view's element count (low dword: count, bias/4; high dword: stride/4,
raw slot), and an access is made only at an element below it and
inside the element (a raw view: inside its bytes), as the console's
range checks do.
- Table races (item 2): upstream wrote the two dwords of an entry apart
from the CPU while lists read them, and remade a raw view in place or
for another slot at once. Here an entry is one 64-bit store, a changed
view gets a raw view in another pool slot, and a raw view given back
waits (with its host buffer held) until every recording that read the
table before has gone, after its submissions (StrideHold, per heap,
taken at the first bind). The slot's own descriptor and entry are
rewritten in place, as the title's descriptor is.
- Release order: entries and raw views of dynamic slots are cleared
before the slots are free (#704, 4e03086 by MichaelSmithAI).
- Buffer views are cut to their host copy and refused when the host
would refuse them (past its end, no elements, a stride over 2048 or
off 4, typeless without the raw flag): VIctory #193's f99b792 clamp,
whose remaining count ignored the title's first element, and the
buffer_view_ok of fxceless's VIctory fork (commit 578d459).
- #704 logged and ran a draw without the table; dropped here, as #193's
head does.
- A raw view in the slot reads at the offset alone (stride 0: the
console's descriptor of no stride), not index * 4.
- Switch off by default (item 4): no upstream run was safe (DEVICE_HUNG
after 111 s; zeros on NVIDIA with #193 alone).
- Not fixed here: slots reached only by an index loaded at run time
stay null views until a draw names them through a table (mirror zeros,
item 3; r4tedx's gpu/run-time-indexed-views); the PCIe cost of reading
the table from upload memory is not measured yet.
Tests (WARP): emit/stride_tests.rs (strides 4, 12, 16, 20, typed, raw,
views off 16 bytes, range checks with a wrapping index and the next
element, an entry of zeros, a slot loaded at run time, the switch);
descriptor/host.rs (entries follow the views, raw views kept while a
list may read them, views cut to their copy, a translated program run
through a real heap's table); draw.rs (a missing table drops the draw).
Mechanical fixes outside the task's files: the new Target field in
literals of apps/xtp/src/survey.rs, apps/xtp/src/translate.rs,
emit/lane_read_loop_tests.rs, emit/loop_limit_tests.rs,
emit/lower/tests.rs, emit/lower/uniform.rs, emit/mesh_tests.rs,
emit/split_tests.rs; the new HostShader field in emit/valu_tests.rs and
emit/waterfall_tests.rs.
Ported from Marvisak/VIctory#193 (head f99b792) by n-romanovich
Ported from Marvisak/VIctory#704 (head 1f3c184) by r4tedx, with its
release-order fix 4e03086 by MichaelSmithAI (its test, fb8ea43, is not
ported: here the entries are cleared in release_all itself, before the
slots' lock, so no other list can lease them in between)
Ported from fxceless's VIctory fork (commit 578d459) by fxceless (its
buffer_view_ok's checks, in fit_view)
…d only through their descriptor) into the integration Our descriptor data keeps its skewed and twin loads and the runtime stride table of Marvisak#193; the PR's new case (a four-dword structured buffer the program only counts the records of) joins our image-only case in the branch for descriptors nothing else uses. Parts gains psv; the PR's emit-based test helper replaces the hand-built one in valu_tests and names the target. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Implements 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.