Description: A tool and a library for bi-directional translation between SPIR-V and LLVM IR
View khronosgroup/spirv-llvm-translator on GitHub ↗
The SPIRV-LLVM Translator, hosted at https://github.com/khronosgroup/spirv-llvm-translator, is a project focused on converting the Standard Portable Intermediate Representation (SPIR-V) to LLVM Intermediate Representation (IR). SPIR-V is a standardized intermediate language used by many modern graphics and compute APIs like Vulkan, OpenGL, and OpenCL, allowing for a common compilation target across different hardware vendors. This translator bridges the gap between SPIR-V and the widely-used LLVM compiler infrastructure, enabling SPIR-V shaders and compute kernels to be further optimized and compiled for a diverse range of target architectures supported by LLVM.
The core functionality of the translator revolves around parsing valid SPIR-V modules and transforming them into equivalent LLVM IR code. This isn't a simple one-to-one mapping; SPIR-V and LLVM IR have different philosophies and capabilities. The translator handles the complexities of SPIR-V’s type system, memory model, and control flow, translating them into LLVM’s equivalent constructs. A key aspect is handling SPIR-V’s capabilities system, which defines the features a shader utilizes (e.g., geometry shaders, tessellation control shaders). The translator ensures these capabilities are correctly represented in the generated LLVM IR, allowing LLVM to perform appropriate optimizations. It supports various SPIR-V versions and profiles, including those targeting graphics, compute, and ray tracing.
The project is built upon LLVM’s existing infrastructure, leveraging LLVM’s parser, builder, and optimization passes. It's implemented as an LLVM pass, meaning it integrates directly into the LLVM compilation pipeline. This allows for seamless integration with other LLVM tools and optimizations. The translator doesn't aim to be a complete, standalone compiler; rather, it's a front-end for LLVM, providing the necessary IR code for LLVM to then perform its backend compilation tasks. The project actively supports both SPIR-V 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5 specifications.
Beyond the core translation functionality, the repository includes tools for testing and validation. These tests verify the correctness of the translation process by comparing the output of the SPIRV-LLVM translator with known-good LLVM IR or by running the translated code and comparing its results with a reference implementation. The repository also contains examples and documentation to help developers understand how to use the translator and integrate it into their own projects. Continuous integration (CI) is employed to automatically build and test the translator on various platforms, ensuring code quality and stability.
The SPIRV-LLVM Translator is crucial for enabling cross-platform shader and compute kernel development. By allowing SPIR-V to be compiled with LLVM, developers can target a wider range of hardware and benefit from LLVM’s powerful optimization capabilities. It's a vital component in the ecosystem surrounding SPIR-V, facilitating its adoption and making it a more practical choice for developers building high-performance graphics and compute applications. The project is actively maintained by Khronos Group contributors and the wider open-source community, ensuring its continued relevance and improvement.
Fetching additional details & charts...