startup: make gfx2hlsl --capture terminate on wrapper cycles and refuse short descs #1521

Merged
RenzoWit35 merged 2 commits from upstream-pr/1528 into main 2026-11-24 14:39:46 +00:00
RenzoWit35 commented 2026-11-24 13:43:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:43:07Z.


Change

The --capture branch of tools/startup/gfx2hlsl.py reads pipeline records from a capture file and writes one translation request per pipeline. Two malformed records made it fail in ways that lose the rest of the run:

  • A path-55 wrapper is followed to its base with while p and p['path'] == 55 and p['base']. A wrapper whose base is itself, or a longer cycle of wrappers, never terminated.
  • A path-57 record with a desc shorter than 96 bytes raised struct.error at struct.unpack_from('<12Q', p['desc'], 0).

The chain walk now keeps a visited set and prints pso <id>: wrapper chain loops back to <id>. A short desc prints pso <id>: pipeline desc is <n> bytes, need 96. In both cases the reader moves on to the next record, in the style of the existing code not captured line. 9 added lines; parse_root, the --pending handling and the ALU lowering are untouched.

No test exercised --capture before (no match in tests/, CMakeLists.txt or the docs). New tests/startup_gfx2hlsl_capture_check.py builds synthetic capture files with the chunk and mem helpers of tests/startup_capture_check.py and runs the tool in a subprocess with a timeout. It is registered as CTest startup_gfx2hlsl_capture, in the python-linux job and in the AGENTS.md list.

Verification

Windows 11, Python 3.14.5, base origin/main 1ca0dec1.

python -B tests/startup_gfx2hlsl_capture_check.py
ok   good path writes request files
ok   self-referencing wrapper terminates cleanly
ok   two-wrapper cycle terminates cleanly
ok   short desc is refused with a message
ok   unknown code reports not captured
startup_gfx2hlsl_capture_check passed

Negative control, with tools/startup/gfx2hlsl.py from main and the new check:

ok   good path writes request files
FAIL self-referencing wrapper terminates cleanly: HUNG: no exit within 20 s

The check stops there. With the cycle cases disabled, the short-desc case on main ends in a traceback with struct.error (buffer of 40 bytes).

Also run on this branch, all exit 0: tests/startup_capture_check.py, tests/startup_translator_check.py, tests/startup_gfx2hlsl_sdwa_check.py, tests/startup_gfx2hlsl_bit_alu_check.py.

Not run: the CTest registration through ctest (the add_test mirrors the neighbouring startup_capture entry), the new check on Linux (this PR's python-linux job is the first Linux run), and GPU tests.

Evidence and follow-up

Inputs are synthetic records built in the test; no captured data from an executable. My open PR #1526 changes parse_root in the same file and adds a line to the same two lists a few lines further down; the two merge cleanly in either order (checked with git merge-tree). Open PR #1471 edits other parts of gfx2hlsl.py.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583149320 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1528). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T13:43:07Z. --- ## Change The `--capture` branch of `tools/startup/gfx2hlsl.py` reads pipeline records from a capture file and writes one translation request per pipeline. Two malformed records made it fail in ways that lose the rest of the run: - A path-55 wrapper is followed to its base with `while p and p['path'] == 55 and p['base']`. A wrapper whose base is itself, or a longer cycle of wrappers, never terminated. - A path-57 record with a desc shorter than 96 bytes raised `struct.error` at `struct.unpack_from('<12Q', p['desc'], 0)`. The chain walk now keeps a visited set and prints `pso <id>: wrapper chain loops back to <id>`. A short desc prints `pso <id>: pipeline desc is <n> bytes, need 96`. In both cases the reader moves on to the next record, in the style of the existing `code not captured` line. 9 added lines; `parse_root`, the `--pending` handling and the ALU lowering are untouched. No test exercised `--capture` before (no match in `tests/`, `CMakeLists.txt` or the docs). New `tests/startup_gfx2hlsl_capture_check.py` builds synthetic capture files with the `chunk` and `mem` helpers of `tests/startup_capture_check.py` and runs the tool in a subprocess with a timeout. It is registered as CTest `startup_gfx2hlsl_capture`, in the `python-linux` job and in the AGENTS.md list. ## Verification Windows 11, Python 3.14.5, base `origin/main` 1ca0dec1. ``` python -B tests/startup_gfx2hlsl_capture_check.py ok good path writes request files ok self-referencing wrapper terminates cleanly ok two-wrapper cycle terminates cleanly ok short desc is refused with a message ok unknown code reports not captured startup_gfx2hlsl_capture_check passed ``` Negative control, with `tools/startup/gfx2hlsl.py` from `main` and the new check: ``` ok good path writes request files FAIL self-referencing wrapper terminates cleanly: HUNG: no exit within 20 s ``` The check stops there. With the cycle cases disabled, the short-desc case on `main` ends in a traceback with `struct.error` (buffer of 40 bytes). Also run on this branch, all exit 0: `tests/startup_capture_check.py`, `tests/startup_translator_check.py`, `tests/startup_gfx2hlsl_sdwa_check.py`, `tests/startup_gfx2hlsl_bit_alu_check.py`. Not run: the CTest registration through `ctest` (the `add_test` mirrors the neighbouring `startup_capture` entry), the new check on Linux (this PR's `python-linux` job is the first Linux run), and GPU tests. ## Evidence and follow-up Inputs are synthetic records built in the test; no captured data from an executable. My open PR #1526 changes `parse_root` in the same file and adds a line to the same two lists a few lines further down; the two merge cleanly in either order (checked with `git merge-tree`). Open PR #1471 edits other parts of `gfx2hlsl.py`. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:01:52 +00:00
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!1521
No description provided.