Two APIs, One Picture: a renderer interface over DirectX 12 and Vulkan
Phase 2 is done: Lintel draws through one rendering interface with a Vulkan backend and a Direct3D 12 backend, and a test proves both produce the same picture.
Phase 1 ended with a dot on a grid, drawn by SDL's 2D renderer as a placeholder. Phase 2 replaces that with the real thing: a rendering hardware interface, RHI for short, with Direct3D 12 underneath on Windows and Vulkan on Linux. Everything above it, from the debug view to the console, now draws through it, and nothing above it knows which API is running.

That cube is the whole of Phase 2 in one picture. It is drawn into a high-dynamic-range texture, tonemapped onto the screen, lit by one light and textured with a checkerboard whose corner and top edge show whether the texture's origin and axes come out the same on both APIs. They do, and a test now checks that on every push.
One interface, built twice
The RHI is a small set of ideas: a device, buffers, textures, pipelines and a command list that records what a frame does. No Vulkan or Direct3D type is visible above it. The Vulkan backend runs on Linux natively, the Direct3D 12 one on Windows, and I could run neither on the other.
The two were brought up in lockstep: clear the screen, then a triangle, then a textured cube, each step working on Vulkan before its twin was written for Direct3D 12. The twin was always easier to write the second time, because the first had settled what the interface meant. Where the two APIs disagree, the interface picks one answer and the other backend bends to it: clip space has Y pointing up, as in Direct3D, so Vulkan draws with a flipped viewport, and the same shader draws the same picture on both.
Shaders, written once
Shaders are HLSL. Microsoft's compiler, DXC, turns each one into DXIL for Direct3D 12 and SPIR-V for Vulkan, and a cooked shader file carries both. The engine reads what a shader needs straight from its SPIR-V with its own small reflection code: how many bytes of constants it takes, which resources it binds, and for compute shaders the size of a workgroup.
Save a shader while the demo runs and the cube changes within a frame. The old pipeline is not destroyed on the spot, because the frames still in flight may be drawing with it; it is retired and freed once the GPU is done.
Every resource has a number
There is no binding of textures to slots before a draw. Every buffer and texture gets a number when it is created, and shaders index two big arrays with it: g_buffers[number] and g_textures[number]. A draw passes the numbers it needs in 128 bytes of push constants, together with its matrices. Even vertices come this way: the vertex shader reads its own vertex from a buffer by index, so there are no vertex layouts to declare.
Vulkan calls this descriptor indexing and Direct3D 12 calls it a bindless heap. Both ended up with the same layout, chosen so that one HLSL file compiles for both.
Memory the engine owns
GPU memory is taken in 64 MiB blocks and handed out by the engine's own sub-allocator; Direct3D 12 places resources into heaps, Vulkan binds them to memory, and the same first-fit allocator sits behind both. Uploads go through a 64 MiB ring on the copy queue, so a texture created during a frame is on the GPU before the frame draws. Data that only lives for one frame, like the user interface's vertices, goes into memory that each frame in flight owns and resets.
The render graph
A frame is described as passes that read and write textures: the scene pass writes the HDR texture and a depth buffer, the tonemap pass reads the HDR texture and writes the screen. From that description the graph works out every barrier itself, the point where the GPU must finish one use of a texture before the next begins. Vulkan calls these pipeline barriers with synchronization2, Direct3D 12 calls them enhanced barriers; both say the same three things, which stage finishes, which access ends and which layout the texture takes, so one description serves both. Textures a frame creates are kept by a pool and handed out again next frame, so a stable frame allocates nothing.
Everything through it
Dear ImGui, the library behind the console and the stats panel, draws through the RHI with a renderer backend of my own: its vertices go into the per-frame memory, its font atlas becomes a normal texture. The debug view's grid and dot are drawn by a small 2D drawer on the same path. SDL's 2D renderer is gone, and with it the last code that bypassed the interface.
One picture
The proof is a test. It renders the scene without a window, on each API, at 1280 by 720, copies the pixels back and compares them with a reference picture that is committed to the repository. At most one percent of the pixels may differ, and only differences larger than 8 of 255 in a channel count.
The reference was rendered by llvmpipe, Mesa's software Vulkan. Against it, llvmpipe itself, an Intel laptop GPU and an NVIDIA RTX 4060 all differ in zero pixels. On Windows, CI renders the scene with WARP, Microsoft's software Direct3D 12, and it stays within the limit on every push. The two APIs never run on the same machine; the picture is what they agree on.
That test found the first real Direct3D 12 bugs. I have no Windows GPU, so until then no Direct3D 12 frame had ever been drawn: CI had only created devices and resources. The first frame drew the tonemap pass into the wrong texture, because the size of a render target view was only set when a swapchain existed, and tripped the debug layer, because textures were created in a state that enhanced barriers refuse to interoperate with. Both were quick to fix once seen, and both would have stayed hidden without a test that draws.
The numbers
| Engine code | about 12,400 lines in 10 modules, of which 7,200 are the RHI, the render graph, the shader pipeline and the shaders |
| Tests | 104 unit tests, plus crash-handler tests; the RHI tests run on llvmpipe and WARP |
| CI | 7 builds per push (GCC, Clang, MSVC, AddressSanitizer, ThreadSanitizer), all green, with a parity picture from each |
Next: Lights Out
Phase 3 is the renderer proper: physically based materials, HDR with exposure, ray-traced soft shadows and global illumination, volumetric fog and the weapon flashlight, in a greybox gas station at night.