shader: harden depth_mask_aot CLI error handling and add pure-Python tests #2101

Merged
Ammmae0x merged 1 commit from upstream-pr/2108 into main 2026-11-25 00:43:03 +00:00
Ammmae0x commented 2026-11-25 00:32:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:32:09Z.


Change

Harden the CLI entry point and lowering error paths in tools/depth_mask_aot.py and add a pure-Python unit/CLI test suite (tests/depth_mask_aot_cli_check.py, registered in CMakeLists.txt as depth_mask_aot_cli):

  • Make main(argv=None) -> int accept an explicit argv list and return an exit status, using parser.exit(1, ...) for operational errors (OSError, ValueError, struct.error, zlib.error) instead of printing raw Python tracebacks.
  • Validate --table pairs are non-empty with non-negative SGPR and byte offset values, validate .hlsl destination suffix and distinct input/output resolved paths, and reject DXBC containers missing a DXIL part with an explicit ValueError.
  • Write generated HLSL via a same-directory temporary file replaced atomically onto the destination, unlinking the temporary file on any exception so pre-existing outputs stay intact and no .tmp artifacts leak.
  • Guard v_fmac_f32_e32 destination register lookups in lower() with an explicit ValueError("Unwritten vector register") instead of raising KeyError.
  • Add 7 pure-Python tests covering synthetic DXBC/FSSM container extraction, binary/unary/cmpx/_e64 lowering, mocked end-to-end CLI output generation, malformed DXBC containers, invalid CLI output paths/--table values, missing DXIL/container I/O errors, unsupported instructions, and atomic temp-file cleanup on write failure.

Verification

Commit: a9da90ec (rebased onto upstream/main 5a0b0aad).

  • out/pe-env/Scripts/python.exe -B tests/depth_mask_aot_cli_check.py -v -> exit 0 (Ran 7 tests in 0.758s, OK)
  • out/pe-env/Scripts/python.exe -B tests/dxcontainer_part_offsets_check.py -> exit 0
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 (Checked 18 Markdown files and 395 links.)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Checked 1421 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot-mutation verification: independently disabling 6 guards (v_fmac_f32_e32 unwritten dest, missing DXIL, temp-file cleanup on OSError, negative/empty --table, non-.hlsl suffix, and dest == src) each caused tests/depth_mask_aot_cli_check.py to fail (exit 1).

No capability skips (exit 77).

Evidence and follow-up

All DXBC/FSSM containers and decoded instruction streams in tests/depth_mask_aot_cli_check.py are synthetically constructed in Python within the test file under the repository MIT license. The pure-Python CLI suite mocks LLVM disassembly to exercise container parsing, CLI validation, lowering, and atomic output handling without requiring LLVM-C.dll or a GPU; end-to-end LLVM + D3D12 verification remains covered by tests/depth_mask_check.py.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594335176 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2108). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:32:09Z. --- ## Change Harden the CLI entry point and lowering error paths in `tools/depth_mask_aot.py` and add a pure-Python unit/CLI test suite (`tests/depth_mask_aot_cli_check.py`, registered in `CMakeLists.txt` as `depth_mask_aot_cli`): - Make `main(argv=None) -> int` accept an explicit `argv` list and return an exit status, using `parser.exit(1, ...)` for operational errors (`OSError`, `ValueError`, `struct.error`, `zlib.error`) instead of printing raw Python tracebacks. - Validate `--table` pairs are non-empty with non-negative SGPR and byte offset values, validate `.hlsl` destination suffix and distinct input/output resolved paths, and reject DXBC containers missing a `DXIL` part with an explicit `ValueError`. - Write generated HLSL via a same-directory temporary file replaced atomically onto the destination, unlinking the temporary file on any exception so pre-existing outputs stay intact and no `.tmp` artifacts leak. - Guard `v_fmac_f32_e32` destination register lookups in `lower()` with an explicit `ValueError("Unwritten vector register")` instead of raising `KeyError`. - Add 7 pure-Python tests covering synthetic DXBC/FSSM container extraction, binary/unary/cmpx/`_e64` lowering, mocked end-to-end CLI output generation, malformed DXBC containers, invalid CLI output paths/`--table` values, missing `DXIL`/container I/O errors, unsupported instructions, and atomic temp-file cleanup on write failure. ## Verification Commit: `a9da90ec` (rebased onto `upstream/main` `5a0b0aad`). - `out/pe-env/Scripts/python.exe -B tests/depth_mask_aot_cli_check.py -v` -> exit `0` (`Ran 7 tests in 0.758s`, `OK`) - `out/pe-env/Scripts/python.exe -B tests/dxcontainer_part_offsets_check.py` -> exit `0` - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (`form coverage checks passed`) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` (`Checked 18 Markdown files and 395 links.`) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Checked 1421 tracked source, script and build/CI files: no bidirectional controls.`) - Spot-mutation verification: independently disabling 6 guards (`v_fmac_f32_e32` unwritten dest, missing `DXIL`, temp-file cleanup on `OSError`, negative/empty `--table`, non-`.hlsl` suffix, and `dest == src`) each caused `tests/depth_mask_aot_cli_check.py` to fail (exit `1`). No capability skips (exit 77). ## Evidence and follow-up All DXBC/FSSM containers and decoded instruction streams in `tests/depth_mask_aot_cli_check.py` are synthetically constructed in Python within the test file under the repository MIT license. The pure-Python CLI suite mocks LLVM disassembly to exercise container parsing, CLI validation, lowering, and atomic output handling without requiring `LLVM-C.dll` or a GPU; end-to-end LLVM + D3D12 verification remains covered by `tests/depth_mask_check.py`. ## 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.
upstream-sync closed this pull request 2026-11-25 01:01:43 +00:00
tedin7 commented 2026-11-25 01:01:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:43:00Z.

Review: COMMENTED


Review of head a9da90ec907a00326118a5cbd4d9e7cfd2593079 (shader: harden depth_mask_aot CLI error handling, add pure-Python tests).

Result: no P1, no P2, 2 P3.

Commands executed locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 2108: all run jobs pass (Windows, Linux Python checks, gfx1013 fixtures).
  • git diff --check origin/main...HEAD: OK.
  • python3 tests/bidi_controls_check.py: pass.
  • python3 tests/docs_links_check.py: pass.
  • python3 -B tests/depth_mask_aot_cli_check.py: 7 tests OK.
  • python3 x2w_pipe.py win2025 2108 --wait 900 (CMake touched): Debug (dev preset) and Release /O2 both 5/5 (depth_mask_aot_cli plus the four depth_mask_*_draw_warp suites).

Mutations (each reverted with git checkout -- .):

  1. tools/depth_mask_aot.py:223 guard if dest not in vector replaced by if False: depth_mask_aot_cli_check.py fails (errors=1). Killed.
  2. tools/depth_mask_aot.py tmp_path.replace(dest) replaced by a no-op rename: fails (failures=1, errors=1). Killed.

Code read: error paths now return exit 1 with a message for OSError, ValueError, struct.error and zlib.error. The output is written through a temp file and then replaced, and the temp file is removed on failure. A container with no DXIL part and an unwritten v_fmac_f32 destination now give clean errors. The only in-tree caller is the module import in shader_profile_audit.py, and main() is unchanged for it.

P3:

  • tools/depth_mask_aot.py:315-325 (NamedTemporaryFile + replace): the temp file is created with mode 0600, so the generated .hlsl now ends up 0600 instead of the umask default (0644). This can surprise other users or CI steps that read the output. Consider os.chmod to 0o666 & ~umask before the replace.
  • tools/depth_mask_aot.py:286: --table is checked for non-negative values, but a huge offset or SGPR is only caught later by lower. Non-blocking; a cap or a test for it would be tidier.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049782971 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2108#pullrequestreview-6049782971). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:43:00Z. **Review:** COMMENTED --- Review of head `a9da90ec907a00326118a5cbd4d9e7cfd2593079` (shader: harden depth_mask_aot CLI error handling, add pure-Python tests). **Result: no P1, no P2, 2 P3.** Commands executed locally: - `git merge-tree --write-tree --name-only origin/main HEAD`: clean, no conflicts. - `gh pr checks 2108`: all run jobs pass (Windows, Linux Python checks, gfx1013 fixtures). - `git diff --check origin/main...HEAD`: OK. - `python3 tests/bidi_controls_check.py`: pass. - `python3 tests/docs_links_check.py`: pass. - `python3 -B tests/depth_mask_aot_cli_check.py`: 7 tests OK. - `python3 x2w_pipe.py win2025 2108 --wait 900` (CMake touched): Debug (dev preset) and Release /O2 both 5/5 (`depth_mask_aot_cli` plus the four `depth_mask_*_draw_warp` suites). Mutations (each reverted with `git checkout -- .`): 1. `tools/depth_mask_aot.py:223` guard `if dest not in vector` replaced by `if False`: `depth_mask_aot_cli_check.py` fails (errors=1). Killed. 2. `tools/depth_mask_aot.py` `tmp_path.replace(dest)` replaced by a no-op rename: fails (failures=1, errors=1). Killed. Code read: error paths now return exit 1 with a message for OSError, ValueError, struct.error and zlib.error. The output is written through a temp file and then replaced, and the temp file is removed on failure. A container with no DXIL part and an unwritten `v_fmac_f32` destination now give clean errors. The only in-tree caller is the module import in `shader_profile_audit.py`, and `main()` is unchanged for it. P3: - `tools/depth_mask_aot.py:315-325` (`NamedTemporaryFile` + `replace`): the temp file is created with mode 0600, so the generated `.hlsl` now ends up 0600 instead of the umask default (0644). This can surprise other users or CI steps that read the output. Consider `os.chmod` to `0o666 & ~umask` before the replace. - `tools/depth_mask_aot.py:286`: `--table` is checked for non-negative values, but a huge offset or SGPR is only caught later by `lower`. Non-blocking; a cap or a test for it would be tidier. AI-assisted; commands listed were executed locally.
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!2101
No description provided.