SPIR-V & LLVM JIT Compiler

Hello,

I’m trying to build an application and would like to load SPIR-V binary files, and JIT Compile it via LLVM to run shaders on CPU.

I would like to use a library (or possibly build my own) that parses SPIR-V and JIT compiles via LLVM API. Then the library can provide C++ interface to compiled data in memory, and I can access resources or call shader methods via the interface.

The reason I’m looking for a C++ library is that I want the LLVM part isolated from my applications.

Steps In My Mind

  • Load/Parse SPIR-V binary files.
  • Generate LLVM IR with LLVM API to JIT Compile shaders in memory via the library.
  • Use a C++ interface to access resources in memory and bind shader methods to call from an application.

Is there a C++ library or code example that I can use for this? Or could you please guide me by providing steps to achieve this in the shortest path?

Best,

Aaron

In terms of something preexisting, Google’s clspv is the only library I know of that can produce Vulkan SPIR-V, but I believe it is limited to compute shaders. There are a few others that deal with OpenCL SPIR-V.

Assuming one of the above suits your need, in order to get JITable modules from LLMV modules you will at the very least need to:

  • alter the target triple of the module to match your CPU/OS/Env
  • translate the address spaces
  • translate/implement the intrinsics/special functions (see libclc for an example for OpenCL)

I plan to get a more cohesive integration of SPIR-V and LLVM at IWOCL in May.

Nic