Commit Graph

21 Commits

Author SHA1 Message Date
aec457e1d7 tests: exercise amd_swizzle guards with isolated dependencies
AI-assisted with OpenAI Codex.
2026-11-30 14:55:41 +01:00
34046550a8 amd_swizzle: validate without numpy, and ask the gate the tool's question
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.
2026-11-30 14:55:41 +01:00
672dba76f9 amd_swizzle: reject impossible sizes, unusable offsets and empty results
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.
2026-11-25 06:33:03 +01:00
8bcf3eba77 tests/test_amd_swizzle: skip the numpy tests without numpy instead of failing (#6686)
Squash-merged after diff review of PR #6686
2026-11-23 10:57:25 -06:00
22a22b206d Merge pull request #3355 from klarnet2009
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:07:22 -05:00
c83f6b65ba fix(amd_swizzle): catch ValueError from Image.save
# Conflicts:
#	tools/amd_swizzle.py
2026-11-23 00:08:25 +02:00
a1961dc8f4 fix(amd_swizzle): validate --out path and guard file I/O errors
# Conflicts:
#	tools/amd_swizzle.py
2026-11-23 00:08:06 +02:00
7d88856054 Merge pull request #3568 from tylerstraub 2026-11-22 17:02:45 -05:00
8051796d19 TEST-734: document the complete amd_swizzle pytest invocation 2026-11-22 12:57:22 -08:00
903ff173bc Merge pull request #2782 from Vonsek 2026-11-22 15:11:58 -05:00
8d744d3938 fix(assets): preview uncompressed R8 and RG8 tiles
The preview tried to decode one- and two-byte elements as BC7, so the CLI could score these candidates but failed to render their pixels.
2026-11-22 19:16:24 +01:00
c14a8d5fcb fix(tools): retain partial BC blocks in AMD swizzle previews
A BC image with a non-aligned dimension still needs its edge blocks for the DDS decoder to read the declared dimensions.
2026-11-22 17:59:01 +01:00
02f84b4e02 amd_swizzle: detile each pattern table with its own block size
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>
2026-11-22 08:29:34 -03:00
c20cb27807 tile_probe/amd_swizzle: a preview must not overwrite the blob it probed
`--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.
2026-11-22 04:45:30 -06:00
3fb15364a7 fix(tools): score uncompressed swizzle guesses from raw RGB
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.
2026-11-22 03:18:10 +01:00
0a35e276d9 fix(tools): derive the 64 KB swizzle block extent from the element count
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.
2026-11-22 02:58:59 +01:00
9a794f631e fix: keep import pytest at top so CI grep filters test_amd_swizzle
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.
2026-11-21 21:25:33 +01:00
e2e5ecd9d8 fix: test_amd_swizzle exits 0 when numpy is absent
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.
2026-11-21 21:17:07 +01:00
711d386320 CI, tests, tools: fix file handle leak, skip without pytest, build GPU tools on Linux
- 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.
2026-11-21 21:10:01 +01:00
617bf181ad CI: keep optional numpy out of module imports and pytest collection 2026-11-21 19:30:39 +00:00
c13ce17f14 amd_swizzle: parse pattern cells instead of eval
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.
2026-11-21 14:47:23 -03:00