Shaders: typed buffer elements crossing the record end read zero #3597
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3597"
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?
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T20:05:43Z.
On RDNA2 (
gfx1036, measured natively in Leonidadocs/design.md), typed buffer loads (buffer_load_format_*/tbuffer_load_format_*) are all-or-nothing against the buffer end: an element whoseoffset + element_sizeextends past the view's byte width returns0in every data channel (with missing channels past the format keeping(0, 0, 0, 1)), rather than returning partial data from leading in-bounds dwords. Onmain,Lower::format_loadissued per-dwordrawBufferLoadcalls and kept data from leading dwords even when trailing dwords were out of bounds.Changes
crates/victory-shader/src/emit/lower.rs(Lower::format_load,521,509bytes /+946vsmain,2,779bytes below the524,288limit):getDimensionson the raw viewh(already post-raw_view, sooffandwidthshare the same coordinate space), computewhole = (off + total / 8 >= off) && (off + total / 8 <= width), and select0for every decoded format channel when!wholewhile leaving constant-1 missing channels intact.#3572inlower.rs.crates/victory-shader/src/emit/valu_tests.rs:typed_elements_ending_past_the_buffer_read_zerocoveringtbuffer_load_format_xy(32_32_UINT, format62,8bytes) on a20-byte raw view at byte12(in-bounds control) and byte16(ending past the buffer ->0).Verification
main): https://github.com/Moon0755/VIctory/actions/runs/46058009518 (failure— 302 passed, 1 failed solely ontyped_elements_ending_past_the_buffer_read_zero:0x22222222instead of0)devin/ci-typed-element-spill): https://github.com/Moon0755/VIctory/actions/runs/46058009634 (success— 303 passed / 0 failed, Clippy + diagnostics Clippy clean,asset policy: 191 files ok)a7b9122):typed_elements_ending_past_the_buffer_read_zero(1/1) andtbuffer(1/1) pass on hardware + WARP; both Clippy configs andcargo xtask policy(191 files ok) clean.DST_SELswizzles on typed OOB, OOB modes0..=2, stride/swizzle/idxen,d16/ narrow-count variants of wide formats,dxil.dll1.7, game files. Synthetic tests only (AI-assisted).— Devin & Neon
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T20:29:02Z.
Verification of head
a7b91220against base main63bcca43(heads/base re-checked unchanged before testing).Hardware: Windows 11 Pro 26200, WARP only (no physical GPU); dxil.dll 1.8.2502.11 (SDK 26100).
Tests (
cargo test -p victory-shader): head 299 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The 4 failures are the same on base and head (synthetic_tests that need a wave-32 pipeline or hardware-specific gather behaviour, unsupported on WARP), so they are pre-existing and unrelated. The new testtyped_elements_ending_past_the_buffer_read_zeropasses on head.Control: base plus only this PR's
valu_tests.rshunks: the new test fails (5 failed vs 4 on base), so it detects the missing behaviour.Clippy:
cargo clippy -p victory-shader --all-targets -- -D warningsclean on head.Review: no defects found. The bounds rule (
off + sizeno wrap and<= widthfrom getDimensions, whole element otherwise all data channels 0) matches the claim, and the default channels (0,0,0,1) for channels past the format are still applied after the select. Sub-dword elements are checked on their own end byte. I only checked this against WARP, not hardware.Size: lower.rs 521,509 bytes (main 520,563), under the 524,288 limit. Textual merge of #3597 + #3602: clean, 521,714. Adding #3587: 522,154. Adding #2997 as well: clean merge but 525,571, which is 1,283 over the limit (main + #2997 alone is 523,980, fine). So the four together will not fit in lower.rs without moving code out.
AI-assisted (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:34Z.
AMD Radeon 780M (RDNA3) + WARP, Windows 11, head
a7b9122.63bcca4+ this PR's test): fails on the hardware adapter. A32_32_UINTelement at byte 16 of a 20-byte view reads0x22222222instead of 0.victory-shader+victory-gpu --features diagnostics): 552 passed.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T16:38:43Z.
NVIDIA row for this PR: it passes on Ampere, and its test fails on this card without the fix, at the same value as on the 780M and in the description.
RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head
a7b9122on main63bcca4(one commit, clean).cargo test --locked -p victory-shader --lib -- typed_elements_ending_past_the_buffer_read_zero --nocapture: 1 passed, 0 failed, 0 ignored, in 3 of 3 runs. Each run checks this card and then WARP, at byte 12 and at byte 16. Three more runs withVICTORY_WARP=1, where every device is WARP, also passed.Negative control: main's
emit/lower.rs, with the test kept invalu_tests.rs.git diff --stat HEAD: 1 file, 18 deletions.git diff --stat 63bcca4: onlyvalu_tests.rs(71 insertions, 1 deletion). Result: 0 passed, 1 failed, in 3 of 3 runs on hardware and 3 of 3 withVICTORY_WARP=1:hardware: 32_32_UINT element at byte 16 of a 20-byte view,left: 572662306(0x22222222),right: 0. WithVICTORY_WARP=1the label is stillhardware, but that run is WARP too.VICTORY_WARP=1runs. Both read0x22222222.That is the
0x22222222instead of 0 that the description's fork CI control and kilolimaVI's 780M give. On main, this card returns the in-bounds dword at 16 and 0 for the dword past the end, the same as AMD and WARP.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:63bcca4: 298 passed, 3 failed, 3 ignored.The 3 failures are the same on both:
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. The skipped test crashes the binary on this card (open issue #2571).The PR does not touch
victory-gpu, so I did not run its lib suite.Nothing NVIDIA-specific: the 3070 reads the partial element the same way as the 780M and WARP on main, and reads zero with the PR.
Not tested:
DST_SELswizzles, OOB modes 0-2, stride, swizzle oridxenaddressing,d16and narrow formats, sub-dword elements;lower.rssize note);AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.