shader: report xbox.* intrinsics as declarations, calls and metadata names #602

Merged
MoonYueya merged 2 commits from upstream-pr/608 into main 2026-11-22 16:13:09 +00:00
MoonYueya commented 2026-11-22 15:36:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MoonYueya on 2026-11-22T15:36:28Z.


Change

Refs #584. Adds a read-only inventory of the xbox.* intrinsic names in a DXIL module, reported in three groups so a gate can later rely on calls alone. It advances S1 of #584 ("report the intrinsic set from dxil_retarget.py, no behaviour change") and lands no gate and no submission behaviour.

tools/probe_roots.py previously derived xbox_call_sites from call instructions only, so a name that a module merely declares, or one that appears in metadata alone, was indistinguishable from a real call. The new xbox_intrinsic_inventory() classifies the same disassembly text into:

  • calls — symbols referenced by call instructions, with a site count;
  • declarations — declare function-table entries;
  • metadata_only — names carried by a metadata string value (!"xbox.…") that are neither declared nor called.

An unused declaration and a metadata-only name therefore never appear under calls. A named-metadata key is a node name, not an intrinsic: !xbox.compiler.options = !{!1} and !xbox.module = !{!0} contribute nothing, so the option node that Xbox modules carry does not surface as an intrinsic name, and neither does an attachment reference such as !xbox.md !3.

Wire-up, all additive:

  • validate_shader() reports the inventory as ir.xbox_intrinsics and takes the unchanged xbox_call_sites value from xbox_intrinsic_inventory()["calls"]; the call-site regular expression is now one module constant shared by both, so the two views cannot drift. On the synthetic shapes below the new calls mapping equals the previous xbox_call_sites mapping exactly.
  • tools/dxil_retarget.py adds xbox_intrinsics to each container entry of the --pe report, taken from the module as submitted (before). In the container mode, --probe root_probe.exe already serialises validation.ir, so the inventory appears there without a new option.
  • docs/experiments.md documents the three groups and the key rule.

Verification

Commit 1edd6bd, Windows x64. Toolchain from the dev preset: Visual Studio 2026 BuildTools 18.11.0 (MSVC 19.51.36260.0), CMake and Ninja from vcvars64.bat, Windows SDK 10.0.26100.0 (dxc.exe and dxil.dll 1.8.2502.11), Python 3.15.0. CMakeLists.txt and CMakePresets.json contain no FetchContent, ExternalProject, vcpkg or file(DOWNLOAD), so the configure and build steps fetch nothing.

> vcvars64.bat
> cmake --preset dev -DINTAKE_PYTHON=C:/Python315/python.exe
-- Configuring done (3.3s)
-- Generating done (1.3s)

> cmake --build --preset dev --target root_probe root_device_probe offscreen_check
[81/81] Linking CXX executable offscreen_check.exe

> ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V
1/6 Test #215: dxcontainer_part_offsets .........   Passed    0.19 sec
2/6 Test #267: shader_metadata_probe ............   Passed    0.41 sec
3/6 Test #268: shader_metadata_controls .........   Passed    0.10 sec
4/6 Test #269: dxil_retarget_probe ..............   Passed    2.82 sec
5/6 Test #270: dxil_retarget_probe_hardware .....   Passed    4.44 sec
6/6 Test #271: dxil_retarget_controls ...........   Passed    0.87 sec

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

-DINTAKE_PYTHON only points the Python-driven tests at the host interpreter: the default out/pe-env/Scripts/python.exe is not created unless a contributor makes it, and without it shader_metadata_* and dxil_retarget_* are not registered at all. No package was installed.

The same inventory was also exercised outside this test suite on the 52 console-compiled compute modules of the DLL that docs/experiments.md already pins by SHA-256 (99f803ac…23707e); no bytes, shader names or derived files are included here, and no test depends on these numbers. That entry already records the split — 9 of the 52 make no direct xbox.* call — and the classifier reproduces it while adding the two columns it does not have:

Result Modules
Reported at least one xbox.* call (the 43 in docs/experiments.md) 43
All three groups empty (the 9 there) 9
metadata_only non-empty, which would mean a named-metadata false positive (!xbox.compiler.options is present in every module) 0
declarations differing from calls 0

Cross-checked against an earlier extraction of the same disassembly that matched @xbox\.(\w+)\(: it agrees on every name it found and misses 19 names across 11 containers, all of them dotted — MakeUniform.i32, MakeUniform.i64, ReadLane.i32, LaneSwizzle.i32, TypedLoad.i32. They are real calls in the text, so a \w+-style pattern silently under-reports these names; CALL_SITE accepts [\w.$-]+, so the inventory has no such gap. Worth knowing for anyone re-deriving that nine-module list.

Evidence and follow-up

The fixtures are original IR text written for this test in tests/dxil_retarget_check.py, in the shape root_probe --disassemble prints, and are contributed under the repository's MIT license; there are no game files, dumps or derived binaries. They verify the classification logic only — the 52-module numbers above are local data, and no CI job depends on them. Each case is a positive control and, for the other two groups, a negative control for calls:

Case Input shape Expected
a declare i32 @xbox.V_ALIGNBYTE_B32(...) plus a call to it, plus !0 = !{!"xbox.V_ALIGNBYTE_B32"} calls has one site; declarations lists it; metadata_only stays empty, so a metadata mention cannot relabel a call
b the declaration only, no call site calls empty; declarations lists it; metadata_only empty
c !xbox.module = !{!0} with !0 = !{!"xbox.V_ALIGNBYTE_B32", i32 332}, no declaration or call metadata_only == ["xbox.V_ALIGNBYTE_B32"]; the key xbox.module is not reported; calls and declarations empty
d an ordinary module calling dx.op.unary.f32 and quoted @"dx.op.threadId.i32", with llvm.module.flags metadata all three groups empty
e !xbox.compiler.options = !{!1} with !1 = !{!"__XBOX_ENABLE_WAVE32=1"}, the shape every Xbox module carries all three groups empty; the option node and its non-intrinsic string are not reported

Assumptions a reviewer should check:

  • The classification reads the disassembler's textual IR, which is the repository's existing definition of an xbox.* call site, rather than decoding function bodies from bitcode. A module therefore needs root_probe.exe (or dxil.dll through it) to be inventoried, exactly as xbox_call_sites does today.
  • Only the call mnemonic is treated as a call, matching the existing analysis; DXIL has no invoke.
  • Metadata names are read from quoted metadata string values; a name embedded inside a longer string therefore has to carry the xbox. prefix itself to be reported.
  • A call made through a bitcast — call void bitcast (void (i32)* @xbox.foo to void (i64)*)(i64 5) — is not matched, because the pattern requires ( immediately after the symbol. The existing xbox_call_sites, and therefore --only-without-xbox-calls, share that gap; it is inherited, not introduced here.
  • The scan runs over every line, so a metadata string whose own text contains call … @xbox.…( would be counted as a call site. No such string occurs in these modules; skipping lines that begin with ! would close it.
  • A ; cuts the line before quoted strings are read, so a metadata string containing ; is cut there and the name inside it is lost rather than shortened. Also inherited from the existing analysis.

Follow-ups in #584 stay separate: S2 gates submission at the adapter with a recording submission stub (calls is the only group that should refuse), S3 replaces the gate with the lowering path. This PR deliberately reports and changes nothing else.

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 (cases b, c and e assert that calls stays empty, and e asserts that a named-metadata key is not a name).
  • 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 and the numbers are pasted from that run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544263522 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/608). Originally posted by [MoonYueya](https://github.com/MoonYueya) on 2026-11-22T15:36:28Z. --- ## Change Refs #584. Adds a read-only inventory of the `xbox.*` intrinsic names in a DXIL module, reported in three groups so a gate can later rely on calls alone. It advances S1 of #584 ("report the intrinsic set from `dxil_retarget.py`, no behaviour change") and lands no gate and no submission behaviour. `tools/probe_roots.py` previously derived `xbox_call_sites` from call instructions only, so a name that a module merely declares, or one that appears in metadata alone, was indistinguishable from a real call. The new `xbox_intrinsic_inventory()` classifies the same disassembly text into: - `calls` — symbols referenced by call instructions, with a site count; - `declarations` — `declare` function-table entries; - `metadata_only` — names carried by a metadata string value (`!"xbox.…"`) that are neither declared nor called. An unused declaration and a metadata-only name therefore never appear under `calls`. A named-metadata key is a node name, not an intrinsic: `!xbox.compiler.options = !{!1}` and `!xbox.module = !{!0}` contribute nothing, so the option node that Xbox modules carry does not surface as an intrinsic name, and neither does an attachment reference such as `!xbox.md !3`. Wire-up, all additive: - `validate_shader()` reports the inventory as `ir.xbox_intrinsics` and takes the unchanged `xbox_call_sites` value from `xbox_intrinsic_inventory()["calls"]`; the call-site regular expression is now one module constant shared by both, so the two views cannot drift. On the synthetic shapes below the new `calls` mapping equals the previous `xbox_call_sites` mapping exactly. - `tools/dxil_retarget.py` adds `xbox_intrinsics` to each container entry of the `--pe` report, taken from the module as submitted (`before`). In the container mode, `--probe root_probe.exe` already serialises `validation.ir`, so the inventory appears there without a new option. - `docs/experiments.md` documents the three groups and the key rule. ## Verification Commit `1edd6bd`, Windows x64. Toolchain from the `dev` preset: Visual Studio 2026 BuildTools 18.11.0 (MSVC 19.51.36260.0), CMake and Ninja from `vcvars64.bat`, Windows SDK 10.0.26100.0 (`dxc.exe` and `dxil.dll` 1.8.2502.11), Python 3.15.0. `CMakeLists.txt` and `CMakePresets.json` contain no `FetchContent`, `ExternalProject`, `vcpkg` or `file(DOWNLOAD)`, so the configure and build steps fetch nothing. ```text > vcvars64.bat > cmake --preset dev -DINTAKE_PYTHON=C:/Python315/python.exe -- Configuring done (3.3s) -- Generating done (1.3s) > cmake --build --preset dev --target root_probe root_device_probe offscreen_check [81/81] Linking CXX executable offscreen_check.exe > ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V 1/6 Test #215: dxcontainer_part_offsets ......... Passed 0.19 sec 2/6 Test #267: shader_metadata_probe ............ Passed 0.41 sec 3/6 Test #268: shader_metadata_controls ......... Passed 0.10 sec 4/6 Test #269: dxil_retarget_probe .............. Passed 2.82 sec 5/6 Test #270: dxil_retarget_probe_hardware ..... Passed 4.44 sec 6/6 Test #271: dxil_retarget_controls ........... Passed 0.87 sec 100% tests passed, 0 tests failed out of 6 Total Test time (real) = 8.84 sec ``` `-DINTAKE_PYTHON` only points the Python-driven tests at the host interpreter: the default `out/pe-env/Scripts/python.exe` is not created unless a contributor makes it, and without it `shader_metadata_*` and `dxil_retarget_*` are not registered at all. No package was installed. The same inventory was also exercised outside this test suite on the 52 console-compiled compute modules of the DLL that `docs/experiments.md` already pins by SHA-256 (`99f803ac…23707e`); no bytes, shader names or derived files are included here, and no test depends on these numbers. That entry already records the split — 9 of the 52 make no direct `xbox.*` call — and the classifier reproduces it while adding the two columns it does not have: | Result | Modules | | --- | --- | | Reported at least one `xbox.*` call (the 43 in `docs/experiments.md`) | 43 | | All three groups empty (the 9 there) | 9 | | `metadata_only` non-empty, which would mean a named-metadata false positive (`!xbox.compiler.options` is present in every module) | 0 | | `declarations` differing from `calls` | 0 | Cross-checked against an earlier extraction of the same disassembly that matched `@xbox\.(\w+)\(`: it agrees on every name it found and misses 19 names across 11 containers, all of them dotted — `MakeUniform.i32`, `MakeUniform.i64`, `ReadLane.i32`, `LaneSwizzle.i32`, `TypedLoad.i32`. They are real calls in the text, so a `\w+`-style pattern silently under-reports these names; `CALL_SITE` accepts `[\w.$-]+`, so the inventory has no such gap. Worth knowing for anyone re-deriving that nine-module list. ## Evidence and follow-up The fixtures are original IR text written for this test in `tests/dxil_retarget_check.py`, in the shape `root_probe --disassemble` prints, and are contributed under the repository's MIT license; there are no game files, dumps or derived binaries. They verify the classification logic only — the 52-module numbers above are local data, and no CI job depends on them. Each case is a positive control and, for the other two groups, a negative control for `calls`: | Case | Input shape | Expected | | --- | --- | --- | | a | `declare i32 @xbox.V_ALIGNBYTE_B32(...)` plus a call to it, plus `!0 = !{!"xbox.V_ALIGNBYTE_B32"}` | `calls` has one site; `declarations` lists it; `metadata_only` stays empty, so a metadata mention cannot relabel a call | | b | the declaration only, no call site | `calls` empty; `declarations` lists it; `metadata_only` empty | | c | `!xbox.module = !{!0}` with `!0 = !{!"xbox.V_ALIGNBYTE_B32", i32 332}`, no declaration or call | `metadata_only == ["xbox.V_ALIGNBYTE_B32"]`; the key `xbox.module` is not reported; `calls` and `declarations` empty | | d | an ordinary module calling `dx.op.unary.f32` and quoted `@"dx.op.threadId.i32"`, with `llvm.module.flags` metadata | all three groups empty | | e | `!xbox.compiler.options = !{!1}` with `!1 = !{!"__XBOX_ENABLE_WAVE32=1"}`, the shape every Xbox module carries | all three groups empty; the option node and its non-intrinsic string are not reported | Assumptions a reviewer should check: - The classification reads the disassembler's textual IR, which is the repository's existing definition of an `xbox.*` call site, rather than decoding function bodies from bitcode. A module therefore needs `root_probe.exe` (or `dxil.dll` through it) to be inventoried, exactly as `xbox_call_sites` does today. - Only the `call` mnemonic is treated as a call, matching the existing analysis; DXIL has no `invoke`. - Metadata names are read from quoted metadata string values; a name embedded inside a longer string therefore has to carry the `xbox.` prefix itself to be reported. - A call made through a bitcast — `call void bitcast (void (i32)* @xbox.foo to void (i64)*)(i64 5)` — is not matched, because the pattern requires `(` immediately after the symbol. The existing `xbox_call_sites`, and therefore `--only-without-xbox-calls`, share that gap; it is inherited, not introduced here. - The scan runs over every line, so a metadata string whose own text contains `call … @xbox.…(` would be counted as a call site. No such string occurs in these modules; skipping lines that begin with `!` would close it. - A `;` cuts the line before quoted strings are read, so a metadata string containing `;` is cut there and the name inside it is lost rather than shortened. Also inherited from the existing analysis. Follow-ups in #584 stay separate: S2 gates submission at the adapter with a recording submission stub (`calls` is the only group that should refuse), S3 replaces the gate with the lowering path. This PR deliberately reports and changes nothing else. ## 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 (cases b, c and e assert that `calls` stays empty, and e asserts that a named-metadata key is not a name). - [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 and the numbers are pasted from that run.
upstream-sync closed this pull request 2026-11-24 06:43:55 +00:00
descent81 commented 2026-11-24 06:48:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T15:41:38Z.


Independent verification of 1edd6bdfb6 on Windows x64.

Built root_probe, root_device_probe and offscreen_check and ran:

ctest --test-dir out/partial --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' --output-on-failure

All six passed (including the WARP and hardware retarget checks), with no skips. The docs links and bidi checks passed as well.

I also exercised the real PE report/filter and retargeting code using a source-built compute container converted to synthetic xb2, with PE enumeration and the probe responses mocked. On both the PR and its parent, declaration-only and ordinary metadata-only cases were processed, and two direct calls to a quoted Xbox symbol caused one container to be skipped. On the PR, the quoted symbol's static count was exactly 2. The processed containers had identical output bytes on both revisions and with or without --report (SHA-256 0c4cc4e989f21c3510838edcdce7e64026934b7882534dc4d3bfc0e0edb6b535).

One inherited edge case is worth recording for S2. With this synthetic disassembly line:

!0 = !{!"call void @xbox.text()"}

the inventory reports calls={"xbox.text": 1} and metadata_only=[] even though the line contains no call instruction. In the mocked PE path, --only-without-xbox-calls skips that container on both the parent and this head. This is existing scanner behavior. A future submission gate should distinguish instruction tokens from metadata string contents before treating this result as a reason to refuse a submission.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7081498268 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/608#issuecomment-7081498268). Originally posted by [descent81](https://github.com/descent81) on 2026-11-22T15:41:38Z. --- Independent verification of 1edd6bdfb6bc83187d668709447036d25fe0a2ad on Windows x64. Built root_probe, root_device_probe and offscreen_check and ran: ```powershell ctest --test-dir out/partial --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' --output-on-failure ``` All six passed (including the WARP and hardware retarget checks), with no skips. The docs links and bidi checks passed as well. I also exercised the real PE report/filter and retargeting code using a source-built compute container converted to synthetic xb2, with PE enumeration and the probe responses mocked. On both the PR and its parent, declaration-only and ordinary metadata-only cases were processed, and two direct calls to a quoted Xbox symbol caused one container to be skipped. On the PR, the quoted symbol's static count was exactly 2. The processed containers had identical output bytes on both revisions and with or without --report (SHA-256 0c4cc4e989f21c3510838edcdce7e64026934b7882534dc4d3bfc0e0edb6b535). One inherited edge case is worth recording for S2. With this synthetic disassembly line: ```llvm !0 = !{!"call void @xbox.text()"} ``` the inventory reports calls={"xbox.text": 1} and metadata_only=[] even though the line contains no call instruction. In the mocked PE path, --only-without-xbox-calls skips that container on both the parent and this head. This is existing scanner behavior. A future submission gate should distinguish instruction tokens from metadata string contents before treating this result as a reason to refuse a submission. AI-assisted.
MoonYueya commented 2026-11-24 06:48:35 +00:00 (Migrated from github.com)

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


Thanks for the independent run and for the mocked PE path. The !0 = !{!"call void @xbox.text()"} case is the second inherited edge listed under Assumptions; we'll treat it as a requirement for S2. Call sites should come only from instruction lines, which means skipping lines that start with ! before matching CALL_SITE. S2 will include your line as a negative control.

Drafted with AI assistance.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7081888994 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/608#issuecomment-7081888994). Originally posted by [MoonYueya](https://github.com/MoonYueya) on 2026-11-22T16:11:55Z. --- Thanks for the independent run and for the mocked PE path. The `!0 = !{!"call void @xbox.text()"}` case is the second inherited edge listed under Assumptions; we'll treat it as a requirement for S2. Call sites should come only from instruction lines, which means skipping lines that start with `!` before matching `CALL_SITE`. S2 will include your line as a negative control. Drafted with AI assistance.
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!602
No description provided.