Commit Graph

146 Commits

Author SHA1 Message Date
f3da088e56 Merge pull request #171 from shelbykb2
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/test_shader_checks.py
2026-11-21 16:08:48 -05:00
b36252415a Merge pull request #185 from Kam471
# Conflicts:
#	docs/design.md
2026-11-21 16:08:26 -05:00
63537ec435 Merge pull request #138 from SuarezPM 2026-11-21 16:08:10 -05:00
b63a6454bc Merge pull request #189 from eIBart0 2026-11-21 16:08:08 -05:00
5026d36f9c Merge pull request #184 from Mokbul Miah 2026-11-21 16:08:07 -05:00
a0611c9fef Merge pull request #177 from simonbronk 2026-11-21 16:08:07 -05:00
0f3383b72c Merge pull request #190 from Kam471 2026-11-21 16:08:07 -05:00
16240a1405 Merge pull request #183 from Kam471 2026-11-21 16:08:06 -05:00
548b445961 Merge pull request #181 from Kam471 2026-11-21 16:08:06 -05:00
b2acfa7205 Merge pull request #178 from Kam471 2026-11-21 16:08:06 -05:00
fd8e2f8f93 Merge pull request #174 from bbareth 2026-11-21 16:08:06 -05:00
70ec7660ad Merge pull request #169 from NWX10 2026-11-21 16:08:05 -05:00
c5aeb1526c Tools: census every map resource in levels.rpf 2026-11-21 21:06:18 +00:00
dd199d1549 rdna2spirv: ignore pos1..pos3 exports when OSG1 is absent 2026-11-21 18:02:52 -03:00
bb20c19651 Textures: make the compact mode split reproducible in scan 2026-11-21 21:02:00 +00:00
d50ba56650 Tools: decode RBF0 trees for UI and subtitles
Add a stdlib record/tree decoder for the measured RBF0 format. It joins 64 KiB continuations, parses the inline descriptor table, builds element/attribute/content/text trees, and writes JSON plus optional generic XML. Unknown descriptors, record types and malformed framing fail closed with a partial tree. Add synthetic tests and the measured grammar, samples and remaining unknowns to docs/rbf0.md; note the rig-set blob tree result in docs/animation.md.
2026-11-21 21:01:14 +00:00
4be73f9bbb Textures: tighten the compact tool wording and BC coverage note 2026-11-21 21:01:03 +00:00
c3cd32888f Textures: report the compact standalone/tail split in scan 2026-11-21 21:01:03 +00:00
39631ee147 Textures: decode the TTPF compact mip tail 2026-11-21 21:01:03 +00:00
503c8716e4 Tools: export stereo streamed-music AWC channels correctly 2026-11-21 21:00:20 +00:00
66a410edf0 Accept LLVM_MC as a whole command in the tests and GPU tools
LLVM_MC may be one executable or a command line such as the WSL llvm-mc documented for Windows. shader_disasm.py already split it, but the tests, runtime/test/shaders/build.py and scripts/run_gpu_tests.py treated it as a single executable, so the documented setup skipped translator tests, and build.py passed a Windows path to WSL. Share the splitter in tools/mc_command.py and feed assembly on stdin.
2026-11-21 21:00:03 +00:00
43daf286dc Tools: catalog the common.rpf XML documents 2026-11-21 20:55:43 +00:00
95b2c091c8 Build a native Windows llvm-mc with the AMDGPU target, no WSL needed
scripts/build_llvm_mc.ps1 sparse-clones the LLVM sources llvm-mc needs,
builds it alone with LLVM_TARGETS_TO_BUILD=AMDGPU, static CRT and the DIA
SDK off (its headers need ATL, which the C++ build tools don't always
include), checks it disassembles an s_endpgm for gfx1013, keeps only
llvm-mc.exe and sets LLVM_MC for the user. README, docs/design.md and the
make_game.py / shader_disasm.py hints mention it next to the WSL route.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 21:50:01 +01:00
16d285e7bc Merge pull request #152 from AlxcBTW
# Conflicts:
#	scripts/run_gpu_tests.py
#	tests/test_shader_checks.py
2026-11-21 15:47:57 -05:00
89ca8c85e5 Merge pull request #149 from eIBart0 2026-11-21 15:47:57 -05:00
e149b42875 Merge pull request #153 from NWX10 2026-11-21 15:47:56 -05:00
180fd6c556 Merge pull request #162 from NWX10 2026-11-21 15:47:56 -05:00
dae4be1781 Merge pull request #151 from andretuta 2026-11-21 15:47:55 -05:00
9b5e01b9c6 Merge pull request #145 from Ayinaki 2026-11-21 15:47:55 -05:00
0788af6303 Merge pull request #144 from errusso 2026-11-21 15:47:55 -05:00
6139be94f5 manifest.py: fail when the input directory cannot be scanned 2026-11-21 21:47:05 +01:00
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
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
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
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
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
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
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
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
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
612f1edebd Root signature packer + reconciler + hard-fail (fix the least verifiable part of the layer)
AI-assisted (Muse Spark + explorer fleet).

Implements docs/d3d12_vulkan.md section 3.5 as code: a portable D3D12
root-signature model (1.0/1.1, no d3d12.h) plus a packer that lays root
parameters into the 32 user-SGPR dwords in root-parameter order (constants
take N, views/tables take 2, static samplers take none). Anything that does
not fit - more than 32 user SGPRs (spill layout unknown) or more than the
64-dword D3D12 cost limit - is refused loudly instead of truncated.

tools/root_sig_contract.py reconciles a candidate signature against every
shader's user_sgpr_reads from spirv/index.json (const32 vs constant dwords,
64-bit VAs vs view/table pairs, unpaired-hi detection) and exits nonzero on
the first contradiction; --cluster shows which read-set shapes the game
actually needs.

The RTS0 chunk reader is marked hypothesis until the new Windows oracle
test (synthetic descs serialized by the real d3d12.dll) confirms the layout;
Tier A (model/packer/canonical codec/RTS0 self-consistency/reconciler) runs
everywhere with no game data and no GPU.

Tested: python -m pytest tests/test_root_sig_contract.py (12 passed);
full suite 651 passed, 20 skipped, 1 xfailed; compileall + make_game --help;
portable C++ test 17/17 PASS under g++ -Wall -Wextra -Wpedantic -Werror with
ASan+UBSan; turing atlas on RTX 2060 SUPER (subgroup 32, mesh/bary/m8/heap
true): compute32/ballot64/f16_input/maintenance8 valid, broken_negative
correctly invalid. Windows-only Tier B (oracle + MSVC build) runs in CI.
2026-11-21 17:04:28 -03:00
78af668e01 Tools: report PSIN LRSC and CHKS fields 2026-11-21 20:02:19 +00:00
7cc6068ab6 Shader stage: resume only finished steps, Windows-safe carve names, clear error on empty unpack (fixes #126)
- make_game.py: a step counts as done only when the file it writes last
  exists (index.json, fssm_index.json, disasm.done, spirv/index.json),
  not when its folder exists or holds >=1000 files. Re-running a step
  drops the later steps' markers so they run again.
- shader_carve.py / fssm_unpack.py: write their index last, via a temp
  file and os.replace, so a stopped run never leaves one behind.
- shader_carve.py: file names are unique without case and Windows device
  names (CON, NUL, COM1...) get a "_" prefix; ~N suffixes never land on
  a real name.
- fssm_unpack.py: exit 1 with a clear message when nothing unpacks,
  before writing the index, instead of an IndexError.
- tests/test_shader_stage_resume.py: 13 tests, standard library only.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:00:32 +03:00