Shaders: assemble dword-straddling global_load_ushort and global_load_sshort #1535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1536"
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 oni-swr on 2026-11-24T18:53:37Z.
Problem
In
Lower::flat(crates/victory-shader/src/emit/lower.rs), sub-dword global loads (global_load_ushortandglobal_load_sshort) assumed the 16-bit value never crosses a 4-byte dword boundary:When
off & 3 == 3,w >> 24reads only the low byte from dwordatand zeros the high byte from dwordat + 4. For example, reading0xFFFE(-2) at byte offset3returned0x0000_00FE(+254) for bothglobal_load_ushortandglobal_load_sshortinstead of0x0000_FFFE/0xFFFF_FFFE. This affects both root-SRV (rawBufferLoad) andCODEconstant-table (code_dword) loads.Fix
Lower::flat, whenwidth == 16and the offset can straddle a dword boundary (a.dynamic.is_some() || a.offset & 3 == 3), load the next aligned dwordat + 4and combine(w >> 24) | (w_next << 8)before the existing sign/zero-extension shift.a.offset & 3 != 3, emit no second load; for static offsets witha.offset & 3 == 3, emit the second load unconditionally without a branch.at + 4load withbegin_guardedonbyte == 3(and the laneguardwhen present) so non-straddling loads near the end of a root SRV never read past the buffer's end.emit::valu_tests::global_load_short_straddling_dword_boundarycoveringglobal_load_ushortandglobal_load_sshortacross dynamic byte offsets0..=10(including straddling offsets3and7, and end-of-buffer offset10) and static straddling offset+3, for both a root SRV and as_getpc_b64CODEconstant table.Verification
origin/mainffe310e):cargo test -p victory-shader --locked global_load_short_straddling_dword_boundaryfailed on RX 7800 XT hardware withsrv global_load_ushort (dyn) at byte offset 3 = 0x000000fe, want 0x0000fffe.cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)cargo test --workspace --locked: 343 passed, 0 failed, 6 ignoredvictory: 1 passed, 0 failed, 0 ignoredvictory_core: 11 passed, 0 failed, 0 ignoredvictory_formats: 23 passed, 0 failed, 4 ignoredvictory_game: 2 passed, 0 failed, 0 ignoredvictory_gpu: 50 passed, 0 failed, 1 ignoredvictory_hle: 95 passed (94 + 1), 0 failed, 0 ignoredvictory_loader: 25 passed (22 + 2 + 1), 0 failed, 0 ignoredvictory_pe: 7 passed, 0 failed, 0 ignoredvictory_pipeline: 4 passed, 0 failed, 0 ignoredvictory_shader: 121 passed, 0 failed, 1 ignored (global_load_short_straddling_dword_boundaryvalidated bydxil.dlland passed on both RX 7800 XT hardware and WARP)xtask: 4 passed, 0 failed, 0 ignored (includingrepository_passes_policy)rustc 1.98.1 (48a229cea 2026-09-01)/cargo 1.98.1 (797e8a9bc 2026-08-05).Not tested
dxil.dllvalidation, hardware RX 7800 XT + WARP dispatch, and the workspace test/clippy suite only).AI use
T3 Code through Antigravity, Gemini 4 Neon.
Update
4b638ff: title-memory coverage and the alignment assumptionmemory_tests.rs:title_memory_is_read_and_written_at_computed_addressesreads title memory withglobal_load_dwordagain, as onmain. The straddlingglobal_load_ushort(offset 3, bytes 3 and 4 across two dwords,0xAB11) is a separate read beside it and a seventh result, so both are checked. The title-memory access count is now 12.SH_MEM_CONFIG.alignment_modeand listsDWORD("automatic alignment to multiple of the smaller of element size or a dword"),DWORD_STRICT,STRICTandUNALIGNED("no alignment requirements"). It sits in the buffer chapter. §12.18.3 (Global) says nothing about alignment. So unaligned mode reads bytes 3 and 4, which this PR emits, andDWORDmode would align a halfword down to bytes 2 and 3. Which mode the console's driver sets is not in the guide, and nothing in this repo or its tests shows it. I found no passage or site to cite for that, so I am not claiming it. The assumption is now a comment next to the straddle inLower::flat.Verification for
4b638ff(WARP only,VICTORY_D3D12_WARP=1,dxil.dllvalidation on):cargo test -p victory-shader --libcargo clippy -p victory-shader --all-targetscargo xtask policyAI use
T3 Code through Antigravity, Gemini 4 Neon. Follow-up commit
4b638ff: Claude Code (Claude Sonnet 5.5).Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T18:56:56Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib global_load_short_straddling_dword_boundary— passed on RTX 5090 hardware and underVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— okClean handling of dword-straddling 16-bit loads at byte offset 3 mod 4, with proper dynamic guard so non-straddling loads never read past buffer end. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T19:12:59Z.
Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at
50cbdd0.cargo test -p victory-shader --lib -- --test-threads=1 --nocapturegives 121 passed, 0 failed, 1 ignored.global_load_short_straddling_dword_boundarypasses on the hardware adapter and WARP.The second load is guarded by
byte == 3only when the offset is dynamic. For a static offset it is emitted only whenoffset & 3 == 3. So aligned loads keep a singlerawBufferLoad, and the extra read can't go past the view for offsets that don't straddle.Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:33:47Z.
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count changes against
main, and the tests pass on Ada.Offline. I merged head
50cbdd0ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either.This is the expected result for a correctness fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests. With the same merge,
cargo test --locked -p victory-shader --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:40:52Z.
Verified commit
50cbdd0on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including the new dword-straddlingglobal_load_ushort/global_load_sshortGPU tests).AI-assisted; synthetic tests only, no game files.
upstream-sync referenced this pull request2026-11-24 21:03:11 +00:00
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-24T23:08:42Z.
Rebased onto
main70564aeas4efcbed. The force-push dismissed the approval, so @DenRakEiw, it needs another look.lower.rs: the fix applied unchanged.valu_tests.rs: the only conflict; upstream also appended tests at the end. I kept both, upstream's first, and updated the regression test to upstream's changes:HostShaderfields, filled fromloweredas upstream's own test builders dorange::buildfor the IR, as production translation now doesd71c388, the global table is a raw view in the resource heap (index 1, with heap index and byte offset in user data); the old root-SRV binding is kept for shaders that report oneTested on an AMD Radeon RX 7800 XT (RDNA3) and WARP, Windows 11, Rust 1.98.1:
lower.rsat70564ae)0x000000fe, want0x0000fffecargo clippy --workspace --all-targets [--all-features] --locked -- -D warningscargo test --workspace --lockedrepository_passes_policy)AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this comment.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:48:07Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. Dword-straddling global_load_ushort/global_load_* assembly — unaligned 16-bit global loads; hardware verification on Windows recommended.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:29:38Z.
Automated triage for the maintainers.
Needs work. Thanks for
4b638ffand for being clear about what is still open. CIcheckpasses at4b638ff, and the branch merges cleanly.title_memory_is_read_and_written_at_computed_addresses(emit/memory_tests.rs) has itsglobal_load_dwordread back, and the straddlingglobal_load_ushortat offset 3 is now a separate read beside it.SH_MEM_CONFIG.alignment_modevalues. UnderUNALIGNED, an odd-address halfword reads bytes 3 and 4 (whatLower::flatnow emits). UnderDWORD, the address is aligned down and the load reads bytes 2 and 3. Nothing in the repo or the thread says which mode the console's driver sets. Until something settles it (a title site whose odd-address halfword load has to cross the dword, or a reference for the console's mode), this can't be a candidate. The comment you added at the straddle, naming the assumption, is the right thing to have in the meantime.If the maintainer already knows the console's alignment mode, that alone would settle it.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T10:11:07Z.
Addressed both triage points and rebased onto
origin/mainat940d32f(updated heada62fe8e).MEMORYaddresses now use the straddling-halfword path. When the access crosses a dword, the high byte is loaded through a fresh title-memory page lookup at address +1, so a 64 KiB page boundary can select a different page/view safely. Added title-memory GPU readback coverage for an unsigned short at offset 3; the existing test covers signed and unsigned odd-address loads through root views and code.AMD's RDNA 2 ISA Reference Guide, §12.18.3 “Global Instructions” (pp. 229–230), lists
GLOBAL_LOAD_USHORT(opcode 10) as “Untyped buffer load unsigned short” andGLOBAL_LOAD_SSHORT(opcode 11) as “Untyped buffer load signed short”: AMD RDNA 2 ISA Reference Guide. The guide identifies the operation and width; direct odd-address readback coverage is provided by the GPU tests.Verification: RX 7800 XT shader lib tests passed (248 passed, 3 ignored), WARP shader lib tests passed (248 passed, 3 ignored), workspace tests passed, clippy passed with
-D warnings, andcargo xtask policypassed (182 files). All Cargo commands usedCARGO_TARGET_DIR=D:\\victory-1536-target.AI use: OpenAI Codex (gpt-6-luna).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T12:11:52Z.
Pushed
4b638fffor the two open triage points.title_memory_is_read_and_written_at_computed_addresseshas itsglobal_load_dwordread back, and the straddlingglobal_load_ushortat offset 3 is a separate read beside it. The program stores both (0x1111_1111and0xAB11), and the title-memory access count goes from 11 to 12.SH_MEM_CONFIG.alignment_modevaluesDWORD,DWORD_STRICT,STRICTandUNALIGNED. It is in the buffer chapter, and §12.18.3 says nothing on alignment. UnderUNALIGNEDthe halfword reads bytes 3 and 4, as this PR emits. UnderDWORDit would read bytes 2 and 3. The guide does not say which mode the console's driver sets, and nothing in the repo shows it. I added a comment at the straddle that names this assumption. If you want it to followDWORDmode, or to stay out until a title site shows which one applies, say so and I will change it.Verified on WARP (
VICTORY_D3D12_WARP=1):cargo test -p victory-shader --lib248 passed, 0 failed, 3 ignored.cargo clippy -p victory-shader --all-targets0 warnings.cargo xtask policy182 files ok. The PR description has the details.AI use: Claude Code (Claude Sonnet 5.5).
Imported from Marvisak/VIctory. Originally posted by qtLkz on 2026-11-25T13:14:29Z.
First NVIDIA run, as far as I can see in this thread: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, this PR merged on main
940d32f(clean merge).cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1emit::valu_tests::global_load_short_straddling_dword_boundary ... ok, with no "no SM 6.6 ... device; skipped" line, so it ran on the hardware adapter and WARP.stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on plain main on this card (#2317, fixed by #2315 + #2322). Nothing new from this PR.AI-assisted (Claude).
Pull request closed