tombox-xshader: rebuild image descriptor words read by ALU from the bound view #381

Open
SchmashinPrunes wants to merge 1 commit from upstream-pr/381 into main
SchmashinPrunes commented 2026-11-25 14:44:50 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-25T14:44:50Z.


This is the translator fix proposed under the OPEN entry "Trackmania video boards black" (r32j_2 root cause) in docs/BLOCKERS.md: synthesise descriptor words read by ALU from GetDimensions of the bound resource, and fail loudly on fields that can't be rebuilt. That entry names an owner (a2a4751). If that work is already in progress, close this one.

The bug

A T# loaded from a root table is resolved statically. hlsl.rs emits only // (descriptor fetch from root table — resolved statically) and never writes the destination SGPRs. A shader that also reads those words as data gets 0. The downsample compute shaders in that entry take the destination size from the width/height fields of dword 2 and BASE_LEVEL of dword 3, so the size comes out as 1x1 and every thread samples one texel.

The change

New module hlsl/desc_words.rs:

  • Recording the reads. In the resource pass, every ALU read of a word of a static image descriptor is recorded with the bits it uses. s_bfe_*/v_bfe_* with constant fields, s_and_b32/v_and_b32 with a constant mask, and s_lshr_b32/v_lshrrev_b32 by a constant give exact bits; any other read counts as all 32 bits. Not counted as reads:

    • copies (s_mov, s_cmov);
    • in-place edits of a descriptor word (destination = source), so shaders that patch a T# before using it translate as before;
    • resource operands (SMEM base, MUBUF/MTBUF/MIMG).
  • Rebuilding the words. At the descriptor load, if an image instruction resolved that descriptor to texN/uavN, the words that are read get written from GetDimensions of the view. Field positions are from Mesa's gfx10 register tables (SQ_IMG_RSRC_WORD*) and its ac_build_gfx10_texture_descriptor. Values are relative to the view, the same convention the translator already uses for mips:

    dword field value
    1 WIDTH_LO [31:30] (width − 1) & 3
    2 WIDTH_HI [11:0], HEIGHT [27:14] (width − 1) >> 2, height − 1
    2 RESOURCE_LEVEL [31] 1
    3 BASE_LEVEL [15:12] 0
    3 LAST_LEVEL [19:16] levels − 1 (log2 of the sample count for MSAA)
    3 TYPE [31:28] from the image dim (1D 8 … 2D MSAA 14)
    4 DEPTH [12:0] depth − 1 or layers − 1; 0 otherwise
    4 BASE_ARRAY [28:16] 0
    5 ARRAY_PITCH [3:0] 1 for a 3D UAV, else 0
    5 MAX_MIP [7:4] same as LAST_LEVEL
  • Refusing the rest. A read of any other bits is refused, and the error names the field and the instruction. Those fields are the base address, MIN_LOD, FORMAT, DST_SEL, SW_MODE, BC_SWIZZLE, PITCH_MSB, the dword 5 hardware fields, the metadata words, and cube DEPTH. The PC view doesn't carry any of them. Durango (GCN) shaders are untouched, since their T# layout differs.

Not covered

  • Buffer descriptors (V#) read by ALU keep today's behaviour. Refusing those would also catch shaders that edit V# words in place and translate fine today.
  • Bindless and multi-candidate descriptors keep today's behaviour too.

Behaviour change to check against the corpus

A shader that reads one of the fields above used to translate and silently get 0. It now fails to translate. The likely case is a null-texture test that compares the base address with 0. Before this change such a test always took the "null" branch. Running the title corpora will show how many shaders that affects.

Tests

New tests/exec_mem/desc_words.rs:

  • image_descriptor_words_read_by_salu_come_from_the_view: 7 pixel-shader cases. Each loads the T#, binds it with image_get_resinfo or image_load, then extracts the fields with SALU the way a compiler expands GetDimensions: width rebuilt from WIDTH_LO | WIDTH_HI << 2, height, LAST_LEVEL, TYPE, BASE_LEVEL, DEPTH, BASE_ARRAY and MAX_MIP. Images:
    • a 38x21 2D SRV with 3 mips (38 − 1 has a nonzero WIDTH_LO);
    • an 8x8x3 2D array with 2 mips;
    • an 8x8 2D UAV.
  • image_descriptor_fields_without_a_pc_source_are_refused: reads of DST_SEL, the base address, FORMAT and SW_MODE are refused with the field named; an in-place edit of dword 3 still translates.

Results (Windows 11, DXC from TOMBOX_DXC_DIR):

run result
WARP, without the hlsl.rs change both new tests fail: all 7 cases read 0 (sizes come out as 1)
WARP, full tombox-xshader suite 34 suites ok, exec 191/191
Radeon RX 9060 XT (TOMBOX_EXEC_HW=1), exec 191/191

The PR gate is clean.

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:5493561917 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/381). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-25T14:44:50Z. --- This is the translator fix proposed under the OPEN entry "Trackmania video boards black" (r32j_2 root cause) in `docs/BLOCKERS.md`: synthesise descriptor words read by ALU from `GetDimensions` of the bound resource, and fail loudly on fields that can't be rebuilt. That entry names an owner (a2a4751). If that work is already in progress, close this one. ### The bug A T# loaded from a root table is resolved statically. `hlsl.rs` emits only `// (descriptor fetch from root table — resolved statically)` and never writes the destination SGPRs. A shader that also reads those words as data gets 0. The downsample compute shaders in that entry take the destination size from the width/height fields of dword 2 and `BASE_LEVEL` of dword 3, so the size comes out as 1x1 and every thread samples one texel. ### The change New module `hlsl/desc_words.rs`: - **Recording the reads.** In the resource pass, every ALU read of a word of a static image descriptor is recorded with the bits it uses. `s_bfe_*`/`v_bfe_*` with constant fields, `s_and_b32`/`v_and_b32` with a constant mask, and `s_lshr_b32`/`v_lshrrev_b32` by a constant give exact bits; any other read counts as all 32 bits. Not counted as reads: - copies (`s_mov`, `s_cmov`); - in-place edits of a descriptor word (destination = source), so shaders that patch a T# before using it translate as before; - resource operands (SMEM base, MUBUF/MTBUF/MIMG). - **Rebuilding the words.** At the descriptor load, if an image instruction resolved that descriptor to `texN`/`uavN`, the words that are read get written from `GetDimensions` of the view. Field positions are from Mesa's gfx10 register tables (`SQ_IMG_RSRC_WORD*`) and its `ac_build_gfx10_texture_descriptor`. Values are relative to the view, the same convention the translator already uses for mips: | dword | field | value | |---|---|---| | 1 | `WIDTH_LO` [31:30] | (width − 1) & 3 | | 2 | `WIDTH_HI` [11:0], `HEIGHT` [27:14] | (width − 1) >> 2, height − 1 | | 2 | `RESOURCE_LEVEL` [31] | 1 | | 3 | `BASE_LEVEL` [15:12] | 0 | | 3 | `LAST_LEVEL` [19:16] | levels − 1 (log2 of the sample count for MSAA) | | 3 | `TYPE` [31:28] | from the image dim (1D 8 … 2D MSAA 14) | | 4 | `DEPTH` [12:0] | depth − 1 or layers − 1; 0 otherwise | | 4 | `BASE_ARRAY` [28:16] | 0 | | 5 | `ARRAY_PITCH` [3:0] | 1 for a 3D UAV, else 0 | | 5 | `MAX_MIP` [7:4] | same as `LAST_LEVEL` | - **Refusing the rest.** A read of any other bits is refused, and the error names the field and the instruction. Those fields are the base address, `MIN_LOD`, `FORMAT`, `DST_SEL`, `SW_MODE`, `BC_SWIZZLE`, `PITCH_MSB`, the dword 5 hardware fields, the metadata words, and cube `DEPTH`. The PC view doesn't carry any of them. Durango (GCN) shaders are untouched, since their T# layout differs. ### Not covered - Buffer descriptors (V#) read by ALU keep today's behaviour. Refusing those would also catch shaders that edit V# words in place and translate fine today. - Bindless and multi-candidate descriptors keep today's behaviour too. ### Behaviour change to check against the corpus A shader that reads one of the fields above used to translate and silently get 0. It now fails to translate. The likely case is a null-texture test that compares the base address with 0. Before this change such a test always took the "null" branch. Running the title corpora will show how many shaders that affects. ### Tests New `tests/exec_mem/desc_words.rs`: - `image_descriptor_words_read_by_salu_come_from_the_view`: 7 pixel-shader cases. Each loads the T#, binds it with `image_get_resinfo` or `image_load`, then extracts the fields with SALU the way a compiler expands `GetDimensions`: width rebuilt from `WIDTH_LO | WIDTH_HI << 2`, height, `LAST_LEVEL`, `TYPE`, `BASE_LEVEL`, `DEPTH`, `BASE_ARRAY` and `MAX_MIP`. Images: - a 38x21 2D SRV with 3 mips (38 − 1 has a nonzero `WIDTH_LO`); - an 8x8x3 2D array with 2 mips; - an 8x8 2D UAV. - `image_descriptor_fields_without_a_pc_source_are_refused`: reads of `DST_SEL`, the base address, `FORMAT` and `SW_MODE` are refused with the field named; an in-place edit of dword 3 still translates. **Results** (Windows 11, DXC from `TOMBOX_DXC_DIR`): | run | result | |---|---| | WARP, without the `hlsl.rs` change | both new tests fail: all 7 cases read 0 (sizes come out as 1) | | WARP, full `tombox-xshader` suite | 34 suites ok, exec 191/191 | | Radeon RX 9060 XT (`TOMBOX_EXEC_HW=1`), exec | 191/191 | The PR gate is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/381:upstream-pr/381'
git switch 'upstream-pr/381'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/381'
git switch 'upstream-pr/381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/381'
git switch 'upstream-pr/381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/381'
git switch 'main'
git merge --squash 'upstream-pr/381'
git switch 'main'
git merge --ff-only 'upstream-pr/381'
git switch 'main'
git merge 'upstream-pr/381'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!381
No description provided.