Leonida

How it works

Leonida is a static recompilation project, not an emulator. The Xbox Series has an x86-64 processor like a PC, so the game’s code can run as it is. The work is everything around it.

Four layers, one road

Think of the game as a car built for the console’s roads. Leonida doesn’t rebuild the car. It lays new road under it, layer by layer, so it can drive on a PC.

  1. The game’s code

    Runs natively

    The executable is mapped into memory and run as it is. Only what can’t run on a desktop is patched: privileged instructions and console-only intrinsics. Exceptions and stack walks unwind through it, and every thread gets its thread-local storage.

    runtime/src
  2. The console’s system software

    Rebuilt as shims

    Every function the game imports from the console’s libraries (GDK, memory, the GPU driver) goes to a shim. Ones that aren’t written yet log once and return a failure, so missing pieces show up the moment they’re called.

    runtime/shims
  3. Graphics

    Translated to Vulkan

    The console’s version of Direct3D 12 is reimplemented on Vulkan. Its GPU programs ship as compiled RDNA2 machine code, and each one is translated to SPIR-V ahead of time.

    tools/rdna2spirv.py
  4. Models, textures and sound

    Read from your copy

    The RPF9 archives and texture pools are read from your game folder. Nothing is downloaded and nothing leaves your PC.

    tools/rpf9dump

Layers from docs/design.md, top to bottom: what the game sees first, down to what your PC provides.

The shader route

The console’s GPU programs ship already compiled for its RDNA2 graphics chip, which a PC driver can’t load. Each one goes through six steps to become something Vulkan can run.

  1. Carve

    Finds each shader container inside shaders.rpf, without its encrypted table of contents.

    shader_carve.py
  2. Unpack

    Opens the XBCH → FSSM wrapper to reach the native RDNA2 program.

    fssm_unpack.py
  3. Disassemble

    Turns the machine code into readable instructions with LLVM’s AMDGPU disassembler.

    shader_disasm.py
  4. Translate

    Rewrites each instruction as SPIR-V, the shader language Vulkan drivers take.

    rdna2spirv.py
  5. Validate

    Checks every module against the SPIR-V specification. All 26,503 pass.

    spirv-val
  6. Warm up

    Creates every shader on your own GPU driver and saves the pipeline cache.

    vk_pipeline_check

What a translation looks like

One RDNA2 instruction becomes a few SPIR-V ones. The console’s registers become variables, and each operation becomes its SPIR-V equivalent. The real translator also handles memory, textures, control flow and the 64-lane wave model.

A simplified illustration, not code from the game.

RDNA2
v_fma_f32  v0, v1, v2, v3
SPIR-V
%a = OpLoad %float %v1
%b = OpLoad %float %v2
%c = OpLoad %float %v3
%r = OpExtInst %float %glsl Fma %a %b %c
     OpStore %v0 %r

Wave64: 64 lanes on a 32-lane card

GPUs run a shader on many pixels or vertices at once, in groups called waves. The console runs most of its shaders 64 wide. 21,545 of the 26,503 are written for that.

AMD graphics cards can run 64-wide groups natively, so those shaders are exact there. NVIDIA and Intel cards run 32 wide. For them, Leonida translates compute and mesh shaders with wave64 emulation, which makes them exact as well. Operations that cross the two halves of a wave in vertex, pixel and geometry shaders are still approximate.

The build picks the right mode for your GPU by itself. The build guide explains what it chooses and why.

Lanes 0–31Lanes 32–63One wave64 on AMD. Two passes of 32 on NVIDIA and Intel.

Direct3D 12, rebuilt on Vulkan

The game talks to the console’s GPU driver, d3d12_xs.dll, through Direct3D 12 interfaces in exactly the order it was compiled against. Leonida replaces that driver with its own objects. They record the game’s commands and replay them on Vulkan, producing exactly the contract the translated shaders expect: one bindless descriptor set, a 144-byte push-constant block and one GPU address space.

It isn’t a general D3D12-on-Vulkan layer. It only needs the calls this game makes, but every call it accepts has to behave like D3D12. In the plan, each claim is marked verified, public, an assumption, or open, with a way to settle it.

Read the D3D12 plan

Running today

Devices, queues, command lists, fences, descriptor heaps, committed and reserved resources, views, samplers and queries. Barriers, clears, uploads, copies, resolves and predication run on Vulkan.

Still to build

Buffer views, root signatures, pipelines, draws and the swapchain: the pieces between “ready” and a frame.

How the work is checked

Without the executable, the only way to know the translation is right is to measure it. Every rule in the translator records how it was confirmed: a GPU test, a Mesa or LLVM reference, or a count over all shaders.

  • Every shader, validated

    All 26,503 translated shaders pass spirv-val, and full-corpus runs are posted to the issue tracker with the commit they ran at.

  • On real drivers

    vk_pipeline_check creates each translated module, and each compute pipeline, on an actual GPU driver and reports any it rejects.

  • On real hardware

    Hand-written RDNA2 test programs run on contributors’ GPUs and compare results with expected values: more than 30 GPU and driver combinations so far.

  • On every change

    Continuous integration runs the unit and translator tests, builds the runtime, runs its tests on Windows and again under Wine, and rejects any commit that tracks game files.

Ground rules

Everything runs from your own copy and stays on your PC. Game files, generated code, shader caches and reports that quote game data are never committed, uploaded or shared. Nothing in the project decrypts, unpacks or works around the package’s protection: the tools only read files that are already plain on disk.

Other people’s research is welcome as facts, never as code. A format layout or a measured behaviour can be reimplemented independently. Related projects records what may be read and where the line is.