Skip to content

xshader: fix swapped GFX10 FLAT load_dwordx3/load_dwordx4 opcodes - #7

Open
marquezinii wants to merge 1 commit into
drycheetah84:masterfrom
marquezinii:xshader-flat-load-dwordx3-x4
Open

marquezinii wants to merge 1 commit into
drycheetah84:masterfrom
marquezinii:xshader-flat-load-dwordx3-x4

Conversation

@marquezinii

Copy link
Copy Markdown

The FLAT mnemonic table mapped opcode 0x0e to flat_load_dwordx3 and 0x0f to flat_load_dwordx4. On GFX10 it is the other way round, in the same order as the MUBUF table in the same file (0x0e dwordx4, 0x0f dwordx3). Source: LLVM llvm/lib/Target/AMDGPU/FLATInstructions.td, FLAT_Real_Base_gfx10<0x00e> / <0x00f> and the matching GLOBAL_* and SCRATCH_* _gfx10 entries.

The translator takes the dword count from the mnemonic, so the code-table load path (s_getpc_b64 + global_load_dword*) got it wrong both ways. A dwordx3 load read four dwords and also wrote the register after its destination range. A dwordx4 load left its last register unwritten.

The fix swaps the two entries.

Verification

New test global_load_dwordx3_and_dwordx4_write_their_own_register_count in tests/synthetic.rs. It translates a small compute program (s_getpc_b64, two v_mov_b32, global_load_dwordx{4,3} v[4:..], v[0:1], off) for each opcode, then checks which of v4..v7 the HLSL writes and what the decoded mnemonic is.

cargo test --release -p tombox-xshader --test synthetic global_load
Build Result
master at 4f66ea9 fails: flat_load_dwordx4 (op 0xe) and v7, left: false, right: true
this branch passes

On this branch, cargo test --locked --release --workspace passes (synthetic: 16 passed, 1 ignored). The CI DLL build (-p d3d12_xs -p xmem -p xcrdapi -p acphal -p dxcompiler_xs -p mfplat with +crt-static) also succeeds. I ran both on Windows 11 with rustc 1.99.1, not the 1.100.0 that CI pins.

I didn't run this against game shaders, so I don't know how many shaders in the packages use either opcode.

The FLAT/GLOBAL table had the two swapped. GFX10 uses the same order as
MUBUF (LLVM FLATInstructions.td, FLAT_Real_Base_gfx10 and
FLAT_Real_AllAddr_gfx10). A global_load_dwordx3 from a code-section table
was translated as four loads and also overwrote the register after its
destination range; a dwordx4 load left its last register unwritten.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant