Repository navigation
GTA6 Xbox boot progress: ~650 D3D12 calls, first frame submits (draft, integrates #7218 #7286 #7078 #6953 #4348 #4313 #4531 #3390 #6709) - #8134
Conversation
Windows gives the process executable module TLS index 0, and MSVC code built with /GA reads TEB->ThreadLocalStoragePointer[0] without loading _tls_index. The loader gave a mapped EXE a gta6rt_tls_host.dll clone's index instead, so a thread_local int v = 42 EXE built /O2 /GA /MD printed tls_index=6 value=0 under gta6rt --run (natively tls_index=0 value=42). Index 0 belongs to gta6rt.exe itself (and to each test EXE that links pe_loader.cpp): measured through _tls_index == 0 before any mapping and the new tls_index0 trace event. All of its own TLS reads go through _tls_index, so the first time an executable is mapped the loader loads one more helper clone (leonida_tls_host_<pid>_home.dll), stops the other threads, swaps slots 0 and the clone's index on every thread and writes that index into the owner's _tls_index. Threads started later swap their own slots first thing in the helper's DLL_THREAD_ATTACH. Both pointers are OS-allocated blocks of that thread and the OS frees every slot at thread exit, so the swap is permanent and nothing is restored. The executable then takes slot 0 (kMainImageSlot) through the existing per-thread install, thread events and ~Loader paths; DLLs keep the helper indices. A second executable mapped while one is live, or a move that cannot be made (a thread kept running in the owner's code for 250 ms), gets a helper index and a stderr note. Measured on Windows 11 26300 to make the swap safe: a new thread publishes its TLS array in the TEB only once it is filled (LdrpAllocateTls), an ending one clears it before freeing the blocks (LdrpFreeTls), LoadLibrary of a TLS DLL updates other threads in one NtSetInformationProcess call, and an EXE's TLS callbacks run after every DllMain for thread attach and detach. Tests: loader_tls_index0 maps tiny_tls_ga.exe (built /GA, code shape checked) next to tiny_tls.dll: 42 on the loading thread, a pre-existing thread and new threads, this EXE's own TLS intact on all of them, two runs in a row, a second executable at once, and a busy thread holding the move off. run_tiny_tls_ga runs it under gta6rt --run and --init and checks the trace names gta6rt.exe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s the EXE's Fixes from the review of the index-0 change: - The lazy move at the first executable map stopped other threads and swapped their slots, guarded by a "thread is inside gta6rt.exe" check. That is not enough: MSVC keeps &ThreadLocalStoragePointer[_tls_index] across calls (zlib_inflate saves it at [rbp-80h] across memset, push_back and inflate_codes, then reads _Init_thread_epoch through it), so a thread stopped in the heap or memset still reads the wrong slot afterwards. The move is now rt::reserve_tls_index0(), done once at process start: gta6rt calls it from a .CRT$XCT initializer, before its own static initializers and before any of its threads; the CRT startup frames above it hold no TLS slot address (checked in the disassembly). It swaps slots 0 and home on the calling thread only; no thread enumeration, suspension, TEB writes or TlsAlloc mark are left. - The home clone's block was the helper's 514 bytes, smaller than gta6rt.exe's 1398-byte TLS. The home clone is now written from gta6rt_tls_host.dll with its TLS directory pointed at a new 16 KiB export, gta6rt_tls_home_template, filled with a copy of the EXE's template and its alignment (LdrpAllocateTls copies End - Start and ignores SizeOfZeroFill, so the zero fill is part of the range). Every new thread then has a fresh copy of gta6rt.exe's TLS at the home index from its first instruction, so no adoption step or window before the helper's DLL_THREAD_ATTACH is left. The mapped template is checked against the EXE's after the load. - The owner is GetModuleHandleW(nullptr) with _tls_index 0, not any module whose index reads 0. - A primary helper without gta6rt_tls_host_set_thread_event is refused. - An executable that does not get index 0 (no reservation, or another executable holds it) is refused by --run and --init with an error; its /GA code would read and write another module's TLS through slot 0. The README no longer says it "reads the first one's slot 0". - Thread attach installs every module's copy before any TLS callback runs, as Windows allocates all blocks before the first DllMain. - Tests: loader_tls_index0 (runs) checks this EXE's block moving from slot 0 to the home index by identity, the home template's size and content, and that the getter reads slot 0 with its _tls_index pointing elsewhere (fails for a non-/GA build of the fixture); loader_tls_index0_threads reserves while threads are being created, with one suspended thread that has no TLS array yet and tiny_thread_hook.dll running test code before the helper's DLL_THREAD_ATTACH; loader_tls_index0_noreserve maps without the reservation. The tiny_tls_ga.cpp comment names the real test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ils cleanly From the second review of 89cec3b8: - The first load_tls_host_clone call is now the home clone, from .CRT$XCT, and it registered cleanup_tls_clones_at_exit with atexit before g_tls_clones was dynamically initialized in .CRT$XCU. The vector's destructor then ran first and the cleanup walked a destroyed vector, so --dry-run, --init and every return-1 path left the slot clones' leonida_tls_host_<pid>_<slot>.dll files in %TEMP%. g_tls_clones is now allocated with the first record and never destroyed, and the atexit handler is registered there. The home clone cannot be deleted while it is mapped (DeleteFileW and a POSIX-semantics delete both fail with ERROR_ACCESS_DENIED), so it is left for the next run's sweep, as the README says. - process_alive() took an ended process as alive while another process still held a handle to it (CMake's execute_process does), so the next run's sweep skipped its files; it now reads the exit code. - reserve_tls_index0 catches what reserve_index0 throws (for example std::filesystem::temp_directory_path) and stores it as the reason, so the reservation fails before main with a message instead of ending gta6rt. The owner's file name is taken before the move, so nothing can throw between the move and recording it. - Tests: run_tiny_tls_clone_cleanup runs gta6rt --dry-run, --init and --dry-run on tiny_tls_clones.exe (three TLS modules, so one slot clone) and checks that each run's PID leaves no clone file but its home clone and that the next run deletes that one; it fails with the old cleanup. run_tiny_tls_ga also runs with TMP and TEMP naming a missing folder: the reservation fails, --run and --init refuse the image with the reason and run none of it, --dry-run maps it with the note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry reads Serve the Xbox DirectStorage API (IDStorageFactoryX2, IDStorageQueueX2, IDStorageFileX, IDStorageStatusArrayX) under dstorage_xs.dll, xcrdapi.dll and dstorage.dll. Declarations are our own (shims/dstorage_xs_abi.h), written from the public GDK reference; layouts are pinned with static_asserts. - OpenFile goes through the registry's kernel32!CreateFileW, so GAME: paths use the console path mapping and the write overlay. GetHandle returns a ReOpenFile handle with its own file position. - One worker thread per queue runs submitted entries in order: file and memory requests, status arrays, ID3D12Fence::Signal, EnqueueSetEvent (on a duplicate of the title's handle taken at enqueue). - Auto-submit at half the capacity (or disabled through DSTORAGE_QUEUE_OPTIONS), enqueue into a full queue waits, CancelRequestsWithTag (a cancelled request is a success and not a failure), error record and error event, Close and the last Release drain the queue, IDStorageFileX::Close waits for the file's submitted reads. - Request checks: reserved bits, source type, BCPack/swizzle ranges, sizes, 1 GiB limit, null and foreign objects and closed files (also for zero-size requests), end of file, inaccessible memory. - zlib, BCPack, swizzle and physical pages return E_NOTIMPL (later PRs). - Interface ids of the X interfaces are not public: a creating call accepts and logs a new id per object kind, but refuses system COM ids (IMarshal, IAgileObject, ...) and the PC DirectStorage ids; QueryInterface accepts only IUnknown, the PC IDStorageStatusArray id (same shape) and the ids creating calls accepted for that kind. Bad arguments are logged once per method. - registry.cpp classifies xcrdapi.dll!DStorageGetFactory as HRESULT; the cl.exe fallback in build_runtime.ps1 builds the new shim too. ctest dstorage: 258 checks over synthetic files in %TEMP%, no GPU, no game data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/directstorage.md records which DLL and ABI the console title is expected to use (dstorage_xs.dll medium, xcrdapi.dll and dstorage.dll low confidence), what is not public (vtable order, interface ids, some constants) and the choice made for each, what owning the modules shadows at run time, what the shim does (including the order of its request checks), and what later PRs add (zlib, BCPack, swizzle, physical pages, GPU-backed destinations, parallel reads). Index row in docs/README.md; the owned-module list in runtime_imports.md and the shim list in runtime/README.md name the new modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # scripts/build_runtime.ps1
# Conflicts: # runtime/src/main.cpp
…mit, /EHa under clang-cl Review fixes for ItsNotRexed#4348 (Flyander, AirKyzzZ): - DSTORAGE_REQUEST allows a buffer over 32 MiB only with 64 KiB or 2 MiB pages, which are not implemented yet, so such a request now fails with E_DSTORAGE_REQUEST_TOO_LARGE before any memory is touched. - TotalRequestCount and the byte totals grow when a request is submitted, not when it is enqueued, and PendingRequestCount counts the request the worker is processing (DSTORAGE_PRIORITY_STATS). - dstorage.cpp is built with /EHa under clang-cl, so guarded_move's __try catches an access violation in a title's buffer there too. Tests: an over-limit and an at-limit 32 MiB copy, and stats checked before Submit and while a copy is held on a guard page. The three new failing checks fail with the previous shim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # scripts/build_runtime.ps1
# Conflicts: # scripts/build_runtime.ps1
# Conflicts: # scripts/build_runtime.ps1
…c and a title's VirtualAlloc The console's allocation type picks the page size with bits the host reads differently: 0x20000000 (2 MiB) is the host's MEM_LARGE_PAGES, which needs SeLockMemoryPrivilege, 0x80000000 (4 MiB) is rejected, and 0x20400000 (64 KiB) becomes MEM_LARGE_PAGES | MEM_PHYSICAL. XMemVirtualAlloc failed the 2 MiB mode and rejected 4 MiB, and the title VirtualAlloc shim forwarded all three. Both now share one path: the bits are decoded (other combinations stay ERROR_INVALID_PARAMETER), never forwarded, and every page size is served from ordinary host pages with the base aligned to the page size (VirtualAlloc2 with an alignment requirement, else a reserve/release/reserve probe with retry), sizes and addresses rounded to whole pages, and one host allocation per region so VirtualFree and VirtualQuery match what was returned. A title's VirtualAlloc still needs an operation; nonzero XMem attribute words still fail with ERROR_NOT_SUPPORTED. Page-size values as read in OpenScarlett (MIT, kernelx_abi.h, xmemory.cpp) and omonkeyz/xbox-emulator (GPL-3.0-or-later, crates/compat/xmem/src/virt.rs); the probe fallback follows xbox-emulator's reserve_aligned (sys.rs). xmem_test gains 2 MiB / 4 MiB / 64 KiB cases for both entry points (24 of 104 checks fail on main; 146/146 pass here), and xmem_probe reruns it with LEONIDA_XMEM_NO_VIRTUALALLOC2 set to cover the fallback. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libHttpClient.GDK.dll and XCurl.dll reach the GDK runtime through
xgameruntime.lib's thunks: LoadLibraryW("xgameruntime.dll"), then
GetProcAddress of InitializeApiImpl, InitializeApiImplEx,
InitializeApiImplEx2, QueryApiImpl, UninitializeApiImpl and XErrorReport.
The shims served only the first five. Without XErrorReport the thunks
refuse the runtime before they call any initializer: under gta6rt --run,
HCInitialize returned 0x89240101 (E_GAMERUNTIME_DLL_NOT_FOUND) and
curl_global_init returned CURLE_FAILED_INIT.
XErrorReport is now served by the function behind IXErrorImpl slot 3, so
a report reaches the XErrorSetCallback callback either way.
xgameruntime_test and the tiny_gdk_load fixture check all six names and
that a report through the export reaches the callback.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only handle the observed reserve-only access and protection pairs. Retain host reservation state, granularity and CPU protection. AI-assisted.
# Conflicts: # docs/runtime_imports.md
…e PC vtable refuse with E_NOTIMPL The retail title calls device slot 133, past the 128-entry table; the call read an empty entry and jumped to 0. Every slot beyond the PC device's vtable now reaches the generic thunk. Mock test covers slot 133. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # runtime/shims/xmem.cpp # runtime/test/xmem_test.cpp
# Conflicts: # runtime/CMakeLists.txt # runtime/README.md # runtime/src/pe_loader.cpp
# Conflicts: # docs/README.md # runtime/CMakeLists.txt
…tRexed#1797) Squash-merged after diff review of PR ItsNotRexed#1797
…/d16, buffer_store_byte/short) (ItsNotRexed#1864) Squash-merged after diff review of PR ItsNotRexed#1864
…ory (VK_EXT_external_memory_host) The retail executable opens the 64 KiB graphics region it has just committed with XMemVirtualAlloc through device slot 48 right after its first queue and fence; the layer answered E_NOTIMPL and the title asserted. The call now answers as the host runtime does on an RTX 4090 and WARP (six cases measured in d3d12_existing_heap_test): the base of a VirtualAlloc allocation committed read-write over its whole size opens a heap of that size, 64 KiB aligned, CUSTOM / WRITE_BACK / L0, SHARED | SHARED_CROSS_ADAPTER | ALLOW_SHADER_ATOMICS; an inner address, a partial or reserve-only commit and a read-only range are E_INVALIDARG. The backing is the range itself, imported with VK_EXT_external_memory_host, which the device and the test device enable when present. CheckFeatureSupport(EXISTING_HEAPS) follows the extension. Placed resources in such a heap are refused (E_NOTIMPL, logged) until the placed path addresses memory outside the arena. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NotRexed#2359) Squash-merged after diff review of PR ItsNotRexed#2359
…183) (ItsNotRexed#2644) Squash-merged after diff review of PR ItsNotRexed#2644
…unaligned title-placed buffers, exception registers Queue slot 35 routed to ExecuteCommandLists following PR ItsNotRexed#7286. Co-Authored-By: Vadson159 <vad.sofr@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LcK6MEZaGkvjgvEZjGx5v2
… the fence proxy); crash dumps for the handle wait Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LcK6MEZaGkvjgvEZjGx5v2
|
Tested It reproduces your stop exactly. The title gets into the main loop, reaches queue slot 35 ( Along the way, 42 slot 67 (FSPX) pipelines fail with AI-assisted. |
|
I tested the slot-8 copy in
The fixture compared all 196,608 destination bytes, including padding, for 908 bytes of generated input. Swapping only the first-mip source pointers between the two RGBA8 array slices still returned six successes and failed the pixel-byte comparison. On merged main The test goes through the registered exports and vtable slot 8. It requires only the original fixture. From a configured Windows build of the verification commit, run Windows 11, MSVC 19.44, Intel Core Ultra 7 265K. GeForce RTX 5070, driver 621.01, idle. The comparison runs peaked at 2.2 MiB per test process. AI-assisted by GPT-6.2 Astra. |
|
Ran this branch (head On: Windows 11, MSVC (VS 2022 Build Tools), NVIDIA GeForce RTX 3060, driver 32.0.16.2124, Vulkan SDK 1.4.363.0. Retail v1.0.2.1 package. Result: the boot does not reach the main loop here. It gets through device creation, slots 25, 26, 41, 61, 74, 127 (the XMemAlloc budget accounting logs its first 33,423,360 B lease) and 133 (a buffer on the title's pages), the first RTV and slot 16, then slot 62 (the BVH builder's first compute pipeline) right after the shader index loads. About 33 s into the run the title's watchdog fires: your trace dumps 47 thread stacks, the title's main thread is in a wait inside its own code (not in the runtime), and no thread is inside So on this machine the stop is the ~30 s watchdog during the BVH builder's pipeline creation (or what the main thread waits on right after it), before the first submit. I have not split the 33 s between loading the shader index, compiling the 52 BVH pipelines on the NVIDIA driver, and the wait itself; happy to rerun with a switch or a timing log if you point me to one. One thing I hit setting it up: if (AI-assisted run and write-up, Claude Code.) |
|
Thanks all — very useful. @Ryx69 thanks for reproducing. That stop is fixed in 5119d85: console queue slots 16–20 sit two past the PC's (16 Signal, 17 Wait, 18 GetTimestampFrequency, 19 GetClockCalibration, 20 GetDesc → PC 14–18). The title calls slot 16 with (fence, 1) from RVA 0x248260e; forwarding it to PC GetTimestampFrequency wrote 1e9 over the fence proxy's vtable, which is the 0x3b9aca60 read. Boot now goes a few calls further and stops at +0x4fb0b03 reading 0x80004001 (an E_NOTIMPL from a still-unsupported slot used as a pointer) — investigating. @jeremygold02 thanks for the XG upload fixture. Happy to pull df0547c into this branch with your authorship if you're OK with that. @JuniorBoschet the 30 s watchdog during the BVH pipelines is what I hit before seeding the Vulkan pipeline cache; I should have written it down. Build a seed once and place it next to gta6rt.exe: |
|
Nice catch on the slots shift! The new crash at In We already prepared and tested the stub for slot 32 on our fork: if constexpr (K == ChildKind::queue && Slot == 32) {
static std::atomic<std::uint64_t> presents{0};
const std::uint64_t n = presents.fetch_add(1, std::memory_order_relaxed) + 1;
if (n <= 4 || n % 1000 == 0) {
std::fprintf(stderr, "[rt] d3d12_xs: queue slot 32 (PresentX) #%llu: count=%u planes=0x%llx params=0x%llx; S_OK stub\n",
static_cast<unsigned long long>(n), static_cast<unsigned>(a1),
static_cast<unsigned long long>(a2), static_cast<unsigned long long>(a3));
}
return S_OK;
}Available on branch: https://github.com/Th3drata/Leonida/tree/pr-8134-queue-layout (commit |
|
Yes, please cherry-pick Windows 11, MSVC 19.44 RelWithDebInfo, Intel Core Ultra 7 265K. CPU-only test. RTX 5070, driver 621.01, idle. AI-assisted. |
|
Thanks @Th3drata! In my traces the 0x80004001 at +0x4fb0b03 comes from fence slot 12, not queue slot 32: the call right before it is Queue slot 32 is still unsupported (called with (1, ptr, ptr, 3)), but its E_NOTIMPL didn't stop the boot here; I'd rather measure what it is before stubbing it as PresentX. Happy to take your stub once we know its arguments. |
|
Correction to my comment above: the slot 32 stub was not tested, only written. Your fence slot 12 diagnosis is the right one — sorry for the noise. |
|
Scope: static analysis of added diff lines only; no code was executed. Please review findings manually. |
|
Second machine: RTX 5080, Windows 11, MSVC 14.44, own 1.0.2.1 copy, #7290 already implements fence slot 12: the completed value at a live address, one mirror per fence refreshed by a thread-pool wait on a completion event, with slot 12 and the CPU The next stop is a read through a null graphics PSO, at ~660 D3D12 calls. This run makes no device slot 57 call at all (compute PSOs through 62/67 only), so the title's PSO table entry is still null when it is read; cf. the slot 57 ( Tests: AI-assisted. (Edited to drop executable addresses, per #7416.) |
|
Queue slot 32 is
macOS data point (first Apple GPU run on this branch, as far as I can see): Apple M4, CrossOver 26.3 (Wine 11.0) + Rosetta 2 + MoltenVK,
Branch: https://github.com/Th3drata/Leonida/tree/dev-boot-tour-v2. Not done: wiring AI-assisted. |
|
Independent Windows Sandbox result for I translated the 1.0.2.1 package with LLVM 23.1.5, SPIRV-Tools v2026.4 and wave64 emulation on. Two launches of AI-assisted verification. Observations only. |
Claimed in the coordination issue as: none — this is a draft progress report from an integration branch, not a claim. Individual fixes can be split into claimed PRs on request.
Depends on: #7218, #7286, #7078, #6953, #4348, #4313, #4531, #3390, #6709
What and why
Draft / progress report — not meant to merge as-is. This branch integrates the open PRs above plus local fixes, and pushes the retail Xbox Series executable (v1.0.2.1) further through boot on a PC through the Vulkan layer.
Where boot gets to: ~650 D3D12 calls (from ~470). The title reaches its main loop and submits its first command lists (queue slot 35). The current stop is in the main thread at
RVA 0x4fb0aec. There, a handle-typed wait (0x9796d0 -> 0x4fb0a50) dereferences an object whose vtable reads0x3b9aca00(1e9). It is likely a frame-fence or timestamp handle the title expects from an unimplemented queue slot 32 or allocator slot 9.Local changes. Each is commented in the code with the measured RVA, and anything unmeasured is marked ASSUMPTION.
GetTimestampFrequencyon the console, not GetDesc. This was measured at RVA 0x24841a6. PC GetDesc wrote 16 bytes over the caller's saved RBX, and that caused a crash much later. Queue slot 35 goes through slot 10's path, so probes are dropped and heaps synced (building on d3d12_xs: route command queue slot 35 to ExecuteCommandLists #7286).xg_xs: a linear XG texture computer (XGCreateTextureComputer,XGSuggestSwizzleMode).vkCmdDrawMeshTasksIndirect(Count)EXT.spirv/bvh.Credit: the integrated PRs' commits keep their authors.
Known gaps:
Tested
scripts/build_runtime.ps1 -FetchSdl3passes, tests included.gta6rtwithLEONIDA_D3D12=vulkanagainst a retail v1.0.2.1 dump. Each fix above was checked by the next run getting past the previous stop.rdna2spirv --wave64-emulate(52 shaders translated). spirv-val was not re-run separately for this report.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator rule changed.)