Two things kept this test file red on a machine where numpy came from
pip install --user:
- the tool imported numpy at module level, so a bad --width reported
"needs numpy" instead of "must be at least 1". numpy is imported late now
and only the computation requires it;
- the skip gate asked whether numpy imports *here*, while the tests run the
tool with -I, which hides the user site. It now probes the way the tool runs.
Measured on main b8bd37111, Windows, Python 3.13: 9 failed, 8 passed, 3 skipped
before; 14 passed, 6 skipped after. On a machine where -I sees numpy, the probe
returns true and the three gated cases run exactly as before.
Written with an AI assistant.
amd_swizzle.py turned bad arguments into tracebacks or into a silent success:
- --width 0 or --height 0 crashed in Pillow with UnidentifiedImageError, and a
negative size crashed in numpy with "negative dimensions are not allowed",
because the guards only checked --out and the blob path.
- A negative --offset sliced from the end of the blob, and an offset past the
end left an empty buffer; both exited 0 and wrote no image.
- A --modes value matching no pattern table produced no line at all, so a
caller could not tell success from a mistyped mode.
- The default header path is a Windows-shaped placeholder, so on a host
without the file the tool died in a raw FileNotFoundError.
Each case now prints one ERROR line and exits 2 before any work starts, and a
missing or malformed gfx10SwizzlePattern.h names AMD_SWIZZLE_HEADER instead of
raising. A valid run is unchanged.
Tests: the six cases above exercise the CLI with a synthetic header; five of
them fail on c7e82e26 and pass here, and the valid-run test passes on both.
The CLI built every equation with 16 address bits and laid blocks out 64 KB apart, whatever table
--modes picked, so a 4K (or 256-byte) table was detiled as if it were 64 KB. --modes also matched
by substring, so "4K" or "4K_S" picked every 64K table as well, and those won. Each table now
gets its block size from its name (256 -> 8 bits, 4K -> 12, 64K -> 16, the values
tex_mode_probe.py already uses), detile() takes block_bytes, and --modes matches whole name parts.
The default (64K) behaves as before.
Real data (counts and scores only, samples deleted afterwards): three 512x512 BC1 textures that
tex_export.py exports as SW_4K_S. With --modes 4K_S, main's best candidates are SW_64K_S_T /
SW_64K_S (scores 15.04 / 14.10 / 53.32); with this change SW_4K_S (14.13 / 12.26 / 52.55), and its
detiled blocks are byte-identical to tex_export.detile_offsets on all three.
Tests: test_cli_detiles_4k_tables_with_4k_blocks tiles a gradient in 4 KB blocks under a synthetic
header with the same entry in a 4K and a 64K table (main: both tables listed, score 3.81 instead
of the gradient's own).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`--out` is written by PIL with no checks: pointing it at the blob being probed
opened the sample for the read and then saved the preview over it, truncating
the very bytes the probe had just read (`tile_probe shot.bin --out shot.bin`
leaves shot.bin as a PNG). A folder that did not exist was a PIL traceback
after the whole probe had already run, and a Pillow install in the --user
site is invisible to the documented `python -I` invocation, which was a
ModuleNotFoundError from inside render() at the same late point.
The path checks now run before the read: refuse a directory, refuse the input
(realpath plus samefile, so a different spelling of the same file is caught),
create the preview's folder, and give Pillow's absence one line at render
time. amd_swizzle imports the same helper for its own preview.
The CLI's --bpe 4 path failed in block_feature, which expects a 16-byte
BC block and read column 8 of a four-byte pixel. Add feature() for 1/2/4
bpe (raw RGB, or channels for 1/2 bpe) and use it in main; block_feature
still handles BC1/BC3/BC5/BC7. Tested synthetically with 4/4 pytest.
The solo-bit heuristic only works for the S modes; in the XOR modes the
high x/y bits are almost always XORed, so the block came out too small
(72/75 RDNA2 R_X entries). Use the same element-count formula as
tex_export.detile_offsets, which matches every 64 KB entry.
Also treat 1/2/4 bpe as one element per pixel in the CLI grid, and write
4 bpe guesses as uncompressed RGBA8 instead of BC7.
Verified with synthetic equations for 1/2/4/8/16 bpe (256x256, 256x128,
128x128, 128x64, 64x64) and the existing parser tests: 3/3 pass.
The CI bash loop in ci.yml runs 'grep -q ^import pytest && continue'
to skip pytest-only files in the standard-library-only check job. My
earlier change removed the top-level import pytest, causing the CI to
try running test_amd_swizzle.py without numpy, which then crashed.
Keep import pytest at module level so the CI skips the file. Under
pytest (the translator-tests job) it works as before; the __main__
guard handles direct python -I invocations locally.
The CI bash loop in CI.yml runs every test that does not import pytest at the
top level. With my earlier change test_amd_swizzle no longer imports pytest,
so the CI tries to run it. A module-level raise unittest.SkipTest produces a
non-zero exit code, which the CI catch with || exit 1.
Fix: store the skip condition in a module-level flag and check it in the
__main__ guard, which exits 0 with a skipped message. The CI passes
and the test still works under both pytest -k and direct invocation.
- tools/awc_opus.py: wrap export_bank file read in a with-statement to
close the handle promptly instead of relying on GC (fixes ResourceWarning
seen in test output).
- tests/test_amd_swizzle.py: use raise unittest.SkipTest instead of
import pytest; pytest.skip so the test works under both python -I and
unittest discovery when numpy is absent. No pytest dependency needed.
- tests/test_d3d12_xs_surface.py: same treatment for the two conditional
skips (Windows SDK headers, SCARAB_REF). The test still skips gracefully
without pytest installed.
- .github/workflows/runtime.yml: add a linux-gpu-tools job that installs
libvulkan-dev, builds all GPU test tools with cmake + ninja + g++, and
verifies every tool binary exists. Rename the Windows job from 'build' to
'windows' to disambiguate. This catches build regressions in GPU tool code
that only manifest on Linux.
AI-assisted.
eval(cell, {}, env) still exposes builtins, so a crafted header
passed via AMD_SWIZZLE_HEADER could run code. addrlib's tables only
use symbols, integers and ^, so parse exactly that and reject the rest.