tombox-xshader: SOP1 ops with a 32-bit result of a 64-bit source write one SGPR #331
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!331
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/331/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?
@GDAgent on GitHub · 2026-11-23 20:21 UTC · original
GDAgent:fix/xshader-sop1-i32-b64-dest→main· +104 −7 · 6 files · 1 commits · closed without mergingLibrary / area:
tombox-xshader(src/hlsl.rs,src/hlsl/rootmem.rs,src/hlsl/smem_bounds.rs)Exports changed (exports.txt rows): none
Source of the behaviour: AMD RDNA2 ISA:
S_FF0_I32_B64,S_FF1_I32_B64,S_BCNT0_I32_B64,S_BCNT1_I32_B64,S_FLBIT_I32_B64andS_FLBIT_I32_I64read a 64-bit SSRC0 and write a 32-bit SDST. Found in a scan of The Matrix Awakens (Xbox Series X build) shaders; native Windows 11 on an RDNA2 GPU, not run under Proton.What
These six SOP1 ops read an SGPR pair but write a single SGPR. Four register-width helpers in the translator took the
_b64(or_u64/_i64) suffix as a 64-bit destination and treateddst+1as written too:collectfallback arm): it dropped whatdst+1held. A root-table pointer copied intodst+1was lost, and the nexts_loadfrom it was refused with "base sN is not a root table pointer".live_in: it markeddst+1as written, so a user-data SGPR read after the op was not seeded and read 0. That is a silent wrong value, not a refusal.sgpr_const_in,sgpr_dead_afterand the SMEM bounds lattice (smem_bounds::wide): the same width mistake for constants and liveness.Change:
i32_result_of_64(m)names these ops (s_*_i32_b64/s_*_i32_i64), and the four sites skipdst+1for them. Every other_b64/_u64/_i64op is handled as before.s_bcnt1_i32_b64now declares the high half of its source (touch), as the other five 64-bit forms already did. Without it, a shader whose only read of that SGPR is this op fails to compile ("use of undeclared identifier 's1'"). The new user-data test found this.Why
Evidence from the title:
CopyStatsCSand aMainCS) were refused becauses_ff1_i32_b64wrote the register just below a table or code pointer. Both translate now and compile with DXC (cs_6_5).Tests
Tests (
tests/exec_mem/sop1_dst.rs; executed on WARP by default, on the GPU withTOMBOX_EXEC_HW=1), one case per op:table_pointer_in_the_next_sgpr_survives_a_32_bit_result_of_a_64_bit_scalar_op: a table pointer copied intodst+1still drives animage_load, and the op's own result is checked.user_data_in_the_next_sgpr_stays_live_after_a_32_bit_result_of_a_64_bit_scalar_op: a user-data SGPR atdst+1stays entry-live and reads its bound value._b64ops. The first gives the refusal above; the second gives "s8 missing from the entry-live registers".cargo test -p tombox-xshader --test exec sop1_dst(WARP): 2 passed, 0 failed.cargo test -p tombox-xshader --no-fail-fast(WARP): lib 116 passed, 0 failed, 3 ignored;exec130 passed, 0 failed, 2 ignored; every other test binary passed (isa_sweep 2, opcodes 26, synthetic 24, mesh 24 plus 1 ignored, and so on). 0 failures.TOMBOX_EXEC_HW=1 cargo test -p tombox-xshader --test exec -- --test-threads=1(AMD Radeon RX 6600 XT, RDNA2): the two new tests pass on the GPU, also when run alone. The fullexecbinary gives 126 passed, 4 failed, 2 ignored. The four failures are existing tests that do not touch SOP1 and that fail the same way on plainmain(f89e410) on this GPU:f16_omod_follows_mode,exec_mem::mtbuf::mtbuf_d16_store_formats,scalar_smem_loadsandvop::basic::vop2_basic. They pass on WARP. I am reporting them in a separate issue and they are not touched here.Not verified
Not verified in a title: the two shaders now translate and compile, but no run of the title used them.
The full
execsuite is not green on the GPU used (see the four existing failures above), so "all GPU tests pass" is not claimed.Tests pass for what is listed above (the 4 GPU-only failures on this card are pre-existing on
main)No game or console files and no binaries included
No fake success; anything not possible is left
missingwith a notes_ff0_i32_b64, s_ff1_i32_b64, s_bcnt0_i32_b64, s_bcnt1_i32_b64, s_flbit_i32_b64 and s_flbit_i32_i64 read an SGPR pair but write a single SGPR. Four register-width helpers took the "_b64" (or "_u64" / "_i64") suffix as a 64-bit destination and treated dst+1 as written: - the SGPR symbol pass dropped what dst+1 held, so a root-table pointer copied into dst+1 was lost and the next s_load was refused ("base sN is not a root table pointer"); - live_in marked dst+1 as written, so a user-data SGPR read after the op was not seeded and read 0; - sgpr_const_in, sgpr_dead_after and the SMEM bounds lattice made the same mistake for constants and liveness. i32_result_of_64() names these ops and the four sites skip dst+1 for them. s_bcnt1_i32_b64 also declares the high half of its source like the other 64-bit forms do; without it a shader whose only read of that SGPR is this op fails to compile ("undeclared identifier"). Seen in The Matrix Awakens: two compute shaders (CopyStatsCS and a MainCS) were refused because s_ff1_i32_b64 wrote the register just below a table pointer. Both translate now and compile with DXC. Of the 379 shaders in that title that use one of these ops, the other 359 that already translated produce byte-identical HLSL, and none fail that did not fail before. Tests (tests/exec_mem/sop1_dst.rs, exec on WARP, or the GPU with TOMBOX_EXEC_HW=1), one case per op: - a table pointer copied into dst+1 still drives an image_load, and the op's own result is checked; - a user-data SGPR at dst+1 stays entry-live and reads its bound value. Before the change both tests fail for the five _b64 ops.@omonkeyz on GitHub · 2026-11-25 13:50 UTC · original
Applied on main in
2f32df0(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.@SchmashinPrunes on GitHub · 2026-11-24 14:34 UTC · original · approved these changes
Update: I've now also read the full diff.
i32_result_of_64matches exactly the six SOP1 ops that write one SGPR, with no other_b64/_i64mnemonic caught by it. It's applied at every width site: the symbol pass,live_in,sgpr_const_in, rootmem and smem_bounds. CI passes. The approval stands.I checked this on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, raw wave32 kernels, so RDNA2, not gfx1013. Each kernel ran twice with identical results, and I compared against the semantics this PR implements (my own port; I didn't run the PR's code).
This confirms the width rule: the six ops read an SGPR pair but write only one SGPR. With
dst+1preset to a sentinel, it was unchanged after every one of 4,096 cases per op, fors_bcnt0_i32_b64,s_bcnt1_i32_b64,s_ff0_i32_b64,s_ff1_i32_b64,s_flbit_i32_b64ands_flbit_i32_i64.The values match the models in the test too:
The bcnt ops set SCC = (result != 0), while ff/flbit leave it unchanged.
(Measured with an AI assistant, Claude.)
Pull request closed