- C++ 97.9%
- PowerShell 0.8%
- NASL 0.7%
- Python 0.3%
- CMake 0.2%
- Other 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WNDJJ83fqbzQY9bvUXJYKA |
||
| assets | ||
| docs | ||
| src | ||
| third_party | ||
| tools | ||
| .gitignore | ||
| CMakeLists.txt | ||
| LICENSE | ||
| README.md | ||
Keylime
Xbox Series game code, running natively on Windows — on Vulkan.
A from-scratch C++20 runtime. First target: GTA VI (Xbox Series build).
Where we are • How it works • Building • Running • Troubleshooting • Other projects • Credits
Important
Keylime contains no game files, keys or console SDK code. You need your own copy of the game. Nothing here downloads or distributes game content.
Where we are
✅ Working
|
🚧 In progress
|
❌ Not yet
|
Milestones
flowchart LR
A[Boot] --> B[Intro & menu] --> C[World loading] --> D[Opening cutscene] --> E[Gameplay]
style A fill:#16a34a,color:#fff,stroke:#15803d
style B fill:#16a34a,color:#fff,stroke:#15803d
style C fill:#16a34a,color:#fff,stroke:#15803d
style D fill:#d97706,color:#fff,stroke:#b45309
style E fill:#6b7280,color:#fff,stroke:#4b5563
- Retail exe boots natively; archives stream through DirectStorage
- Intro and main menu with all audio
- World loading after the menu, into the opening cutscene
ExecuteIndirect(single-argument signatures) and GPU memory waits- Mesh shader dispatches without an amplification shader
- Mesh shaders emit their geometry; no loop spins to its cap in the hot draws
- Free roam drawn correctly
- Opening cutscene drawn at 15+ fps
- Amplification shaders, multi-argument
ExecuteIndirect - Gameplay
What we're fighting right now
| Problem | What happens | Status |
|---|---|---|
| Mesh shaders drew nothing / took ~5 ms each | Every mesh shader emitted 0 triangles (s_sendmsg GS_ALLOC_REQ was dead code), and the hot ones spun to their loop cap: the decoder read a VOPC SDWA compare's destination SGPR as a byte select, so a counting loop never ended |
Fixed (Nov 29): world geometry draws; those draws went from ~5 ms to 0.1–0.3 ms. Covered by keylime selftest |
| Shader loops cut short | Loop caps of 512–8192 passes stopped genuine long loops (e.g. a compute dispatch loop of hundreds of cases) | Raised to 65,536 for every stage (VIctory uses 1,048,576) |
| Wave64 code twice the size | Every wave64 compute/mesh shader ran two console lanes per thread, doubling SPIR-V, compile time and ALU work | Now only shaders that need the whole wave (LDS, v_readlane/v_writelane) do: ~40 % smaller mesh shaders |
| Image sampling | Explicit-LOD samples of 2D textures read the LOD from the wrong register; _cl/_cd variants were taken for depth compares; gathers ran as plain samples |
Fixed in the translator (Nov 29); 3D / cube / array textures and depth compares still to do |
| New shaders at the cutscene | ~3,000 compute pipelines appear at once; each must be translated and compiled by the driver before the game can continue | Urgent compile queue, compiles start when a list is recorded, keylime precompile, private driver cache (cache\nvidia) — compiles went from 35–60 s to ~1 s each |
| Translated shaders are big | 1–4 MB of SPIR-V per shader; big compute shaders take the driver 15–30 s even unoptimized, so a cold cache leaves the world black for minutes | Next: a translator in VIctory's style (SSA, lane masks as per-lane booleans, guards proven away) with a SPIR-V back end |
| Wrong data from some compute shaders | Stores to addresses gigabytes past any buffer; GPU counters the game waits on are never written; the game traps on bad data (int3) |
Stores outside GPU memory are skipped and logged; root cause being traced |
| Game's GPU watchdog | Ends the game when GPU work takes ~25 s | Its thread is parked instead (KEYLIME_WATCHDOG=1 to disable) |
Component status
| Area | State |
|---|---|
| Loader (PE mapping, static TLS redirect, import binding) | 🟢 working |
Kernel, files (G: package, T: temp), memory (xmem, physical pages) |
🟢 working |
| DirectStorage (worker pool, zlib, BCPack) | 🟢 working |
| GameInput (XInput pads, keyboard as a pad) | 🟢 working |
Audio: AcpHal XMA, Opus (xapu), DSP (chad) |
🟢 working (reverb is dry) |
xgameruntime (XUser, XStore, XGameSave, XAsync, …) |
🟡 enough for the menus; some stubs |
| XG texture layouts (AMD addrlib) | 🟢 working |
| GPU objects: device, queues, fences, lists, heaps, resources, views, pipelines | 🟢 working |
| GFX10 decoder and GFX10 → SPIR-V translator | 🟡 every VS/PS/CS/MS shader translates; ~6 % still skip an instruction (image atomics, image_get_lod) |
Translator self-tests (keylime selftest) |
🟢 synthetic GFX10 programs run on the GPU and checked |
| Running the game's command lists on Vulkan | 🟡 menus fully; cutscene runs but doesn't draw |
How it works
We don't emulate the CPU. The console's x86-64 code runs directly on the host CPU; Keylime supplies everything around it — the loader, the console system libraries, and a GPU layer on Vulkan with our own translator from the console's RDNA 2 machine code to SPIR-V.
flowchart TB
subgraph Game["game_scarlett_master.exe (runs natively)"]
G1[Game code]
end
subgraph Keylime
L[Loader<br/>PE mapping · TLS · imports]
H[Console libraries<br/>kernel · files · xmem · DirectStorage<br/>GameInput · xgameruntime · audio]
D[D3D12.X on Vulkan<br/>command lists · resources · fences]
T[Shader translator<br/>RDNA 2 GFX10 → SPIR-V]
C[(Shader caches<br/>cache/spirv · cache/nvidia)]
end
V[Vulkan driver → GPU]
G1 --> H
G1 --> D
L --> G1
D --> T --> C --> V
D --> V
Design choices
| Keylime | |
|---|---|
| Graphics API | Vulkan 1.3 / 1.4 |
| Shaders | SPIR-V written directly from GFX10 machine code — no HLSL or DXIL round trip |
| Memory | Title memory imported zero-copy behind a GPU page table (console addresses → wherever the page lives) |
| Descriptors | Real RDNA 2 descriptor words; images and samplers found through a GPU hash table into bindless arrays |
| Queues | Asynchronous, timeline semaphores, no wait after each submission |
| Shader compiles | Never on the game's threads; urgent queue for what a draw or dispatch waits on; two-level disk cache |
| Frame pacing | High-resolution waitable timers |
More detail: docs/translator.md · docs/rdna2-descriptors.md
Shader pipeline
flowchart LR
A[Console shader<br/>GFX10 code] --> B[Decode] --> C[Structure control flow<br/>ifs · loops · parts] --> D[SPIR-V] --> E{In cache?}
E -- yes --> F[Ready instantly]
E -- no --> G[Quick build ~1 s] --> F
G -.background.-> H[Optimized build] -.swap in.-> F
Building
Needs: Windows 10/11 x64 · Visual Studio 2022 (or Build Tools) with the C++ workload (CMake and Ninja ship with it) · a GPU driver with Vulkan 1.3.
powershell -File tools\build.ps1
Running
tools\play.ps1 # live log console + the game
build\keylime.exe run <dir>\game_scarlett_master.exe --execute
| Command | What it does |
|---|---|
keylime run <exe> --execute |
Run the game |
keylime precompile <dir> |
Build every compute shader in <dir> (*.bin containers) into the caches; resumable |
keylime imports <exe> |
Map and bind only; list unimplemented functions |
keylime shader <dir|file> [--dis] |
Parse or disassemble console shader containers |
keylime shader <dir> --spirv |
Translate shaders and build them as driver pipelines |
keylime selftest [filter] |
Translator tests: small GFX10 programs assembled by name, translated, run on the GPU, results checked (no game needed) |
Controls
A keyboard stands in for a controller (any XInput pad works too).
| Key | Pad | Key | Pad |
|---|---|---|---|
| Enter | A | Backspace | B |
| Esc | Menu | Tab | View |
| Arrows | D-pad | WASD / IJKL | Left / right stick |
| Q / E | Shoulders | Z / C | Triggers |
F3 toggles the debug panel (fps, frame-time graph, GPU work, shader compiles, VRAM, streaming).
Shader cache
Console games ship shaders as finished AMD machine code, so each one has to be translated to SPIR-V and compiled by the driver once. Keylime does that for the whole game up front, like a PC game's "compiling shaders" screen:
tools\build-shader-cache.ps1 # extracts all 26,503 shaders the game ships, compiles the compute ones
tools/extract_shaders.pypulls every shader out ofshaders.rpf(its records are plain deflate streams even though the pack's table is encrypted);tools/extract_embedded_shaders.pyfinds the ones inside the executable and DLLs (BVH builder, AMD upscaler). Files are named by the same FNV-1a hash the runtime keys its caches by.- The results live in
cache\spirv(our translations) andcache\nvidia(a private, 100 GB driver disk cache so the game's thousands of multi-megabyte pipelines don't overflow NVIDIA's shared 1 GB cache). - The cache is keyed by
TRANSLATOR_VERSIONinsrc/shader/translate.cpp, not by the build. Rebuilding Keylime or changing anything else keeps every shader. Raise the version only for a translation fix that must reach shaders already cached. - An NVIDIA driver update empties the driver's half (as for every PC game); run the script again.
Environment variables
| Variable | Effect |
|---|---|
KEYLIME_TRACE=1 |
Detailed logging |
KEYLIME_OVERLAY=0 |
Start with the debug panel hidden |
KEYLIME_DUMP_SHADERS=<dir> |
Save every shader the game uses (for precompile) |
KEYLIME_KEYS=14:RETURN,30:A |
Scripted key presses at those seconds (testing without a person) |
KEYLIME_SNAPSHOTS=<dir> |
Save some shown frames as BMP files |
KEYLIME_STACKS_AT=<s> |
Log every thread's stack at that second |
KEYLIME_STORE_GUARD=0 |
Don't skip shader stores outside GPU memory |
KEYLIME_DRAW_WAIT_MS=4000 |
How long a frame waits for draw pipelines still compiling before skipping those draws |
KEYLIME_DISPATCH_WAIT_MS=12000 |
The same for compute dispatches |
KEYLIME_BACKLOG_DRAW_WAIT_MS=10 |
The draw wait while more urgent builds are queued than the workers clear in a few seconds |
KEYLIME_BACKLOG_DISPATCH_WAIT_MS=30 |
The same for compute dispatches |
KEYLIME_WATCHDOG=1 |
Let the game's GPU watchdog end the game |
KEYLIME_PROFILE=1 |
Log the GPU time and shader hashes of the heaviest pipelines every 10 s |
KEYLIME_SAMPLE=<start>,<secs> |
Sampling profiler of the whole process; writes logs\profile.txt |
KEYLIME_LOOP_REPORT=<hashes>|all |
Log lanes stopped by a shader loop's trip cap every 2 s |
KEYLIME_BVH=on |
Run real ray-tracing node tests (image_bvh*_intersect_ray); defaults to miss |
KEYLIME_PRECOMPILE_WORKERS=8 |
Driver compiles at once in precompile (each big shader takes gigabytes) |
KEYLIME_FLAT=0 |
Reach title memory through the page table instead of the flat sparse view |
KEYLIME_VALIDATION=1 |
Vulkan validation layers |
Troubleshooting
| File | What's in it |
|---|---|
logs\keylime.log |
Full log; every 2 s a frame: line (ms per frame, GPU busy, pipeline waits, work run and skipped) and a compile: line |
logs\crash.dmp |
Minidump of an unhandled crash (each distinct fault is also logged once) |
logs\stacks.txt |
Every thread's stack when no frame is shown for 5 s and 20 s, plus what each GPU queue waits on |
logs\profile.txt |
Sampling profiler output when KEYLIME_SAMPLE is set |
cache\used-pipelines.txt |
Pipelines used so far; the next run starts them as soon as the game creates them |
Other projects
Several projects are working on GTA VI's Xbox build on PC. Keylime is in the same family as VIctory and XCL — the console's own x86-64 code runs natively, with the system libraries and GPU replaced around it — but we take a different graphics path: we drive Vulkan and write SPIR-V ourselves, where the others go through Direct3D 12 and DXIL.
| Project | Approach | Scope | Graphics path |
|---|---|---|---|
| Keylime | Native runtime, C++20, from scratch | GTA VI first | Vulkan; RDNA 2 → SPIR-V directly |
| VIctory | Compatibility layer, Rust | GTA VI | RDNA 2 → DXIL via DXC |
| victory-fork | VIctory plus rendering and speed fixes | GTA VI | Same as VIctory |
| ztrx | VIctory-based | GTA VI | Same as VIctory |
| XCL | Wine-style compatibility layer | Any Xbox Series game | RDNA 2 → HLSL → DXIL |
| Xbox2Windows | Static recompilation to C++ | Any Xbox Series game | DXIL |
| TuxBox | Native-first layer, tested on Linux via Proton | Any Xbox Series game | Not stated |
| xbox-emulator | Rust runtime (continues TomBox) | Any Xbox Series game | Not stated |
| ScarlettX | Clean-room HLE of the Scarlett OS and GDK | Any Xbox Series game | Not stated |
| OpenScarlett CE | AGPL layer swapping console DLLs for PC ones | Any Xbox Series game | Direct3D 12 |
Other projects' progress is their own reporting.
Layout
src/loader.*, src/pe.* mapping and binding the game's images
src/hle/ console system libraries (kernel, files, xmem, dstorage, gameinput, xg)
src/hle/xgr/ xgameruntime (user, store, saves, async, other areas)
src/formats/ BCPack decoder
src/audio/ AcpHal (XMA), xapu (Opus), chad (DSP)
src/gpu/ D3D12.X objects on Vulkan: memory (flat sparse view), images, present
src/gpu/exec.cpp the command executor; its parts in src/gpu/exec/:
queues.inc host queues, GPU waits on memory, submission
pipelines.inc shader modules, caches, compile workers, wait budgets
builder.inc recording a title command list into Vulkan commands
src/shader/ containers, GFX10 decoder, control-flow structuring
src/shader/translate.cpp the RDNA2 -> SPIR-V translator; its parts in src/shader/translate/:
helpers, memory, setup, results, alu, vmem, atomics, image, export, control
src/selftest/ `keylime selftest`: GFX10 assembler, GPU runner, test cases
assets/ the Keylime logo and application icon
third_party/ miniz, libopus, AMD addrlib, Vulkan and SPIR-V headers
tools/ build, play, update, saves, build-shader-cache, shader extractors
Credits and licence
Keylime is licensed under the GNU GPL v3.0 or later (see LICENSE).
- Many console interface layouts (object slot maps, structure shapes, file formats) were reverse engineered by VIctory (GPL-3.0); we reuse that knowledge and port some of its code (noted in the files concerned).
- Ideas from ztrx, victory-fork (GPL-3.0) and XCL (GPL-2.0) are reimplemented here, not copied: per-stage shader loop caps, the wait comparison codes and mask, type 105 as a dispatch, an indirect work budget, and parking the game's GPU watchdog.
- The XMA decoder follows FFmpeg's
wmaprodec.c(LGPL-2.1-or-later) via VIctory. - Third-party code keeps its own licence: miniz (MIT), libopus (BSD-3-Clause), AMD addrlib from Mesa (MIT), Khronos Vulkan / SPIR-V headers (Apache-2.0 / MIT), GFX10 opcode tables from Mesa's ACO (MIT) and register layouts from Mesa (MIT).
Keylime is written with the help of Claude, Anthropic's AI model.
Not affiliated with Microsoft, Rockstar Games or Take-Two Interactive.