tombox-xshader: SOP1 ops with a 32-bit result of a 64-bit source write one SGPR #331

Closed
github-bot wants to merge 1 commit from gh-pr/331/head into gh-pr/331/base
Owner

@⁠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 merging

Library / 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_B64 and S_FLBIT_I32_I64 read 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 treated dst+1 as written too:

  • SGPR symbol pass (collect fallback arm): it dropped what dst+1 held. A root-table pointer copied into dst+1 was lost, and the next s_load from it was refused with "base sN is not a root table pointer".
  • live_in: it marked dst+1 as 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_after and 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 skip dst+1 for them. Every other _b64 / _u64 / _i64 op is handled as before.
  • s_bcnt1_i32_b64 now 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:

  • Two compute shaders (CopyStatsCS and a MainCS) were refused because s_ff1_i32_b64 wrote the register just below a table or code pointer. Both translate now and compile with DXC (cs_6_5).
  • 379 shaders of the title use one of the six ops. With the old and new translator side by side:
    • 359 give byte-identical HLSL;
    • 2 newly translate (the pair above);
    • 18 still fail, as before, for unrelated reasons;
    • none changed output, and none newly fail.

Tests

Tests (tests/exec_mem/sop1_dst.rs; executed on WARP by default, on the GPU with TOMBOX_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 into dst+1 still drives an image_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 at dst+1 stays entry-live and reads its bound value.
  • Before the change, both tests fail for the five _b64 ops. 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; exec 130 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 full exec binary 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 plain main (f89e410) on this GPU: f16_omod_follows_mode, exec_mem::mtbuf::mtbuf_d16_store_formats, scalar_smem_loads and vop::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 exec suite 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 missing with a note

**@⁠GDAgent** on GitHub · 2026-11-23 20:21 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/331) `GDAgent:fix/xshader-sop1-i32-b64-dest` → `main` · +104 −7 · 6 files · 1 commits · closed without merging **Library / 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_B64` and `S_FLBIT_I32_I64` read 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 treated `dst+1` as written too: - **SGPR symbol pass** (`collect` fallback arm): it dropped what `dst+1` held. A root-table pointer copied into `dst+1` was lost, and the next `s_load` from it was refused with "base sN is not a root table pointer". - **`live_in`**: it marked `dst+1` as 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_after` and 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 skip `dst+1` for them. Every other `_b64` / `_u64` / `_i64` op is handled as before. - `s_bcnt1_i32_b64` now 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: - Two compute shaders (`CopyStatsCS` and a `MainCS`) were refused because `s_ff1_i32_b64` wrote the register just below a table or code pointer. Both translate now and compile with DXC (`cs_6_5`). - 379 shaders of the title use one of the six ops. With the old and new translator side by side: - 359 give byte-identical HLSL; - 2 newly translate (the pair above); - 18 still fail, as before, for unrelated reasons; - none changed output, and none newly fail. ## Tests Tests (`tests/exec_mem/sop1_dst.rs`; executed on WARP by default, on the GPU with `TOMBOX_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 into `dst+1` still drives an `image_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 at `dst+1` stays entry-live and reads its bound value. - Before the change, both tests fail for the five `_b64` ops. 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; `exec` 130 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 full `exec` binary 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 plain `main` (f89e410) on this GPU: `f16_omod_follows_mode`, `exec_mem::mtbuf::mtbuf_d16_store_formats`, `scalar_smem_loads` and `vop::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 `exec` suite is not green on the GPU used (see the four existing failures above), so "all GPU tests pass" is not claimed. - [x] Tests pass for what is listed above (the 4 GPU-only failures on this card are pre-existing on `main`) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
s_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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:19:13 +00:00
github-bot closed this pull request 2026-11-26 06:19:13 +00:00
Author
Owner

@⁠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.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/331#issuecomment-7164357022) Applied on main in 2f32df0 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.
Author
Owner

@⁠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_64 matches exactly the six SOP1 ops that write one SGPR, with no other _b64/_i64 mnemonic 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+1 preset to a sentinel, it was unchanged after every one of 4,096 cases per op, for s_bcnt0_i32_b64, s_bcnt1_i32_b64, s_ff0_i32_b64, s_ff1_i32_b64, s_flbit_i32_b64 and s_flbit_i32_i64.

The values match the models in the test too:

  • popcounts;
  • first-set and first-clear bit, 0xffffffff when there is none;
  • leading zeros for flbit_b64;
  • leading sign-equal bits for flbit_i64, 0xffffffff for 0 and -1.

The bcnt ops set SCC = (result != 0), while ff/flbit leave it unchanged.

(Measured with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/331#pullrequestreview-6041178170) · **approved these changes** **Update:** I've now also read the full diff. `i32_result_of_64` matches exactly the six SOP1 ops that write one SGPR, with no other `_b64`/`_i64` mnemonic 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+1` preset to a sentinel, it was unchanged after every one of 4,096 cases per op, for `s_bcnt0_i32_b64`, `s_bcnt1_i32_b64`, `s_ff0_i32_b64`, `s_ff1_i32_b64`, `s_flbit_i32_b64` and `s_flbit_i32_i64`. The values match the models in the test too: - popcounts; - first-set and first-clear bit, 0xffffffff when there is none; - leading zeros for flbit_b64; - leading sign-equal bits for flbit_i64, 0xffffffff for 0 and -1. The bcnt ops set SCC = (result != 0), while ff/flbit leave it unchanged. (Measured with an AI assistant, Claude.)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.