Scripts: harden check_layout CLI, DXBC validation, and error handling #2141
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2151"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by HumanlyDev on 2026-11-25T06:24:45Z.
Harden
scripts/re/check_layout.pyso malformed/non-DXBC files, DXBC blobs withoutRTS0, subdirectories, disassembler errors, off-boundary loads, and missing/invalid CLI arguments are handled cleanly instead of crashing or silently passing, and add unit tests inscripts/test_check_layout.py. Non-runtime change underscripts/.What is in it
scripts/re/check_layout.py:if __name__ == '__main__':(parse_args,check_listing,main) with<dir> [--xcl <path>]argument validation.b'DXBC'magic and chunk/RTS0 bounds inparts()andlayout(), skip subdirectories and non-.dxbcfiles, handlers is Nonecleanly, and read files withwith open(...).xclbinary exists andsubprocess.runexits0, and return exit code1when off-boundary loads (bad > 0) or disassembler errors occur.scripts/test_check_layout.py:parts/layout(with/withoutRTS0, non-DXBC, truncated containers), directory scanning with subdirs/non-.dxbc/invalid.dxbc, mockedxcl disasmfailures and missing--xcl, on-boundary vs off-boundarys_load_dworddetection, and CLI argument error handling.Tested
32.0.16.1088), AMD Ryzen 5 7600, Windows 11 Pro10.0.26200(build26200), Python3.14.6,rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.8.2502.11.python -m unittest scripts/test_check_layout.py -v: 8 passed, 0 failed (OKin 0.218s)..\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4, RTX 4060, debug): 1154 passed, 0 failed, 46 ignored across 21 targets (25 SKIPPED GPU checks: 20no wave64, 3per-lane form#1426refusals, 1no heap windows, 1cannot disable the driver cache (Windows Developer Mode is required)).Regression run
scripts/(no runtime files undercrates/xcl/src/modified).Not tested
scripts/re/check_layout.pyagainst a live directory of extractedbvhb_shaders.py.dxbcfiles (not present on this machine), retail titles /XCL_SAMPLE_*, AMD RDNA3/4, Linux / Wine.AI use
scripts/re/check_layout.py, wrote the hardening changes andscripts/test_check_layout.py, ran the unit tests and workspace suite, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T07:04:46Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T10:46:47Z.
Diff audited (
scripts/re/check_layout.pybounds checks +test_check_layout.py) and CI workflow approved (running). NeedsBuild and testgreen plus independent test verification.Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-25T11:43:14Z.
I compared this head (
aa825c088e65db380f67a112e0474e56ea841b6a) with #1088 using a native disassembler stand-in and the same two synthetic shader files. Both reported stderr, but a child that exited 23 with a stdout-only diagnostic lost its message here. A one-line follow-up and regression assertion retain stdout when stderr is empty. The batch still checks the second file, counts its successful load and exits 1. Stderr still takes precedence; a silent failure retains the numeric fallback. Five native cases passed on the candidate, including an all-success control. The new assertion failed on the original script; with the fix,python -B -m unittest discover -s scripts -p "test_*.py"passed 33/33. The eight focused tests also passed when combined locally with the earlier null-offset candidate931c40a. Windows 11, Core i7-13700, Python 3.14.3; no retail shaders or GPU work. OpenAI Codex (GPT-6) prepared the fix and ran the checks.Earlier verification
Tested
aa825c088e65db380f67a112e0474e56ea841b6aon Windows 11 24H2 (26100.9711), i7-13700, Python 3.14.3.Tested
python -B -m unittest discover -s scripts -p test_check_layout.pypassed all 8 tests (0 failures, 0 skips).scripts/re/check_layout.py <fixture-dir> --xcl <fixture-disasm.cmd>on a synthetic root signature with one 8-byte CBV at offset 0. The stand-in printed the pointer-copy instructions and one scalar load. Offsets0x0and0x4each counted as one on-boundary load (exit 0). Offset0x8counted as one off-boundary load (exit 1).s_load_dword s5, s[2:3], null, the checker reported 0 on, 0 off (exit 0). This exact load is in the tracked LLVM example, and XCL's formatter emitsnullfor this case.nullthen counted as one on-boundary load and the other three results stayed the same.Not tested
Actual XCL disassembly, retail shader inputs or the Rust/GPU workspace suite.
AI use
OpenAI Codex (GPT-6) ran the tests, wrote the CLI fixture and follow-up patch, and prepared this report.
Follow-up on the review at
aa825c088e65. Tested candidate 23825658d. A directory containing only a four-byteDXBCfile previously returned 0. The candidate returned 1 and reported that no valid container remained, without invoking disassembly. The existing mixed batch with a valid container lackingRTS0and an invalid file still passed. All 34 script tests passed.Command on the candidate:
python -B -m unittest discover -s scripts -p "test_*.py". Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T18:28:33Z.
Review note on
aa825c0:@RavenCurseBurgnoted thatscripts/re/check_layout.pymisses zero-offsets_load_dword ..., nullspellings (emitted by XCL's formatter and LLVM AMDGPU examples). Addressing that plus getting independent verification oftest_check_layout.pywill unblock merge.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T10:06:03Z.
Review: COMMENTED
On
aa825c0, a directory whose only.dxbcfile is malformed now exits 0 after validating nothing. I reproduced this with a four-bytebad.dxbccontaining onlyDXBCand an existing stand-in--xclexecutable that was never called. This head printedskipping invalid DXBC (not a DXBC container)andloads on parameter boundaries: 0, off: 0, then exited 0; the PR base and current main exited 1 on the same input. The new catch skips the file without incrementingerrors, so an all-invalid batch appears green. The existing mixed-file fixture expects success despite a corrupt file, which leaves the intended contract for an all-invalid directory unclear.Could the script distinguish malformed inputs from valid files that simply lack
RTS0, and fail when no checkable file remains (or count malformed.dxbcfiles as validation errors if that is the intended policy)? A malformed-only fixture should pin down the exit status while the scanner still continues through a mixed batch. This was an exact-head CPU-only differential; no GPU shader disassembly ran.Imported from ivall/xcl. Originally posted by throny on 2026-11-28T08:01:46Z.
Two contributors checked independently and found that #1196 solves the same problem in a different way: #1607, group D146. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:29:36Z.
Triage (#1607) – head
aa825c0Overlaps with other open
check_layout.pyPRs. #1196 rewrites the same CLI: it finds xcl throughXCL_EXEor the target dirs and adds-h. This PR adds argparse--xcland validates DXBC/RTS0 bounds instead. #1088 also reportsxcl disasmfailures, but it exits on the first one. #1729 (and #1196) also skip shaders without RTS0. They all rewrite the same loop, so only one can merge cleanly.No problems found in the diff. The tests mock
subprocess.runand cover the new exit codes.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:58:14Z.
merge-check
base:
1c8b551475head:
aa825c088emerge: clean (
git merge-tree --write-tree 1c8b5514 aa825c08-> tree47a90845e6d3,git diff --checkclean;scripts/re/check_layout.pyandscripts/test_check_layout.py, +338/-21)build: not run (Tier 0 Python script diff; no Rust code changed)
tests:
python -m unittest -v scripts/test_check_layout.py-> 8 passed, 0 failed;python -m unittest discover -s scripts -p "test_*.py"-> 73 passed, 1 error (test_discord_mirror.pymissing%ComSpec%/%SystemRoot%on Windows, same failure on base1c8b5514). Rust workspace tests not run (Tier 0).review: Read the full merged diff (+338/-21). Findings: (1) Corrupt
.dxbcinputs silently succeed with exit code 0: inscripts/re/check_layout.py:119-126, catchingValueErrorprints a message to stderr andcontinues without incrementingerrors, somainreturns0at line151(reproduced locally on a 4-byteDXBCfile:rc=0,loads on parameter boundaries: 0, off: 0, stderrbad.dxbc: skipping invalid DXBC (not a DXBC container)). (2)scripts/re/check_layout.py:141reads onlyproc.stderr.strip()on non-zeroxcl disasmexit, dropping stdout-only diagnostics. (3)scripts/re/check_layout.py:86-89only matches hex offsets(0x[0-9a-f]+), missing zero-offsetnullspellings. Also overlaps#1196and#1088(#1607group D146).performance: none (offline analysis script in
scripts/re/; zero runtime impact)verdict: not yet: malformed
.dxbcfiles still causemain()to exit 0 without counting an error (scripts/re/check_layout.py:124-126,151), stdout-only disassembler failure messages are dropped (:141), and overlap with#1196/#1088(#1607D146) is unresolvedhardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Python 3.15.2, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by misaka-maples on 2026-12-03T03:13:12Z.
merge-check
base:
395405e4c0head:
aa825c088emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 5 failed, 56 ignored. SKIPPED: 28 notices (22 no wave64, 2 no heap windows, 2 missing d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 could not disable the driver cache). Failing: gpu::dxil::fuzz_tests::{fuzz_validate_and_gpu_0, fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_2, fuzz_validate_and_gpu_3} and gpu::dxil::ops_tests::int64_bit_ops_match_cpu. All five reproduced on this base with cargo test -p xcl --lib -- --test-threads=4 (2851 passed, 5 failed, 36 ignored on each tree for the library target), with the same fuzz seeds and CreateComputePipelineState result 0x8007000E. Python: python -B -m unittest scripts/test_check_layout.py -v -> 8 passed. Top-level script discovery (python -B -m unittest discover -s scripts -p "test_*.py" -v) -> 94 passed, 1 error on the merge and 86 passed, 1 error on the base. The same Discord mirror test cleared ComSpec and SystemRoot before invoking the Windows shell on both trees.
title run: none
review: scripts/re/check_layout.py:124-126,151 can report success when every DXBC input is invalid. A batch containing one plain-text .dxbc returned 1 on this base and 0 on the merge, with zero loads checked and a warning. The new unit tests check that invalid files can be skipped but leave the malformed-only success case unguarded. Existing coverage gap: XCL emits null for zero offsets, which check_layout.py:86-89 does not match. The new mocks use 0x0. This is a Tier 0 change confined to the standalone script and its unit tests.
performance: No default frame-time or runtime memory impact is expected from this standalone Python tool. Its parser now collects every chunk before looking for RTS0, so standalone CLI memory use can increase. No timing measurement was taken.
verdict: not yet: the layout checker returns success for malformed-only input after checking zero loads.
hardware / tool and model: NVIDIA GeForce RTX 5060 Laptop GPU (8151 MiB, driver 592.19), Intel Core i7-14650HX, Windows 11 25H2 build 26200.9168, rustc 1.100.1 (MSVC), DXC 1.9.2609.5, Python 3.13.15 / OpenAI Codex (GPT-6)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.