shader: refuse executable xbox.* calls before a PSO submission #684

Merged
MoonYueya merged 3 commits from upstream-pr/690 into main 2026-11-22 21:56:19 +00:00
MoonYueya commented 2026-11-22 20:29:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MoonYueya on 2026-11-22T20:29:49Z.


Change

Refs #584. This adds a submission gate for modules that still call xbox.* intrinsics: check the module and refuse executable calls before a PSO is created, reporting the names. S3, routing these modules to a lowering, stays open, so this does not close the issue.

tools/xbox_intrinsic_gate.py reads the read-only inventory from tools/probe_roots.py that landed in #608 and keeps the three groups apart. What blocks submission is a call the module still executes; a symbol that is only declared, or one that only metadata mentions, does not. dxil_retarget.py gates the bytes it would submit with --pso-probe: the module after retargeting. A refused module returns the decision with the call names and the probe process is never started, so it produces zero submissions rather than a creation failure such as E_FAIL.

The inventory is mandatory. check_compute_pso() without one records {"verdict": "NOT_CHECKED", "reason": "module-not-disassembled"} and returns before the probe starts, so subprocess count is zero; the CLI always passes the final module's inventory, and a module that was never disassembled (no --probe) therefore submits nothing and says so on stderr.

An adapter status is advisory. Every call the module still executes blocks, and an adapter's LOWERED answer is recorded on that entry without changing the verdict: a lowering counts only when it is visible in the transformed module, as a call that is gone from the instructions. status_table() is a Python API for that reporting; dxil_retarget.py exposes no lowering switch, and check-text no longer takes --lowered.

Reporting stays read-only otherwise: each --pe entry carries the decision as gate, and the report counts gate_rejected and, with a probe, pso_refused.

Verification

Commits d868476 + 5e56e6a on base ba329ec, Windows 11 build 26300.9711 (version string 10.0.26300.9711). Configured with the dev preset (Ninja) inside vcvars64.bat from Visual Studio Build Tools 18.11.0: MSVC 19.51.36260.0 (cl 14.51.36231), Windows SDK 10.0.26100.0, dxc/dxil.dll 1.8.2502.11, Python 3.15.0 with -DINTAKE_PYTHON pointing at it (without it the Python-driven tests are not registered at all).

> ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V
1/7 Test #229: dxcontainer_part_offsets .........   Passed    0.22 sec
2/7 Test #289: shader_metadata_probe ............   Passed    0.39 sec
3/7 Test #290: shader_metadata_controls .........   Passed    0.10 sec
4/7 Test #291: shader_metadata_census ...........   Passed    0.69 sec
5/7 Test #292: dxil_retarget_probe ..............   Passed    3.31 sec
6/7 Test #293: dxil_retarget_probe_hardware .....   Passed    4.95 sec
7/7 Test #294: dxil_retarget_controls ...........   Passed    1.40 sec

100% tests passed, 0 tests failed out of 7
Total Test time (real) =  11.08 sec

No skip anywhere in the run. The hardware case ran on a physical adapter and really submitted for both fixtures, which is the check that the inventory reaches the probe path:

293: fixture compute_root.cso: container=0x00000000 module=0x00000000 signed=af12de56.. pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok)
293: fixture CopyBlocksSM65.cso: container=0x00000000 module=0x00000000 signed=b673b50c.. pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057)
293: validator=dxil.dll file_version=1.8.2502.11 module_only=validated

root_device_probe.exe picks the adapter with EnumAdapterByGpuPreference and DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE and reports its PCI ID as adapter_id, but the fixture line the test prints keeps only the PSO results, so this log does not record which adapter ran. This host has NVIDIA GeForce RTX 3080 (driver 32.0.16.1742) and AMD Radeon(TM) Graphics (driver 32.0.11024.2), listed from Win32_VideoController; that preference should select the RTX 3080, so the adapter is inferred rather than observed by the test. The D3D12 debug layer was not enabled for this run: the probe creates its devices with CreateDXGIFactory2 and D3D12CreateDevice and never calls D3D12GetDebugInterface, so the results carry no debug-layer messages.

The new comparisons are registered in dxil_retarget_controls (#294). The same pure-Python block also runs inside #292 and #293, so its line appears three times in the verbose log:

294: submission gate controls: executable call refused with 0 submissions; declared only, metadata only
     and ordinary modules submit once; an advisory LOWERED status still refuses while the call remains
     and clears once the call is gone; missing inventory starts 0 probe processes; a metadata string
     that spells a call and a ';' inside a metadata string still pass; without --probe the CLI records
     NOT_CHECKED and submits nothing
Case Expected
A module that still calls @xbox.V_ALIGNBYTE_B32 refused, names reported, submission stub called 0 times
Declaration only, no call site submits once
Name only in a metadata string value submits once
Ordinary module with dx.op calls submits once
Executable call plus an advisory LOWERED status still refused, 0 submissions, advisory recorded; the same module clears once the call is removed
check_compute_pso() with no inventory NOT_CHECKED, probe started 0 times
Submission boundary, check_compute_pso with mocked subprocess.run refused: 0 probe processes; allowed: exactly 1
!0 = !{!"call void @xbox.text()"} (reported by @descent81 on #608) submits once; the name is metadata-only, not a call
!0 = !{!"xbox.a;xbox.b"} both names kept, no comment truncation
CLI with --pso-probe and no --probe gate.verdict = "NOT_CHECKED", no warp_pso, nothing submitted, warning on stderr

python -B tests/docs_links_check.py (10 files, 133 links) and python -B tests/bidi_controls_check.py (596 files) both pass.

Evidence and follow-up

  • Fixtures: the IR text in tests/dxil_retarget_check.py is original, and the synthetic DXBC containers are assembled in the same file from that text and the repository's own bitstream helpers. No game data, dumps or external samples are involved, and the contribution is under this repository's MIT license.
  • probe_roots.strip_comment() is the prerequisite fix for the gate: without it a ; inside a quoted metadata string truncates a name, and the gate would miss that call or name.
  • The gate reads instructions, not claims: an adapter that lowers a call must show it as a call that no longer exists, and this patch does not decide whether a lowering is correct. Once S3 routes these modules to a lowering, the transformed module stops calling those symbols and the gate admits it.
  • validate_pe_containers(), the CLI and the hardware wrapper all pass the final module's inventory, so no path can submit without a gate; a caller that has no inventory gets NOT_CHECKED instead of a submission.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture (the refused module asserts zero submissions; an advisory LOWERED status still refuses; a missing inventory starts no probe process; @descent81's metadata string is the negative control for the inventory).
  • I updated README/docs when a capability or build requirement changed (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

Drafted with AI assistance; the commands above were run on the author's Windows x64 host.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547400523 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/690). Originally posted by [MoonYueya](https://github.com/MoonYueya) on 2026-11-22T20:29:49Z. --- ### Change Refs #584. This adds a submission gate for modules that still call `xbox.*` intrinsics: check the module and refuse executable calls before a PSO is created, reporting the names. S3, routing these modules to a lowering, stays open, so this does not close the issue. `tools/xbox_intrinsic_gate.py` reads the read-only inventory from `tools/probe_roots.py` that landed in #608 and keeps the three groups apart. What blocks submission is a **call the module still executes**; a symbol that is only declared, or one that only metadata mentions, does not. `dxil_retarget.py` gates the bytes it would submit with `--pso-probe`: the module after retargeting. A refused module returns the decision with the call names and the probe process is never started, so it produces **zero submissions** rather than a creation failure such as `E_FAIL`. The inventory is mandatory. `check_compute_pso()` without one records `{"verdict": "NOT_CHECKED", "reason": "module-not-disassembled"}` and returns before the probe starts, so subprocess count is zero; the CLI always passes the final module's inventory, and a module that was never disassembled (no `--probe`) therefore submits nothing and says so on stderr. An adapter status is advisory. Every call the module still executes blocks, and an adapter's `LOWERED` answer is recorded on that entry without changing the verdict: a lowering counts only when it is visible in the transformed module, as a call that is gone from the instructions. `status_table()` is a Python API for that reporting; `dxil_retarget.py` exposes no lowering switch, and `check-text` no longer takes `--lowered`. Reporting stays read-only otherwise: each `--pe` entry carries the decision as `gate`, and the report counts `gate_rejected` and, with a probe, `pso_refused`. ### Verification Commits `d868476` + `5e56e6a` on base `ba329ec`, Windows 11 build 26300.9711 (version string 10.0.26300.9711). Configured with the `dev` preset (Ninja) inside `vcvars64.bat` from Visual Studio Build Tools 18.11.0: MSVC 19.51.36260.0 (cl 14.51.36231), Windows SDK 10.0.26100.0, `dxc`/`dxil.dll` 1.8.2502.11, Python 3.15.0 with `-DINTAKE_PYTHON` pointing at it (without it the Python-driven tests are not registered at all). ```text > ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V 1/7 Test #229: dxcontainer_part_offsets ......... Passed 0.22 sec 2/7 Test #289: shader_metadata_probe ............ Passed 0.39 sec 3/7 Test #290: shader_metadata_controls ......... Passed 0.10 sec 4/7 Test #291: shader_metadata_census ........... Passed 0.69 sec 5/7 Test #292: dxil_retarget_probe .............. Passed 3.31 sec 6/7 Test #293: dxil_retarget_probe_hardware ..... Passed 4.95 sec 7/7 Test #294: dxil_retarget_controls ........... Passed 1.40 sec 100% tests passed, 0 tests failed out of 7 Total Test time (real) = 11.08 sec ``` No skip anywhere in the run. The hardware case ran on a physical adapter and really submitted for both fixtures, which is the check that the inventory reaches the probe path: ```text 293: fixture compute_root.cso: container=0x00000000 module=0x00000000 signed=af12de56.. pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok) 293: fixture CopyBlocksSM65.cso: container=0x00000000 module=0x00000000 signed=b673b50c.. pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057) 293: validator=dxil.dll file_version=1.8.2502.11 module_only=validated ``` `root_device_probe.exe` picks the adapter with `EnumAdapterByGpuPreference` and `DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE` and reports its PCI ID as `adapter_id`, but the fixture line the test prints keeps only the PSO results, so this log does not record which adapter ran. This host has NVIDIA GeForce RTX 3080 (driver 32.0.16.1742) and AMD Radeon(TM) Graphics (driver 32.0.11024.2), listed from `Win32_VideoController`; that preference should select the RTX 3080, so the adapter is inferred rather than observed by the test. The D3D12 debug layer was not enabled for this run: the probe creates its devices with `CreateDXGIFactory2` and `D3D12CreateDevice` and never calls `D3D12GetDebugInterface`, so the results carry no debug-layer messages. The new comparisons are registered in `dxil_retarget_controls` (#294). The same pure-Python block also runs inside #292 and #293, so its line appears three times in the verbose log: ```text 294: submission gate controls: executable call refused with 0 submissions; declared only, metadata only and ordinary modules submit once; an advisory LOWERED status still refuses while the call remains and clears once the call is gone; missing inventory starts 0 probe processes; a metadata string that spells a call and a ';' inside a metadata string still pass; without --probe the CLI records NOT_CHECKED and submits nothing ``` | Case | Expected | | --- | --- | | A module that still calls `@xbox.V_ALIGNBYTE_B32` | refused, names reported, submission stub called 0 times | | Declaration only, no call site | submits once | | Name only in a metadata string value | submits once | | Ordinary module with `dx.op` calls | submits once | | Executable call plus an advisory `LOWERED` status | still refused, 0 submissions, advisory recorded; the same module clears once the call is removed | | `check_compute_pso()` with no inventory | `NOT_CHECKED`, probe started 0 times | | Submission boundary, `check_compute_pso` with mocked `subprocess.run` | refused: 0 probe processes; allowed: exactly 1 | | `!0 = !{!"call void @xbox.text()"}` (reported by @descent81 on #608) | submits once; the name is metadata-only, not a call | | `!0 = !{!"xbox.a;xbox.b"}` | both names kept, no comment truncation | | CLI with `--pso-probe` and no `--probe` | `gate.verdict = "NOT_CHECKED"`, no `warp_pso`, nothing submitted, warning on stderr | `python -B tests/docs_links_check.py` (10 files, 133 links) and `python -B tests/bidi_controls_check.py` (596 files) both pass. ### Evidence and follow-up - Fixtures: the IR text in `tests/dxil_retarget_check.py` is original, and the synthetic DXBC containers are assembled in the same file from that text and the repository's own bitstream helpers. No game data, dumps or external samples are involved, and the contribution is under this repository's MIT license. - `probe_roots.strip_comment()` is the prerequisite fix for the gate: without it a `;` inside a quoted metadata string truncates a name, and the gate would miss that call or name. - The gate reads instructions, not claims: an adapter that lowers a call must show it as a call that no longer exists, and this patch does not decide whether a lowering is correct. Once S3 routes these modules to a lowering, the transformed module stops calling those symbols and the gate admits it. - `validate_pe_containers()`, the CLI and the hardware wrapper all pass the final module's inventory, so no path can submit without a gate; a caller that has no inventory gets `NOT_CHECKED` instead of a submission. ### Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture (the refused module asserts zero submissions; an advisory LOWERED status still refuses; a missing inventory starts no probe process; @descent81's metadata string is the negative control for the inventory). - [x] I updated README/docs when a capability or build requirement changed (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. Drafted with AI assistance; the commands above were run on the author's Windows x64 host.
upstream-sync closed this pull request 2026-11-24 06:44:21 +00:00
R0Y00 commented 2026-11-24 06:44:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:12:02Z.

Review: CHANGES_REQUESTED


The read-only inventory and the CLI NOT_CHECKED result are useful. Please make the actual Windows submission helper fail closed too. check_compute_pso() still starts the probe if intrinsics is None, and its status_of adapter can mark an xbox.* declaration as lowered by name and allow submission even while that call remains in the final module. For #584, require the final module's inventory on the submission path and refuse any remaining executable xbox.* call. A lowering should be reflected in the transformed, validated module itself. Keep the status table for advisory reporting if useful. Add direct helper controls that record zero subprocess calls for missing inventory and for an executable call whose name an advisory adapter calls lowered, alongside the declarations-only and metadata-only controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6014555632 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/690#pullrequestreview-6014555632). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:12:02Z. **Review:** CHANGES_REQUESTED --- The read-only inventory and the CLI `NOT_CHECKED` result are useful. Please make the actual Windows submission helper fail closed too. `check_compute_pso()` still starts the probe if `intrinsics` is `None`, and its `status_of` adapter can mark an `xbox.*` declaration as lowered by name and allow submission even while that call remains in the final module. For #584, require the final module's inventory on the submission path and refuse any remaining executable `xbox.*` call. A lowering should be reflected in the transformed, validated module itself. Keep the status table for advisory reporting if useful. Add direct helper controls that record zero subprocess calls for missing inventory and for an executable call whose name an advisory adapter calls lowered, alongside the declarations-only and metadata-only controls.
MoonYueya commented 2026-11-24 06:48:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MoonYueya on 2026-11-22T21:43:53Z.


Thanks — all three points are in, on top of the reviewed head. The branch is rebased onto ba329ec; the changes are in 5e56e6a, plus a one-line docs clarification in efc986b.

1. check_compute_pso() now fails closed. The inventory is mandatory: calling the helper without one records {"verdict": "NOT_CHECKED", "reason": "module-not-disassembled", "checked": false} and returns before the probe process starts, so subprocess count is zero. There is no optional-gate branch left. validate_pe_containers() and the CLI always pass the final module's inventory; the hardware wrapper in tests/dxil_retarget_check.py now threads it through too, so dxil_retarget_probe and dxil_retarget_probe_hardware still submit for real — the latter reports pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok) with no skip.

2. An adapter status can no longer clear a call. decide() puts every call the module still executes into blocking and keeps the adapter's answer as an advisory field on that entry (advisory: "LOWERED"), which the verdict ignores. The message says what was claimed and that the module still calls the symbol, e.g. REJECT: 1 executable xbox.* call(s): xbox.V_ALIGNBYTE_B32 (advisory reports LOWERED for V_ALIGNBYTE_B32; the module still calls them). A lowering only counts when it is visible in the transformed module — the call is gone from the instructions, so the inventory no longer lists it. status_table() is now advisory only and the check-text --lowered switch is gone.

3. Two new comparisons sit next to the declaration-only and metadata-only ones. In dxil_retarget_controls (pure Python): an executable call with an advisory LOWERED status produces zero submissions and stays REJECT, and a missing inventory produces zero probe processes. Both also cover the transition in the same case: the same module flips to ALLOW once the call is removed.

ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V passes 7/7 with no skip, including shader_metadata_census from main; docs_links_check.py and bidi_controls_check.py pass. The verbose log line for the new comparisons:

submission gate controls: executable call refused with 0 submissions; declared only, metadata only
and ordinary modules submit once; an advisory LOWERED status still refuses while the call remains
and clears once the call is gone; missing inventory starts 0 probe processes; a metadata string
that spells a call and a ';' inside a metadata string still pass; without --probe the CLI records
NOT_CHECKED and submits nothing

docs/experiments.md and the module docstring now describe that rule, and the PR body is updated to match.

Drafted with AI assistance; the commands above were run on the author's Windows x64 host.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086270931 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/690#issuecomment-7086270931). Originally posted by [MoonYueya](https://github.com/MoonYueya) on 2026-11-22T21:43:53Z. --- Thanks — all three points are in, on top of the reviewed head. The branch is rebased onto `ba329ec`; the changes are in `5e56e6a`, plus a one-line docs clarification in `efc986b`. **1. `check_compute_pso()` now fails closed.** The inventory is mandatory: calling the helper without one records `{"verdict": "NOT_CHECKED", "reason": "module-not-disassembled", "checked": false}` and returns before the probe process starts, so subprocess count is zero. There is no optional-gate branch left. `validate_pe_containers()` and the CLI always pass the final module's inventory; the hardware wrapper in `tests/dxil_retarget_check.py` now threads it through too, so `dxil_retarget_probe` and `dxil_retarget_probe_hardware` still submit for real — the latter reports `pso=(hardware:unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok)` with no skip. **2. An adapter status can no longer clear a call.** `decide()` puts every call the module still executes into `blocking` and keeps the adapter's answer as an advisory field on that entry (`advisory: "LOWERED"`), which the verdict ignores. The message says what was claimed and that the module still calls the symbol, e.g. `REJECT: 1 executable xbox.* call(s): xbox.V_ALIGNBYTE_B32 (advisory reports LOWERED for V_ALIGNBYTE_B32; the module still calls them)`. A lowering only counts when it is visible in the transformed module — the call is gone from the instructions, so the inventory no longer lists it. `status_table()` is now advisory only and the `check-text --lowered` switch is gone. **3. Two new comparisons sit next to the declaration-only and metadata-only ones.** In `dxil_retarget_controls` (pure Python): an executable call with an advisory LOWERED status produces zero submissions and stays REJECT, and a missing inventory produces zero probe processes. Both also cover the transition in the same case: the same module flips to ALLOW once the call is removed. `ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V` passes 7/7 with no skip, including `shader_metadata_census` from main; `docs_links_check.py` and `bidi_controls_check.py` pass. The verbose log line for the new comparisons: ```text submission gate controls: executable call refused with 0 submissions; declared only, metadata only and ordinary modules submit once; an advisory LOWERED status still refuses while the call remains and clears once the call is gone; missing inventory starts 0 probe processes; a metadata string that spells a call and a ';' inside a metadata string still pass; without --probe the CLI records NOT_CHECKED and submits nothing ``` `docs/experiments.md` and the module docstring now describe that rule, and the PR body is updated to match. Drafted with AI assistance; the commands above were run on the author's Windows x64 host.
R0Y00 commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T21:55:31Z.


Reviewed efc986ba40c1ced5473272fac6ca9d411982a74c. My requested changes are satisfied. The CLI and PE path inventory the final retargeted module, and the submission helper returns NOT_CHECKED without spawning the probe when that inventory is missing. The verdict uses actual call sites even when an adapter claims LOWERED. Run 45073727008 confirms the zero-invocation controls for both scenarios and for a live call, the one-invocation controls after removal and for metadata/declaration-only modules, and green dxil_retarget_probe and dxil_retarget_controls in both Windows presets. The scope is the retargeting tool's compute submission path.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086417143 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/690#issuecomment-7086417143). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T21:55:31Z. --- Reviewed `efc986ba40c1ced5473272fac6ca9d411982a74c`. My requested changes are satisfied. The CLI and PE path inventory the final retargeted module, and the submission helper returns `NOT_CHECKED` without spawning the probe when that inventory is missing. The verdict uses actual call sites even when an adapter claims `LOWERED`. Run `45073727008` confirms the zero-invocation controls for both scenarios and for a live call, the one-invocation controls after removal and for metadata/declaration-only modules, and green `dxil_retarget_probe` and `dxil_retarget_controls` in both Windows presets. The scope is the retargeting tool's compute submission path.
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
R0Y00/Xbox2Windows!684
No description provided.