Commit Graph

19 Commits

Author SHA1 Message Date
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
dd25fe67b5 Report unsupported AMD swizzle element sizes (#6609)
Squash-merged after diff review of PR #6609
2026-11-23 11:16:46 -06:00
241a26ff94 amd_swizzle: offsets/detile evaluate the XOR address bits per axis (~65x faster) (#6914)
Squash-merged after diff review of PR #6914 - amd_swizzle: offsets/detile evaluate the XOR address bits per axis (~65x faster, bit-exact)
2026-11-23 09:42:19 -06: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
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
a7ce9414e4 Merge pull request #1459 from Rafael 2026-11-22 06:38:09 -05: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
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00: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
c55246b128 fix(tools): close file handles with context managers under -W error::ResourceWarning 2026-11-22 00:55:45 -03: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
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
4f1ff7d85b Replace local drive paths with placeholders
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:59:05 -05:00
db0dc8bd5e Initial commit: Leonida, build-it-yourself PC port groundwork
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V),
asset export via rpf9-explorer's Core (submodule), PE loader and shim
skeleton, and make_game.py, which builds from the user's own copy of the game.
No game data, keys or executables are included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:22:16 -05:00