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

Open
github-bot wants to merge 1 commit from github-bot/gh-381 into main AGit
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-25 14:44 UTC · original
SchmashinPrunes:desc-words-from-view → main · +295 −1 · 4 files · 1 commits · open

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

**@⁠SchmashinPrunes** on GitHub · 2026-11-25 14:44 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/381) `SchmashinPrunes:desc-words-from-view` → `main` · +295 −1 · 4 files · 1 commits · open 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)
A T# loaded from a root table was resolved statically and its SGPRs were
never written, so SALU/VALU reads of its words returned 0 (BLOCKERS,
Trackmania video boards: downsample shaders read the size from dword 2
and BASE_LEVEL from dword 3 and got 1x1).

Record every ALU read of a static image descriptor word with the bits it
uses, and at the load write the read words from GetDimensions of the
resolved texN/uavN: WIDTH_LO, WIDTH_HI, HEIGHT, RESOURCE_LEVEL,
BASE_LEVEL, LAST_LEVEL, TYPE, DEPTH, BASE_ARRAY, ARRAY_PITCH and
MAX_MIP, view-relative, laid out per the gfx10 SQ_IMG_RSRC_WORD tables.
Reads of fields the PC view does not carry (address, format, DST_SEL,
SW_MODE, MIN_LOD, metadata) are refused with the field named. Copies,
in-place edits and resource operands are not reads. Durango and buffer
descriptors are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:20:58 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/381/head:github-bot/gh-381'
git switch 'github-bot/gh-381'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-381'
git switch 'github-bot/gh-381'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-381'
git switch 'github-bot/gh-381'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-381'
git switch 'main'
git merge --squash 'github-bot/gh-381'
git switch 'main'
git merge --ff-only 'github-bot/gh-381'
git switch 'main'
git merge 'github-bot/gh-381'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.