tombox-xshader: read scalar NULL operands as zero #308
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!308
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/308/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?
@BaggyALPHA on GitHub · 2026-11-23 17:31 UTC · original
BaggyALPHA:fix/scalar-null-zero→main· +60 −3 · 2 files · 2 commits · closed without mergingNULL reads can reuse values written to the translator's internal HLSL discard variable. For example,
s_mov_b32 null, 1makes a subsequent move from NULL return 1. Reads encoded in SOPK's destination/source field can also leak discarded values: after writing0x7fffffffto NULL,s_addk_i32 null, 1incorrectly sets signed-overflow SCC;s_setreg_b32can copy a discarded value into MODE.Resolve explicit
Opnd::Nullsource expressions to0uand route the encoded source reads ins_addk_i32,s_mulk_i32, ands_setreg_b32through the same operand-expression helper. Retain the internal discard destination so instructions such ass_not_b32 null, nullstill derive SCC from their computed result.Library / area:
tombox-xshader, scalar operand lowering and synthetic execution tests.Exports changed (exports.txt rows): None.
Source of the behaviour: AMD RDNA 2 ISA: section 5.2, Table 10 defines NULL reads/writes; section 12.2 defines add-immediate overflow and hardware-register writes; section 13.1.2, Table 65 includes NULL in the SOPK SDST field, which can supply an input operand.
Validation:
Original six-case regression: five fail on upstream main. All six pass with the fix.
Additional 24-case SOPK regression: seven fail on the initial PR commit
dc6c49b; all 24 pass after the follow-up. Coverage includes NULL add-immediate overflow flags, NULL MODE-register writes, ordinary-SGPR overflow controls, and ordinary-SGPR MODE writes.Both regression tests (30 cases) pass on WARP and the hardware D3D12 path (
TOMBOX_EXEC_HW=1).Full
cargo test --locked -p tombox-xshader --no-fail-fast: exit 0, 347 passed, zero failed, 18 ignored. The execution target passed 130 tests with two ignored.WARP ISA sweep: 544 passing mnemonics, zero unexpected failures, 11 known WARP deviations and 28 skipped mnemonics. Deviations/skips are not claimed as bit-exact passes.
cargo check --locked -p tombox-xshader --all-targets: passed.Contribution gate: two files checked, zero problems. Whitespace and patch application checks passed.
Full default crate test command run; limitations below remain.
No game or console files and no binaries included.
No fake success; no export status changes.
Related to #187's request for synthetic instruction edge-case coverage. Fixture-dependent tests may be conditionally excluded or return early without title/console inputs. No console DLL oracle, native RDNA2 silicon execution, or title compatibility validation is claimed; this does not establish completion of a shader stage.
Required upstream CI results remain separate from local validation.
@omonkeyz on GitHub · 2026-11-25 13:49 UTC · original
Applied on main in
15d9930(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. The
Null => "0u"arm is inr()only, so writes to NULL still go to the discard variable, and the SCC ofs_not_b32 null, nullstill comes from the computed result. Thes_setreg_b32,s_addk_i32ands_mulk_i32changes read the field as a source, which is right. Scope: CI hasn't run on this PR yet; the workflows are waiting for maintainer approval. My approval covers the semantics and the code, not the build or the test run.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).
The NULL rules hold on hardware:
s_mov_b32 null, X(4,096 random X),s_mov_b32 sN, nullreads 0.s_add_u32 sN, null, Ygives Y with SCC 0.s_addk_i32 null, 1after writing 0x7fffffff to NULL leaves SCC 0, so the add reads 0, not the discarded value.s_not_b32 null, nullsets SCC 1, which is the computed result's SCC, as you describe.I didn't check the
s_setreg_b32case.(Measured with an AI assistant, Claude.)
Pull request closed