Three dataflow rules for mask provenance, descriptor provenance and buffer stride, stated against your open PRs on the same seams #1482
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#1482
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@MoonYueya on GitHub · 2026-11-24 18:20 UTC · original
What this is, and what it is not
A second, independent GTA VI Xbox→PC attempt (Project Leonida). We classified 303 translation failures from one world-frame window (posted separately); this issue is the three rules we use where the same seams your open PRs are already working. For each rule we say first what overlaps, then only what does not.
AI-assisted write-up, human-checked against our own reports. No game bytes, no shader names.
We are not offering a patch in this issue. Where we have code, it goes as a PR and gets linked here.
Rule 1 — A mask needs materialising only if something downstream reads its whole value
Overlaps: #1115 (a
v_cndmask_b32whose mask iss_cselect -1, 0is refused as "an untracked mask"), #878 (mask dwords at data joins; ready to merge), #750 (redundant masked write after a per-lane descriptor join). Yourir.rs:551 liveness()already computeslive_in/live_out— but at block granularity, aRegSetper basic block.What we do differently is the granularity and the question. Instead of asking "is this value a mask?" at the use site, ask "does anything read this register's whole value before it is overwritten, and if not, does it need a value at all?"
VCCZ, and so on.v_cndmask_b32's mask, the carry-in ofv_add_co_ci/v_sub(rev)_co_ci— and that lane's half of the wave already holds it.The point is that the refusal condition cannot arise for the first class, so it stops being an error path rather than becoming a special case.
Three details that cost us real debugging time. They are the difference between this producing a refusal and producing a silently wrong translation:
s_cmov*(conditional), nots_addk/s_mulk/s_bitset*(they read the old value), nots_movreld/s_movrelsd(they writes[dst + m0]), and not SDWA compares that write their SDST instead of VCC.s_movrels*readss[src + m0], so every register fromsrcupward is live, not justsrc. SDWA scalar sources (S0 / S1) and SMEM register offsets are reads too.EXECis always whole-live; every SGPR is whole-live at the end of a program that reads state back; and anything live after an emitted loop is live before each of its instructions, because the loop may be left at its iteration-budget check.Where this lands relative to #878. #878's data-join shortcut takes
undefon the non-data edge, which is the same assumption #180 makes for descriptor dwords. That is sound only if rule detail 1 holds — if a register that looks dead is actually read-merged, theundefbecomes a wrong value rather than a refusal.Honest scope: this involves all 127 class-A failures, but we are not claiming it recovers all 127. The 60
a lane mask holding lanes elsewhere read as datacases read bits belonging to the other half of the wave; whether whole-liveness covers them depends on where those bits are consumed, and we have not measured that split.Rule 2 — A descriptor's console fields survive translation; only word 0 and the sampler index change
Overlaps: #1130 (a descriptor read only as data takes the kind of another load of the same heap entry — 819 → 53 programs), #1067 (kind from the table range — 4,123 → 3,749), #1325 (4-dword buffer views inferred from
UsedResource, closed), plus #979 and #798. These are the right direction and they cover most of class B (62 failures).What we would add is a representation argument, not a tracking one. Our lowering never rebuilds a descriptor from host-side knowledge at the use site. The console's words live in SGPRs and the shader reads them raw:
tw0is exactly the SGPR the descriptor was loaded into — no mask, no shift. What makes that legal is that the runtime rewrites the descriptor on the way into the heap:Why that dissolves the largest class-B shape.
a descriptor read only as data(51 of 62) means the program used the descriptor's words for arithmetic — dimension reads, address arithmetic — without ever sampling through it. If words 1–3 still hold the console's own numbers, a program doing arithmetic on stride,num_recordsor format gets the values it expects, with no inference needed at all. Only word 0 means something different, and word 0 is the field a program should not be doing arithmetic on. In our corpus it does not: the arithmetic touches dwords 1–3.Your
resource.rs:47comment already recordsdword 1 (stride, swizzle), dwords 2 and 3 as givenfor the built case, so the field semantics are clearly understood here. The open question we would raise is whether the loaded path keeps those fields byte-identical when the descriptor reaches the shader.One measurement worth having before anyone treats the descriptor heap address as a blocker. We spent a round convinced the 32-bit table address in a root argument was fatal, because our host heaps all landed above 4 GiB — 19 segments of 65,536 descriptors, every one of them. It was not fatal; we had conflated two layers. On the console, that dword is the 32-bit UMA address of the table's first slot. After translation it must be the heap-relative index of that slot. If any part of a pipeline treats it as an address end to end, a whole cluster of descriptor failures can come from that one representation question. (This measurement is from a separate experiment in our project, not the three-minute run above.)
Rule 3 —
stride == 0is a raw buffer, not an unknown oneOverlaps: #155 (runtime stride channel, design + anchors), #193 (runtime stride table for structured buffers), #704 (unknown-stride buffers read through a raw view of the same bytes, stacked on #193). Those three are the complete line on this, and #704 in particular is close to the conclusion.
The predicate we use for the same V# field:
num_recordscounts bytes, and the descriptor is a flat byte buffer.num_recordscounts elements, and the element size is the stride.The stride is V# dword 1 bits [29:16], the count is dword 2. So a stride-0 descriptor arriving at a structured-buffer path is not an unknown stride — it is the wrong path. Concretely, your three refusals read
if stride < 4 || !stride.is_multiple_of(4) { return Err("a structured buffer of unknown stride") }(emit/lower.rs:6281,:6364,:6425), which catches 0, 1, 2 and 3 together.What we would check first: how many of the 27 are stride exactly 0. If they are, the fix is a branch rather than an analysis, and the error string is currently hiding a routing decision inside a tracking failure. We have not measured that split on your corpus — this is a hypothesis with a cheap test.
A second suggestion for class D, on
a scalar memory read as data(18). #979 reports 771 programs offline with this string and finds the use instruction is always ans_operation. One addition: not everys_loadis a descriptor load.s_load_dwordfrom a constant table appended after the code — read throughs_getpc_b64— is data by construction, and it appears in the same programs. Splitting on "is the base as_getpc_b64result" separates two populations that currently share one string, and only one of them is a descriptor problem.What we are not claiming
Related PRs will be linked here.
Project Leonida, 2026-11-24. AI-assisted write-up, human-verified.
Measurements behind these rules: #1481.
@studiostephe on GitHub · 2026-11-25 07:16 UTC · original
Rule 3, confirmed and fixed: a used-resource
strideof 0 is a raw buffer, not an unknown one.What's wrong
Lower::bufferreads a table descriptor's element through the index arm, which checksstride < 4 || !stride.is_multiple_of(4)and refuses otherwise (lower.rsload:9072, store:8964, atomic:8830onmain940d32f). That catches 0 together with the genuinely unknown 1, 2 and 3. On the console a stride of 0 means the buffer is raw —num_records(descriptor dword 2) counts bytes, not elements, and the element index is a byte offset. So a raw buffer read by element is refused as "a structured buffer of unknown stride" instead of being addressed through the raw view, as the unindexedNonearm already does.Fix
In all three paths, when the used-resource entry's
strideis 0 (and the access is not a typed-format load, which takes its own path), address the element as a byte offset into the raw view — exactly theNone/unindexed arm — instead of refusing:The load path emits the
rawBufferLoad.f32directly (it has noargs/byte-bookkeeping to share with the match, so it lowers inline and drops the index toNone); the store and atomic paths setindex = Noneso the existingNonearm runs unchanged. Strides 1, 2 and 3 stay refused — a raw buffer's stride is 0, not a small non-multiple-of-4.Verified
emit::stride0_tests::a_stride_zero_buffer_is_raw_not_an_unknown_stride: a table SRV (user data 0) read by element (buffer_load_dword … idxen) plus a table UAV store, descriptor loaded at the access's own site (s_mov+s_load_dwordx4, the shaperesource::trackaccepts asSource::Loaded).stride = 4lowers (the structured control).stride = 0lowers (was refused before).stride = 1, 2, 3still refuse with "a structured buffer of unknown stride" (non-vacuous: the fix is the 0 case, not "always raw").cargo test -p victory-shader --libon macOS, Rust 1.98.1: 145 passed / 0 failed / 2 ignored (144 before; +1 is the new test).lower.rsreverted to940d32f, thestride = 0case panics witha structured buffer of unknown stride is not supported; with the fix it lowers.rustfmt --edition 2024 --check: the new test file is clean;lower.rsshows the same 19 pre-existing fmt diffs with and without the change (my lines add none).cargo clippy -p victory-shader --all-targets: no new warnings (5 pre-existing, unchanged).Not covered
stride = 0element load emits is arawBufferLoad.f32at a byte offset into the raw view. I did not run it on a GPU or WARP (no host device on this Mac, and the test is CPU-side: it lowers and checks the refusal, not the readback). The byte-offset addressing is the same one the unindexedNonearm uses, which the existingstride_testsexercise on hardware; but I have not measured that a real title raw buffer read by element returns the same bytes through this path as through the unindexed form.tbuffer_load_format_*) are excluded from the 0-stride raw path (they take theformatarm); a raw typed buffer read by element would still hit thea typed buffer load by indexrefusal, as before.qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles
@Marvisak on GitHub · 2026-11-25 10:21 UTC · original
Automated triage for the maintainers.
This is a proposal for three translator rules, and each one overlaps existing work. It is tracked here as a request.
mainby PR #1221. Thev_cndmask_b32lowering incrates/victory-shader/src/emit/lower.rsnow resolves masks fromStructured::other.main(940d32f).Lower::bufferincrates/victory-shader/src/emit/lower.rsrefuses an indexed access whose used-resource stride is below 4 or not a multiple of 4, in its atomic, store and load paths. So 0 is refused together with 1 to 3.The comment above posts a patch for stride 0 inline. Pull requests are open to everyone, so please open one with the patch and its test. One point for review there: the patch keys on the
strideof the shader's used-resource entry (crates/victory-shader/src/native.rs), not on descriptor dword 1. Whether 0 in that entry means a raw buffer or that no stride was recorded is the question to settle. On hardware, an index with stride 0 adds nothing to the address. This matches the patch dropping the index.Rule 2 is a design point for the maintainers. The measurements behind these rules are in #1481.
Generated by Claude Code