tombox-xshader: lower scratch (private memory) loads and stores to a per-thread array #284
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!284
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/284/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?
@MeNoSkills on GitHub · 2026-11-23 12:15 UTC · original
MeNoSkills:feat/scratch-memory→main· +247 −1 · 5 files · 1 commits · closed without mergingScratch (thread-private memory) loads and stores were refused: a
flat_store_*in the scratch segment failed with "scratch-segment access unsupported" and aflat_load_*with "scratch-memory load unsupported", so any shader that spills to scratch did not translate. This lowers them.Model
Scratch is memory private to each lane. The translator runs one lane per thread, so a
static uint tb_scr[1024]in the translated HLSL (a static global is thread-private in HLSL) is that memory. The address of an access is:plus the signed 12-bit instruction offset. The offset decoding is unchanged (and pinned by
opcodes.rs::flat_global_and_scratch_offsets_do_not_take_the_dlc_bit).All the plain flat load and store widths take part:
ubyte,sbyte,ushort,sshort,dword,dwordx2,dwordx3,dwordx4, and the storesbyte,short,dword,dwordx2,dwordx3,dwordx4with the_d16_hivariants. Sub-dword and unaligned accesses are done byte by byte, so they work at any alignment. A lane with exec off neither reads nor writes.New
hlsl/scratch.rsholds the helpers andemit_scratch;hlsl.rsgets ascratchmodule, auses_scratchflag and one match arm forEnc::Flatwith the scratch segment, placed before the global routing arm. The global path is untouched.Assumptions, stated plainly
scratch::DWORDS). The real scratch size of a shader is not in anything the translator reads, so I did not guess a per-shader value. An access outside the array reads 0 and a write outside it is dropped; on the console that would be a fault._d16loads), and the LDS=1 forms.Tests
exec_vop::scratch(new): 22 cases, run through the pixel-shader exec harness. Round trips for dword, with the offset positive and negative and the address in a second register; an out-of-range access (reads 0); every sub-dword load (ubyte/sbyte/ushort/sshort, signed and unsigned results);store_byteandstore_shortread-modify-write inside a dword; an unaligned dword store read back at three alignments;dwordx2/dwordx4store and load, and one dword read out of adwordx4store; and two cases that address the access through an SGPR (SADDR set), one for a store, one for a load.TOMBOX_EXEC_HW=1). Without the change all of them fail with "scratch-segment access unsupported".exec_mem::global::global_routing_and_refusalsasserted that a scratch store is refused; that case now uses a scratch-segment atomic, which is still refused with an error that names "scratch".--lib116,--test synthetic24,--test isa_sweep2,--test mesh24,--test opcodes26, and the full--test execrun withTOMBOX_EXEC_HW=1: 130 passed, 0 failed, 2 ignored (1704 s).python .github/scripts/pr_gate.py --base upstream/main --head HEAD: 0 problems. The branch is on mainf89e410.Stage criteria
Per the answer in #187 this does not move a stage by itself: it removes one reason a real shader could fail to translate, and adds bit-exact exec tests for the new instructions. It is not tied to a BLOCKERS item.
Not verified
No real shader, and nothing run on AMD hardware. The 4 KiB size and the out-of-range behaviour are my choices (above), not measured console behaviour.
@omonkeyz on GitHub · 2026-11-23 14:08 UTC · original
Applied locally on main with your authorship kept (cherry-picked,
4f1cd12); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.@omonkeyz on GitHub · 2026-11-25 13:08 UTC · original
Applied on main in
4f1cd12(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed