vulkan_format() had no entry for R16_UINT, R16_SINT, R16_SNORM, R8_UINT, R8_SINT, R8_SNORM, R8_TYPELESS, R16G16_UNORM, R16G16_SNORM, R16G16B16A16_SNORM or A4B4G4R4_UNORM, so CreateCommittedResource refused them with E_INVALIDARG and FORMAT_SUPPORT answered DXGI_ERROR_UNSUPPORTED where native D3D12 creates them (item 1 of the FORMAT_SUPPORT finding in #1380). A4B4G4R4_UNORM keeps alpha in bits 0-3 and red in 12-15 (cleared and read back on native D3D12, RX 9070 XT and WARP), which is Vulkan's R4G4B4A4_UNORM_PACK16; its T# row reads that as W, Z, Y, X. Copies get the formats' texel sizes, D16 copies pair with R16 SNORM/UINT/ SINT like the other R16_TYPELESS members, and the colour-resolve check refuses every integer format by numeric class instead of a list that missed R8/R16 and the SINT forms of R8G8B8A8, R32 and R32G32B32A32. Tests: d3d12_vulkan_device creates each format (as the host does), copies a 4x4 upload in and back out bit for bit, and clears an A4B4G4R4 render target to R, G, B and A; d3d12_descriptor_test samples A4B4G4R4 through a T# alongside B4G4R4A4 and B5G5R5A1. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gta6rt
gta6rt is the native Windows runtime for the Xbox Series build. It is deliberately small: the game
executable is still missing from the package used here, so this directory contains the machinery that
can be built and tested without it — the PE loader, the measured import shims, and the GPU/Vulkan test
tools.
Build
The normal path is the repository build script:
powershell -File scripts/build_runtime.ps1
It uses CMake + Ninja from Visual Studio when available, otherwise cl.exe, and writes
runtime\build\gta6rt.exe plus gta6rt_tls_host.dll (the loader's TLS-index helper; it must stay next to
the executable). The direct CMake path works too:
cmake -S runtime -B runtime/build
cmake --build runtime/build --config RelWithDebInfo
Requirements: Windows x64, Visual Studio 2022 with the C++ desktop workload. The GPU tools need the Vulkan SDK; the runtime and CPU tests do not. The loader is x64-only and the PE mapper rejects any other machine.
Dry run
gta6rt --dry-run <image.exe|image.dll> [--game-dir <package>] [--overlay <dir>]
--overlay is where a mapped title's writes go (default <game-dir>\overlay); GAME: paths read from
--game-dir. See Console paths and the write overlay.
The dry run maps the image and the bundled modules it imports, applies base relocations, binds every
import through the shim registry, a host DLL, or another bundled module, parses exports, installs static
TLS for the calling thread, applies section protections, and
prints a per-module report. It does not call DllMain, TLS callbacks, or the entry point, so no
code from the mapped images runs. TLS reserves its module index through the runtime's own
gta6rt_tls_host.dll, and host imports load system DLLs, as they did before.
gta6rt --init <image> runs the same mapping and then Loader::initialise(): each module's TLS
callbacks and each DLL's DllMain(DLL_PROCESS_ATTACH), dependencies first. An EXE's entry point is not
run. When the loader is destroyed, initialised modules receive TLS callbacks and DLL entry-point calls with
DLL_PROCESS_DETACH, in reverse initialisation order. All mapped images, unwind tables and static TLS stay
available until these notifications finish, so DLLs can release resources such as FLS callbacks safely. The reserved
argument is null (explicit unload). A map-only load receives no detach notifications.
--dry-run, --init and --run are separate modes: give exactly one. Two together (--dry-run --run)
print the usage and exit 2 before anything is mapped.
The report line is:
<name> base=<addr> size=<image size> entry=+<rva> shim=N host=N module=N unimplemented=N
Shim and unimplemented imports are listed by name. A non-zero unimplemented count is the useful
signal: it names the next shim that is missing. The measured result for the 16 DLLs shipped in the
package is recorded in the runtime-imports documentation.
After the totals the report counts the unimplemented imports by return class, and marks the HRESULT ones in the list:
UNIMPLEMENTED xgameruntime.dll!XUserAddAsync [returns HRESULT]
1 module(s) mapped, 1 unimplemented import(s)
unimplemented by return policy: hresult=1 other=0
Unimplemented imports at run time: LEONIDA_UNIMPLEMENTED
An import with no shim, host function or bundled module is bound to a thunk. What a call to it does is set by the
environment variable LEONIDA_UNIMPLEMENTED, read once per process:
| value | a call to the thunk |
|---|---|
log (default) |
prints [rt] unimplemented: dll!name once and returns 0 in rax and xmm0. This is what the runtime always did. |
fail |
the same, but returns E_NOTIMPL (0x80004001) for imports known to return an HRESULT, and 0 for all others. |
stop |
on the first call prints the import, the caller's return address as module+RVA, and rcx, rdx, r8 and r9 as the game passed them; then breaks if a debugger is attached (continuing returns the fail value), else ends the process with exit code 3. |
No mode writes to an out parameter: a function that fills one in on success leaves it as the caller had it. Under
log an HRESULT function therefore returns S_OK with its outputs unset, which is why fail exists; with fail
the caller sees an error and can take its own failure path. Any other value is reported and treated as log.
Whether an import returns an HRESULT is decided by DLL and name alone (classify_import in
shims/registry.cpp, where each entry names its source). The list is short on purpose and every entry was checked
against the public Microsoft documentation: D3D12Create*/D3D12Serialize* and the D3D12 debug/experimental
entries, CreateDXGIFactory* and two DXGI functions, XGameRuntimeInitialize, and the GDK families XAsync*,
XTaskQueue*, XUser*, XStore*, XGameSave*, XPackage*, XGameUi* minus the functions the same pages document
as void/bool/int. A function that is not on the list gets 0 under fail, exactly as under log.
The thunk keeps the Win64 argument registers and the return address intact (it is entered by the game's call), and
reaches a shared stub that saves them, so a floating-point caller still reads 0.0 from xmm0 and a debugger can unwind
through it.
PE loader
src/pe_loader.cpp maps x86-64 images at their preferred base, or elsewhere (with relocations) when
that base is taken, copies headers and sections, applies IMAGE_REL_BASED_DIR64 relocations, binds
imports by name or ordinal, parses the export table, sets section protections, and registers the
image's x64 unwind table (.pdata) with RtlAddFunctionTable, so exceptions raised in or passing
through a mapped image are dispatched and stack walks can step over its frames. The table is validated
first (entries in bounds, sorted and non-overlapping) and removed when the loader is destroyed. Modules
are deduped by lower-case file name, so an import graph that reaches the same DLL twice maps it once.
MSVC C++ exceptions need one more piece. _CxxThrowException stores the throwing image's base in the
exception record, from RtlPcToFileHeader, and the catch side adds the throw's RVAs to it; Windows' own
RtlPcToFileHeader only knows images its loader mapped, so for a mapped image the base is 0 and no
catch matches. When the loader binds a host copy of the MSVC runtime (vcruntime140.dll,
msvcp140.dll and the rest of that list), it points that DLL's import of RtlPcToFileHeader at a
version that asks Windows first and then the modules a live Loader maps. The redirect stays for the
process lifetime and answers as Windows does when no Loader is alive.
load() also installs static TLS for the calling thread. __declspec(thread) reads TEB->ThreadLocalStoragePointer[_tls_index], which is a
different index space from the TlsAlloc slots, and only the OS loader can allocate a module index.
The runtime therefore ships a minimal gta6rt_tls_host.dll; the loader reuses the index the OS assigns
it, writes that index into the image's AddressOfIndex, and copies the image's TLS template into the
slot. This reserves one index, so one manually mapped TLS module can be live at a time; a second
one is rejected with an error instead of sharing the slot. Images without a TLS directory (or with an
all-zero one) load normally.
Current limits, by design:
load()runs no image code. Static TLS is data, not code. The TLS index helper is the runtime's owngta6rt_tls_host.dll; host imports still load system DLLs as before.--dry-runnever runs image code.initialise()runs TLS callbacks and a DLL'sDllMain;run_tls_callbacks()is the seam for callers that do not useinitialise(). An EXE's entry point is the caller's to run.- Every thread started after
load()gets its own copy of the TLS template, fromgta6rt_tls_host.dll'sDLL_THREAD_ATTACH, and gives it back atDLL_THREAD_DETACH, also when the thread outlives itsLoader. Frominitialise()until~Loaderstarts the process detach, those events also run the module's TLS callbacks, with the thread's copy already in place. A thread that existed beforeload()gets nothing: callinstall_tls_for_thread()before mapped code runs on it anduninstall_tls_for_thread()before it exits. Mapped DLLs'DllMainis not called with thread events. Destroy theLoaderon the thread that calledload(). - The TOC of the game's RPF archives is encrypted and is not read here. The loader works on the PE files and on any images the caller passes it.
Shims
shims/registry.cpp holds the static tables. The current shims are:
-
xmem.dll—XMemAlloc,XMemFree, the measured two-argumentXMemGetWorkingSetStatistics(kind, out), and the measured three-argumentXMemVirtualQuery(process, address, out). Allocations are 64-byte aligned; the working-set and virtual-query outputs fill the observed 64-byte structures and returnFALSE/0on a null or bad address. -
The
kernel32.dllfile API —CreateFileA/W,FindFirstFileA/W/FindNextFileA/W/FindClose,GetFileAttributesA/W,GetFileAttributesExA/WandDeleteFileA/W: aGAME:path maps under--game-dir, an open that can write and a delete go to--overlay DIR(default<game-dir>\overlay), which reads prefer, and a path that climbs aboveGAME:is refused. The package is never modified. See docs/runtime_imports.md. -
d3d12_xs.dll—D3D12SerializeVersionedRootSignatureandD3D12CreateRootSignatureDeserializer, with the console root-signature high byte (0x03000000) cleared on a copy before forwarding to the PCd3d12.dll.D3D12XboxCreateDevicewraps a device in the measured-slot Xbox-ABI proxy: the host PCID3D12Deviceby default, or the Vulkan-backed device (shims/d3d12_vulkan_device.cpp) whenLEONIDA_D3D12=vulkanis set and the runtime was built with the Vulkan SDK and Python 3. The Vulkan device covers command submission, descriptor heaps, render-target and depth views, committed resources and copies (uploads, readbacks, BC textures); seedocs/d3d12_vulkan.mdsection 3.2 for what is missing. -
gameinput.dll/xgameruntime.dll—GameInputCreate: the v0 GameInput API for gamepads on SDL3 (shims/gameinput.cpp), so any controller SDL supports works, with rumble, Xbox trigger rumble, and on a DualSense adaptive-trigger effects and the lightbar. Optional and CMake-only: built when an installed SDL3 is found, or with-DLEONIDA_SDL3_FETCH=ONto download the pinned release; nothing is downloaded otherwise, and thescripts/build_runtime.ps1cl.exe fallback never builds it. See docs/gameinput.md for the mapping, theLEONIDA_DS_*settings and what is unverified.
The two serializer functions and D3D12XboxCreateDevice are the only d3d12_xs imports used by the
shipped DLLs (measured; see docs/design.md and docs/d3d12_vulkan.md). The game executable's own
imports are unknown until it is available.
Tests
For a Visual Studio build, pass CTest the same configuration you built above.
ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure
On Windows the build configures the CPU tests that do not need a GPU or game files, including the
root-signature forwarding test (root_sig_test) and the clear-command test. The Vulkan tools and
D3D12-over-Vulkan COM targets are built when Vulkan headers are found (via VULKAN_SDK, an installed
SDK, or -DLEONIDA_VULKAN_HEADERS_FETCH=ON to download the pinned Khronos Vulkan-Headers release):
vk_harness— hand-written RDNA2 shader programs on a real Vulkan device.vk_texture_test,vk_compute_test,vk_store_test— texture, LDS/compute, and buffer-store paths.vk_command_replay_test,d3d12_com_test,d3d12_vulkan_device_test— the D3D12 command path on Vulkan: replay, the COM command objects, and the Vulkan device behind the Xbox-ABI proxy.- GPU tests count only validation-type errors. Loader and layer messages, such as a third-party implicit layer
that fails to load, are printed but don't fail the run; to silence one, set
VK_LOADER_LAYERS_DISABLE=<layer name pattern>. d3d12_draw_test— milestone M1: a VS+PS pipeline found by FSSM hash, the input layout matched by semantic, and five draws plus a culled triangle, compared pixel by pixel. They also cover an unbound render target and DSV, a rebound root signature, instance step rate 0, an unbound vertex slot, and PSOs, buffers and heaps that must be refused. A second pass draws a full-screen triangle with no vertex input and an XOR logic op.d3d12_translated_draw_test— milestone M1.5: the same with translator output.test/shaders/vs_m15.asm(vertex fetch through a V#) andps_m15.asm(constants read through the code base) are built bytest/shaders/build.pyand found by FSSM hash; three draws into a float target, compared bit for bit. Needsllvm-mc(LLVM_MC) and the Vulkan SDK'sspirv-asandspirv-valat build time.d3d12_compute_test— the compute path: root signature, a compute PSO found by its FSSM hash in a translator-style index, root arguments through the GPU address arena, and two dispatches.d3d12_set0_compute_test— set 0 from the compute bind point: a compute PSO whose index entry lists set-0 bindings, and four dispatches that sample two SRVs, bytes no view was made for and a clamping sampler through the bindless set the layer binds.d3d12_present_test— milestone M0: opens a window and presents 60 cleared frames through the proxy on Vulkan, resizes it and presents 10 more, and checks the colour on screen. A driver double then injects an out-of-date and a suboptimal present, a failed semaphore during a swapchain recreation and a failed blit submission, which the presenter must survive. SetLEONIDA_VK_VALIDATION=1to run them under the Khronos validation layer.vk_pipeline_check <spirv dir> [cache.bin] [--jobs N] [--start I] [--count N] [--max-bytes N]- creates a shader module and, for compute shaders, a pipeline for every entry in the translator'sindex.json; reportsMODULE FAIL/PIPELINE FAILper shader and a summary.--max-bytesnames and skips modules larger than the limit, which is how the corpus run works around the driver's compile time on multi-megabyte ray-tracing shaders. The measured partial pass is in docs/pipeline_check.md.
gameinput_test (only with SDL3; otherwise CTest lists gameinput as not run) drives the GameInput shim on SDL virtual joysticks (no controller needed): enumeration, readings
and the button/axis mapping, rumble and trigger rumble, DualSense effect bytes, a dispatcher, and hot-plug.
gameinput_probe [--seconds N] [--rumble] is the manual check on a real pad: it prints live readings and plays each
motor and trigger.
unimplemented_policy_test builds a small image whose two imports bind to nothing and checks log, fail and
stop on it: return values, untouched out parameter, xmm0 = 0, environment parsing, and (in a child process) the
stop message with the caller's module+RVA and the argument registers. It also checks that the stub keeps the stack
16-byte aligned at the call into the runtime, that rbx/rbp/rdi/rsi/r12-r15 and xmm6-xmm15 survive a call
(test/fixtures/abi_probe.asm, MASM; skipped without ml64), and that RtlVirtualUnwind from inside the call walks
back to the caller.
The PE-loader and Bink-decode tests that need the retail package are optional: when
LEONIDA_GAME_DIR (and, for Bink, LEONIDA_MOVIE) is unset they print SKIP and exit 0. They read
the files in place and never copy or commit game data.
Current limits
gta6rt --run <exe> [-- args] runs an executable's entry point inside the runtime (shims/process.cpp gives it its
own command line and turns its exit into the end of the run); CTest's run_tiny_game does that with a stand-in game.
The game does not boot yet. The missing executable blocks the import-driven work: the real device
entry point, command-list/queue/fence extensions, PresentX, and most of the xgameruntime surface (an offline
shim covers XGameRuntimeInitialize, device/console queries, XTaskQueue and XAsync; see xgameruntime_test). The
D3D12-to-Vulkan design and the measured console ABI are in
docs/d3d12_vulkan.md; the shader translator and its GPU checks are described
in docs/design.md, and the differential-validation design is in the shader-validation
work.
No game data, keys, or extracted assets belong in this directory or in the repository.
First-boot D3D12 trace
On a Vulkan-enabled build, select the Vulkan backend to trace device, command-list and queue calls handled
by Leonida. Put --trace-d3d12 before the separator for game arguments.
$env:LEONIDA_D3D12 = 'vulkan'
.\runtime\build\gta6rt.exe --run $gameExe --trace-d3d12 2>&1 |
Select-String '^\[d3d12-trace\]'
Each trace line contains a sequence number, a fixed API name and an outcome. called marks a void API call
whose validation may be deferred. ok, failed and unsupported report known results. ignored marks a no-op.
Share only the lines prefixed with [d3d12-trace]. Other runtime diagnostics are separate.
Typed clear regression
clear_color_test checks numeric UINT conversion and unchanged float clears without a GPU.
d3d12_clear_test compares full/rectangle readbacks with Windows WARP across UNORM, SNORM, FLOAT, UINT and SINT
render-target formats, plus depth and stencil clears. Fixtures are synthetic; no shaders or game data are needed.
The GPU test runs explicitly, while the CPU test is registered in CTest.
ctest --test-dir runtime/build -C RelWithDebInfo -R '^clear_color$' --output-on-failure
$env:LEONIDA_VK_VALIDATION = '1'
$env:VK_VALIDATION_VALIDATE_SYNC = '1'
.\runtime\build\RelWithDebInfo\d3d12_clear_test.exe
RGBA8 typeless RTV clear regression (phase 1)
typeless_rtv_test checks typed-view recording and replay without a GPU. It is registered in CTest.
d3d12_typeless_rtv_test compares synthetic full and rectangular clears with Windows WARP through explicit
UNORM/SRGB/UINT RTVs on a one-mip, one-layer, single-sample 2D RGBA8 typeless resource. It checks descriptor
snapshots, alternating view formats, SRGB with UAV resource usage, and invalid view rejection.
Other typeless families, typed-resource casts, SINT/SNORM, mip/array expansion, MSAA and 3D views are not added.
ctest --test-dir runtime/build -C RelWithDebInfo -R '^typeless_rtv$' --output-on-failure
$env:LEONIDA_VK_VALIDATION = '1'
$env:VK_VALIDATION_VALIDATE_SYNC = '1'
.\runtime\build\RelWithDebInfo\d3d12_typeless_rtv_test.exe
96-bit R32G32B32 textures (D3D-62)
d3d12_rgb96_test compares footprints, uploads, readbacks, boxes, texture-to-texture copies and CPU copies of
R32G32B32_FLOAT/UINT/SINT/TYPELESS textures (2D arrays with mips, and volumes) with Windows WARP, bit for bit,
and prints how long an upload and a readback take. d3d12_descriptor_test samples them (alpha reads as one). It
is registered in CTest (d3d12_rgb96).
$env:LEONIDA_VK_VALIDATION = '1'
$env:VK_VALIDATION_VALIDATE_SYNC = '1'
.\runtime\build\RelWithDebInfo\d3d12_rgb96_test.exe
RGBA8 typeless RTV clears support explicit UNORM/SRGB/UINT views of 2D mip slices and contiguous array-layer ranges, with sample count 1. Other format families, typed-resource casts, MSAA and 3D views are not expanded.
Resource descriptions
d3d12_resource_desc_test creates the same committed and reserved resources on the Vulkan-backed device and on
Windows D3D12 (the default adapter and WARP, whichever exist) and compares every field of ID3D12Resource::GetDesc:
the Alignment and MipLevels a description left at 0 must read back as the host fills them in. A description the
host refuses is skipped, and one only the layer refuses (1D textures today) is listed and not compared. It needs a
Vulkan GPU and runs explicitly.
$env:LEONIDA_VK_VALIDATION = '1'
.\runtime\build\RelWithDebInfo\d3d12_resource_desc_test.exe
Depth and stencil resolves
d3d12_depth_resolve_test resolves one plane of a 4x D32 or D24S8 target into a 1x one with
ResolveSubresourceRegion (MIN and MAX of depth or stencil, AVERAGE of depth by its own format; whole and by
rectangle) on the Vulkan-backed device and on Windows D3D12 (the default adapter and WARP), and compares the
destinations read back. Calls the layer refuses must fail Close and leave the destination as cleared. Clears give
every sample of a pixel one value, so the modes over differing samples are not checked. It needs a Vulkan GPU.
$env:LEONIDA_VK_VALIDATION = '1'
.\runtime\build\RelWithDebInfo\d3d12_depth_resolve_test.exe
Predicate capture lifetime
vk_predicate_capture_test checks full-width predicate snapshots, offset rebinding and reset with 32 gated submissions, then reuses completed command-buffer slots. Run explicitly on a Vulkan GPU with conditional rendering; it uses only synthetic data.