shader: re-sign retargeted DXIL containers and verify compute PSO creation #341

Merged
alexander-src merged 2 commits from upstream-pr/346 into main 2026-11-22 03:44:34 +00:00
alexander-src commented 2026-11-21 22:51:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T22:51:35Z.


Change

Implements DXBC container re-signing and desktop CreateComputePipelineState verification for retargeted dxil-ms-xb2 shaders, closing the separate-work item noted in docs/experiments.md ("Retargeting dxil-ms-xb2 modules to desktop DXIL").

Previously, tools/dxil_retarget.py zeroed the 16-byte DXBC header digest after rewriting dxil-ms-xb2 bitcode and clearing Xbox RTS0 flags (0x03000000), so retargeted containers could pass dxil.dll validation without being loadable into desktop CreateComputePipelineState.

  • tools/root_probe.cpp: add --sign, which validates and signs a DXBC container in place through dxil.dll (IDxcValidator::Validate with DxcValidatorFlags_InPlaceEdit) and writes the signed container to binary stdout (or diagnostics to stderr with exit code 5 on failure).
  • tools/root_device_probe.cpp: add --compute-pso (combinable with --warp-only), reporting each adapter's shader model plus CreateRootSignature and CreateComputePipelineState HRESULTs for a DXBC container on stdin.
  • tools/dxil_retarget.py: add sign_container, check_compute_pso, and CLI flags --sign, --pso-probe, and --warp-only in both single-file and --pe modes.
  • tests/desktop_gpu.h, tests/compute_check.cpp, tests/offscreen_check.cpp: add --compute-root-file <path> (check_compute_file) to run an external compute_root.cso binary through run_compute with CPU readback and D3D12 debug-layer checks.
  • tests/dxil_retarget_check.py, CMakeLists.txt, docs/experiments.md: extend dxil_retarget_controls and dxil_retarget_probe with signing, CreateComputePipelineState, and WARP compute dispatch controls and update the documentation.

Verification

Commit 9350177 (Linux host, Python 3.13, no Windows SDK / D3D12 runtime locally):

  • python3 -B tests/dxil_retarget_check.py -> pure-python dxil_retarget controls: ok (covers sign_container, check_compute_pso, and CLI flag rejection controls).
  • python3 -B tests/shader_probe_check.py -> all 9 controls passed.
  • python3 -B tests/docs_links_check.py -> Checked 10 Markdown files and 69 links.
  • python3 -B tests/bidi_controls_check.py -> Checked 286 tracked source, script and build/CI files: no bidirectional controls.

Windows build, root_probe --sign, WARP CreateComputePipelineState (root_device_probe --compute-pso --warp-only), and live WARP compute dispatch (offscreen_check warp --compute-root-file) could not be executed locally on this Linux host and are verified by the build-and-test Windows CI job (dxil_retarget_probe).

Evidence and follow-up

  • All fixtures are source-built in this repository (tests/compute.hlsl -> compute_root.cso, tests/buffer_ops.hlsl -> CopyBlocks.cso, MIT license) and synthetically injected with dxil-ms-xb2, xbox.compiler.options, BitcodeOffset=112, and RTS0 flags 0x03000000.
  • Negative controls verify:
    • root_probe --sign rejects invalid synthetic xb2, dxil-ms, and --keep-root-flags containers without writing stdout bytes.
    • CreateComputePipelineState on WARP rejects unsigned (zero-digest) retargeted containers and 1-bit-tampered signed containers.
    • offscreen_check warp --compute-root-file rejects the unsigned retargeted compute_root.cso and passes with mismatches=0 for the re-signed container.
  • For CopyBlocks.cso (cs_6_5), the WARP PSO check inspects warp_shader_model and skips on WARP adapters below SM 6.5 (such as Windows 10 in-box WARP 6.2), matching the repo's existing cs_6_5 test policy.
  • Follow-up for contributors with a local copy of XboxBvhBuilder.dll: running tools/dxil_retarget.py --pe ... --only-without-xbox-calls --sign --probe root_probe.exe --pso-probe root_device_probe.exe can now test live desktop CreateComputePipelineState across the 9 modules without xbox.* calls.

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.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535441996 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/346). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T22:51:35Z. --- ## Change Implements DXBC container re-signing and desktop `CreateComputePipelineState` verification for retargeted `dxil-ms-xb2` shaders, closing the separate-work item noted in `docs/experiments.md` ("Retargeting dxil-ms-xb2 modules to desktop DXIL"). Previously, `tools/dxil_retarget.py` zeroed the 16-byte DXBC header digest after rewriting `dxil-ms-xb2` bitcode and clearing Xbox `RTS0` flags (`0x03000000`), so retargeted containers could pass `dxil.dll` validation without being loadable into desktop `CreateComputePipelineState`. - `tools/root_probe.cpp`: add `--sign`, which validates and signs a DXBC container in place through `dxil.dll` (`IDxcValidator::Validate` with `DxcValidatorFlags_InPlaceEdit`) and writes the signed container to binary stdout (or diagnostics to stderr with exit code 5 on failure). - `tools/root_device_probe.cpp`: add `--compute-pso` (combinable with `--warp-only`), reporting each adapter's shader model plus `CreateRootSignature` and `CreateComputePipelineState` HRESULTs for a DXBC container on stdin. - `tools/dxil_retarget.py`: add `sign_container`, `check_compute_pso`, and CLI flags `--sign`, `--pso-probe`, and `--warp-only` in both single-file and `--pe` modes. - `tests/desktop_gpu.h`, `tests/compute_check.cpp`, `tests/offscreen_check.cpp`: add `--compute-root-file <path>` (`check_compute_file`) to run an external `compute_root.cso` binary through `run_compute` with CPU readback and D3D12 debug-layer checks. - `tests/dxil_retarget_check.py`, `CMakeLists.txt`, `docs/experiments.md`: extend `dxil_retarget_controls` and `dxil_retarget_probe` with signing, `CreateComputePipelineState`, and WARP compute dispatch controls and update the documentation. ## Verification Commit `9350177` (Linux host, Python 3.13, no Windows SDK / D3D12 runtime locally): - `python3 -B tests/dxil_retarget_check.py` -> `pure-python dxil_retarget controls: ok` (covers `sign_container`, `check_compute_pso`, and CLI flag rejection controls). - `python3 -B tests/shader_probe_check.py` -> all 9 controls passed. - `python3 -B tests/docs_links_check.py` -> `Checked 10 Markdown files and 69 links.` - `python3 -B tests/bidi_controls_check.py` -> `Checked 286 tracked source, script and build/CI files: no bidirectional controls.` Windows build, `root_probe --sign`, WARP `CreateComputePipelineState` (`root_device_probe --compute-pso --warp-only`), and live WARP compute dispatch (`offscreen_check warp --compute-root-file`) could not be executed locally on this Linux host and are verified by the `build-and-test` Windows CI job (`dxil_retarget_probe`). ## Evidence and follow-up - All fixtures are source-built in this repository (`tests/compute.hlsl` -> `compute_root.cso`, `tests/buffer_ops.hlsl` -> `CopyBlocks.cso`, MIT license) and synthetically injected with `dxil-ms-xb2`, `xbox.compiler.options`, `BitcodeOffset=112`, and `RTS0` flags `0x03000000`. - Negative controls verify: - `root_probe --sign` rejects invalid synthetic `xb2`, `dxil-ms`, and `--keep-root-flags` containers without writing stdout bytes. - `CreateComputePipelineState` on WARP rejects unsigned (zero-digest) retargeted containers and 1-bit-tampered signed containers. - `offscreen_check warp --compute-root-file` rejects the unsigned retargeted `compute_root.cso` and passes with `mismatches=0` for the re-signed container. - For `CopyBlocks.cso` (`cs_6_5`), the WARP PSO check inspects `warp_shader_model` and skips on WARP adapters below SM 6.5 (such as Windows 10 in-box WARP 6.2), matching the repo's existing `cs_6_5` test policy. - Follow-up for contributors with a local copy of `XboxBvhBuilder.dll`: running `tools/dxil_retarget.py --pe ... --only-without-xbox-calls --sign --probe root_probe.exe --pso-probe root_device_probe.exe` can now test live desktop `CreateComputePipelineState` across the 9 modules without `xbox.*` calls. ## 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. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: yes.
upstream-sync closed this pull request 2026-11-24 06:42:33 +00:00
roansystemlabs commented 2026-11-24 06:48:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-21T23:22:15Z.


Windows run of #346 on real hardware, since the description notes it could only be checked on Linux plus the WARP CI job.

Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3070 (10de:2484, driver 32.0.16.2101, SM 6.5 reported), WARP 10.0.26100.9818, MSVC 19.44.35230 (VS Build Tools 2022), Windows SDK 10.0.26100.0 DXC/dxil.dll, Python 3.12. D3D12 debug layer not installed on this PC.
Tested head: e2d9f02ed678cc135d52d69469ac492c687eebf3 (as pushed, base b860dd5).

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error
ctest --preset dev -R '^dxil_retarget_' -V

Full suite: 146/146 passed, 3 capability skips (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp, the same as main bc24dfd on this PC). No build warnings.

138: pure-python dxil_retarget controls: ok
138: fixture compute_root.cso: container=0x00000000 module=0x00000000 signed=46fd7743.. pso=(unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok)
138: fixture CopyBlocks.cso: container=0x00000000 module=0x00000000 signed=e2ef7403.. pso=(unsigned=0x80070057 signed=0x00000000 tampered=0x80070057)

Hardware path (not covered by the ctest, which passes --warp-only). I rebuilt the same synthetic xb2 containers with the test's own helpers (_inject_xb2_into_container, retarget_container, sign_container) and ran root_device_probe --compute-pso without --warp-only, then offscreen_check hardware --compute-root-file:

Container RTX 3070 CreateRootSignature RTX 3070 CreateComputePipelineState WARP PSO
compute_root unsigned (zero digest) 0x00000000 0x80070057 0x80070057
compute_root re-signed 0x00000000 0x00000000 0x00000000
compute_root 1-bit tampered digest 0x00000000 0x80070057 0x80070057
CopyBlocks unsigned 0x00000000 0x80070057 0x80070057
CopyBlocks re-signed 0x00000000 0x00000000 0x00000000
CopyBlocks 1-bit tampered digest 0x00000000 0x80070057 0x80070057
offscreen_check hardware --compute-root-file unsigned: exit=1  Create compute pipeline failed (HRESULT 0x80070057)
offscreen_check hardware --compute-root-file signed:   exit=0  layout=root output_words=257 guard_words=63 mismatches=0
offscreen_check warp     --compute-root-file signed:   exit=0  layout=root output_words=257 guard_words=63 mismatches=0

So the signing behaves the same on an NVIDIA driver as on WARP: for both fixtures only the re-signed container creates a PSO, and the re-signed compute_root dispatches with the CPU-checked readback matching (CopyBlocks was checked up to PSO creation only). No problems found.

Optional: a dxil_retarget_probe_hardware variant (without --warp-only, skipping with 77 when there is no hardware adapter) would keep this covered on contributors' GPUs, in line with the other _warp/_hardware test pairs.

AI-assisted: run and prepared with the support of Roan System.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070828362 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/346#issuecomment-7070828362). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-21T23:22:15Z. --- Windows run of #346 on real hardware, since the description notes it could only be checked on Linux plus the WARP CI job. **Environment:** Windows 11 build 26200, NVIDIA GeForce RTX 3070 (`10de:2484`, driver 32.0.16.2101, SM 6.5 reported), WARP 10.0.26100.9818, MSVC 19.44.35230 (VS Build Tools 2022), Windows SDK 10.0.26100.0 DXC/`dxil.dll`, Python 3.12. D3D12 debug layer not installed on this PC. **Tested head:** `e2d9f02ed678cc135d52d69469ac492c687eebf3` (as pushed, base `b860dd5`). ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error ctest --preset dev -R '^dxil_retarget_' -V ``` **Full suite:** 146/146 passed, 3 capability skips (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`, the same as `main` `bc24dfd` on this PC). No build warnings. ```text 138: pure-python dxil_retarget controls: ok 138: fixture compute_root.cso: container=0x00000000 module=0x00000000 signed=46fd7743.. pso=(unsigned=0x80070057 signed=0x00000000 tampered=0x80070057 dispatch=ok) 138: fixture CopyBlocks.cso: container=0x00000000 module=0x00000000 signed=e2ef7403.. pso=(unsigned=0x80070057 signed=0x00000000 tampered=0x80070057) ``` **Hardware path (not covered by the ctest, which passes `--warp-only`).** I rebuilt the same synthetic xb2 containers with the test's own helpers (`_inject_xb2_into_container`, `retarget_container`, `sign_container`) and ran `root_device_probe --compute-pso` without `--warp-only`, then `offscreen_check hardware --compute-root-file`: | Container | RTX 3070 `CreateRootSignature` | RTX 3070 `CreateComputePipelineState` | WARP PSO | |---|---|---|---| | `compute_root` unsigned (zero digest) | `0x00000000` | `0x80070057` | `0x80070057` | | `compute_root` re-signed | `0x00000000` | `0x00000000` | `0x00000000` | | `compute_root` 1-bit tampered digest | `0x00000000` | `0x80070057` | `0x80070057` | | `CopyBlocks` unsigned | `0x00000000` | `0x80070057` | `0x80070057` | | `CopyBlocks` re-signed | `0x00000000` | `0x00000000` | `0x00000000` | | `CopyBlocks` 1-bit tampered digest | `0x00000000` | `0x80070057` | `0x80070057` | ```text offscreen_check hardware --compute-root-file unsigned: exit=1 Create compute pipeline failed (HRESULT 0x80070057) offscreen_check hardware --compute-root-file signed: exit=0 layout=root output_words=257 guard_words=63 mismatches=0 offscreen_check warp --compute-root-file signed: exit=0 layout=root output_words=257 guard_words=63 mismatches=0 ``` So the signing behaves the same on an NVIDIA driver as on WARP: for both fixtures only the re-signed container creates a PSO, and the re-signed `compute_root` dispatches with the CPU-checked readback matching (`CopyBlocks` was checked up to PSO creation only). No problems found. Optional: a `dxil_retarget_probe_hardware` variant (without `--warp-only`, skipping with 77 when there is no hardware adapter) would keep this covered on contributors' GPUs, in line with the other `_warp`/`_hardware` test pairs. _AI-assisted: run and prepared with the support of Roan System._
Jess-Doit commented 2026-11-24 06:48:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-22T02:24:08Z.


Windows 10 GTX 1060 and in-box WARP results at e2d9f02.

Tested on Windows 10 22H2 build 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094, SM 6.5) and in-box WARP 10.0.19041.5794 (SM 6.2). Release build with MSVC 19.44.35230, Windows SDK 10.0.26100.0 and dxil.dll 1.9.2602.17.

  • Both CTest checks passed with ctest --test-dir out/build/inbox --no-tests=error -V -R "^dxil_retarget_(controls|probe)$". I also ran root_device_probe --compute-pso with both adapters enabled.
  • Unsigned compute_root failed pipeline creation on both adapters with 0x80070057. After signing, offscreen_check <hardware|warp> --compute-root-file passed on both with 257 output words, 63 guard words and zero mismatches. The enabled D3D12 debug layer reported zero errors or warnings on the signed dispatches.
  • Signed CopyBlocks created a pipeline on the GTX 1060. In-box WARP rejected even the original SM 6.5 compiler output, consistent with its SM 6.2 limit.

I also tried the documented local DLL follow-up with the matching SHA-256. I ran dxil_retarget.py --pe <local-dll> --only-without-xbox-calls --probe <root_probe> --pso-probe <root_device_probe> with and without --sign. All nine selected SM 6.5 shaders passed container and module validation. On the GTX 1060 all nine created compute pipelines after signing, and all nine unsigned controls returned 0x80070057. In-box WARP accepted their root signatures and rejected pipeline creation. The DLL was read as data and the check ended at pipeline creation.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7072884805 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/346#issuecomment-7072884805). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-22T02:24:08Z. --- Windows 10 GTX 1060 and in-box WARP results at e2d9f02. Tested on Windows 10 22H2 build 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094, SM 6.5) and in-box WARP 10.0.19041.5794 (SM 6.2). Release build with MSVC 19.44.35230, Windows SDK 10.0.26100.0 and dxil.dll 1.9.2602.17. - Both CTest checks passed with `ctest --test-dir out/build/inbox --no-tests=error -V -R "^dxil_retarget_(controls|probe)$"`. I also ran `root_device_probe --compute-pso` with both adapters enabled. - Unsigned `compute_root` failed pipeline creation on both adapters with 0x80070057. After signing, `offscreen_check <hardware|warp> --compute-root-file` passed on both with 257 output words, 63 guard words and zero mismatches. The enabled D3D12 debug layer reported zero errors or warnings on the signed dispatches. - Signed `CopyBlocks` created a pipeline on the GTX 1060. In-box WARP rejected even the original SM 6.5 compiler output, consistent with its SM 6.2 limit. I also tried the documented local DLL follow-up with the matching SHA-256. I ran `dxil_retarget.py --pe <local-dll> --only-without-xbox-calls --probe <root_probe> --pso-probe <root_device_probe>` with and without `--sign`. All nine selected SM 6.5 shaders passed container and module validation. On the GTX 1060 all nine created compute pipelines after signing, and all nine unsigned controls returned 0x80070057. In-box WARP accepted their root signatures and rejected pipeline creation. The DLL was read as data and the check ended at pipeline creation. AI-assisted.
Jess-Doit commented 2026-11-24 06:48:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-22T03:11:27Z.


Follow-up dispatch check at e2d9f02 on the GTX 1060 6 GB (driver 32.0.15.6094, Shader Model 6.5, Windows 10 22H2 build 19045.6456). I checked the documented span-copy operation from the hash-matched local DLL. The re-signed shader uses the same root signature as the source-built CopySpan fixture.

I used the four span cases from bvh_buffer_ops_hardware with disjoint buffers, one or two groups, and source length parameters 0 and 16 (64 and 1,088 bytes). For the package shader, I set the reset constant to 0 and 1 in separate runs and omitted the fixture's second dispatch in both. Each variant passed 10/10 runs with all 384 readback words per case matching the CPU reference and zero D3D12 debug errors or warnings.

The source-built control passed with the ordered ResetBounds dispatch. With that dispatch removed, all four cases failed at word 4, expected 0x7f7fffff and observed 0x000272b7. That control confirms the fixture can detect a missing reset. The result covers the tested buffer layout and dispatch settings on this adapter.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073382172 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/346#issuecomment-7073382172). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-22T03:11:27Z. --- Follow-up dispatch check at e2d9f02 on the GTX 1060 6 GB (driver 32.0.15.6094, Shader Model 6.5, Windows 10 22H2 build 19045.6456). I checked the documented span-copy operation from the hash-matched local DLL. The re-signed shader uses the same root signature as the source-built CopySpan fixture. I used the four span cases from bvh_buffer_ops_hardware with disjoint buffers, one or two groups, and source length parameters 0 and 16 (64 and 1,088 bytes). For the package shader, I set the reset constant to 0 and 1 in separate runs and omitted the fixture's second dispatch in both. Each variant passed 10/10 runs with all 384 readback words per case matching the CPU reference and zero D3D12 debug errors or warnings. The source-built control passed with the ordered ResetBounds dispatch. With that dispatch removed, all four cases failed at word 4, expected 0x7f7fffff and observed 0x000272b7. That control confirms the fixture can detect a missing reset. The result covers the tested buffer layout and dispatch settings on this adapter. AI-assisted.
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!341
No description provided.