tooling: print the normalized first-refusal shape of each refused key #3946

Manually merged
github merged 3 commits from github-bot/gh-3944 into gh-pr/3944/base 2026-12-03 16:47:02 +00:00 AGit
Owner

@⁠triggered02 on GitHub · 2026-12-03 15:59 UTC · original
triggered02:feat/refusal-shapes → main · +546 −6 · 3 files · 3 commits · merged 2026-12-03 16:40 UTC

Refs #3705, #3816.

tools/startup/refusal_census.py ranks refused keys by the draws and dispatches they block, but it only shows the normalized refusal text — never the instruction window. That is why the #3705 rows (H1/H2/U1) are on hold for "normalized first-refusal shapes" and why the #3816 pixel bands cannot become fixtures: as the issue says, a fixture without the shape "would only be guessing".

What this adds. --shapes decodes each refused key's cached request program around the instruction offset its first refusal names, using the translator's own printer (tools/disasm_rdna2.py through gfx2hlsl.strip_header/decode_instruction — the same one that produced the refusal text, so the decoding cannot disagree with it), and aggregates the normalized window:

| # | keys | blocked weight | stages | shape |
| 1 |  2   |      11        | compute | s_mov_b32 sN, 0xK
|   |      |                |         | buffer_load_dword vN, vN, s[N:N+3], sN idxen offset:K
|   |      |                |         | **ds_swizzle_b32 vN, vN offset:swizzle(SWAP,K)**
|   |      |                |         | v_mov_b32_e32 vN, sN
|   |      |                |         | s_endpgm |

Registers become sN/vN/ttmpN with the range width kept, immediates 0xK/K, offsets offset:K; the refusing instruction is bold; keys sharing a window collapse into one row with their count and summed blocked weight. In the synthetic capture, two keys that differ in every register, every immediate and the capture layout (one carrying a 36-byte native header with a capture-relative PC) collapse to a single shape.

Safe to paste into an issue. The section prints counts and normalized instruction text only — no program bytes, request keys, module names or title data — and the docstring, --help and the docs entry all say so. Without the repository disassembler it exits with a capability message instead of a traceback.

Tests: six new cases in tests/startup_refusal_census_check.py (so the existing ctest startup_refusal_census picks them up) covering the collapse, the stripped-relative offset convention, the mnemonic fallback with its .rtv base-request variant, the key-free unshaped report (asserting the raw words and keys never appear), the capability error and --shape-window validation. python3 -B tests/startup_refusal_census_check.py → 17 tests, OK; docs_links_check and bidi_controls_check pass.

What it cannot do — and the useful part of that. It needs a real capture to be useful; the tests prove the mechanism, not any translateable shader. And a refusal line carrying neither +0x nor a mnemonic has no site, so it is counted under a fixed reason rather than guessed. Many slot-86 .m86/.ps86 refusals are DXC diagnostics with no instruction offset, so for the #3816 bands this will mostly report "the refusal text names no site" — which is itself actionable: it says a PC-bearing refusal line is needed before those bands can become fixtures. It proves the first-refusal site and its operand shape, not the lowering.

**@⁠triggered02** on GitHub · 2026-12-03 15:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944) `triggered02:feat/refusal-shapes` → `main` · +546 −6 · 3 files · 3 commits · merged 2026-12-03 16:40 UTC Refs #3705, #3816. `tools/startup/refusal_census.py` ranks refused keys by the draws and dispatches they block, but it only shows the normalized refusal *text* — never the instruction window. That is why the #3705 rows (H1/H2/U1) are on hold for "normalized first-refusal shapes" and why the #3816 pixel bands cannot become fixtures: as the issue says, a fixture without the shape "would only be guessing". **What this adds.** `--shapes` decodes each refused key's cached request program around the instruction offset its first refusal names, using the translator's own printer (`tools/disasm_rdna2.py` through `gfx2hlsl.strip_header`/`decode_instruction` — the same one that produced the refusal text, so the decoding cannot disagree with it), and aggregates the normalized window: ``` | # | keys | blocked weight | stages | shape | | 1 | 2 | 11 | compute | s_mov_b32 sN, 0xK | | | | | buffer_load_dword vN, vN, s[N:N+3], sN idxen offset:K | | | | | **ds_swizzle_b32 vN, vN offset:swizzle(SWAP,K)** | | | | | v_mov_b32_e32 vN, sN | | | | | s_endpgm | ``` Registers become `sN`/`vN`/`ttmpN` with the range width kept, immediates `0xK`/`K`, offsets `offset:K`; the refusing instruction is bold; keys sharing a window collapse into one row with their count and summed blocked weight. In the synthetic capture, two keys that differ in every register, every immediate **and** the capture layout (one carrying a 36-byte native header with a capture-relative PC) collapse to a single shape. **Safe to paste into an issue.** The section prints counts and normalized instruction text only — **no program bytes, request keys, module names or title data** — and the docstring, `--help` and the docs entry all say so. Without the repository disassembler it exits with a capability message instead of a traceback. **Tests:** six new cases in `tests/startup_refusal_census_check.py` (so the existing ctest `startup_refusal_census` picks them up) covering the collapse, the stripped-relative offset convention, the mnemonic fallback with its `.rtv` base-request variant, the key-free unshaped report (asserting the raw words and keys never appear), the capability error and `--shape-window` validation. `python3 -B tests/startup_refusal_census_check.py` → **17 tests, OK**; `docs_links_check` and `bidi_controls_check` pass. **What it cannot do — and the useful part of that.** It needs a real capture to be useful; the tests prove the mechanism, not any translateable shader. And a refusal line carrying neither `+0x` nor a mnemonic has no site, so it is counted under a fixed reason rather than guessed. Many slot-86 `.m86`/`.ps86` refusals are DXC diagnostics with no instruction offset, so for the #3816 bands this will mostly report *"the refusal text names no site"* — which is itself actionable: it says a PC-bearing refusal line is needed before those bands can become fixtures. It proves the first-refusal site and its operand shape, not the lowering.
refusal_census.py ranked refused shader keys by blocked weight but never
showed the instruction window, so the rows of #3703 and the pixel bands of
#3814 could not be turned into fixtures without guessing the shape.

--shapes disassembles each refused key's cached request program around the
instruction offset its first refusal names, using the translator's own
decoder (tools/disasm_rdna2.py through tools/startup/gfx2hlsl.py), and
aggregates the normalized window: registers as sN/vN/ttmpN with the range
width kept, immediates as 0xK/K, offsets as offset:K. Keys that differ only
in a register number or an immediate share one row with a key count and the
summed blocked weight. A refusal that names no +0x offset is placed by the
one mnemonic it names when that mnemonic occurs once; otherwise the key is
listed under a fixed reason. The section prints counts and normalized
instruction text only: no program bytes, request keys, module names or title
data. Without the repository disassembler the mode fails with a capability
message instead of a traceback.

Tests: six new cases in startup_refusal_census_check.py cover the
normalization collapse (including the 36-byte native header and both offset
conventions), the graphics mnemonic fallback with an RTV variant, the
key-free unshaped report, the capability error and the window validation.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 16:08:54 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-03 15:59 UTC · original · edited 2026-12-03 16:03 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T16:03:44.425658Z 10bbaf1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-03 15:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#issuecomment-7384080564) · edited 2026-12-03 16:03 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"10bbaf184b68d8338f84019e1e2d29cc652771ab","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-12-03T16:03:44.425658Z">2026-12-03T16:03:44.425658Z</relative-time> | `10bbaf1` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-03 16:03 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10bbaf184b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-03 16:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#pullrequestreview-6173479065) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `10bbaf184b` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
@ -273,0 +335,4 @@
line = SHAPE_REGISTER.sub(r"\1N", line)
line = SHAPE_HEX.sub("0xK", line)
line = SHAPE_FLOAT.sub("F", line)
line = SHAPE_NUMBER.sub("K", line)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-03 16:03 UTC · original

P2 Badge Keep numeric opcode suffixes in refusal shapes

When instruction mnemonics contain digits, such as buffer_load_dwordx2 versus buffer_load_dwordx4, this replacement normalizes opcode characters as well as operand values, so distinct operations collapse into the same shape row. The census can therefore report different refusal causes as one shared shape; restrict number normalization to operands and offsets.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-03 16:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#discussion_r4787516767) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep numeric opcode suffixes in refusal shapes** When instruction mnemonics contain digits, such as `buffer_load_dwordx2` versus `buffer_load_dwordx4`, this replacement normalizes opcode characters as well as operand values, so distinct operations collapse into the same shape row. The census can therefore report different refusal causes as one shared shape; restrict number normalization to operands and offsets. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -273,0 +410,4 @@
"""
if offset is None:
return None
for at in dict.fromkeys((offset, offset - header)):
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-03 16:03 UTC · original

P2 Badge Apply the header shift before matching native offsets

For a native refusal against a capture with a stripped header, if both offset and offset-header are valid instruction boundaries containing the same mnemonic, this loop picks offset first. Native failures report capture-relative PCs, so the actual instruction is at offset-header; the emitted window then describes another occurrence and contaminates shape aggregation. Select the offset convention from the refusal source or prefer the shifted candidate for native lines.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-03 16:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#discussion_r4787516782) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Apply the header shift before matching native offsets** For a native refusal against a capture with a stripped header, if both `offset` and `offset-header` are valid instruction boundaries containing the same mnemonic, this loop picks `offset` first. Native failures report capture-relative PCs, so the actual instruction is at `offset-header`; the emitted window then describes another occurrence and contaminates shape aggregation. Select the offset convention from the refusal source or prefer the shifted candidate for native lines. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 16:13 UTC · original · requested changes

Independent check on 10bbaf18: the census suite passed 17/17 and the docs check passed 1,010 links. A source-built case shows the wrong instruction can still be marked as the first refusal.

I appended harmless v_mov instructions before s_endpgm in the existing 0x24-byte-header fixture, so the native capture-relative +0x38 is also a valid stripped-program boundary. The actual ds_swizzle_b32 is at stripped +0x14. With a native diagnostic that gives only the PC, shape_of returns a bold v_mov_b32_e32 at stripped +0x38. Giving the diagnostic an explicit ds_swizzle_b32 mnemonic produces the correct +0x14 shape. The first case silently counts the shape against the wrong opcode.

Please resolve the offset in the coordinate system of the diagnostic producer (or report the site as ambiguous if that origin cannot be established). Add a fixture where both offsets are valid boundaries and the native diagnostic has no mnemonic, plus the stripped-program counterpart so neither producer regresses.

**@⁠R0Y00** on GitHub · 2026-12-03 16:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#pullrequestreview-6173664867) · **requested changes** Independent check on 10bbaf18: the census suite passed 17/17 and the docs check passed 1,010 links. A source-built case shows the wrong instruction can still be marked as the first refusal. I appended harmless v_mov instructions before s_endpgm in the existing 0x24-byte-header fixture, so the native capture-relative +0x38 is also a valid stripped-program boundary. The actual ds_swizzle_b32 is at stripped +0x14. With a native diagnostic that gives only the PC, shape_of returns a bold v_mov_b32_e32 at stripped +0x38. Giving the diagnostic an explicit ds_swizzle_b32 mnemonic produces the correct +0x14 shape. The first case silently counts the shape against the wrong opcode. Please resolve the offset in the coordinate system of the diagnostic producer (or report the site as ambiguous if that origin cannot be established). Add a fixture where both offsets are valid boundaries and the native diagnostic has no mnemonic, plus the stripped-program counterpart so neither producer regresses.
A native refusal's PC counts from the capture (the native compiler decodes
from the captured entry, 0x24 into a headered c67), while a translator
refusal counts from the stripped program. instruction_at tried both
readings and preferred the unshifted one, so when both happened to be
instruction boundaries - harmless v_mov words appended before s_endpgm -
a native PC-only diagnostic was silently attributed to the wrong opcode
(the v_mov at stripped +0x38 instead of the ds_swizzle_b32 at +0x14,
reproduced by R0Y00 on hardware).

The offset is now resolved in the coordinate system of the diagnostic's
producer first: a "native compute +0x..." line (the native compiler's
refuse(), written verbatim into <key>.fail by compile_dxil.cpp) shifts by
the stripped header before matching, and every other line keeps the
translator's stripped coordinates. When the producer's own convention
lands on no instruction boundary but the other one does, the key is
listed under a fixed ambiguity reason instead of silently taking the
other reading; a mnemonic the same line names that matches that other
boundary still establishes the site, because the bold opcode is then the
one the diagnostic itself names.

The normalized first-refusal text also keeps mnemonics verbatim, digits
included: they are part of the opcode, so buffer_load_dwordx2 and
buffer_load_dwordx4 no longer collapse into one row.

Tests: four new cases cover the native PC-only capture where both offsets
are boundaries (bold ds_swizzle_b32 at stripped +0x14, never a v_mov), a
translator PC read from the stripped program, the fixed ambiguity reason
row, and the distinct x2/x4 shapes and class rows. The 17 existing cases
keep passing.

Refs #3944
Author
Owner

@⁠triggered02 on GitHub · 2026-12-03 16:23 UTC · original

@⁠R0Y00 Fixed in 47959c62, and your reproduction is now a test rather than an anecdote.

The coordinate system. The producer is now established from the diagnostic text: a native compute +0x…: line (src/gfx1013_compute_native.cpp) decodes from the captured entry, so its PC is capture-relative and the stripped header is applied before matching; every other line is gfx2hlsl's, which decodes strip_header(code), so it is already stripped-relative.

The both-boundaries case. If the producer's own convention lands on no instruction boundary but the other one does, the key is listed under a fixed reason — "the refusal offset is an instruction boundary only in the other producer's coordinate system" — instead of silently taking the other reading. The exception, which is what keeps translator offsets working: a mnemonic the same line names that matches the other boundary still establishes the site, because then the bold opcode is exactly the one the diagnostic named.

Against your fixture (0x24 header, v_movs appended so stripped +0x38 is also a boundary, native PC-only diagnostic):

before:  ...**v_mov_b32_e32 vN, sN**...                                  <- confidently wrong
after:   s_mov_b32 sN, 0xK / buffer_load_dword … / **ds_swizzle_b32 …** / v_mov_b32_e32 …

and the ambiguity control (a translator +0x38 that only the capture shift places) now reports the fixed reason with 0 shaped keys instead of guessing ds_swizzle.

Codex's two P2s:

  • opcode digits survive normalization now — buffer_load_dwordx2 and buffer_load_dwordx4 produce two rows instead of collapsing into one class row (the digit-eater was in the class text normalization, not in the shape line);
  • the header shift is applied before matching, not as a fallback — same root cause as the blocker.

Fixture and tests (both in tests/startup_refusal_census_check.py, still ctest startup_refusal_census): your both-boundary native case, a translator stripped-PC case, the fixed ambiguity row, and the x2/x4 split — 21 tests, OK; docs_links_check (285 files, 1010 links) and bidi_controls_check (3090 files) pass.

What is still uncertain, stated plainly: the producer is inferred from the diagnostic text, not from metadata. Only the native compute +0x…: prefix is recognised as capture-relative — it is the sole native refusal shape today, since one refuse() is shared by the compute/graphics/mesh paths and compile_dxil writes error.what() verbatim. Any other producer with capture-relative offsets would be read as stripped, and would only be caught when the stripped reading fails. A mesh/graphics capture whose strip_header length disagrees with the native entry offset also degrades to the ambiguity row rather than to a wrong opcode. In a real census, that row means "the tool could not establish the origin", not "this key has no shape".

**@⁠triggered02** on GitHub · 2026-12-03 16:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#issuecomment-7384774089) @⁠R0Y00 Fixed in `47959c62`, and your reproduction is now a test rather than an anecdote. **The coordinate system.** The producer is now established from the diagnostic text: a `native compute +0x…:` line (`src/gfx1013_compute_native.cpp`) decodes from the captured entry, so its PC is **capture-relative** and the stripped header is applied **before** matching; every other line is gfx2hlsl's, which decodes `strip_header(code)`, so it is already stripped-relative. **The both-boundaries case.** If the producer's own convention lands on no instruction boundary but the other one does, the key is listed under a fixed reason — *"the refusal offset is an instruction boundary only in the other producer's coordinate system"* — instead of silently taking the other reading. The exception, which is what keeps translator offsets working: a mnemonic the *same line* names that matches the other boundary still establishes the site, because then the bold opcode is exactly the one the diagnostic named. **Against your fixture** (0x24 header, `v_mov`s appended so stripped `+0x38` is also a boundary, native PC-only diagnostic): ``` before: ...**v_mov_b32_e32 vN, sN**... <- confidently wrong after: s_mov_b32 sN, 0xK / buffer_load_dword … / **ds_swizzle_b32 …** / v_mov_b32_e32 … ``` and the ambiguity control (a translator `+0x38` that only the capture shift places) now reports the fixed reason with 0 shaped keys instead of guessing `ds_swizzle`. **Codex's two P2s:** - opcode digits survive normalization now — `buffer_load_dwordx2` and `buffer_load_dwordx4` produce two rows instead of collapsing into one class row (the digit-eater was in the class text normalization, not in the shape line); - the header shift is applied before matching, not as a fallback — same root cause as the blocker. **Fixture and tests** (both in `tests/startup_refusal_census_check.py`, still ctest `startup_refusal_census`): your both-boundary native case, a translator stripped-PC case, the fixed ambiguity row, and the x2/x4 split — **21 tests, OK**; `docs_links_check` (285 files, 1010 links) and `bidi_controls_check` (3090 files) pass. **What is still uncertain, stated plainly:** the producer is inferred from the diagnostic text, not from metadata. Only the `native compute +0x…:` prefix is recognised as capture-relative — it is the sole native refusal shape today, since one `refuse()` is shared by the compute/graphics/mesh paths and `compile_dxil` writes `error.what()` verbatim. Any other producer with capture-relative offsets would be read as stripped, and would only be caught when the stripped reading fails. A mesh/graphics capture whose `strip_header` length disagrees with the native entry offset also degrades to the ambiguity row rather than to a wrong opcode. In a real census, that row means "the tool could not establish the origin", not "this key has no shape".
github-bot changed target branch from main to gh-pr/3944/base 2026-12-03 16:46:48 +00:00
github manually merged commit 47959c62cb into gh-pr/3944/base 2026-12-03 16:47:02 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 16:40 UTC · original · approved these changes

Re-reviewed 47959c62. The census suite passed 21/21 and the docs check passed 1,010 links. I reran the two-valid-boundaries collision independently: with a 0x24-byte header and +0x38 in the diagnostic, a native PC-only message now marks ds_swizzle_b32 at stripped +0x14, while a translator message marks the actual v_mov_b32_e32 at stripped +0x38. The offset-only ambiguity control remains unshaped without an established boundary. The x2 and x4 opcode suffixes stay distinct with operand redaction preserved. Both previous findings are addressed. The required Windows job passed and the main trial merge is clean.

**@⁠R0Y00** on GitHub · 2026-12-03 16:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3944#pullrequestreview-6174129697) · **approved these changes** Re-reviewed 47959c62. The census suite passed 21/21 and the docs check passed 1,010 links. I reran the two-valid-boundaries collision independently: with a 0x24-byte header and +0x38 in the diagnostic, a native PC-only message now marks ds_swizzle_b32 at stripped +0x14, while a translator message marks the actual v_mov_b32_e32 at stripped +0x38. The offset-only ambiguity control remains unshaped without an established boundary. The x2 and x4 opcode suffixes stay distinct with operand redaction preserved. Both previous findings are addressed. The required Windows job passed and the main trial merge is clean.
This discussion has been locked. Commenting is limited to contributors.
No description provided.