Commit Graph

778 Commits

Author SHA1 Message Date
45676e838a Merge pull request #239 from natterman12/runtime/compat-load-no-error-dialog
pe_loader: a compat DLL Windows cannot load is refused without a "Bad Image" box (RT-COMPAT-ERRBOX)
2026-11-23 22:36:32 -05:00
fabe844cd8 Merge pull request #131 from Mumogg/restore-directstorage
runtime: restore the console DirectStorage shim, with the typed-error inflate it needs (RT-DSTORAGE-RESTORE, #47)
2026-11-23 22:36:12 -05:00
682fd0561c pe_loader: a compat DLL Windows cannot load is refused without a "Bad Image" box
resolve_compat() calls LoadLibraryExW on a file from LEONIDA_COMPAT_DIR. For
a file Windows cannot map (truncated, wrong machine, not a PE image) the
system raises a modal "Bad Image" hard-error box, and LoadLibraryExW does
not return until someone clicks OK. The loader reports that failure itself
one line later, so the box only stalls it: gta6rt hangs on a headless
machine, and loader_test, which writes such a file on purpose, waits for a
click in every unattended ctest run.

The load now runs with SEM_FAILCRITICALERRORS set on the calling thread, and
the thread's previous error mode is restored afterwards. The Windows error
code is read before the mode is put back.

loader_test checks that the mode comes back unchanged, that the message
still carries the error code, and that the refusal does not wait on a box.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 21:50:56 -05:00
2d7be48dec runtime: restore the console DirectStorage shim (DStorageGetFactory) on main
The merge that brought the mirrored pull requests into main (6dece9231) left the DirectStorage shim out, noting
that it "needs the typed-error zlib inflate". The shim's commits (f87d05fdd, ac1843da2, 00551ba00, by
mariuslozo-boop and Kelebek) are ancestors of main, but its files are not in the tree, so the retail
executable's XCRDAPI.dll!DStorageGetFactory import is unimplemented (issue #47, stop 5 of
docs/retail_boot_chain.md).

- shims/dstorage.cpp, shims/dstorage_xs_abi.h, test/dstorage_test.cpp and docs/directstorage.md are back as
  those commits left them.
- leonida::zlib_inflate reports why it failed through an optional ZlibError* (header, data, checksum, limit),
  which the shim turns into its E_DSTORAGE_ZLIB_* codes. This is the same interface the shim was written
  against, added to main's current table-driven inflater; callers that pass no pointer behave as before.
- registry.cpp classes xcrdapi.dll!DStorageGetFactory as an HRESULT import, the retail spelling #47 found
  missing.
- CMake and scripts/build_runtime.ps1 build the shim into gta6rt, and CMake builds and registers dstorage_test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
2026-11-23 20:23:21 -06:00
41478fc0ca runtime: load pipeline-library shader index for slot 67
ShaderLibrary::load read the main index plus fspx/ and bvh/, but not library/index.json, where the pipeline library's compute programs are translated. Slot-67 FSPX lookups therefore found no entry for those programs even when the index existed.

Read library/index.json as an optional sub-index and count its entries with the FSPX ones. Add regression coverage for fspx/-before-library/ ordering, code/state lookup, and absent or malformed library indexes.
2026-11-23 20:36:52 -05:00
e7f17716f1 fix(runtime): validate TiledKind and D3D12 bounds in resource_tiling
(cherry picked from commit b07c4747f16af7cebd50d9d8a93f952fde560784)
2026-11-23 19:42:49 -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
be4a51f5d4 Merge remote-tracking branch 'origin/pr/8964'
# Conflicts:
#	runtime/shims/d3d12_vulkan_device.cpp
2026-11-23 17:43:36 -05:00
b05999eb74 Merge remote-tracking branch 'origin/pr/8969' 2026-11-23 17:41:01 -05:00
f942545cf6 Merge remote-tracking branch 'origin/pr/8978' 2026-11-23 17:40:58 -05:00
bc13d83d27 Merge remote-tracking branch 'origin/pr/8981' 2026-11-23 17:40:58 -05:00
120dea0054 Merge remote-tracking branch 'origin/pr/8997' 2026-11-23 17:40:54 -05:00
7734b05623 Merge remote-tracking branch 'origin/pr/9002' 2026-11-23 17:40:53 -05:00
bea01df57a Merge remote-tracking branch 'origin/pr/9487' 2026-11-23 17:32:50 -05:00
f7b3afcda9 Merge remote-tracking branch 'origin/pr/9754'
# Conflicts:
#	scripts/build_runtime.ps1
2026-11-23 17:29:12 -05:00
527fc199f8 Merge remote-tracking branch 'origin/pr/9767' 2026-11-23 17:24:53 -05:00
5f855fb695 Merge remote-tracking branch 'origin/pr/9766' 2026-11-23 17:24:53 -05:00
868002b0d8 Merge remote-tracking branch 'origin/pr/9745' 2026-11-23 17:24:48 -05:00
d0707969f0 Merge remote-tracking branch 'origin/pr/9742' 2026-11-23 17:24:47 -05:00
c48a663a82 d3d12/spirv_f16_halves: fix linker fast-path, Private decorations, and device location budget
Fixes four bugs in --f16-interp-fallback per-pipeline linking:
1. link_f16_halves() no longer skips patching on its fast path when static
   VS/PS half locations exceed top_location or when an unused VS static half
   collides with a raw PS input location.
2. Demoting an unused VS static half Output variable to Private now strips
   all interface-only decorations (NoPerspective, Flat, Patch, Centroid,
   Sample, Invariant, Location, Component), avoiding invalid SPIR-V.
3. keep_ps_locs now preserves raw PS input locations (ps_raw_locs) when
   picking relocation slots.
4. CreateGraphicsPipelineState now runs link_f16_halves() when only VS
   declares f16_halves and derives top_location from the physical device's
   min(maxVertexOutputComponents, maxFragmentInputComponents) instead of
   hardcoding 29.

Adds regression tests (cases 6-10) and interface-only decoration validation
in runtime/test/spirv_f16_halves_test.cpp.

AI-assisted (Antigravity).
2026-11-23 23:18:39 +01:00
2f48417d49 fix: refuse a mesh PSO whose workgroup memory is over maxMeshSharedMemorySize 2026-11-23 23:16:12 +01:00
805a88b7f3 Merge PR #9598 2026-11-23 17:08:50 -05:00
4226afe625 Merge PR #9572 2026-11-23 17:08:07 -05:00
ca9f9856bb Merge PR #9569 2026-11-23 17:08:01 -05:00
14773047f5 Merge PR #9566 2026-11-23 17:07:56 -05:00
ad6e5d6bbe gta6rt: --init/--run stop with a clear message on a host without AVX
The game runs AVX code from its TLS callbacks on, so a CPU or OS without
AVX (a QEMU qemu64 guest) died with a bare 0xC000001D. Check CPUID.1
AVX/OSXSAVE and XCR0 YMM state first, print one line and exit 4 (3 is
LEONIDA_UNIMPLEMENTED=stop). --dry-run is unchanged and
LEONIDA_SKIP_CPU_CHECK=1 skips the check.

AI-assisted.
2026-11-23 23:07:51 +01:00
ff41d844bf Merge PR #9558 2026-11-23 17:07:32 -05:00
dbb79106ce Merge PR #9555 2026-11-23 17:07:25 -05:00
d892ec96c9 Merge PR #9554 2026-11-23 17:07:24 -05:00
3d1387b3b9 Merge PR #9531 2026-11-23 17:06:48 -05:00
2a99db7d64 Merge PR #9505 2026-11-23 17:06:10 -05:00
c89b413448 Finish a pending presenter capture before reusing its staging buffer 2026-11-23 22:05:11 +00:00
cb29a2b88f d3d12_xs: slot 133 commits the buffer's xmem pages before the host-pointer import
xmem commits physical pages on first touch (#7556), so a range the title has
mapped but not written yet is still MEM_RESERVE when it places a buffer on it
through device slot 133, and the Vulkan layer's import (#7218) refuses reserved
pages and answers with its fallback buffer, which the title's writes never reach.

Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to
set_placed_at_va_handler) with the buffer's range before the handler; gta6rt
registers rt::xmem::commit_physical_range. A failed commit is logged once and the
handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem.

Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture
cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical
pages and checks the fallback without the hook, and with it the import and a GPU
copy reading the CPU's writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:51:49 -03:00
88797f3ebd d3d12: LEONIDA_CAPTURE writes the presented frames to disk
A question that keeps coming back on the boot path is "what is actually on screen", and the window is not a reliable
answer: under Wine it is not mapped at all, and even on Windows a compositor or a capture-blocked surface can hide
the content. The presenter already copies every presented frame into a staging buffer when capture is enabled, so
this adds the disk side: `LEONIDA_CAPTURE=<dir>` writes each captured frame as a binary PPM and appends the extent
and the mean RGB to `<dir>/index.txt`, with `LEONIDA_CAPTURE_EVERY` and `LEONIDA_CAPTURE_LIMIT` bounding the run.

Off unless set, and created with the folder if it is missing. The write happens on the fence that already covers the
copy, so the present path is untouched.

d3d12_present_test turns it on and checks the files against the colour the test clears to: at least half the captured
frames (it resizes and injects failures on purpose, so a frame caught mid-transition is a near miss), and no frame
black. A capture that reads the wrong or a stale buffer fails there instead of in a report months later.
2026-11-24 00:48:42 +03:00
88045c7ae8 Keep buffer registrations atomic on host allocation failure 2026-11-23 16:37:09 -05:00
e063e5ead6 code_hooks: unwind data for the thunks, so exceptions and stack walks pass through them 2026-11-23 22:32:01 +01:00
3ce953ae80 d3d12: a depth clear outside [0, 1], NaN, or with no clear flag no longer fails the list
`CommandList::clear_depth_stencil` (`runtime/src/command_list.h`) refused a `ClearDepthStencilView` whose depth was
outside [0, 1] or NaN, and one whose `D3D12_CLEAR_FLAGS` were 0, so `Close` answered `E_INVALIDARG` and the whole
`ExecuteCommandLists` submission was dropped. Windows' D3D12 closes those lists: on WARP a `D32_FLOAT` target keeps
1.5, -0.5 and NaN exactly as given, and a clear that names no plane clears nothing. `d3d12_clear_test` now reads those
back on WARP and on the layer, and `d3d12_close_parity_test` measures the four `Close` verdicts.

A title that clears depth with a computed value (or wraps the clear in a flag mask that can be 0) lost that frame's
depth clear and, with it, the whole submission's work. The call is now recorded with the depth as given (a D16 target
still quantizes at replay) or, with no plane named, recorded as nothing.

d3d12_clear_test adds three read-back comparisons (1.5/-0.5, NaN, flags 0), command_list_test asserts the accepted
calls and the stored values, and the four close-parity rows move from the known-difference table to `match`.
2026-11-23 22:31:56 +01:00
bcb1f888aa shader_library: 9-bit canonical Huffman LUT and 64-bit BitReader refill (PERF-ZLIB-HUFFMAN-LUT) 2026-11-23 22:31:03 +01:00
08d91830ef Make BufferVaIndex insertion atomic on allocation failure 2026-11-23 16:29:23 -05:00
bcfabd83d7 Enable subgroup size control on Vulkan 1.2 devices 2026-11-24 02:56:34 +05:30
42374fb2bc Recognize the documented wave64 exchange mode 2026-11-24 02:56:33 +05:30
aecb0809c7 Reject conflicting FSPX metadata for bare programs 2026-11-24 02:56:33 +05:30
0eb99fbe9a Fix VulkanQueue constructor cleanup on holder allocation failure 2026-11-23 16:17:15 -05:00
4710549aff pe_loader: a thread that existed before load() gets the /GA TLS view too (EGEN-GA-TLS-EXISTING-THREAD)
load() rewrites a /GA executable's `mov r64, gs:[58h]` reads to a TlsAlloc slot whose value is a per-thread
view with the image's block at [0] (pe_loader.h, tls_ga_slot). install_thread_block creates that view for
the loading thread and for threads started after load(), but install_on_existing_threads gave the threads
that were already running only the block in TEB->ThreadLocalStoragePointer[tls_index]. A rewritten index-0
read on such a thread then loaded null and dereferenced it: the task queue runs a title's callbacks on pool
workers that predate the load, so this is the same AV the main thread had at exe+0x104075, moved to a worker.

Each existing thread now also gets a view of its own in TEB->TlsSlots[ga_slot], and ~Loader, the thread's
detach event and a reused thread id free it with the block.

Tested: runtime/test/loader_tls_test.cpp maps a new handmade /GA EXE fixture (tiny_ga_tls) and reads its
__declspec(thread) value from the loading thread, from a thread that existed before load() and from a later
one, then again after a second load(). Without the pe_loader change that test dies with 0xC0000005 on the
existing thread; with it all 95 checks pass. ctest -R loader: 4/4 passed (Windows 11, MSVC 19.44,
RelWithDebInfo, no GPU needed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:13:50 +01:00
6ad9db8e99 Merge upstream main 5d74c2723 into own/main
main's XErrorReport export (6312c057f) duplicated the one ladder-frame
already has; kept ladder-frame's definition and table entry. Brings in
the /GA TLS index 0 loader change (b7a3fed28).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:07:56 +00:00
ea7ddc4416 Merge #7403 (latest head) into own/main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:07:05 +00:00
254cabbd29 Merge #4313 (latest head) into own/main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:07:05 +00:00
b3baf25c38 Merge #8869 (device slot 81 GetFrameEventsX) into own/main
Slot 81 goes through route_xbox_device_slot like the other Xbox routes, so
an override onto 70 or 74 still wins. Kept ladder-frame's slots 86/101/108
and the 74 env-slot mode next to #8869's slot 81 tests and its
LEONIDA_XS_FRAME_EVENTS_SLOT override. The handled-slots comment in the
header is rewritten as one list that matches device_slot_overridden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:53:23 +00:00
89b6201ebb present: console frame-pacing uncap via LEONIDA_PRESENT_UNCAP
Any non-empty value other than "0" lifts the frame-event cap: a
WaitFrameEventX hands its token out at once (no vblank grid, no latency
throttle) and PresentX presents unsynced, so the frame rate is whatever
the title renders. Registration and suspension keep their errors, an
uncapped frame's statistics report its present time, and the flag
survives suspend/resume. frame_pacer_test covers the grid's removal and
restoration.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-23 13:46:59 -07:00
b7a3fed28d pe_loader: give a /GA executable its own TLS at index 0 (retail boot AV at exe+0x104075)
The retail game_scarlett_master.exe is built with /GA: it reads its TLS as
ThreadLocalStoragePointer[0] directly, without _tls_index, because the process
EXE always owns index 0. Mapped into gta6rt, index 0 belongs to gta6rt.exe, so
the game's allocator read gta6rt's TLS block and faulted at exe+0x104075.

load() now rewrites each `mov r64, gs:[58h]` in the EXE's executable sections
(53,246 sites in the retail exe) to `mov r64, gs:[1480h + 8 * slot]`, reading a
TlsAlloc slot (TEB->TlsSlots). Each thread's value there is a small view with
the image's TLS block at [0] and at [tls_index]. The rewrite is the same length
and runs before any of the image's code, TLS callbacks included. DLLs and
images whose index is already 0 are left alone; LEONIDA_TLS_GA_PATCH=0 turns it
off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:34:37 -05:00