shader: add dxil-ms-xb2 to dxil-ms-dx retarget tool and fixtures #247

Merged
MarlomMedeiros merged 1 commit from upstream-pr/250 into main 2026-11-21 20:55:31 +00:00
MarlomMedeiros commented 2026-11-21 19:16:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T19:16:59Z.


Refs #132

Summary

  • New tools/dxil_retarget.py: LLVM 3.7 bitcode + DXBC container rewrite that retargets dxil-ms-xb2 modules to dxil-ms-dx (note: desktop DXC rejects dxil-ms), removes the xbox.compiler.options named metadata, canonicalizes the DXIL program header (BitcodeOffset=16, drops trailing xbop), retargets DXIL STAT parts, clears Xbox RTS0 flags 0x03000000, and zeroes the stale DXBC digest. --pe batch mode extracts and validates embedded containers.
  • New tests/dxil_retarget_check.py: pure-Python controls plus synthetic fixtures injecting xb2 triple/metadata/offset/flags into source-built compute_root.cso and CopyBlocks.cso, with negative controls.
  • Documents measured results in docs/experiments.md.

Shared interfaces and overlapping work

  • Reuses resource_inventory.parts(), call_evidence.shader_containers(), probe_roots.validate_shader() and drives root_probe.exe.
  • Overlaps the RTS0 0x03000000 flag-clearing precedent in tools/root_probe.cpp (deserialized in-memory copy; this change clears the bits in the serialized container bytes).
  • Detection of xbox.* call sites and dxil-ms-xb2 triple reuses the probe_roots classification.

Test plan

  • ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V: 5/5 passed (dxil.dll 1.9.2602.17).
  • Local observation (no package bytes included): on the inspected local XboxBvhBuilder.dll (SHA-256 pinned in experiments.md), the 9 embedded modules without xbox.* calls pass ModuleOnly 9/9 after bitcode retarget, and pass container validation 9/9 after also clearing 0x03000000.
  • Follow-ups: signed-container PSO creation, IR lowering for the 43 modules calling xbox.* intrinsics and non-DXIL aggregate instructions.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533289970 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/250). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T19:16:59Z. --- Refs #132 ## Summary - New `tools/dxil_retarget.py`: LLVM 3.7 bitcode + DXBC container rewrite that retargets `dxil-ms-xb2` modules to `dxil-ms-dx` (note: desktop DXC rejects `dxil-ms`), removes the `xbox.compiler.options` named metadata, canonicalizes the DXIL program header (BitcodeOffset=16, drops trailing `xbop`), retargets DXIL `STAT` parts, clears Xbox `RTS0` flags `0x03000000`, and zeroes the stale DXBC digest. `--pe` batch mode extracts and validates embedded containers. - New `tests/dxil_retarget_check.py`: pure-Python controls plus synthetic fixtures injecting xb2 triple/metadata/offset/flags into source-built `compute_root.cso` and `CopyBlocks.cso`, with negative controls. - Documents measured results in `docs/experiments.md`. ## Shared interfaces and overlapping work - Reuses `resource_inventory.parts()`, `call_evidence.shader_containers()`, `probe_roots.validate_shader()` and drives `root_probe.exe`. - Overlaps the RTS0 `0x03000000` flag-clearing precedent in `tools/root_probe.cpp` (deserialized in-memory copy; this change clears the bits in the serialized container bytes). - Detection of `xbox.*` call sites and `dxil-ms-xb2` triple reuses the `probe_roots` classification. ## Test plan - `ctest --preset dev --no-tests=error -R 'dxil_retarget|shader_metadata|dxcontainer_part_offsets' -V`: 5/5 passed (dxil.dll 1.9.2602.17). - Local observation (no package bytes included): on the inspected local `XboxBvhBuilder.dll` (SHA-256 pinned in experiments.md), the 9 embedded modules without `xbox.*` calls pass `ModuleOnly` 9/9 after bitcode retarget, and pass container validation 9/9 after also clearing `0x03000000`. - Follow-ups: signed-container PSO creation, IR lowering for the 43 modules calling `xbox.*` intrinsics and non-DXIL aggregate instructions.
upstream-sync closed this pull request 2026-11-24 06:42:02 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 06:42:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-21T19:17:07Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007632632 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/250#pullrequestreview-6007632632). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-21T19:17:07Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
R0Y00 commented 2026-11-24 06:47:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:28:22Z.


Please validate the encoded operand widths when reading abbreviation definitions. BitReader.read_vbr builds mask and high from the supplied width before checking the input has that many bits; the current lower bound alone allows an invalid width to consume excessive memory instead of returning a format error. Enforce the LLVM bitstream width bounds before those shifts, and add a small synthetic rejection test alongside the existing round-trip controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068776699 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/250#issuecomment-7068776699). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:28:22Z. --- Please validate the encoded operand widths when reading abbreviation definitions. `BitReader.read_vbr` builds `mask` and `high` from the supplied width before checking the input has that many bits; the current lower bound alone allows an invalid width to consume excessive memory instead of returning a format error. Enforce the LLVM bitstream width bounds before those shifts, and add a small synthetic rejection test alongside the existing round-trip controls.
MarlomMedeiros commented 2026-11-24 06:48:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-21T20:42:05Z.


Done at cf77eda. BitReader.read now rejects widths outside [0,64] and read_vbr rejects widths outside [2,32] before the mask and high-bit shifts, matching the LLVM bitstream bounds (uint64 field read and MaxChunkSize). A crafted abbreviation operand now returns a format error instead of allocating width-proportional integers.

Added a synthetic rejection control covering both encodings: an abbrev definition declaring ENC_VBR width 33 and one declaring ENC_FIXED width 65, each parsed from a serialized stream and asserted to raise.

Verification: ctest --preset dev --no-tests=error -R 'dxil_retarget' -V passes 2/2; dxil_retarget_probe still validates retargeted fixtures end to end on dxil.dll 1.9.2602.17 with module_only=validated.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068943417 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/250#issuecomment-7068943417). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-21T20:42:05Z. --- Done at cf77eda. `BitReader.read` now rejects widths outside [0,64] and `read_vbr` rejects widths outside [2,32] before the mask and high-bit shifts, matching the LLVM bitstream bounds (uint64 field read and MaxChunkSize). A crafted abbreviation operand now returns a format error instead of allocating width-proportional integers. Added a synthetic rejection control covering both encodings: an abbrev definition declaring `ENC_VBR` width 33 and one declaring `ENC_FIXED` width 65, each parsed from a serialized stream and asserted to raise. Verification: `ctest --preset dev --no-tests=error -R 'dxil_retarget' -V` passes 2/2; `dxil_retarget_probe` still validates retargeted fixtures end to end on dxil.dll 1.9.2602.17 with `module_only=validated`.
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!247
No description provided.