xshader: deterministic HLSL emission; GDS base from M0[31:16] per ISA #21
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21"
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 omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T17:37:29Z.
Library / area: tombox-xshader (HLSL emission, GDS lowering)
Exports changed (exports.txt rows): none
Source of the behaviour: brcly/TomBox 2c729ef (GDAgent, crates declare MIT OR Apache-2.0); AMD RDNA2 ISA guide (30 Nov 2020) §3.7 and §10.5
1. Deterministic HLSL
emit_bodybuilds its loop list by iterating aHashMap, so thebool tb_c{b}declarations come out in hash order. The same shader can then give different HLSL text, and so a different shader-cache key and a recompile. The list is now sorted before emission (port of 2c729ef). I checked every otherHashMap/HashSetiteration inhlsl.rsandhlsl/*.rs; none of them affects the emitted text.New test
tests/synthetic.rs::loops_translate_deterministicallytranslates a 6-loop compute shader 17 times. It fails without the sort and passes with it.2. GDS base = M0[31:16]
hlsl/gds.rsusedm0 & 0xffffas the GDS base. The ISA defines GDS M0 as{base[31:16], size[15:0]}in bytes (§3.7 M# descriptor, §10.5 "[15:0] holds SIZE … [31:16] holds BASE"; DS_APPEND/DS_CONSUME useM0.base). LLVM's GWS/append lowering also puts the base in the high half. The existing test was written to the same low-bits assumption. Now:addr = ((m0 >> 16) + vaddr + offset) & ~3(onlyoffsetfor append/consume);vaddr + offset < (m0 & 0xffff)and inside the emulated buffer. Out of range: writes are dropped and reads return 0, which is the existing path (§3.6, §10.4.3).tests/exec_mem/gds.rsnow builds M0 asbase << 16 | size. It covers nonzero bases (0x100, 0x200, 0xfbf8 at the buffer limit) and a size-clamp case where half the lanes fall outsidesize. The new tests fail against the oldgds.rs(0/2) and pass with the fix (2/2).I had no title GDS shader to check this against (none in the repo). If you have title evidence that M0 carries the base in the low bits, that would override the ISA reading.
Tests
cargo test -p tombox-xshader --release --test exec exec_mem::gds: 2/2cargo test -p tombox-xshader --release --test synthetic: 8/8cargo test -p tombox-xshader --release --lib: 8/8full
--test exec: no new failures. The 4vop::basicfailures are already present at226938cand are fixed in a separate PR.--test fixtureswas not run:analysis/shadersis not in the repo (see #13).cargo test -p tombox-xshaderpasses (except the pre-existing failures above)No game or console files and no binaries included
No fake success; anything not possible is left
missingwith a noteImported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T21:03:20Z.
Merged in the source sync
1159c96(adapted). Thanks! Closing.Pull request closed