Skip to content

runtime: emulate missing Xbox boot interfaces for retail startup - #8831

Closed
pawlickerr wants to merge 12 commits into
ProjectLeonida:mainfrom
pawlickerr:main
Closed

pawlickerr wants to merge 12 commits into
ProjectLeonida:mainfrom
pawlickerr:main

Conversation

@pawlickerr

Copy link
Copy Markdown

Claimed in the coordination issue as:

Depends on: #7180, #7527

What and why

Adds missing Xbox runtime compatibility needed by the retail executable during startup, including CPU instruction emulation, DirectStorage support, Xbox D3D12 ABI handling, shader-library compute pipelines, TLS handling, and XG resource helpers.

The changes advance startup through DirectStorage and D3D12 initialization to the Xbox BVH builder. The title does not reach the main menu yet; the current stop is a C++ exception while creating the first BVH compute pipeline.

Tested

Tested on Windows 11 with the Xbox Series 1.0.2.1 package and a Vulkan-capable NVIDIA GPU.

  • Runtime build: passed
  • Selected CTest suite: 23/23 passed
  • No-game-data check: passed
  • Python compilation checks: passed
  • Retail startup test: 1,846 supplementary shaders loaded; startup reaches XboxBvhBuilder initialization

AI-assisted: yes

Checklist

  • No game data, keys or decryption, including in quoted logs or reports.
  • No new shader translator rule was introduced.

Integrate the measured Xbox ABI shims, memory and descriptor handling, command-object proxies, CPU instruction emulation, DirectStorage zlib requests, pipeline-library compute shader loading, and focused regression coverage used by the retail boot path.
# Conflicts:
#	docs/d3d12_vulkan.md
#	docs/runtime_imports.md
#	make_game.py
#	runtime/CMakeLists.txt
#	runtime/shims/xg_xs.cpp
#	runtime/shims/xmem.cpp
#	runtime/src/shader_library.h
@Digit4w

Digit4w commented Nov 23, 2026

Copy link
Copy Markdown

Review of ba5f3b26 (based on main 867d922f): changes needed. 25 runtime tests regress against main, all from one cause. The PR also carries code from three other open PRs without saying so.

Windows 11 build 26200.9974, MSVC (VS 2022 Build Tools), Vulkan SDK 1.4.363.0, AMD Radeon gfx1036 iGPU (driver 25.10.42) pinned with LEONIDA_VK_DEVICE. I did not run the retail boot. The blocker below shows up without game files.

1. ShaderLibrary::load() no longer reads <dir>/index.json (blocker)

runtime/src/shader_library.h: the new load() loops over {"fspx", "bvh", "library"} only. The load_index(dir, "", fail) call for the main index was removed, together with its try/fail("index.json could not be read"). So no translated game shader is ever found. Only the side-folder programs load, which would also explain the "1,846 supplementary shaders loaded" in the description.

ctest -C RelWithDebInfo: 247/274 pass, 27 fail. I built main in a separate worktree and ran the same 27 there: 25 pass, and only d3d12_depth_resolve and d3d12_vulkan_device fail on main too. The 25 regressions:

shader_library (line 388: library.load(...) && library.size() == 6), and the D3D12 tests that build a PSO from a temp shader folder, which print 0 translated shaders from ... and then fail Create{Compute,Graphics}PipelineState: d3d12_compute, d3d12_draw, d3d12_fspx_compute, d3d12_set0_compute, d3d12_descriptor, d3d12_bundle, d3d12_geometry, d3d12_msaa_draw, d3d12_depth24_draw, d3d12_f16_halves, d3d12_pso_validation, d3d12_typeless_families, d3d12_stores_atomics, d3d12_pipeline_library, d3d12_indirect_dispatch_count, d3d12_execute_indirect_validation, d3d12_conservative_raster, d3d12_conservative_tier2, d3d12_conservative_tier3, d3d12_inner_coverage_guards, d3d12_inner_coverage_native, d3d12_bindless_churn, d3d12_bindless_churn_validated.

Separately, xg_xs fails 4 checks (XGSuggestSwizzleMode / XGCreateTextureComputer returns E_NOTIMPL, ...). The PR changes that behaviour but not the test. The PR's "Selected CTest suite: 23/23" did not include these tests.

2. Code from other open PRs, not declared

3. Other findings (code read, each checked in the source)

  • D3D12 list CPU descriptor handles are not translated. translate_cpu_descriptor_handle (d3d12_xs_device.cpp:3524) has no caller outside xs_proxy_mock_test.cpp. The XMem-backed heaps hand the title custom_cpu_start addresses, but the list proxy forwards OMSetRenderTargets, ClearRenderTargetView / ClearDepthStencilView and ClearUAV* handles unchanged.
  • The upload arena only grows. In upload_alloc (~1720-1740), chunk->used is never reset per frame or fence, so steady AllocateUploadMemory traffic adds an 8 MiB UPLOAD chunk each time the last one fills, until the device dies.
  • The upload fallback hands a CPU address out as a GPU VA. In upload_chunk_new (~1683-1691), when CreateCommittedResource or Map fails, gpu_base = the VirtualAlloc pointer. The comment says this is for mocks, but the path is live in the real build.
  • Silent S_OK for unmodelled slots: list slots not forwarded (return 0, ~1954) and queue slots past the table (return hr_to_u64(S_OK), ~1474). Real commands (e.g. CopyTextureRegionX) vanish after a first-call log line. The project rule is "fix, don't disable", and the comment calls these a refusal while they return success.
  • DirectStorage:
    • describe() reads the title's r.Name without the guarded_move the other title pointers get (dstorage.cpp:897-898).
    • A status entry enqueued on a closed queue is set to E_PENDING (:535) and then dropped (:674-679), so it never completes. The log line says so.
  • TLS index-0 move: reserve_tls_index0 runs on every gta6rt start, writes a DLL copy to %TEMP%, and when it fails --run / --init of any EXE with TLS is now refused. Antivirus blocking a fresh DLL in TEMP (as AGENTS.md notes for loader_test) would stop runs that worked before. A fallback or a clear message would help.

Checked and fine

  • check_no_game_data.py on all 85 changed files is clean.
  • No keys, decryption or online services. The doc links are public GDK reference pages.
  • compileall passes, and tests/test_cpu_feature_scan.py gives 22/22.
  • tests/test_text_write_line_endings.py fails the same way on main (tools/leonida_tui.py, tools/wave_diff.py), so that failure is not this PR's.

AI-assisted (Claude).

@lohant27-netizen

Copy link
Copy Markdown

Tested ba5f3b26a merged alone onto main 867d922f0 (clean merge) on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), MSVC with SDK 10.0.26100, Release: builds, but 26 tests that pass on main fail (full ctest: 28 failures, against 2 on main without this PR).

What the failures share:

  • Pipeline creation: CreateGraphicsPipelineState returns E_FAIL (0x80004005). d3d12_draw fails at line 169, and d3d12_pso_validation reports [gfx: baseline]: layer returned 0x80004005, expected 0x00000000. The compute slot 62 also fails (d3d12_compute line 354). This takes down the draw, compute, MSAA, mesh, geometry, conservative-raster, bundle and pipeline-library tests.
  • shader_library fails at line 388: library.load(dir.string(), &error) && library.size() == 6. That's probably the root of the PSO failures, since this PR changes shader-library loading.
  • xg_xs: FAIL XGSuggestSwizzleMode returns E_NOTIMPL. The PR implements it, but the test still expects the stub.
  • d3d12_vulkan_device now fails earlier, at line 5770 (CreateMetaCommand(unknown_command, ...) == E_INVALIDARG && meta == nullptr), instead of the known tiles == 1.
  • Also failing: d3d12_descriptor, d3d12_execute_indirect_validation, d3d12_typeless_families, d3d12_f16_halves, d3d12_fspx_compute, d3d12_set0_compute, d3d12_stores_atomics, d3d12_bindless_churn(_validated) and d3d12_indirect_dispatch_count (the last passes on main now).

The description's "selected CTest suite: 23/23" doesn't include these. Separately, the claim line is still the template placeholder, and the PR covers areas with their own open PRs (Xbox device slots, TLS index 0 in #8379/#8622, xmem). Splitting it would make each part reviewable and testable on its own.

@Digit4w

Digit4w commented Nov 23, 2026

Copy link
Copy Markdown

Update for the new head 007863e1, pushed while I was writing the review above (same machine and setup). It restores the main load_index(dir, "", fail) in ShaderLibrary::load() (shader_library.h:760), so finding 1 is fixed: 21 of the 25 regressions now pass.

ctest -C RelWithDebInfo on 007863e1: 267/274 pass. Against main, 4 still regress:

  • xg_xs: the same 4 E_NOTIMPL checks as before. The PR changes the behaviour, not the test.
  • d3d12_descriptor: line 509: FAILED(device->CreateCommittedResource(&default_heap, ..., nullptr)).
  • d3d12_bindless_churn and d3d12_bindless_churn_validated: SEGFAULT. On ba5f3b26 they failed at PSO creation instead, so the crash was hidden behind finding 1.

Not counted: d3d12_depth_resolve and d3d12_vulkan_device fail on main too. crt_timed_wait failed once in the parallel full run and passed 3/3 on its own, so it is timing under load.

I have not reviewed the new runtime/shims/acphal.cpp (+197) or the ExecuteCommandListsX changes. Findings 2 and 3 above are unchanged by these commits.

AI-assisted (Claude).

@adrianmjim

Copy link
Copy Markdown

Tested the current head cb23cfab applied onto main 867d922f (clean). AMD Radeon RX 7900 XT (RDNA3, Navi 31, mesh shaders supported), AMD Windows 26.11.2, Windows 11 Pro 26300, MSVC 14.44 (VS 2022 generator), RelWithDebInfo, -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON, full ctest -j 1 on both trees, same machine and session.

main: 270/275. This head: 274/284. All 10 new tests pass, but 5 tests that pass on main fail on this head, and a sixth now fails earlier than on main.

New tests, all passing here: cpu_emulation, dstorage, loader_tls_index0, loader_tls_index0_threads, loader_tls_index0_noreserve, run_tiny_tls_ga, run_tiny_tls_clone_cleanup, xs_proxy_mock_env_slots_70, xs_proxy_mock_env_slots_74.

Test main cb23cfab
xg_xs Passed Failed: the 4 E_NOTIMPL checks (as Digit4w reported on 007863e1)
d3d12_descriptor Passed Failed: line 509, CreateCommittedResource (as reported)
d3d12_bindless_churn, _validated Passed SegFault (as reported)
d3d12_mesh Passed Failed: line 372, list->Close() == S_OK. Not reported yet, probably because the test skips on GPUs without mesh shaders.
d3d12_vulkan_device Failed at line 6574 (tiles == 1, known on main) Fails earlier, at line 5770: CreateMetaCommand(unknown) == E_INVALIDARG && meta == nullptr. The main failure hides this one, but it is a separate regression (lohant27 saw it on ba5f3b26).

The other 4 failures are the same on both trees (vk_queue_query_sync, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; see #8426).

Root cause of the bindless_churn crashes and the d3d12_mesh failure: the PR adds console_lists to create_device_proxy with a default of true (d3d12_xs_device.h:91). d3d12_mesh_test.cpp:149 and d3d12_bindless_churn_test.cpp:110 are PC-header callers and still use the two-argument call, so they now get console-shaped command lists and call PC vtable slots on them. As a local experiment (not pushed), I passed false in those two calls and rebuilt the two targets. All three tests then pass. With the files restored, they fail again (SegFault ×2, line 372). Either those callers pass false, or the default should be false with the title path opting in, so PC callers keep main's behaviour.

d3d12_vulkan_device line 5770: proxy slot 61 is always routed as Xbox CreateSamplerX (d3d12_xs_device.cpp:2688). In PC order slot 61 is ID3D12Device5::CreateMetaCommand, so a PC caller gets S_OK without its output being written. This is the same PC-vs-console split as above; the routing probably needs the same console_lists-style switch.

Separately: the head adds tools/Extract Shaders.cmd, which hardcodes paths from the author's machine (C:\Users\paw\...) and prepends one of them to PATH. It looks like a local helper committed by accident and is probably worth dropping from the PR.

No game files (nothing here needs them). AI-assisted (Claude Code).

rafaelpssz and others added 2 commits November 23, 2026 13:23
… shader as a no-op stub

A diagnostic switch for following a boot without translated shaders. When a
graphics or compute pipeline has no shader library, or no library entry for
its program, CreateGraphicsPipelineState / CreateComputePipelineState return
S_OK with a pipeline that is never registered: SetPipelineState then binds
no PSO and the draws and dispatches recorded with it are no-ops (D3D-482).
Off by default; every other refusal is unchanged.

d3d12_stub_pipelines_test: with no library, a graphics PSO is E_FAIL with
the switch off or "0", S_OK and unregistered with it on, and a bad
description is still E_INVALIDARG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bare kind-6 program whose translations differ has translations; it is
refused with E_INVALIDARG even with the switch on, as the description
says. Only a missing translation becomes a stub. d3d12_fspx_compute_test
checks both with a loaded library: an unknown kind-0 state is stubbed,
the ambiguous bare program is still refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@whilowcx

Copy link
Copy Markdown

I prepared a dependent fix against your current main (dd47ee94): pawlickerr#1

It scopes the A8_UNORM boot fallback to the console device while retaining PC validation, fixes the PC command-list ABI in the bindless and mesh harnesses, forwards PC slot 61 to CreateMetaCommand, and updates the xg_xs test for its implemented behavior.

On Windows 11 / RX 9070 XT, the five targeted GPU/runtime tests and eight Xbox proxy mock cases pass; A8 creation also passes with Vulkan validation. d3d12_vulkan_device gets past the earlier CreateMetaCommand failure and stops at the previously reported tiles == 1 baseline failure. No retail game files were used. AI-assisted.

@LaugeM LaugeM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the D3D12 slot part (the DirectStorage files have their own comment).

  • Device slot 26: proxy_get_custom_heap_properties (runtime/shims/d3d12_xs_device.cpp:2826, called at 3218) is #6964's function, byte for byte. The descriptor heap hook (kXmemDescriptorHeapAttributes, 2510-2529) is #7021's. Please drop both and depend on those PRs. Otherwise this branch conflicts with each of them once it lands.
  • The committed-resource lease, attach_xmem_backing (2974-3001), is #7235's: it leases the PC GetResourceAllocationInfo size. On #7240 it was measured that the PC answer overruns the title's 64 MiB range on AMD's Windows driver (513 instead of 510 tiles for a 3840 x 2160 RGBA8 target), and that the console tile size is what clears stop 17 on both vendors. The run in the description is on NVIDIA only, so it does not show the AMD case. Take #7240's lease_size instead.

The claim line is still the template placeholder, so the D3D12 part has no item ID either.

AI-assisted review (Opus 5.5). Read the diff against main; not built. Compared the functions against #6964, #7021 and #7235 heads.

@LaugeM LaugeM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the DirectStorage part: runtime/shims/dstorage.cpp, dstorage_xs_abi.h and runtime/test/dstorage_test.cpp on this branch are identical to #7180's head (git diff against it is empty), and docs/directstorage.md is #7180's copy with further edits. That code is reviewed and tested on #8461 and #7180, which land in that order. Carrying a copy means this PR conflicts add/add with #8461 in all three files (git merge-tree), and with both once they merge. I would drop these files from the branch, move the directstorage.md edits to a follow-up on top of #7180, and add #8461 to Depends on:, which already names #7180. That also shrinks the diff by about 2,900 lines. The claim line in the description is still a placeholder.

AI-assisted review (Opus 5.5). Read the diff against main; not built.

@tigre437

Copy link
Copy Markdown

Static review of the commits since ba5f3b26a (diff only; nothing from the PR was run), now at dd47ee949. Two points not raised above:

  1. Queue slot 35 can throw out of a thunk. runtime/shims/d3d12_xs_device.cpp:1471-1479 copies the title's array into a std::vector (reserve, then push_back), so an allocation failure throws std::bad_alloc into the title's code. That breaks the rule at line 1203: "Nothing here throws, since an exception must not leave a thunk for the title's code". It also reads source[i] without checking source for null when count is nonzero. The no-throw UnwrappedArray helper (line 905: 16 entries inline, new (std::nothrow) beyond that) does this exact copy.
  2. The PresentX window is still renamed. Lines 1317 and 1322 register the class as AmericasPresentX and title the window Americas, where ba5f3b26a had LeonidaPresentX and Leonida. The rename came with caed12cbc ("show shader extraction screen in Americas window"). cb23cfabb removed that screen but kept the rename.

Findings come from a static, AI-assisted review of this PR's diff (the PR's code was not executed). This comment text is AI-generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants