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

Manually merged
github merged 2 commits from gh-pr/1528/head into gh-pr/1528/base 2026-11-26 23:14:23 +00:00
Owner

@⁠RenzoWit35 on GitHub · 2026-11-24 13:43 UTC · original
RenzoWit35:startup/gfx2hlsl-capture-wrapper-cycle → main · +101 −0 · 5 files · 2 commits · merged 2026-11-24 14:39 UTC

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.

**@⁠RenzoWit35** on GitHub · 2026-11-24 13:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1528) `RenzoWit35:startup/gfx2hlsl-capture-wrapper-cycle` → `main` · +101 −0 · 5 files · 2 commits · merged 2026-11-24 14:39 UTC ## 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.
The --capture reader followed path-55 wrapper bases with no visited set, so a
wrapper whose base is itself (or a longer cycle) looped forever. A path-57
record with a desc shorter than 96 bytes raised struct.error. Both now print a
one-line "pso <id>: ..." message and the reader moves on to the next call.

tests/startup_gfx2hlsl_capture_check.py builds synthetic captures and runs the
tool with a timeout: good path, self-reference, two-wrapper cycle, short desc,
and the existing "code not captured" report.
# Conflicts:
#	.github/workflows/windows.yml
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:14:21 +00:00
github manually merged commit 906fc90a26 into gh-pr/1528/base 2026-11-26 23:14:23 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.