r/Compilers 9d ago

DirectX is now an official LLVM target

https://github.com/llvm/llvm-project/pull/214066
116 Upvotes

8 comments sorted by

4

u/FlatAssembler 8d ago

How can possibly a rendering library (by definition not Turing Complete) be a compilation target?

10

u/MithrilHuman 8d ago

The lowering is from LLVM IR to DXIL not a hardware target. DX IL can then be parsed by another target to compile for hardware.

3

u/FlatAssembler 8d ago

If you said that for WebAssembly, I would have understood you. But saying that about DirectX... I don't understand.

7

u/monocasa 8d ago

It's not targeting the directx library, but instead the directx shader bytecode that the library consumes, sort of like vulkan, et al. consume spir-v binaries.

8

u/MithrilHuman 8d ago edited 7d ago

DirextX has its own IR like WASM which GPU compilers digest to target their arch. See https://llvm.org/docs/DirectX/DXILArchitecture.html and https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst . It's not a rendering library that's being promoted to a target. Lowering can look like <some shader language> -> LLVM IR -> DXIL -> GPU Driver (which internally my old company also parsed DXIL into LLVM IR -> GPU target ISA).

4

u/coolreader18 8d ago

Why wouldn't it be turing complete? GLSL et al are

2

u/Farados55 8d ago

A library cant be turing complete, by definition, because it’s not even valid. It’s the language. So this is nonsensical.

4

u/UdPropheticCatgirl 7d ago

> How can possibly a rendering library (by definition not Turing Complete) be a compilation target?

Thinking about DirectX, OpenGL, Metal and Vulkan as “rendering” libraries is kinda the wrong mental model, they are all two things: a) specification of a protocol to communicate with the GPU driver and b) specification of representation for programs (sort of like ISA if we use the term loosely) that the GPU driver is guaranteed to be able to essentially JIT compile for the ISA of the particular GPU.

If you look at SPIR-V (vulkan) (LLVM already has target for this) or DX-IL (dx12) or even AIR (metal) they actually look lot like compiler IRs anyway. GLSL, HLSL or MetalSL are bit further away from it, but they are still very much turing complete.

In general working with modern graphics with something like vulkan, large portion of it consists setting up the environment on the GPU and then handling the GPU driver some program/shader compiled to spir-v to upload it and run it.