Shader: LDS bytes and halves, constant sample offsets, descriptor-data reasons #383
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!383
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/383/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?
@xmvo on GitHub · 2026-11-24 02:49 UTC · original
xmvo:shader/more→main· +631 −30 · 5 files · 2 commits · closed without mergingBuilds on #318 (its commit is the first of the two here); merge that first, or this one instead of it.
What
LDS bytes and halves.
ds_read_{u,i}{8,16},ds_write_b{8,16}and their_d16/_d16_hiforms now lower within their dword:and, thenor), so lanes writing other bytes of the same dword keep theirs.Constant sample offsets.
image_sample_o,image_sample_lz_oandimage_sample_l_opass a constant offset word as the sample's immediate offsets. A computed word, or an offset outside -8..7, stops the program with its own reason.image_sample_l(_o)now reads its level after the extra words (it assumed none).Descriptor data. A buffer descriptor read as data and by
s_buffer_loadis now sized from its raw SRV, as buffer-instruction uses already were. The other paths that returned "a scalar memory read as data" now each have their own reason. The title's census stopped 573 programs with that message, and this tells the causes apart.Adds
BitcodeModule::int_value(an integer constant's value).Census buckets addressed
s_buffer_load+ raw SRV case translates)Testing
lds_byte_and_half_writes_keep_the_rest_of_the_dword/lds_byte_and_half_reads_extend_as_the_console(valu_tests): validated by dxil.dll and run on the hardware device. They need a one-wave group with LDS, which takes the console's wave size, and WARP can't run that, sorun_cases_onlets these choose backends.image_testsmodule: a synthetic program loads a UAV, a 4×4 texture and a sampler from tables and samples it. Validated, then run on hardware and WARP:image_sample_lz_owith a constant offset,image_sample_l_o(level after the offset word),image_sample_l_owith a16: coordinates in the VGPR after the offset word (the #318 layout; the oldk / 2read the offset word as u, v),image_sample_d_cl(coordinates after the gradients, then the clamp).cargo test -p victory-shader: 76 pass (hardware: RTX 3060).cargo clippy -p victory-shaderand rustfmt clean.With a16 the address VGPRs were read as one run of 16-bit pairs. The hardware (and image_addr_dwords, which counts them) gives each extra word (texel offsets, bias, comparison value) a whole VGPR, pads each direction of an odd number of gradients to whole VGPRs and begins the coordinates in a new VGPR. image_address_place now places each address that way, so a16 biased samples translate (the bias is the f16 in its word's low half) and a16 gathers with an offset word read their coordinates from the right VGPR. image_sample_d_cl lowers to sampleGrad with the clamp that follows the coordinates. In a census of the title's shaders these stopped 108 ("a biased image sample with 16-bit coordinates") and 27 (image_sample_d_cl) programs.- ds_read_{u,i}{8,16}, ds_write_b{8,16} and their _d16/_d16_hi forms read and write within their dword: reads shift and zero- or sign-extend (d16 keeps the VGPR's other half), writes clear then set their bits with two atomics so lanes writing other bytes of the same dword keep theirs. - image_sample_o, image_sample_lz_o and image_sample_l_o pass a constant offset word as the sample's immediate offsets (each 6-bit offset within -8..7; a computed word or a wider offset stops the program with its own reason). image_sample_l(_o) reads its level after the extra words. - A buffer descriptor read as data and by s_buffer_load is sized from its raw SRV. The other ways a scalar memory read as data stops now have their own reasons, to tell apart the 573 programs a census of the title stopped with "a scalar memory read as data". Tests: LDS byte/half reads and writes run on the hardware device (one wave with LDS takes the console's wave size, which WARP lacks); a new image_tests module samples a 4x4 texture on hardware and WARP with offsets, an a16 extra word, and gradients with a clamp.@SpaghettiMaster545 on GitHub · 2026-11-24 03:48 UTC · original
Tested with the title at
b6af8b1. The branch also carries #318's commit1d7bf9b, so this measures both together.maind2a4bae(clean), its own emptyVICTORY_CACHE_DIR,VICTORY_KEYSinto story mode, until the host GPU failure (#71, unrelated); compared program by program with amainrun made the same way (#400 has the setup).maintranslate and run. 0 programs that ran onmainstop. This run ended earlier (63 s) than themainone, so it reached fewer programs and the count is a lower bound.Not tested: this PR without #318, AMD GPUs, a release build, image results.
(Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)
@jeremygold02 on GitHub · 2026-11-24 04:21 UTC · original
I ran the shader crate’s unit suite at head
b6af8b177e46e14b0ac9e372c287a8db63c83630:Result: 76 passed, 0 failed, 0 ignored. Relevant checks include
lds_byte_and_half_reads_extend_as_the_console,lds_byte_and_half_writes_keep_the_rest_of_the_dword, the image sampling offset tests, and the shader lowering/bitcode tests. These are synthetic unit checks; this run does not validate rendered image output or title behavior.@ghost on GitHub · 2026-11-24 05:50 UTC · original
Review note on head
b6af8b1: fords_read_*_d16/_d16_hi,crates/victory-shader/src/emit/lower.rs:2138keeps the destination's other half by reading its old value withinst.read(Reg::V(reg)), and falls back to 0 when that isNone.On
main,ir.rseffects()(theFields::Dsarm, around line 842) adds ads_readdestination only to the written registers, andInst::readonly searches the read list. So for these readsinst.readis alwaysNoneand the kept half is always zeroed: a_d16read clears the high 16 bits, a_d16_hiread clears the low 16.#116 fixes this in
effects():This PR would need the same, plus a test that writes a known value to the destination first and checks the other half survives.
Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and
mainatd2a4bae. Context: the triage in #366.@iurysf on GitHub · 2026-11-24 07:21 UTC · original
Measured offline against main
d2a4baewithvictory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17: failures 3,733 -> 3,588 (−145), with no regressions (194 rejected by the validator, against 185). Most of the change is reclassification. "a scalar memory read as data" (573) goes to 0 here, but mostly by splitting into "descriptor address/format" (71 -> 595) rather than by translating. For comparison, #136 + #180 together take failures to 3,080 and clear both categories (details on #136).AI-assisted.
@slint6614-dev on GitHub · 2026-11-24 07:47 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae(emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.image_sample_o,image_sample_d_cl, the 108 biased 16-bit samples and the 573 "scalar memory read as data", but those mostly move to other reasons ("a descriptor's address or format read as data" 71 → 595, "an image address" 2 → 27), and the signature mismatches go 21 → 29 (input) and 25 → 26 (output).cargo test -p victory-shader --releasecrashed withSTATUS_ACCESS_VIOLATIONin 2 of 6 parallel runs (0 of 6 on main;--test-threads=1always passes, 76 tests). Possibly a race in one of the new tests.@adamdotpy on GitHub · 2026-11-24 15:55 UTC · original
Reviewed
b6af8b1. Two things first, then what I found in each part.It no longer applies to
main. The branch is based ond2a4bae;git merge-treeagainstffe310econflicts incrates/victory-shader/src/emit/lower.rsand.../valu_tests.rs, which is why the PR reads asdirty. @SpaghettiMaster545's title test merged ontod2a4baecleanly, so the conflict came in with the commits after that; a rebase is needed before anyone can judge the merge or re-run a census.Run here (Windows 11, Rust 1.98.1):
cargo test -p victory-shader— 76 passed, 0 failed, matching @jeremygold02._d16/_d16_hikept half: the source is the wrong one, and this test cannot see it@TrashTalker3460 is right that the kept half is unreliable, but the mechanism is worth stating precisely, because it explains why
lds_byte_and_half_reads_extend_as_the_consolepasses on hardware:ir.rs'seffects()puts adsdestination only in the write list, and chainsdatainto the read list (Fields::Ds,addr.iter().chain(data)).inst.read(Reg::V(vdst))returns something only because the encoding'sdata0field is parsed as an operand and names that register. In the testds(op, 0, 5, 0, offset)hasdata0 = 0, i.e. v0, andvdstis also v0, preloaded with the LDS content — so the "kept" half happens to be the value the test expects. In a title shader whosedata0names another register (hardware ignores that field on a read), the kept half comes from that register instead._d16and_d16_hi.A test that would catch it: same program, but
vdst = 2with the address inv5anddata0naming a third register (or 0 whilevdst != 0), so the kept half can only come from v2's own previous value.LDS bytes and halves
The part I expected to be wrong is right.
hole = mask << shift,keep = ~hole, value masked intohole: mask and value are disjoint per write, so theandthenorpair commutes and lanes writing different bytes of one dword cannot lose each other's bits. Two notes:image_address_placeper = grads / 2is safe only because the caller computesgrads = 2 * spatial, so it is never 1. Nothing in the function says that, and the comment right above talks about odd gradient counts being padded — adebug_assert!(per > 0 || grads == 0)or a sentence would keep the next edit from dividing by zero inside the translator rather than failing a shader.Descriptor data — three PRs, one case
Your
Fields::Smemarm is the same fix as #953 (a buffer descriptor also read bys_buffer_loadbecomes a raw SRV,(11 | u, 0)), reached independently, and the reason split around it is what #1083 does. Whichever lands first, the other two rebase:Fields::Flat, the other arms) and drops theFields::Smemtranslation;One shared open question: both use
(11 | u, 0)regardless ofused.stride, sogetDimensions().xon that raw view is bytes/4 while a console structured descriptor's dword 2 is bytes/stride — 4× at stride 16, and it is the record count. I raised it on #953; if it turns out to matter, it matters identically here.@adamdotpy on GitHub · 2026-11-24 15:58 UTC · original
For the LDS half of this PR, #571 is the better implementation of the same ground: it handles the halfword at byte 3 by straddling into the next dword (64-bit shift on read, 64-bit mask/data on write, past-the-end clamped with reads seeing 0), where this PR documents the straddle as a shortcut that loses the spilling byte. I would land #571 for LDS and rebase this one to keep only the
image_sample_oand descriptor-data work, which nothing else covers.Both PRs share the same question about the
_d16kept half — the destination register is read viainst.read(Reg::V(dst))whileir.rs::effects()only declaresdstas written, and the tests cannot see it becausevdstand the data field coincide. I left the details with an experiment on #571. One fix upstream would close both.@pablogonz12 on GitHub · 2026-11-24 16:20 UTC · original
I ran the CI clippy on head
b6af8b1(the branch has no checks):cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warningsfails on two points, both the first error in their crate:crates/victory-shader/src/emit/valu_tests.rs:757:type_complexityon the[(u8, u16, fn(u32) -> u32); 6]table inlds_byte_and_half_reads_extend_as_the_console— atypealias (or#[allow(clippy::type_complexity)]) clears it.crates/victory-gpu/src/host.rs:267:undocumented_unsafe_blocks, which is not from this PR: current main has since added a// SAFETY:comment above thatraw.cast::<IDXGIAdapter1>()line, so rebasing on main fixes it.Also, when this meets current main:
image_tests.rsneedsemit(..., Target::ANY)andraw_view_tests.rsneeds the extralanesargument ofresource::track(I hit both in my tree).No game data, just the two compiler messages.
@adamdotpy on GitHub · 2026-11-24 16:29 UTC · original
Reproduced the flaky release-test crash on
b6af8b1, and found the cause. Windows 11, Rust 1.98.1, the branch's release test binary run 6 times with default (parallel) threads:That is 2 of 6, same as your report, and
--test-threads=1passes every time. So it is a parallel-run race, not a broken assertion.The cause is that this branch's base predates the GPU-test serialization. Current
main'svalu_tests.rshas:and
run_casestakes it before touching a device. Your merge base'svalu_tests.rshas noONE_AT_A_TIMEat all (git show <merge-base>:…valu_tests.rs | grep -c ONE_AT_A_TIME→ 0), and the newrun_cases_onin this branch — called from the two new LDS tests and fromimage_tests.rs— createsHost::newand dispatches without taking any lock. Two of those on the same device (hardware or WARP) at once is precisely the access violationmain's comment names. I could not make the LDS tests alone crash in 10 parallel runs, so the full suite's contention is what tips it over; the missing lock is still the defect.The fix is one line after the rebase: have
run_cases_ontakeONE_AT_A_TIMElikerun_casesdoes on current main (it will be in scope after rebasing, since it ispub(super)in the same module). Until then,--test-threads=1is the honest way to run it, as you found.On @pablogonz12's two clippy points: the
type_complexityon the[(u8, u16, fn(u32) -> u32); 6]table atvalu_tests.rs:757is yours — an alias or#[allow]clears it. Theundocumented_unsafe_blocksathost.rs:267is a rebase artifact, confirmed: currentmainhas the// SAFETY: EnumWarpAdapter returns a DXGI adapter…comment on exactly thatraw.cast::<IDXGIAdapter1>()line, so mergingmainin clears it. Your other two notes (theTarget::ANYandlanessignature changes) are the same class — they come from meeting currentmain, not from this diff.Nothing changed on your branch from me; this is evidence only. The shader-side substance (LDS sub-dword handling, sample offsets, descriptor-data reasons) I reviewed earlier still stands, and the #571 comparison note from before is unchanged: for the LDS half, #571 is the stronger implementation.
Pull request closed