Commit Graph

11 Commits

Author SHA1 Message Date
15c34d7971 tools: add auto fallback to python disassembler in shader_disasm and shader_library 2026-11-27 14:01:03 +01:00
570db1d58f shader_library: keep each state of a compute program, select by code hash (TOOLS-LIBRARY-COMPUTE-BY-HASH)
The run time finds a pipeline-library compute program by the SHA-256 of
its code and of its record's state blob. shader_library.py kept one
state per program, the last record's, so when two compute records used
one program with different state blobs only one of the two pairs got an
entry and a .state file.

Each distinct state of a program is now written: the first under the
program's name, each further one as <name>_state_<blob index>, with its
own .code, .json, .state, listing and index entry. library.json names
the entry of each record. A program with one state, the case of every
program in the measured 1.0.2.1 library, is written exactly as before.

--compute-hashes FILE writes only the compute programs whose code has
one of the SHA-256 digests listed in FILE, with every state they are
used with. It cannot be combined with --stages, and a digest no compute
program has is an error before anything is written.

tests/test_shader_library.py gets three tests on a synthetic library;
all three fail on the base. The standard-library tests and the
translator suite add no failing file. No retail library was read for
this change.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 21:39:34 -06:00
39879ce0fd Merge main into RT-PROTON-STORY-LOAD (#984)
Merges main at 1154976d4 into the integration branch at 273b3bdf9 (merge base ece4ba5b3). 42 files conflicted;
this commit is the resolution only. Build and test repairs follow in their own commits.

Rule of resolution: where both sides added different things, both stay; where both made the same change in two
forms, main's reviewed form stays and whatever #984's form did in addition is carried into it; where the two
changed the same code for different purposes, both purposes are kept.

Xbox proxy code (runtime/shims/d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_xs.cpp, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, registry.cpp):
- d3d12_xs_device.cpp is #984's file with main's differing pieces ported in: env_slot and the configurable device
  routes, XboxQueueSlotRoutes, PresentationHandler / set_presentation_handler, the console caller rule for device
  slots 61 and 74 (#383, #385), route_xbox_device_slot, slot 81 as GetFrameStatisticsX, create_host_device, the
  console-form rule for slots 25 and 56, the console list IID of #359, and the forms of queue slot 18 (#403) and
  list slot 139 (#396).
- Kept from #984: the list proxy with handle translation, queue slots 16/17 as Signal/Wait, the fence's
  completed-value mirror, the shared FrameTokenSource, PresentX through queue_present_x when no handler is
  attached (slot 30, or 32 on a queue detected as the newer layout), slots 27/53/55/57/70/71/133, the wider
  pc_resource_desc, S_OK for queue slots past the PC table.
- Dropped: #984's GetFrameEventsX and LEONIDA_XS_FRAME_EVENTS_SLOT, its second-word rule for slot 61, its
  undetected-layout rule for queue slot 18, its list IID mapping to GraphicsCommandList6; main's copy of the base
  list proxy, its null-view slot 70 and its refusing slot 133.

Proxy tests (runtime/test/xs_proxy_mock_test.cpp, device_proxy_test.cpp, queue_proxy_test.cpp):
- Checks of both sides, each run once; main's forms of the render-target size and layout checks with #984's extra
  cases added; main's --env-slots-74 and #984's --env-slots-70.
- Adapted to the merged code: the queue tail answers S_OK, slot 73 answers an unknown IID with the list proxy,
  the queue slot 18 case installs a console caller. Dropped: #984's slot 81 GetFrameEventsX cases.

D3D12/Vulkan layer (runtime/shims/d3d12_com.cpp, d3d12_vulkan_device.cpp, runtime/src/command_list.h,
frame_pacer.h, shader_library.h, vulkan_backend.h, vulkan_replay.h, runtime/test/command_list_test.cpp,
d3d12_close_parity_test.cpp, d3d12_execute_indirect_validation_test.cpp, replay_texture_barrier_test.cpp,
vk_pipeline_check.cpp, vk_test_device.h):
- Resource::create_texture: #984's title images (deferred placed, pending streamed, title pool) and main's
  ordinary textures (#1413 shared blocks, #1364 staging fallback) are exclusive branches chosen by the texture's
  origin, so both pools run on disjoint sets of textures.
- frame_pacer.h is main's pacer (#402) with #984's FrameTokenSource as the token counter.
- main's forms kept for ExecuteIndirect (#1066, #377), the barrier into LAYOUT_UNDEFINED (#1055), the B4G4R4A4
  stand-in, per-face stencil masks, the unaligned tile staging (#528) and the device-lost flag (#980).
- shader_library.h: main's block inflate; #984's `bulk` parameter now defaults to true so main's callers keep it.
- Dropped: #984's B8G8R8A8 stand-in for B4G4R4A4 targets, its refusal of separate stencil masks, its zero-count
  refusal in ExecuteIndirect, its wider UNDEFINED -> UNDEFINED release and the test case for it.

Other shims (runtime/shims/dstorage.cpp, file_system.cpp, gameinput.cpp, xgameruntime_offline.cpp,
runtime/test/xgameruntime_offline_test.cpp, xmem_test.cpp):
- ReadFile and DirectStorage reads: #984's pinned kernel_writes read, then main's touch_pages retry on
  ERROR_NOACCESS. main's rt::fs::read_file is folded into #984's read_file.
- gameinput: main's strict LEONIDA_INPUT_SCRIPT parser with #984's rsup/rsdown entries.
- Speech synthesis: main's one silent voice and handle checks; #984's accept-anything form dropped.

Build, tools, docs (runtime/CMakeLists.txt, runtime/cmake/translator_deps.cmake, scripts/build_runtime.ps1,
make_game.py, tools/rdna2spirv.py, shader_disasm.py, shader_ir.py, shader_library.py,
runtime/test/shaders/cs_imgload_tfe.asm, cs_imgload_d16_tfe.asm, docs/README.md, boot.md, d3d12_vulkan.md,
runtime/README.md):
- Unions of the test, target and source lists; spirv_loop_guard.py added to translator_deps.cmake.
- rdna2spirv.py: main's DPP compare rule (#957), SMEM vcc base (#647) and widen_wave64_masks (#1021); #984's
  restore_skipped_instructions and restore_dot4_inline_sel. #984's duplicate widen_wave64_valu_masks dropped.
- shader_disasm.py and shader_ir.py: main's structure with #984's one-line-per-dword llvm-mc input and wave flags.
- shader_library.py: main's structure with #984's --compute-hashes and per-state compute variants.

One file that did not conflict is changed here: tools/rdna2_decode.py. Git kept both sides' decoders for a VOPC
compare with a DPP operand, and #984's narrower one shadowed main's; it is main's file again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 19:38:04 -05:00
273b3bdf9d [integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
One squashed commit of a fork that was developed on a Linux/Proton machine and
tested on two native Windows machines. On all of them the retail 1.0.2.1
package now launches, shows its launch movie, first-run pages and landing
prompt, runs the story load to its end with the loading slideshow drawing its
artwork, and enters the world phase. A first world frame is not verified yet.
docs/linux_proton.md has the setup, a healthy boot's timeline, the machines
and where it stops.

Runtime: frames in the title's own window; DirectStorage pinned reads,
page-list scatter/gather, BCPack and unshuffle with a locally generated
predictor file; pooled, device-local and deferred image backing for streamed
and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table
that degrades instead of refusing a submission; a descriptor hash finalizer
(off until a library carries it); directly indexed heap offsets for compute
dispatches and VS/PS/GS draws; title buffer windows outside a fragmented
arena; opt-in device-local copies of streamed buffer views; write-fault
retries under the tracker lock, shared trackers and write-watched title memory
for native Windows; device-loss, compute-input and memory probes.

Translator: loop bounds at structured exits, the eight FidelityFX programs
that use a packed-dot form the disassembler skips, buffer bounds modes per
view kind, a compaction option, the hash finalizer option.

Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows
boot script, the paired compute translation script.

No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted
by people on the machines named in docs/linux_proton.md.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:42:12 -06:00
0db11decd0 Reject shader library save paths that overlap extraction outputs 2026-11-24 00:45:13 -05:00
ee2b087b66 shaders: add library_shaders build stage and guard NONE compute states
Add the build-side pipeline-library translation stage to make_game.py on top of the .state emission already merged in tools/shader_library.py, and fix a TypeError when a compute pipeline record has a NONE (0xFFFFFFFF) state index.

- tools/shader_library.py: filter NONE program/state indices when building cs_state so records without a state blob do not crash with TypeError.
- make_game.py: add LIBRARY_ARCHIVE, LIBRARY_TOOLS, library_settings(), and library_shaders() to the shaders() stage (unpacking cs programs with --disasm and --carve, translating via rdna2spirv.py, validating fspx_key_clash against non-dict/unreadable indexes, cleaning stale unpacked artifacts, and writing library_build.json).
- docs/fspx.md, docs/shader_library.md: document library_shaders(), .state emission, and runtime loading of library/index.json.
- tests/test_shader_library.py, tests/test_library_shaders_stage.py: add NONE-state cleanup and shared-code/distinct-state regression tests plus full stage reuse, invalidation, stale-artifact cleanup, clash, malformed-index, and real-tool tests.
2026-11-23 20:38:06 -05:00
6dece92317 Merge TreXito's unmerged PRs: translator fixes, fuzzers, CPU emulation, xapu/chad shims
Merged from the TreXito/mangrove copy of the original repository, which carried
contributor pull requests that were never merged here.

Kept: rdna2spirv fixes (ds_append/ds_consume, v_ldexp_f16 under MODE.FP_ROUND,
thread-group SGPR, fma exact), the differential fuzzers (dot, vint, wint, vrel, cvt,
f16misc, salu, mode) with their tests, the exe/import fail-fast and int3 cause tools,
Zen 2 instruction emulation (cpu_emulation.h) and the xapu.dll/chad.dll shims.

Not taken, because they conflict with different implementations already on main:
the D3D12 Xbox-ABI layer, xmem, acphal, loader TLS, f64_diff, DirectStorage (needs the
typed-error zlib inflate), and the copy's own MANGROVE.md and README changes.
2026-11-23 19:42:33 -05:00
6032af5ef1 shader_library: report unreadable or corrupt carve containers 2026-11-23 22:34:49 +01:00
b93ffa5617 shaders: translate the pipeline library's compute pipelines, which the executable creates with slot 67 (RT-5)
The retail executable calls Xbox device slot 67 (DeserializeComputePipelineStateX) itself during boot, and every
call fails with "no translated compute shader": the build only translates the FidelityFX DLL's 29 FSPX programs.
The programs come from the pipeline library in shaders.rpf (docs/shader_library.md), which the title reads through
DirectStorage zlib requests: a compute record's state blob, blob, program and layout blob are FSPX kinds 0, 1, 6
and 7, the four pairs of the slot-67 description.

- tools/shader_library.py writes each compute program's record state blob as fspx/<name>.state, so the index gets
  fspx_state_sha256 (slot 67 always passes kind 0). In 1.0.2.1 each of the 2,684 compute programs has one.
- make_game.py's shaders stage gets library_shaders(): shader_library.py --stages cs --disasm --carve into
  <work>/shaders/library, rdna2spirv.py into <work>/shaders/spirv/library, with the stage's wave64 and fallback
  flags, the FSPX step's key-clash check and its own library_build.json for reuse.
- ShaderLibrary::load also reads <dir>/library/index.json; its entries are found by the same two keys.

Tests: test_library_shaders_stage.py (tool calls, reuse, invalidation, empty index, key clash),
test_shader_library.py (.state contents and both keys), shader_library_test (library entries found by code and
state key, a broken or missing index leaves the others).
2026-11-23 17:59:53 +01:00
26e56f5942 shader_library: tolerate missing program/blob in compute pipelines (#6902)
Squash-merged after diff review of PR #6902 - shader_library: tolerate missing program/blob in compute pipelines
2026-11-23 09:43:23 -06:00
51eb39f288 shader_library: unpack the pipeline library in shaders.rpf's zlib part
Behind its 26,503 shader entries, shaders.rpf holds one more file as 64 KiB
zlib blocks: a precompiled pipeline library with 25,471 graphics and 2,693
compute pipeline records, 54,576 state blobs and 21,522 native programs.
shader_carve.py never read it.

tools/shader_library.py reassembles and parses it (sizes checked against
the header), writes the programs in the fspx/ layout rdna2spirv.py already
reads, and with --carve names each program's source: the 16 bytes after
the stage blob's 0x43 word are the source container's HASH digest, as in
an FSPX kind-7 entry. 21,509 of the 21,522 programs link to 6,522 carved
shaders with matching stages; they are pipeline builds, not copies of the
FSSM code. 17,955 translate and pass spirv-val.

rdna2spirv: a missing <name>.dxbc is Unsupported for that shader
(shader_container), not a FileNotFoundError that stopped the whole run.

docs/shader_library.md has the layout, the counts, what stops the rest
(mostly SGPR tuples into vcc that llvm-mc rejects) and a scan of the other
74 archives, which found no other shaders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 01:54:56 +01:00