tooling: the shader scan reports an unbound entry register as a translator rejection (bare KeyError) #1307

Closed
opened 2026-11-24 07:41:12 +00:00 by MasterDomino · 3 comments
MasterDomino commented 2026-11-24 07:41:12 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T07:41:12Z.


tools/scan_unsupported_shaders.py reports a record as "opcodes recognized, translator rejected" whenever pixel_aot.lower() raises. On one local input, 10,861 of 12,101 records reach that verdict through a bare KeyError. The cause is an entry register that the scanner never binds, not an instruction the translator refuses. The recorded reason is just the register name, 's9'. The scan therefore cannot show what actually blocks the translator.

Setup

  • upstream/main at f9710f64, Windows 11 (build 26300), Python 3.13.1, LLVM 15.0.7 LLVM-C.dll.
  • One local input (12,101 PS records, the same population as #711), extracted with tools/extract_shaders.py --stage pixel --format native. Aggregates only.
  • python -B tools/scan_unsupported_shaders.py --llvm <LLVM-C.dll> --output-dir <out> <records>

What the scanner does

analyze_shader_instructions calls lower() with the same arguments for every record: texture_sgpr=20, interp_sgpr=24, sampler=[1, 2, 3, 4] and no constant bindings. It stores str(e) for any exception. lower() reads an unbound register with a plain scalar[src] / vector[src] lookup, so the stored reason is the bare key.

Measured (lower_error in shader_scan_report.json)

reason records
bare KeyError on an SGPR ('s9' 10,112, 's11' 263, 's17' 159, 's12' 98, 's15' 70, others 46) 10,748
bare KeyError on a VGPR ('v3' 108, others 5) 113
32-bit execution mask save requires a validated wave32 guest profile 826
Unexpected sample count or missing color export 315
Unresolved constant buffer binding 53
other ValueError (writelane, compr export, ds_swizzle, unbound pixel input at a conversion, …) 46
accepted 0

Here is where the unbound register is first read, using LLVM 15 disassembly of the same records with the scanner's arguments. Of the 10,785 records that raise a bare KeyError there:

  • s_mov_b32 sN, sN (a copy of an entry SGPR): 10,334
  • s_mov_b32 m0, sN: 323
  • v_mov_b32_e32 vN, vN: 107
  • other: 21

The scanner and LLVM counts differ slightly because the scanner disassembles with disasm_rdna2.

Experiment, not a proposal. As a local hypothesis check, I patched TrackedScalar.__getitem__ to return an opaque value for any unbound SGPR. With that patch, the first rejections are:

reason records
Unresolved constant buffer binding 7,097
Unbound pixel input vN at v_cvt_u32_f32_e32 921
Unbound texture descriptor offset 834
wave32 profile 801
bare KeyError on a VGPR 451

So even past the entry copy, almost every record stops on a missing binding contract rather than on an instruction. Without per-record bindings, the scan's translator column mostly measures the harness.

Proposed change (one small PR)

  1. pixel_aot.lower(): report an unbound entry register as a ValueError that names the register and the instruction, e.g. Unbound scalar input s9 at instruction N: <instruction>. This matches the existing Unbound pixel input vN at … messages. One way is a single translation of KeyError at the per-instruction dispatch, which covers every handler without touching them one by one. The CLI already catches KeyError and would print the clearer message. Two checks in tests/pixel_aot_check.py currently assert the bare key (('v20',) for the v_mac_legacy accumulator and ('s9',) for an unbound table register). They would assert the new message instead. Both still require a refusal, and the new assertions are stricter.
  2. scan_unsupported_shaders.py: keep the per-record lower_error, but add a summary field that separates unbound entry register (no binding contract supplied) from real translator rejections. The Markdown report would then state that the translator column only covers records whose bindings the scan supplies. No change to the opcode coverage columns.

Out of scope here: inferring each record's real binding contract (descriptor tables, interpolation base, constant buffers). That needs data the extractor does not carry yet. If you prefer, part 2 could wait until such a contract exists, and part 1 could go alone.

@R0Y00, is this worth doing, and should both parts go in one PR or two? I can take it once you confirm.

Limits

  • One local input, and one machine (Windows, LLVM 15.0.7).
  • The opaque-register run is a local diagnostic patch, not translator semantics. Its table only shows what the next missing contract is.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6577023532 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1314). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T07:41:12Z. --- `tools/scan_unsupported_shaders.py` reports a record as "opcodes recognized, translator rejected" whenever `pixel_aot.lower()` raises. On one local input, 10,861 of 12,101 records reach that verdict through a bare `KeyError`. The cause is an entry register that the scanner never binds, not an instruction the translator refuses. The recorded reason is just the register name, `'s9'`. The scan therefore cannot show what actually blocks the translator. ## Setup - `upstream/main` at `f9710f64`, Windows 11 (build 26300), Python 3.13.1, LLVM 15.0.7 `LLVM-C.dll`. - One local input (12,101 PS records, the same population as #711), extracted with `tools/extract_shaders.py --stage pixel --format native`. Aggregates only. - `python -B tools/scan_unsupported_shaders.py --llvm <LLVM-C.dll> --output-dir <out> <records>` ## What the scanner does `analyze_shader_instructions` calls `lower()` with the same arguments for every record: `texture_sgpr=20`, `interp_sgpr=24`, `sampler=[1, 2, 3, 4]` and no constant bindings. It stores `str(e)` for any exception. `lower()` reads an unbound register with a plain `scalar[src]` / `vector[src]` lookup, so the stored reason is the bare key. ## Measured (`lower_error` in `shader_scan_report.json`) | reason | records | |---|---:| | bare `KeyError` on an SGPR (`'s9'` 10,112, `'s11'` 263, `'s17'` 159, `'s12'` 98, `'s15'` 70, others 46) | 10,748 | | bare `KeyError` on a VGPR (`'v3'` 108, others 5) | 113 | | `32-bit execution mask save requires a validated wave32 guest profile` | 826 | | `Unexpected sample count or missing color export` | 315 | | `Unresolved constant buffer binding` | 53 | | other `ValueError` (writelane, `compr` export, ds_swizzle, unbound pixel input at a conversion, …) | 46 | | accepted | 0 | Here is where the unbound register is first read, using LLVM 15 disassembly of the same records with the scanner's arguments. Of the 10,785 records that raise a bare `KeyError` there: - `s_mov_b32 sN, sN` (a copy of an entry SGPR): 10,334 - `s_mov_b32 m0, sN`: 323 - `v_mov_b32_e32 vN, vN`: 107 - other: 21 The scanner and LLVM counts differ slightly because the scanner disassembles with `disasm_rdna2`. **Experiment, not a proposal.** As a local hypothesis check, I patched `TrackedScalar.__getitem__` to return an opaque value for any unbound SGPR. With that patch, the first rejections are: | reason | records | |---|---:| | `Unresolved constant buffer binding` | 7,097 | | `Unbound pixel input vN` at `v_cvt_u32_f32_e32` | 921 | | `Unbound texture descriptor offset` | 834 | | wave32 profile | 801 | | bare `KeyError` on a VGPR | 451 | So even past the entry copy, almost every record stops on a missing binding contract rather than on an instruction. Without per-record bindings, the scan's translator column mostly measures the harness. ## Proposed change (one small PR) 1. **`pixel_aot.lower()`:** report an unbound entry register as a `ValueError` that names the register and the instruction, e.g. `Unbound scalar input s9 at instruction N: <instruction>`. This matches the existing `Unbound pixel input vN at …` messages. One way is a single translation of `KeyError` at the per-instruction dispatch, which covers every handler without touching them one by one. The CLI already catches `KeyError` and would print the clearer message. Two checks in `tests/pixel_aot_check.py` currently assert the bare key (`('v20',)` for the `v_mac_legacy` accumulator and `('s9',)` for an unbound table register). They would assert the new message instead. Both still require a refusal, and the new assertions are stricter. 2. **`scan_unsupported_shaders.py`:** keep the per-record `lower_error`, but add a summary field that separates `unbound entry register` (no binding contract supplied) from real translator rejections. The Markdown report would then state that the translator column only covers records whose bindings the scan supplies. No change to the opcode coverage columns. Out of scope here: inferring each record's real binding contract (descriptor tables, interpolation base, constant buffers). That needs data the extractor does not carry yet. If you prefer, part 2 could wait until such a contract exists, and part 1 could go alone. @R0Y00, is this worth doing, and should both parts go in one PR or two? I can take it once you confirm. ## Limits - One local input, and one machine (Windows, LLVM 15.0.7). - The opaque-register run is a local diagnostic patch, not translator semantics. Its table only shows what the next missing contract is. AI-assisted.
R0Y00 commented 2026-11-24 08:01:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:57:12Z.


Please take this as one focused diagnostics PR. Give missing scalar and vector operand reads a structured diagnostic with the register and instruction (and the byte offset when available), then have the scanner count that diagnostic separately while retaining the per-record reason. Keep unexpected lookup errors distinguishable so an internal bug does not get reported as a missing binding. A small source-built check should distinguish an unbound SGPR, an unbound VGPR, an unsupported opcode, and a bound sample that still translates. Keep the opcode column as-is and describe the acceptance totals as conditional on the bindings supplied by the scan.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125555918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1314#issuecomment-7125555918). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:57:12Z. --- Please take this as one focused diagnostics PR. Give missing scalar and vector operand reads a structured diagnostic with the register and instruction (and the byte offset when available), then have the scanner count that diagnostic separately while retaining the per-record reason. Keep unexpected lookup errors distinguishable so an internal bug does not get reported as a missing binding. A small source-built check should distinguish an unbound SGPR, an unbound VGPR, an unsupported opcode, and a bound sample that still translates. Keep the opcode column as-is and describe the acceptance totals as conditional on the bindings supplied by the scan.
MasterDomino commented 2026-11-24 09:04:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T08:02:22Z.


Claiming this as one diagnostics PR: a structured missing-operand diagnostic for scalar and vector reads (register, instruction, byte offset when available), unexpected lookup errors kept distinguishable, the scanner counting it separately with the per-record reason kept, a source-built check (unbound SGPR, unbound VGPR, unsupported opcode, bound sample that translates), opcode column unchanged and acceptance totals described as conditional on the scan's bindings. I'll link the PR here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125652722 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1314#issuecomment-7125652722). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T08:02:22Z. --- Claiming this as one diagnostics PR: a structured missing-operand diagnostic for scalar and vector reads (register, instruction, byte offset when available), unexpected lookup errors kept distinguishable, the scanner counting it separately with the per-record reason kept, a source-built check (unbound SGPR, unbound VGPR, unsupported opcode, bound sample that translates), opcode column unchanged and acceptance totals described as conditional on the scan's bindings. I'll link the PR here. AI-assisted.
MasterDomino commented 2026-11-24 09:04:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T08:28:57Z.


PR: https://github.com/R0Y00/Xbox2Windows/pull/1337. UnboundOperand (a ValueError) names the bank, register, instruction and byte offset; other missing keys stay KeyError and the scan counts them as unexpected errors. On the local input every verdict is unchanged; the 10,861 bare-key rejections now split into 10,748 unbound scalar and 113 unbound vector operands, leaving 1,240 real rejections.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126187831 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1314#issuecomment-7126187831). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T08:28:57Z. --- PR: https://github.com/R0Y00/Xbox2Windows/pull/1337. `UnboundOperand` (a `ValueError`) names the bank, register, instruction and byte offset; other missing keys stay `KeyError` and the scan counts them as unexpected errors. On the local input every verdict is unchanged; the 10,861 bare-key rejections now split into 10,748 unbound scalar and 113 unbound vector operands, leaving 1,240 real rejections. AI-assisted.
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#1307
No description provided.