Skip to content

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

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
RenzoWit35:startup/gfx2hlsl-capture-wrapper-cycle
Nov 24, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
RenzoWit35:startup/gfx2hlsl-capture-wrapper-cycle

Conversation

@RenzoWit35

Copy link
Copy Markdown
Contributor

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 1ca0dec.

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.

…se short descs

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.
…ure-wrapper-cycle

# Conflicts:
#	.github/workflows/windows.yml
@R0Y00
R0Y00 merged commit a600aca into R0Y00:main Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants