Shader bytecode JIT

Hi all. I'm writing a remote 2D graphics API for embedded devices.
It includes a little GLSL 1.0-esque shader language, which is compiled
to executable SSE code at runtime.

Is LLVM a good fit for this sort of thing? At the moment I'm
compiling NASM into my code, but it doesn't do any register allocation
(which is why I'm considering LLVM). I don't want to add too much
bloat to the final compiled binaries, nor do I wish to restructure my
build system to match LLVM's.

Thanks,
Joe

Hi Joe,

If you’re not doing many optimizations in your current compiler you may find that LLVM improves the quality of your generated code. The cost (in terms of binary size and performance of your compiler) will depend on exactly how much of LLVM you pull in, what optimizations you use, etc, but if your existing compiler is relatively simple I’d expect you to see an increase in both binary size and shader compile-time.

I doubt you’ll need to restructure your build system. Most JIT clients that I know of build LLVM as a separate project and just add a dependence on LLVM’s headers and libraries to their existing project.

  • Lang.

Hi all. I'm writing a remote 2D graphics API for embedded devices.
It includes a little GLSL 1.0-esque shader language, which is compiled
to executable SSE code at runtime.

You should take a look at the Mesa Project: http://www.mesa3d.org/
One of its drivers (llvmpipe) is a software rasterizer that uses
LLVM to generate shader code for x86 and other CPUs.

-Tom

Hi all. I'm writing a remote 2D graphics API for embedded devices.
It includes a little GLSL 1.0-esque shader language, which is compiled
to executable SSE code at runtime.

Is LLVM a good fit for this sort of thing? At the moment I'm
compiling NASM into my code, but it doesn't do any register allocation
(which is why I'm considering LLVM). I don't want to add too much
bloat to the final compiled binaries,

It depends what you mean by "bloat", LLVM with only X86 configured is probably 20-25MB.

nor do I wish to restructure my
build system to match LLVM's.

Well, somehow you'll have to integrate with LLVM libraries (includes/link).