Commit Graph

18350 Commits

Author SHA1 Message Date
85c660bfa1 rpf9_carve.py: survive a Bink signature cut off by the end of the file, and an empty data area
- A 'KB2x' match within the last 0x1C bytes of the archive (what a
  truncated copy can end with) read the header's size and width/height
  fields past the end of the file. struct.error is not caught, so the run
  died without writing index.json, losing the whole carve. Such a match is
  now skipped like any other non-video candidate.
- An archive whose data area is empty (its data offset is the file size),
  or --start at the end, gave span 0 and a ZeroDivisionError in the final
  "readable" line after index.json was written. The percentages now divide
  by at least 1; the summary still records span 0.
- tests/test_rpf9_carve.py: one synthetic case each; both fail on main.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:38:51 +03:00
d2c3283b54 tests: pin the shader_ir operand grammar and the pc walk
shader_ir.py is the parser both the translator and cpu_ref read listings
with, and the only assertions on it covered two scalar-load lines. These
cases cover every operand form, the modifier list, split_args nesting and
parse_file's pc stepping, so a parser regression fails here first.
2026-11-21 20:38:41 +00:00
73997793eb Docs: mark GCL8 resolved in PR #164 2026-11-21 20:37:36 +00:00
82a1e229c9 Runtime: implement FNV-1a descriptor hash table for shader contract (set 0, binding 2) 2026-11-21 21:37:24 +01:00
b7db55a428 make_game.py: reject --jobs below 1, compare the game folder without case on Windows
- --jobs 0 (or a negative count) was accepted: translate() then started no
  rdna2spirv.py shard, found no failed shard, and ran --merge over nothing,
  so the translation step looked finished; shader_disasm.py's thread pool
  raises on 0 workers. --jobs now takes a positive integer (the same check
  as tools/manifest.py's positive_int); argparse exits 2 otherwise.
- The "--out and --work must be outside the game folder" check compared
  paths with case, so on Windows `--out c:\games\gta6\out` passed for the
  game folder C:\Games\GTA6. Both sides now go through os.path.normcase.
- tests: two new cases in test_make_game_argparse.py (the case test runs
  on Windows only, where paths compare without case).

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:32:11 +03:00
87989cea5f Parse RTS0 via DXBC chunk walk; fix OOB wrap and FourCC typo
The MS serializer returns a DXBC container, not a bare payload (proven
by the CI blob dump starting with DXBC). parse_rts0 now walks the chunk
table like input_signature does and decodes the RTS0 payload.

Also fixed: 'O' (0x4F) vs '0' (0x30) in the FourCC check, which silently
missed every chunk, and u32 arithmetic wrap in the bounds checks (a hostile
offset could wrap off+8 past the guard into an OOB read).

Adds a hand-built DXBC container test covering the walk path.
2026-11-21 17:31:08 -03:00
d3f69013c1 Docs: measure rest-of-world and script archive composition
Add the full core_restofworld scan (1.21 GiB, 96% Bink 2 plus model/page data), re-measure story000_restofworld and story000_script, and cover the three small archives. Cross-check PSIN against script.rpf/story000 and core pages/models against packs.rpf/levels.rpf. Add a stdlib-only stream index tool and synthetic-header tests. No game data.
2026-11-21 20:30:47 +00:00
55af930bcc runtime: add public ID3D12GraphicsCommandList8 to the D3D12 proxy
The command list implements the SDK's GCL8 chain (IID ee936ef9-599d-4d28-938e-23c4ad05ce51), so a GCL8 QueryInterface succeeds and slot 81 (byte offset 0x288) is OMSetFrontAndBackStencilRef(UINT, UINT). The method records both values on the list and Reset clears them. Nothing applies them yet: Vulkan's dynamic stencil reference is per face, but only a pipeline that consumes it can, and the layer has no pipeline or draw path. The call is reported once rather than silently dropped.

d3d12_gcl8_test creates only an allocator and a list (no Vulkan device), checks the interface pointer, the raw slot 81 call, both recorded values and the QueryInterface reference count. It runs under CTest.
2026-11-21 20:30:33 +00:00
49dd92d41d translator: SMEM loads with soffset and imm add both (the imm was dropped)
What was wrong
An RDNA2 SMEM load can carry a register offset and an immediate at once.
llvm-mc prints that form as "s_buffer_load_dword s12, s[24:27], s40 offset:0x4".
shader_ir.parse_line puts "offset:0x4" in mods, and Gen.scalar_load only read
the third operand, so the immediate was dropped without a diagnostic: the line
translated to the same SPIR-V with and without the modifier, and spirv-val
accepted both.

Evidence
Measured on an AMD Radeon RX 6800 (gfx1030) by running the instructions as a
raw compute kernel: for s_buffer_load_dword/x2/x4/x8 the address is
base + soffset + imm + 4*i, e.g. soffset 8 + imm 4 reads the dword at +12.
s_load_dword* with both offsets was not measured; it shares the SMEM encoding
(soffset_en + imm), so giving it the same rule is an inference.

Change
- scalar_load adds the immediate when the third operand is a register and mods
  has offset:N. The no-modifier forms emit the same code as before.
- Forms llvm-mc does not accept (immediate operand plus offset:, two offset:
  modifiers, a fourth operand, an unparseable offset) raise Unsupported.
- Not changed, and listed in docs/design.md as known differences: the hardware
  truncates base, soffset and imm each to a multiple of 4 and s_buffer_load
  returns 0 past NUM_RECORDS; the translator does neither. A negative s_load
  immediate is still zero-extended from 32 bits, in both forms (not measured).

Tests
- tests/semantic/test_scalar_mem_smem.py: SmemSoffsetImmTranslatorTests runs
  the code scalar_load emits against concrete SGPRs and memory and asserts the
  addresses and values read (9 tests; 7 fail on main, where the loads read +8
  instead of +12, and the imm-only / soffset-only regression cases pass).
- runtime/test/shaders/cs_smem_soffset_imm.asm, wired into check.py and
  scripts/run_gpu_tests.py. Not run on a GPU in this change.
- unittest discover -s tests/semantic: 335 -> 344, all pass.
- pytest tests (--capture=sys, llvm-mc through WSL): 883 -> 893 passed, the
  same 6 test_rtti_scan failures before and after (pefile not installed).
- The 27 hand-written GPU shaders: 27 translated, 27 pass spirv-val before and
  after, output byte-identical.

AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 13:28:03 -07:00
f67d3c109a README: add the measured music/radio config row 2026-11-21 20:27:52 +00:00
8ea0e072dc tests: repair the stale stdin handle pytest's fd capture leaves on Windows; mutation test without cwd=HERE
On Windows `python -m pytest tests` fails at random places with
"OSError: [WinError 6] The handle is invalid" (subprocess.py, _make_inheritable).
pytest's default fd capture replaces fd 0 with os.dup2(), which closes the
handle fd 0 had, but the process's STD_INPUT_HANDLE keeps that number.
subprocess starts from GetStdHandle(), so a child that has its output captured
but is given no stdin=/input= (23 of the 25 call sites in tests/) gets a closed
handle, or, once the number has been reused, some unrelated file. Logged per
hook, the same number was a file, a pipe and invalid within one two-test
session. In conftest._has_amdgpu the OSError is caught, so a working llvm-mc
was reported as missing and all of test_translate.py skipped.

Fix in one place: when tests/conftest.py loads (before its llvm-mc probe) and
STD_INPUT_HANDLE is not fd 0's handle, point it at a NUL handle of our own.
Nothing happens on Linux, with -s or --capture=sys, or without pytest: there
the two handles are equal (checked for python -I <file>, python -m unittest
and unittest discover with console, NUL and pipe stdin), so the stdlib entry
points cannot hit this and need nothing. Per-call stdin=DEVNULL was the
alternative; the next new test would bring the failure back. A config file
forcing --capture=sys would change what is captured for everyone.
_has_amdgpu keeps catching OSError: a candidate that is not a program arrives
as a plain OSError (WinError 216), and it must be skipped, not crash collection.

Only stdin is repaired. STD_OUTPUT_HANDLE and STD_ERROR_HANDLE go stale the
same way, but fd 1 and fd 2 change handles for every test phase, and every
test that redirects a child's output redirects both streams, so subprocess
never reads those two. A test that redirects only one (stdout=PIPE alone,
check_output) would still fail under fd capture: use capture_output=True.

Separately, run_semantics() started its child with cwd=tests/semantic. Windows
refuses a working directory over 258 characters (WinError 267), so the mutation
tests failed in a checkout in a deep folder (measured with a 250-character
root, where tests/semantic is 265). The child now finds test_ps_semantics
through PYTHONPATH.

Tested on Windows 11, Python 3.14.7, pytest 9.2.0, main d51bddc:
- pytest tests, two runs each. Before: 6 and 44 failed without LLVM_MC, 94 and
  6 failed with it. After: 6 failed, 823 passed, 65 skipped without, and
  6 failed, 883 passed, 4 skipped, 1 xfailed with, both runs. The 6 are
  test_rtti_scan needing pefile, which is not installed here; the skip reasons
  are unchanged (ffmpeg, SCARAB_REF, llvm-mc).
- STD_INPUT_HANDLE forced to a number that is never valid, LLVM_MC set:
  44 failed and all 61 translator tests skipped before (the probe rejected
  llvm-mc), same as the clean run after. The unforced 94-failure run above has
  50 of them in conftest's Shader.validate (spirv-as).
- A copy with a 250-character root: test_mutations 14 failed before, passes after.
- Ubuntu (WSL), Python 3.14.4: unittest discover -s tests/semantic and the
  python -I tests/test_*.py loop print the same before and after.
No GPU involved. AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 13:27:44 -07:00
dcf5f44879 Translator: decide VOP3 for 16-bit integer ops from the encoding size, not the _e64 suffix
LLVM 21 prints the VOP3 form of v_lshlrev_b16, v_add_u16 etc. without _e64. All of them in the game's
shaders are 8-byte VOP3 encodings, so they were translated as VOP2 writes and lost the high half that
the hardware keeps (about 340 shaders). Found by #78's ps_ops5 on the GPU. Both runners now check
ps_ops5/ps_ops6, run_gpu_tests skips the interpreter-only ps_vcc_x2 (it lost the device), and
test_shader_checks derives its total from check.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 15:27:02 -05: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
ab270f39d6 Harden RTS0/oracle path: bound sampler counts, dump blob bytes on parse
The Windows oracle test segfaulted in CI. Most likely cause: an
unbounded static-sampler reserve driven by real-blob bytes under a wrong
layout hypothesis. Both decoders now refuse absurd sampler counts, and the
oracle test prints the blob size plus the first 32 bytes before parsing so
the next CI log shows the true D3D12 layout either way.
2026-11-21 17:24:55 -03:00
aa2febee17 tests: cover the stdlib DDS decoder with synthetic buffers
dds_png.py had no tests, so header parsing, the BC block decoders and the
PNG writer were only ever checked by eye. These cases pin the exact pixel
output of BC1, BC2, BC3, BC4 and BC5 against hand-computed values, plus
the uncompressed swizzles, the box-filter downscaler and the PNG chunks.
2026-11-21 20:24:54 +00:00
52e1ac3cd7 Support mipmapped 3D texture transfers on the Vulkan device 2026-11-21 21:24:04 +01:00
65d927b61a rpf9dump: write every output under a temporary name and rename it into place
make_game.py takes ttpf manifest.json and audio_manifest.json as proof that
a step finished, and every exporter skips a file that already exists. Both
were written in place, so a stopped run or a full disk could leave:

- a truncated manifest, after which make_game.py skips that texture pool
  or the audio banks on every later run, or
- a truncated .dds / .obj / .xma.wav under its final name, kept forever
  because the next run sees it exists.

All outputs (ttpf DDS + manifest, audio_manifest.json, XMA2 .xma.wav,
model .obj, embedded and dictionary .dds) now go through Util.WriteAtomic:
written to <path>.partial, then File.Move'd over the final name; the
temporary is removed on failure, and a stale one from a stopped run is
deleted first (WriteXmaWave opens its target with FileMode.CreateNew).
The models manifest already worked this way.

Util moves to its own file so tests/Rpf9DumpDiagnostics can link it; the
diagnostics program gains four checks for WriteAtomic.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:22:35 +03:00
2381b53337 Docs: add rest-of-world archive row 2026-11-21 20:21:27 +00:00
d488b0f9e5 Docs: index the new format notes 2026-11-21 20:20:42 +00:00
580aa8e0ff docs/design.md: wave64 emulation row, count on main's skip logic
Without --wave64-emulate the RTX 5070 now skips the wave64 tests (as main
does since 4c75ce5) instead of failing them: 19/37 pass, the rest skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:19:29 +01:00
1f95634ed4 Docs: measure the audio-config station records and content ids 2026-11-21 20:19:22 +00:00
725052d731 GPU tests: say which test programs are missing instead of a traceback
check.py and run_gpu_tests.py both died with a FileNotFoundError traceback when vk_compute_test, vk_store_test
or vk_harness was not built, which on Linux happens whenever CMake does not find the Vulkan headers. They now
name the missing programs, how to build them, and the "Vulkan SDK not found" hint, and exit 1.
run_gpu_tests.py checks before translating; check.py checks in run(), which the unit tests mock.
2026-11-21 22:19:13 +02:00
6ee1904094 Docs: add page-directory, story, audio-station and command-object rows 2026-11-21 20:19:12 +00:00
ab35e9a64f Translator: exact wave64 compute and mesh shaders on any subgroup size
Add --wave64-emulate to tools/rdna2spirv.py. A wave64 compute or mesh
shader then uses no subgroup operation: everything a lane needs from the
rest of its wave (votes for s_cbranch_*/SCC, whole-mask words for
s_bcnt1/s_ff1/v_mbcnt, v_readlane, v_readfirstlane, ds_bpermute,
ds_swizzle, v_permlane16/x16) goes through a Workgroup buffer. The
program runs in rounds that end at one OpControlBarrier in uniform
control flow; a cross-lane op cuts its basic block, and the rest runs one
round later, when all 64 lanes have written. s_barrier becomes a
scheduler state, and conflicting memory accesses in one segment are
ordered by a round. This answers #94 and #101 for compute and mesh
shaders: on 32-wide subgroups (NVIDIA) they are now exact, not
approximate.

Two fixes that apply without the flag:
- v_writelane_b32 in cs/ms selects the lane by the wave lane. On a
  32-wide subgroup writes to lanes 32-63 were lost.
- ds_bpermute_b32 in wave64 runs as two wave32s (RDNA ISA 10.4.4): on a
  64-wide subgroup lanes 32-63 read the low half, and an inactive source
  lane now reads 0.

New hand-written GPU tests cs_w64x_* and ms_w64x_ballot pin down the
cross-half semantics. LEONIDA_W64_EMULATE=1 makes build.py,
run_gpu_tests.py and check.py use the flag. Other translator output is
byte-identical.

Tested on NVIDIA GeForce RTX 5070 Laptop (driver 617.42, subgroup 32) and
AMD Radeon 880M (driver 26.11.2 LLPC, subgroup 64):
run_gpu_tests.py 37/37 on both with the flag (RTX 5070 without it: 21/37;
880M without it: 37/37, was 36/37 before the bpermute fix).

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:18:05 +01:00
ab5e88950e tools, tests: add stdlib paths for tex_headers and rtti_scan and un-skip CI tests 2026-11-21 17:18:04 -03:00
6b6b9bf143 Translator: s_bcnt1_i32_b32 counts the high word again (#132 kept it for b64 only)
A lane mask of a wave32 shader in a 64-lane subgroup has bits there; s_bcnt0_i32_b32 still counts the
low word only. Restores test_wave64_bfm64_and_half_cmp_emit_wave_ops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 15:17:58 -05:00
da1ce50287 Merge pull request #125 from TricksterG 2026-11-21 15:17:51 -05:00
36cedb8522 Merge pull request #78 from Kam471 2026-11-21 15:17:51 -05:00
ce4e26cc14 Merge pull request #113 from eIBart0 2026-11-21 15:17:51 -05:00
da4d686c7a Merge pull request #122 from Ayinaki 2026-11-21 15:17:51 -05:00
0a65e6a2ba Merge pull request #136 from NWX10
# Conflicts:
#	tools/fssm_unpack.py
2026-11-21 15:17:51 -05:00
9fd504ca10 Merge pull request #132 from 0xTehuti 2026-11-21 15:17:51 -05:00
94746381a3 Merge pull request #124 from Kam471
# Conflicts:
#	docs/rpf.md
2026-11-21 15:17:50 -05:00
d701f3b47f Merge pull request #128 from Kam471 2026-11-21 15:17:50 -05:00
377a4b9428 Merge pull request #129 from Kam471 2026-11-21 15:17:50 -05:00
3b7c30a75e Merge pull request #133 from Kam471 2026-11-21 15:17:50 -05:00
46a19983fd Merge pull request #134 from Kam471 2026-11-21 15:17:50 -05:00
340f3fa627 Merge pull request #137 from Kam471 2026-11-21 15:17:50 -05:00
2f030be75f Merge pull request #139 from Kam471 2026-11-21 15:17:49 -05:00
eb85039a58 Assets stage: resume stopped audio steps, keep no partial files, retry failed XMA decodes
The audio steps had the same resume problem as the shader stage (#126):

- make_game.py: the Ogg Opus and XMA2 steps counted as done once their
  folder existed, which a stopped run also leaves. They now count as done
  by a marker (audio/ogg.done, audio/xma.done) written after the step
  succeeds.
- make_game.py: XMA2 -> WAV with ffmpeg now runs on every assets run for
  the streams that have no .wav yet, writes to a temporary name renamed on
  success, and checks ffmpeg's exit code. A failed or stopped decode no
  longer leaves a short .wav, and installing ffmpeg after the first run now
  decodes the streams instead of never trying again.
- awc_opus.py: .ogg/.wav files are written under a temporary name and
  renamed, so a stopped run or a full disk never leaves a truncated file.
  A read/write error (OSError) now fails the run (exit 1) so the step is
  retried; banks that do not parse are still skipped as before.
- tests: new tests/test_audio_stage_resume.py (10 tests, standard library
  only); WavValidationTest updated to set up the new markers.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:17:32 +03:00
9d3743bd47 docs: tighten command-object citations 2026-11-21 20:17:27 +00: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
e4f1d65e93 docs: measured D3D12 command queue/list/fence surface 2026-11-21 20:15:37 +00:00
d2debe87af Fix MSVC build: std::memcpy instead of __builtin_memcpy
The 'build' and 'check' jobs failed with C3861 on MSVC 14.52:
__builtin_memcpy is GCC/Clang-only. std::memcpy (<cstring>) works
everywhere the portable model compiles.
2026-11-21 17:15:29 -03:00
28cf235061 d3d12_xs device proxy: slot 62 takes (desc, w2, w3, riid, out)
The proxy read device slot 62 as (desc, riid, out), so XboxBvhBuilder's constructor, the only
known caller, got E_POINTER on its first compute PSO and threw it. Recorded on 1.0.2.1: the
DLL calls slot 62 with (desc, 0, 0, &IID_ID3D12PipelineState, out), the shape the prior art
had documented (d3d12_vulkan.md, sections 4.8 and 7). Read the IID and the output from the
fourth and fifth arguments, and log the two extra words once if they are ever non-zero.
device_proxy_test now calls slot 62 in that shape.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:13:10 +01:00
c2099b3c02 Runtime: report pipelines compiled without the requested subgroup size 2026-11-21 20:12:23 +00:00
67735ca1d4 Tools: parse PE images with struct instead of pefile
tools/pe_inspect.py imported pefile at module level, which the contributing rules do not allow, and which kept
the tool out of the standard-library check job: no test imported it, so CI only syntax-checked it while
scripts/first_look.ps1 still ran it on the executable people bring. It now reads the DOS and NT headers, the
section table and the import, delay-import, export, TLS and relocation directories with struct, and writes the
same JSON and Markdown with the same keys.

Delay-import descriptors without dlattrRva store 32-bit virtual addresses, so they are converted with the image
base instead of being read as RVAs. The Markdown shim list no longer tests for a classifier result that is never
produced.

tests/test_pe_inspect.py builds a 64-bit and a 32-bit image byte by byte and covers both descriptor forms,
imports by name and ordinal, an ordinal-only export, .pdata and TLS callback counts, DLL classification, the
CLI's output files and its rejection path.
2026-11-21 20:11:55 +00: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
d2a7fb643b Docs: link the audio-config table from the audio guide 2026-11-21 20:08:08 +00:00
da499ab911 Loader: initialise dependencies before their importers
map_image pushes a module into order_ before bind_imports maps the modules it
imports, so order_ lists an importer ahead of its DLLs, and initialise() ran
TLS callbacks and DllMain in that order. Keep a separate init_order_ filled
after a module's imports are loaded and initialise from it. modules() stays
mapping order. pe_loader_test checks tiny_dll comes before tiny_exe.
2026-11-21 21:07:23 +01:00