How libcg/grvk works
Main components
• API Frontends (DLLs): These are the mantle*.dll libraries (both 32-bit and 64-bit) along with the mantleaxl*.dll. They form the interfaces that games load. They intercept Mantle (and Mantle extension library) API calls.
• Translation and Adaptation Layers: The core code in the “src/mantle”, “src/mantleaxl”, and “src/mantleinfo” directories implement the translation logic. They take the intercepted Mantle calls and translate them into Vulkan calls.
• AMDIL Compiler Subsystem: The “src/amdilc” directory contains the AMDIL compiler’s source code. This module handles compiling, decoding, and converting AMD’s intermediate language (possibly to SPIR-V) as needed.
• Vulkan Loader & Integration: Look at the files like “src/mantle/vulkan_loader.c/h” that bridge the calls once translated. They invoke Vulkan API functions from the rendered Vulkan library.
• Logging and Debugging Components: The “src/logger” directory provides logging functionality to capture runtime details, errors, and information about the translation process.
• & Library Files: The “include” directories (with subdirectories for “amdil”, “mantle”, “spirv”, “vulkan”) supply the necessary headers, while the “lib” directories link the Vulkan loader. These represent external dependencies and interface definitions.
Relationships and interactions
• When a game calls a Mantle API function (via the DLL dropped into its directory), the API call is intercepted by one of the mantle/mantleaxl DLL modules.
• These DLL frontends then route the call to the translation layer (the logic in “src/mantle” and “src/mantleaxl”), which performs any necessary processing or state management.
• If shader compilation or intermediate language decoding is necessary, the call passes into the AMDIL subsystem (“src/amdilc”) for conversion, producing output in SPIR-V format using headers under “include/spirv”.
• Finally, the translation layer uses the Vulkan loader (e.g., “src/mantle/vulkan_loader.c”) to make Vulkan API calls to the underlying graphics drivers.
• Throughout this process, the logging module captures key events and errors, writing to log files as determined by environment variables.
Architectural patterns and design principles
• Layered Architecture: Clearly separate the interceptor DLLs (API frontend), translation logic (core conversion engine), and the external dependencies (Vulkan and logging).
• Modularity: Different components (Mantle core, AXL extension, AMDIL compiler, and logger) are isolated in their own directories, suggesting independent modules that interact through well-defined interfaces.
• Adaptation: Emphasize the translator design pattern, as the system adapts Mantle calls to Vulkan calls.
• Cross-Platform Considerations: The use of Meson build files for configuring both 32-bit and 64-bit builds hints at careful deployment planning.