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

Manually merged
github merged 1 commit from gh-pr/250/head into gh-pr/250/base 2026-11-26 21:37:33 +00:00
Owner

@⁠MarlomMedeiros on GitHub · 2026-11-21 19:16 UTC · original
dxil-xb2-retarget → main · +1199 −0 · 5 files · 1 commits · merged 2026-11-21 20:55 UTC

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.
**@⁠MarlomMedeiros** on GitHub · 2026-11-21 19:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/250) `dxil-xb2-retarget` → `main` · +1199 −0 · 5 files · 1 commits · merged 2026-11-21 20:55 UTC 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:37:30 +00:00
github manually merged commit cf77eda5df into gh-pr/250/base 2026-11-26 21:37:33 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 20:28 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-21 20:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/250#issuecomment-7068776699) 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.
Author
Owner

@⁠MarlomMedeiros on GitHub · 2026-11-21 20:42 UTC · original

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.

**@⁠MarlomMedeiros** on GitHub · 2026-11-21 20:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/250#issuecomment-7068943417) 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`.
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-21 19:17 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-21 19:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/250#pullrequestreview-6007632632) · **reviewed** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.