How lunarg/gfxreconstruct works
Project type and purpose
• GFXReconstruct is an open-source, cross-platform tool suite for capturing and replaying graphics API calls (Vulkan, D3D12, experimental OpenXR).
• It provides a modular framework (“framework/…”) for encoding (capture), formatting (serialize), decoding (replay), and a set of CLI tools (“tools/…”) that drive those modules.
File structure
• Top-level:
– CMake build scripts and project configs (CMakeLists.txt, BUILD.md, scripts/).
– external/… — vendored third-party libs (AgilitySDK, SPIRV-Reflect, LZ4, Zstandard, nlohmann-json, Catch2).
– framework/… — core modules subdivided into application (window/OS abstraction), encode (capture), format (file schema), decode (replay), generated code (API bindings).
– layer/… — API injection layers (Vulkan, D3D12, DXGI, AGS) that hook into target applications.
– tools/… — standalone command-line front ends (capture, replay, info, compress, extract, convert, optimize, tocpp, etc.).
– android/… — Android build, framework integration, test apps, and Android variants of tools.
– test/… — unit tests, mock ICDs, known-good traces, test applications for validation.
README for additional insights
• Describes each CLI tool’s purpose (gfxrecon-replay, info, compress, extract, convert, optimize).
• Notes the framework design for easy extension of capture/replay tools.
• Specifies supported platforms and APIs.
a. Main components
• "Application Under Test" – any Vulkan/D3D12/OpenXR app.
• API Hooking Layers – Vulkan layer, D3D12 DLL interceptors, DXGI hooks, AGS layer.
• Encode Module – framework/encode: wraps API calls and writes command stream.
• Format Module – framework/format: serializes calls into .gfxr file (binary + JSON metadata).
• Storage – capture file on disk.
• CLI Tools – each tool invokes framework modules:
– capture (wrap + write)
– replay (read + decode + replay)
– info (read + format to console)
– compress/decompress (apply LZ4, Zstd, zlib)
– extract (SPIR-V export)
– convert (JSON Lines output)
– optimize (file rewriting for speed)
• Decode/Replay Module – framework/decode: reads .gfxr, reconstructs API calls, feeds replay consumer.
• Application Framework – framework/application + framework/graphics + framework/util: windowing, context creation, resource management.
• Rendering Backend – actual Vulkan / D3D12 / OpenXR driver invocation at replay time.
• Codegen & Scripts – python and CMake scripts under framework/generated and scripts/ that produce API binding code.
• External Libraries – highlighted as dependencies behind capture/replay and tools.
b. Relationships & data flows
1. App → API Layer hooks → Encode → Format → .gfxr file
2. .gfxr file → (optional) compress/convert/extract/optimize/info tools → new .gfxr or report
3. .gfxr file → Decode → Replay consumer → Application framework → Graphics driver → Display
4. Codegen scripts feed into the build process to generate encode/decode classes.
5. Android variants follow the same flow, but via android/layer & android/tools.
c. Architectural patterns & design principles
• Modular “framework” – clear separation of capture (encode), serialization (format), and replay (decode).
• Plugin/Layer architecture – API interception layers for different graphics APIs.
• Code generation – avoids manual API binding by generating encoders/decoders per API.
• CLI front-ends – minimal glue invoking the shared framework modules.
• Cross-platform abstraction – framework/application hides OS/windowing differences.
d. Key technologies
• CMake + Python scripts (build & codegen)
• C/C++ core (encode/decode/format/application)
• API injection: Vulkan’s layer mechanism, DLL hook (Detours) for D3D12/DXGI
• Serialization: custom binary format + JSON metadata, LZ4/Zstd/zlib compressors
• External libs: AgilitySDK (D3D12), SPIRV-Reflect, nlohmann-json, Catch2
Elements
• Clear labels for each component block.
– Blue: capture chain (layers → encode → format → file)
– Green: replay chain (file → decode → replay → driver)
– Orange: CLI tools orbiting the file
– Gray: external libraries/dependencies
– Yellow: Android-specific modules