Commit Graph

4696 Commits

Author SHA1 Message Date
f9896e0fe5 local: merge #9137 (slot 133 kept as on ladder-frame) 2026-11-23 15:21:22 -06:00
ced87bf258 runtime/shims: shim api-ms-win-core-com-l1-1-0..3 lifecycle and helpers
Refs: https://github.com/ItsNotRexed/Leonida/issues/9065#issuecomment-7114294575
2026-11-24 04:21:05 +07:00
237f9e0ba8 local: diagnostics (draw/present/clear/rect state), rect experiments 2026-11-23 15:20:43 -06:00
ccd36246f7 runtime: acphal.dll shim with APU heap management and SHAPE context allocation (RT-5, ASSET-587)
- Resolve Stop 28 boot blocker preventing GTA 6 from launching: acphal.dll!ApuCreateHeap and AcpHalAllocateShapeContexts.
- Implement genuine APU physical memory management (ApuCreateHeap, ApuAlloc, ApuFree, ApuIsVirtualAddressValid, ApuMapApuAddress, ApuMapVirtualAddress):
  - Support cached and non-cached heap allocations with flags routing (flags=2 to non-cached, flags=1/0 to cached).
  - Genuine block tracking allowing proper memory reclamation and reuse upon ApuFree.
  - Disjoint APU 32-bit physical address space mapping with round-trip address conversions.
- Implement IAcpHal interface in AcpHalCreate:
  - Slot 0 (connect): S_OK.
  - Slot 1 (disconnect): S_OK.
  - Slot 2 (submit_command): S_OK (unblocks fatal int3 at +0x43ad94e at boot).
  - Slots 3 and 4 (pop_message, get_num_messages): return 0.
  - Slot 5 (release): releases object.
- Implement GDK SHAPE_CONTEXTS and exact layout:
  - Six context counts and arrays: SRC, EQCOMP, FILTVOL, DMA, XMA, PCM.
  - Structure alignment with xmaContextArray at offset +0x38, matching retail executable measurement (350 contexts x 64 bytes).
  - AcpHalReleaseShapeContexts releases allocated context arrays.
- Classify acphal.dll HRESULT imports in registry.cpp and update unimplemented_policy_test.cpp.
- Add acphal_test in runtime/CMakeLists.txt and python verification test tests/test_acphal_abi.py.
- Update fallback file list in scripts/build_runtime.ps1.

No game data. AI-assisted.
2026-11-23 22:19:47 +01:00
0eb99fbe9a Fix VulkanQueue constructor cleanup on holder allocation failure 2026-11-23 16:17:15 -05:00
4ca00caf38 runtime/README: name LEONIDA_TLS_GA_PATCH
runtime/src/pe_loader.cpp reads LEONIDA_TLS_GA_PATCH in ga_tls_patch_enabled()
to switch the /GA slot-0 TLS rewrite (patch_ga_tls_reads) off, and no document
named it: tests/test_docs_env_vars.py failed on current main (5d74c27) with
"read by the code and named in no .md file: LEONIDA_TLS_GA_PATCH
(runtime/src/pe_loader.cpp:519)".

Document it in the PE loader's TLS section, next to the TLS index the loader
assigns: what the rewrite does, when it runs, and that "0" turns it off.

Tested with python -I tests/test_docs_env_vars.py (4/4 pass; the same test
fails on main) on macOS 27.0.1 arm64, Python 3.12.10.
2026-11-23 13:17:12 -08:00
ebad0ab568 Test measured slot 127 texture and buffer flags
Hand port of 356e77ec3 (#7052) onto own/main, whose slot 127 test had diverged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:16:23 +00:00
c297bb5770 d3d12_xs_rootsig: validate DXBC container, hash, and RTS0 chunk before rewriting 2026-11-23 22:16:04 +01:00
8567b8e440 cmake: resolve relative XWIN_DIR from the environment 2026-11-23 16:14:39 -05:00
6bdeabd7de xmem: publish a split span only for a view that keeps pages outside the range
A view unmapped whole has nothing to remap, so a fault on it is a real fault. Publishing it anyway
overwrote g_last_split, and a reader still faulting on the remainder of the split before it was
not retried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:14:26 +00:00
e3a33db9d0 Merge #7584 (xmem: consecutive physical pages as one view) at cef56a296
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:14:12 +00:00
a443ab5574 Tests: GPU coverage for ds_mskor, ds_and/xor_b64, ds_add_rtn_f32 and ds_inc/dec/rsub_u32
docs/design.md lists these LDS atomics as not GPU-verified: the
instructions were measured with tools/hw_oracle and the translations
CPU-checked, but the translated SPIR-V never ran on a GPU.
cs_lds_atomics_ext.asm runs one lane through ds_mskor_b32 (DATA2 bits
outside DATA ORed in), ds_mskor_rtn_b32, ds_xor_rtn_b64 then ds_and_b64
on the same element, ds_add_rtn_f32 (1.5 + 2.25), and ds_inc_rtn_u32,
ds_dec_u32 and ds_rsub_u32 at their edge cases. The eight expected
words are derived in its header from the design.md rows. The fixture
is registered in check.py and run_gpu_tests.py next to
cs_lds_b64_cmpst, and the four rows note the GPU check.
2026-11-23 13:14:04 -08: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
cef56a296e fix: publish each split span as one word so the handler never mixes two spans 2026-11-23 18:11:14 -03:00
7651b77059 test: cover small descriptor token in mock
(cherry picked from commit 8e700080066d7bbc0528aeaae5c8fb6c9cfdc347)
2026-11-23 21:10:35 +00:00
tf
6946344eb0 d3d12_xs: derive pipeline states for device slot 55
Slot 55 is the console's CreateDerivedPipelineState(pBasePSO, n, pRecords,
riid, ppv): n = 1..4 records of 0x14c bytes (a u32 tag, payload at +4) that
patch the base PSO's state before a new PSO is created.

- Slot 86 keeps a deep copy of the stream it creates on the returned PSO
  (ID3D12Object private data, released with the PSO): shader bytecode,
  stream-output and input-layout arrays and strings, cached blobs, and
  AddRef'd root signatures.
- Slot 55 patches a copy of the base stream and creates the PSO through the
  slot 86 path, so a derived PSO can itself be a base.
- Tags: 0 = DEPTH_STENCIL (or the DEPTH_STENCIL1 prefix), 1 = RASTERIZER,
  2 = BLEND, 3 = sample mask (TomBox layout; the 1.0.2.1 title does not write
  it), 5 = StencilReadMask and StencilWriteMask bytes overlaid on the base's
  DEPTH_STENCIL, applied in record order. Other tags are refused.
- A base not created through slots 86/55, a base without the matching
  subobject, malformed records, and n outside 1..4 are refused with E_FAIL or
  E_INVALIDARG and a null output, each logged once.
- Slot 55 shadows PC CreateReservedResource1 (PC slot 55) on the proxy, as
  slot 78 shadows PC CreateReservedResource2 in #7125; the vulkan device test
  calls the PC method on the real device behind the proxy.

Tests: pso_stream_test (synthetic streams: console subobject offsets, deep
copy, patching, tag 5 overlay and record order, refusals) and
device_proxy_test over WARP (refusals, graphics base via slot 86, n = 3 and
n = 4 derivations, a derivation from a derived PSO).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LwHrL5Lxc1rum25b6tnpo8
(cherry picked from commit d80c40845d7eca9163f937de943b65482b7f0657)
2026-11-23 21:10:16 +00:00
c915e1da45 d3d12_xs: slot 61 is CreateSamplerX only for the title's calls; a host caller gets PC CreateMetaCommand
The proxy also serves host callers: d3d12_vulkan_device_test drives the Vulkan device through it,
and its ID3D12Device5::CreateMetaCommand call (PC slot 61) landed in proxy_create_sampler_x
(found by nullmarsh on #7115: the test stopped at line 5763 instead of main's known line 6574).

Slot 61 now checks the caller's return address with a classifier the runtime installs
(set_console_caller, the name #7490 uses): D3D12XboxCreateDevice installs
rt::shims::mapped_image_base, so only a caller in an image the guest loader mapped gets
CreateSamplerX. Any other caller, and every caller when no classifier is installed, is forwarded
to the PC slot 61.

xs_proxy_mock_test checks all three cases: no classifier (PC slot 61), a guest caller (PC
CreateSampler with the same words; a null description skipped) and a host caller under an
installed classifier (PC slot 61). d3d12_vulkan_device_test again stops at line 6574, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8f756ebe048af042638ce51a61490f35f4f44ee3)
2026-11-23 21:10:00 +00:00
6a96084978 d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78
#6935 routes the Xbox device proxy's slot 78 to the title's SetFrameIntervalX, by design: the proxy is the
title's device, answers ID3D12Device11 with itself, and shadows PC slots the way 62 and 76 already are. The
test still called the PC ID3D12Device10::CreateReservedResource2 through the proxy, so the call reached
SetFrameIntervalX and `tiles == 1` failed (@fever308's finding on #7049). The PC method is now checked on
the Vulkan device behind the proxy, the same call and the same expectations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 703fc03a72694da4b9bcf47ba5399db34600fec5)
2026-11-23 21:09:32 +00:00
ed7efccf31 d3d12: strip incompatible UAV flags from Xbox resource descriptions
(cherry picked from commit a9c59607b8ad94f7982bc5d63dd22a9fe41cb58e)
2026-11-23 21:09:19 +00:00
136efd5b59 d3d12: normalize additional console layouts in slot 25
(cherry picked from commit b8cbab6ab0b37920addfc5a362449f49a8220637)
2026-11-23 21:08:55 +00: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
a3425aa4e8 Merge #7201 (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
cf69f16b64 Merge remote-tracking branch 'origin/main' into fix/xmem-physical-page-runs 2026-11-23 18:03:15 -03:00
f262cdea1a fix: retry only faults inside a split span; split the reader's view on every step in the test 2026-11-23 18:02:52 -03: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
0e4dd78f82 tests: GPU fixture cs_imgload_d16_tfe, the d16 form of cs_imgload_tfe
Under d16 one component fills one VGPR and the tfe status follows it, so vdata is v[7:8] / v[11:12]. Same 1000 seeds and the same check as cs_imgload_d16 (vk_store_test load-d16, saturation row included). Suggested by nnonno91, who ran this companion on gfx1036 and an RTX 5090.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:45:09 -03:00
4b075160b7 docs: note unmap_range has no rollback, move test comments to their tests 2026-11-23 17:40:34 -03:00
e64653e585 Merge branch 'pr7448' into local/ladder-frame-wine 2026-11-23 14:35:25 -06:00
6312c057f8 xgameruntime: export XErrorReport, which XGameRuntimeInitialize requires
xgameruntime.lib's XGameRuntimeInitialize looks up "XErrorReport" with
GetProcAddress next to QueryApiImpl, the InitializeApiImpl* entries and
UninitializeApiImpl, and refuses to initialise when it is missing. In the
retail executable that is the lookup at +0x55e2b7e and the null check at
+0x55e2c08, after which boot stops at an int3 (+0x5a91c21).

The shim now exports XErrorReport(HRESULT, const char*) as a DLL export,
forwarding to the IXErrorImpl report it already served (callback, S_OK).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:34:37 -05: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
1c3e043167 Merge remote-tracking branch 'pr/8591' into own/main
# Conflicts:
#	docs/d3d12_vulkan.md
2026-11-23 20:25:18 +00:00
269cabfd97 Merge branch 'rt/fence-slot12-completed-value' into own/main 2026-11-23 20:25:08 +00:00
d0c38a541c d3d12_xs: document LEONIDA_XS_FRAME_EVENTS_SLOT and use slot 102 in remap test 2026-11-23 21:21:15 +01:00
81caaa1653 d3d12: rect_list_geometry records that packed f16 attributes cannot be told apart from float outputs on the vertex side (comment only) 2026-11-23 21:19:02 +01:00
28f19186db fix(xmem): a thread touching a page of a view being split waits for the remap
unmap_range unmaps a straddling view whole and maps its remainders again, so pages the caller did not name are
briefly unmapped (aslan2142, #7584). The span being split is published and a vectored handler makes a faulting
access inside it wait, then retries it once the page is mapped again.
2026-11-23 17:18:35 -03:00
6d1f046da6 docs, comments: describe the title's VA by its range, not by a measured value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:13:38 +01:00
dbab003b0e d3d12: quad lists draw as triangle-list indices (0 1 2) (0 2 3) so flat inputs use the first quad vertex, and the PSO topology type is read as raw bits
Taken from the follow-up patch of @matheuskshn (930e78a2, tested by them on an RTX 4070 Ti: replay_quad_list_test fails the two non-indexed cases on a6b31d51 and passes with it). Re-run here: replay_quad_list_test and d3d12_rect_list_test exit 0 on the pod (Wine, RTX 4090).
2026-11-23 21:11:37 +01:00
d90903a631 d3d12_xs: implement console ListProxy with cursor pinning and queue unwrapping
- Implement ListProxy for Xbox-ABI command lists returned by slot 73
  (CreateCommandListX) with 160-slot vtable and inline cursor pinned to limit
- Keep slot 12 (CreateCommandList) returning unwrapped PC-shaped list so
  desktop test harnesses (run_tiny_frame, tiny_frame.cpp) keep slot 48
  (ClearRenderTargetView) working without regression
- Route console command list slots:
  * 0..26: PC order
  * 27..30: unforwarded console extras
  * 31: ExecuteBundle (unwraps bundle command list proxy)
  * 32: SetDescriptorHeaps (unwraps heap proxies via UnwrappedArray)
  * 33..59: shifted +4 to PC slots 29..55
  * 60: EndEvent -> PC slot 58
  * 61: ExecuteIndirect -> PC slot 59
  * 85: CopyTextureRegionX -> PC slot 16
  * 146: Barrier -> PC slot 80 (ID3D12GraphicsCommandList7)
  * 148: AllocateUploadMemory stub (returns null, logged once)
  * 10: Reset unwraps allocator proxy and re-pins inline cursor
- Unwrap command list proxies in queue slot 10 (ExecuteCommandLists)
- Add comprehensive mock tests verifying routing, pinning, and unwrapping
2026-11-23 21:09:38 +01:00
1d4d2952e8 d3d12_existing_heap_test: the cache-modifier loop's buffer no longer hides the function's pages (C4456)
Found in review under MSVC /W4: the loop's local 'pages' shadowed the function's own. Renamed to
cached_pages; no behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:06:13 +01:00
f9db5e6bb3 d3d12: a bound table's slots the title wrote in its own heap backing are pulled in before the scan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:05:45 +01:00
86ac5d5eba runtime: handle Xbox device slot 81 (GetFrameEventsX) 2026-11-23 21:01:00 +01:00
6d7842a55e d3d12: read LEONIDA_TITLE_WINDOWS_MB with getenv_s, as the file's other variables
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:59:21 +01:00
e997a1f28f test: cs_user_data's root-view-to-table mode names its pointer target, not the GLSL keyword out
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:59:03 +01:00
5ea96b8591 runtime: support KHR CopyRaytracingAccelerationStructure (CLONE/COMPACT) and COMPACTED_SIZE postbuild 2026-11-23 20:56:28 +01:00
e1ec785b2d d3d12: ExecuteIndirect bounds the span max_count * stride, and checks the offset at max_count 0
d3d12_execute_indirect_validation reports five host-parity mismatches on the RTX 5060 and on
WARP: the layer accepts an argument buffer range the host refuses. Both live hosts bound the
bytes the signature can walk, max_count * stride, so a record that fits at the end of the
buffer while its stride runs past it is refused (offset 240 with stride 20 in a 256-byte
buffer), and both check the offset itself when max_count is 0, which the layer skipped
entirely.

The layer validated with (max_count - 1) * stride + record_size and only when max_count was
non-zero. It now uses the same span as the host and validates every call, in d3d12_com.cpp
(recording, so Close fails as the host's does) and in vulkan_replay.h (replay, which had its
own copy of the old arithmetic).

The test's positive GPU path recorded the same out-of-range calls the parity table marks as
refused, so it moves to an exact-fit range (244 + 12 == 256) and a max_count 0 no-op at the
buffer's end (offset 256), and the five parity rows take the verdict both hosts give here.
2026-11-24 03:55:56 +08:00
14d54d0d76 d3d12: a placed buffer keeps its heap's arena range after the heap is released
A placed buffer is a range of its heap's arena memory, but only the heap
held that range: releasing the application's last ID3D12Heap pointer
freed it while placed buffers in it were still alive, so the next heap
or committed buffer got the same GPU address and the arena zeroed and
overwrote the live buffer. On D3D12 a placed resource holds a reference
on its heap, so releasing the heap first is legal.

The placed buffer now holds the heap's range (the shared allocation
whose deleter returns it to the arena). New d3d12_placed_heap_lifetime
test: red on main (the new heap's buffer lands on 0x10000, the live
buffer's address), green with the fix.

AI-assisted (Claude Code)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:55:13 -06:00
0c2effa27f fix(vulkan): use memory_type_order and validate stride/alignment in IndirectDispatchCounter 2026-11-23 16:54:12 -03:00