tooling: add a translator corpus hash check and an IR dump option #3791

Merged
Leyukaka merged 3 commits from upstream-pr/3791 into main 2026-12-02 05:18:39 +00:00
Leyukaka commented 2026-12-01 22:54:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T22:54:14Z.


Problem

There is no single check that says whether a change to the native translator alters its output. Refactors, build-flag changes and cache changes each have to argue "no output change" from individual fixtures.

Change

  • tests/translator_corpus_hash.py runs compile_dxil over a source-built corpus (graphics pairs, RTV variants, compute requests, raw mesh shaders) and writes a sorted TSV: one row per request with its status and either a SHA-256 fingerprint of the published DXIL or the refusal reason. Running the same script and DXC directory against two builds and diffing the TSVs compares their output.
  • compile_dxil --dump-ir writes the exact text handed to the compiler beside each stage as OUTPUT.cso.ir. The corpus script accepts --ir to fingerprint that text instead.
  • Two CTests, native_translator_corpus_dxil and native_translator_corpus_ir, check known compilations and refusals and compare two cold snapshots byte for byte. The IR test also compares DXIL from runs with and without the dump option.
  • The corpus reuses the existing synthetic fixtures; the refusal, watch and mesh checks only expose their request builders as helpers. No lowering code changes.
  • docs/experiments/translator-corpus.md has the base-to-head procedure.

Possible follow-up: a translator-corpus job in windows.yml that builds compile_dxil for the PR head and its merge base and requires identical TSVs.

Validation

Windows, MSVC, dev preset, at 2568a0d59: 8/8 tests passed.

cmake --build --preset dev --target compile_dxil
ctest --preset dev --no-tests=error -R '^(native_translator_corpus_(dxil|ir)|native_compile_dxil_(refusals|rekey|watch)|native_direct_mesh|native_rtv_variant_controls|startup_compute_translate_requests)$' --output-on-failure

Comparing two builds:

$sdk = (Get-Content out/build/dev/x2w-dxc-dir.txt -Raw).Trim()
python -B tests/translator_corpus_hash.py $baseCompiler $sdk --out out/translator-base.tsv
python -B tests/translator_corpus_hash.py $headCompiler $sdk --out out/translator-head.tsv
git diff --no-index --exit-code -- out/translator-base.tsv out/translator-head.tsv

Fixtures are generated from the synthetic instruction words already in the repository's tests.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5596117882 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3791). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T22:54:14Z. --- ## Problem There is no single check that says whether a change to the native translator alters its output. Refactors, build-flag changes and cache changes each have to argue "no output change" from individual fixtures. ## Change - `tests/translator_corpus_hash.py` runs `compile_dxil` over a source-built corpus (graphics pairs, RTV variants, compute requests, raw mesh shaders) and writes a sorted TSV: one row per request with its status and either a SHA-256 fingerprint of the published DXIL or the refusal reason. Running the same script and DXC directory against two builds and diffing the TSVs compares their output. - `compile_dxil --dump-ir` writes the exact text handed to the compiler beside each stage as `OUTPUT.cso.ir`. The corpus script accepts `--ir` to fingerprint that text instead. - Two CTests, `native_translator_corpus_dxil` and `native_translator_corpus_ir`, check known compilations and refusals and compare two cold snapshots byte for byte. The IR test also compares DXIL from runs with and without the dump option. - The corpus reuses the existing synthetic fixtures; the refusal, watch and mesh checks only expose their request builders as helpers. No lowering code changes. - `docs/experiments/translator-corpus.md` has the base-to-head procedure. Possible follow-up: a `translator-corpus` job in `windows.yml` that builds `compile_dxil` for the PR head and its merge base and requires identical TSVs. ## Validation Windows, MSVC, `dev` preset, at `2568a0d59`: 8/8 tests passed. ```powershell cmake --build --preset dev --target compile_dxil ctest --preset dev --no-tests=error -R '^(native_translator_corpus_(dxil|ir)|native_compile_dxil_(refusals|rekey|watch)|native_direct_mesh|native_rtv_variant_controls|startup_compute_translate_requests)$' --output-on-failure ``` Comparing two builds: ```powershell $sdk = (Get-Content out/build/dev/x2w-dxc-dir.txt -Raw).Trim() python -B tests/translator_corpus_hash.py $baseCompiler $sdk --out out/translator-base.tsv python -B tests/translator_corpus_hash.py $headCompiler $sdk --out out/translator-head.tsv git diff --no-index --exit-code -- out/translator-base.tsv out/translator-head.tsv ``` Fixtures are generated from the synthetic instruction words already in the repository's tests.
R0Y00 commented 2026-12-02 01:56:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T01:56:03Z.


The reviewed head passed Windows and Linux CI, but GitHub reports a merge conflict against current main. Please rebase compile_dxil.cpp while preserving #3794's MSVC warning handling, and rerun the batch, refusal and IR-dump tests on the rebased head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7332272400 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3791#issuecomment-7332272400). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T01:56:03Z. --- The reviewed head passed Windows and Linux CI, but GitHub reports a merge conflict against current main. Please rebase `compile_dxil.cpp` while preserving #3794's MSVC warning handling, and rerun the batch, refusal and IR-dump tests on the rebased head.
Leyukaka commented 2026-12-02 04:13:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T04:13:39Z.


Rebased onto main (0dd65da11) after #3794 merged. The only conflict was in tools/startup/compile_dxil.cpp, where the IR dump option now sits after the #pragma warning(suppress: 4996) that #3794 added. The CTest selection from the description passes again with MSVC on the new head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7334690720 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3791#issuecomment-7334690720). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T04:13:39Z. --- Rebased onto `main` (0dd65da11) after #3794 merged. The only conflict was in `tools/startup/compile_dxil.cpp`, where the IR dump option now sits after the `#pragma warning(suppress: 4996)` that #3794 added. The CTest selection from the description passes again with MSVC on the new head.
R0Y00 commented 2026-12-02 05:17:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:17:55Z.

Review: APPROVED


Thanks for the rebase. I confirmed the MSVC warning suppression still surrounds the legacy environment lookup and the explicit dump path is reserved alongside the output paths. On Windows Debug at 13625d24, the eight tests selected by ctest --preset dev --no-tests=error -j 2 -R '^(native_translator_corpus_(dxil|ir)|native_compile_dxil_(refusals|rekey|watch)|native_direct_mesh|native_rtv_variant_controls|startup_compute_translate_requests)$' --output-on-failure passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145172096 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3791#pullrequestreview-6145172096). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:17:55Z. **Review:** APPROVED --- Thanks for the rebase. I confirmed the MSVC warning suppression still surrounds the legacy environment lookup and the explicit dump path is reserved alongside the output paths. On Windows Debug at `13625d24`, the eight tests selected by `ctest --preset dev --no-tests=error -j 2 -R '^(native_translator_corpus_(dxil|ir)|native_compile_dxil_(refusals|rekey|watch)|native_direct_mesh|native_rtv_variant_controls|startup_compute_translate_requests)$' --output-on-failure` passed.
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!3791
No description provided.