This page documents the DirectX renderer backends for Dear ImGui, covering DirectX 9, 10, 11, and 12 implementations. These backends translate ImDrawData into DirectX graphics commands, handling vertex/index buffer management, shader setup, texture binding, and render state configuration.
For information about platform backends (Win32, etc.), see Platform Backends. For general backend architecture concepts, see Backend Architecture Overview. For other renderer backends (Vulkan, OpenGL, Metal), see Renderer Backends.
Dear ImGui provides four DirectX renderer backends, each targeting a specific DirectX API generation:
| Backend | File | Primary Use Case | Complexity |
|---|---|---|---|
| DirectX 12 | imgui_impl_dx12.cpp | Modern Windows applications, explicit GPU control | High |
| DirectX 11 | imgui_impl_dx11.cpp | General Windows development, mature API | Medium |
| DirectX 10 | imgui_impl_dx10.cpp | Legacy support, similar to DX11 | Medium |
| DirectX 9 | imgui_impl_dx9.cpp | Legacy applications, fixed-function pipeline | Low |
All DirectX backends implement:
ImGuiBackendFlags_RendererHasVtxOffset - Large mesh support (64k+ vertices)ImGuiBackendFlags_RendererHasTextures - Dynamic font atlas updatesSources: backends/imgui_impl_dx12.cpp1-60 backends/imgui_impl_dx11.cpp1-43 backends/imgui_impl_dx10.cpp1-40 backends/imgui_impl_dx9.cpp1-42
All DirectX backends follow a consistent initialization and rendering pattern:
Sources: backends/imgui_impl_dx12.cpp726-780 backends/imgui_impl_dx11.cpp384-429
Each backend maintains state in a dedicated structure stored in io.BackendRendererUserData:
Sources: backends/imgui_impl_dx12.cpp92-120 backends/imgui_impl_dx11.cpp69-88 backends/imgui_impl_dx10.cpp67-85 backends/imgui_impl_dx9.cpp57-67
All backends dynamically resize vertex and index buffers as needed:
Sources: backends/imgui_impl_dx12.cpp226-267 backends/imgui_impl_dx11.cpp178-202
DirectX 12 is the most complex backend due to its explicit resource management model. It requires descriptor heaps, command allocators, fences, and explicit synchronization.
Title: DX12 Backend Component Structure
The backend maintains separate pipeline states and root signatures for linear and nearest sampling modes, introduced to support different texture filtering requirements:
Title: DX12 Descriptor Allocation Flow
Sources: backends/imgui_impl_dx12.h33-54 backends/imgui_impl_dx12.cpp92-122
DX12 uses two separate pipelines to support both linear and nearest texture sampling:
Title: DX12 Root Signature Layout
The root signature defines two parameters:
The static sampler is configured at root signature creation time, which is why the backend maintains two separate root signatures (pRootSignatureLinear and pRootSignatureNearest).
Sources: backends/imgui_impl_dx12.cpp587-642
DX12 requires CPU and GPU descriptor handles for texture access. The backend uses application-provided allocator callbacks:
The texture handle used as ImTextureID is actually the D3D12_GPU_DESCRIPTOR_HANDLE cast to ImTextureID:
Sources: backends/imgui_impl_dx12.cpp82-89 backends/imgui_impl_dx12.cpp369-462
DX12 uses fences for GPU/CPU synchronization and maintains per-frame resources:
Sources: backends/imgui_impl_dx12.cpp129-136 backends/imgui_impl_dx12.cpp220-224
DX12 render state configuration involves setting the pipeline, root signature, viewport, and vertex/index buffers:
Title: DX12 Render State Setup Sequence
The projection matrix is computed from draw_data->DisplayPos and draw_data->DisplaySize to create an orthographic projection that maps ImGui's coordinate space to normalized device coordinates:
float mvp[4][4] = {
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.5f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }
}
Sources: backends/imgui_impl_dx12.cpp164-213
DX12 texture uploads use a dedicated command allocator and list, with a reusable staging buffer:
Sources: backends/imgui_impl_dx12.cpp110-115 backends/imgui_impl_dx12.cpp369-550
DirectX 11 is simpler than DX12 due to its implicit resource management and immediate context model. The backend uses a single device context for all operations:
Title: DX11 Backend State Structure
Sources: backends/imgui_impl_dx11.cpp70-90
DX11 compiles HLSL shaders at runtime using D3DCompile(). The vertex shader transforms vertices using a constant buffer projection matrix:
Title: DX11 Shader and Input Layout
The input layout matches the ImDrawVert structure:
POSITION: 2D position (8 bytes)TEXCOORD: UV coordinates (8 bytes)COLOR: RGBA color packed as 4 bytesSources: backends/imgui_impl_dx11.cpp332-476
DX11 uses ID3D11ShaderResourceView* directly as ImTextureID:
Texture updates use Map()/Unmap() for dynamic updates or UpdateSubresource() for initial creation:
Sources: backends/imgui_impl_dx11.cpp63-67 backends/imgui_impl_dx11.cpp241-330
DX11 render state setup involves mapping the constant buffer, configuring the input assembler, setting shaders, and configuring output merger states:
Title: DX11 Render State Configuration
The backend explicitly clears geometry, hull, domain, and compute shader stages to ensure no unexpected shaders are active. The blend state is configured for alpha blending with SrcAlpha and InvSrcAlpha factors.
Sources: backends/imgui_impl_dx11.cpp105-160
As of version 1.92, DX11 backend supports both linear and nearest texture sampling. The sampler state objects are created during device object initialization:
Title: DX11 Sampler State Configuration
The default sampler used during render is pTexSamplerLinear. Applications can change the sampler via the ImGui_ImplDX11_RenderState structure exposed in callbacks.
Sources: backends/imgui_impl_dx11.cpp478-522
The DirectX 10 backend is architecturally similar to DirectX 11, providing compatibility with Windows Vista systems. It uses the ID3D10* interface family instead of ID3D11*.
Title: DX10 vs DX11 API Comparison
The main difference is that DX10 combines device and context into a single ID3D10Device interface, while DX11 separates them. The rendering logic and shader code are otherwise identical.
Title: DX10 Backend Structure
Sources: backends/imgui_impl_dx10.cpp68-87 backends/imgui_impl_dx10.cpp102-160
DirectX 9 uses the legacy fixed-function pipeline instead of programmable shaders. The backend configures the pipeline through render states, texture stage states, and transform matrices:
Title: DX9 Backend State Structure
Title: DX9 Fixed Function Pipeline Configuration
Sources: backends/imgui_impl_dx9.cpp58-67 backends/imgui_impl_dx9.cpp91-162
DX9 uses a Flexible Vertex Format (FVF) descriptor instead of an input layout. The vertex data must be converted from ImDrawVert to CUSTOMVERTEX:
Title: DX9 Vertex Format Conversion
The color conversion macro IMGUI_COL_TO_DX9_ARGB adapts to the build configuration:
When IMGUI_USE_BGRA_PACKED_COLOR is defined, Dear ImGui packs colors in BGRA order, which matches DX9's native D3DCOLOR format (ARGB in memory, BGRA in register order on little-endian systems).
Sources: backends/imgui_impl_dx9.cpp69-81 backends/imgui_impl_dx9.cpp211-233
DX9 uses state blocks to capture and restore the application's render state, ensuring ImGui rendering doesn't affect the application's state:
Title: DX9 State Block Save and Restore
The state block captures the entire Direct3D 9 state, including:
After ImGui rendering completes, the state block is applied to restore the application's original state, then released.
Sources: backends/imgui_impl_dx9.cpp165-269
DX9 texture creation and updates are simpler than modern APIs due to implicit resource management:
Title: DX9 Texture Creation and Update
The D3DPOOL_MANAGED flag allows the driver to manage texture memory automatically. The LockRect() call provides direct CPU access to texture memory. For RGBA format, each row is copied individually to handle potential stride differences.
Sources: backends/imgui_impl_dx9.cpp272-356
| Feature | DX12 | DX11 | DX10 | DX9 |
|---|---|---|---|---|
| Programmable Shaders | ✓ | ✓ | ✓ | ✗ (fixed) |
| Explicit Synchronization | ✓ | ✗ | ✗ | ✗ |
| Descriptor Heaps | ✓ | ✗ | ✗ | ✗ |
| Command Lists | ✓ | ✗ | ✗ | ✗ |
| 64k+ Vertices | ✓ | ✓ | ✓ | ✓ |
| Dynamic Textures | ✓ | ✓ | ✓ | ✓ |
| Render State Exposure | ✓ | ✓ | ✓ | ✗ |
| BGRA Packed Color | - | - | - | ✓ (optimal) |
| Backend | Init Function | Key Parameters |
|---|---|---|
| DX12 | ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo*) | Device, CommandQueue, NumFramesInFlight, RTVFormat, Descriptor callbacks |
| DX11 | ImGui_ImplDX11_Init(ID3D11Device*, ID3D11DeviceContext*) | Device, DeviceContext |
| DX10 | ImGui_ImplDX10_Init(ID3D10Device*) | Device |
| DX9 | ImGui_ImplDX9_Init(IDirect3DDevice9*) | Device |
Sources: backends/imgui_impl_dx12.h51 backends/imgui_impl_dx11.h28 backends/imgui_impl_dx10.h28 backends/imgui_impl_dx9.h30
Sources: backends/imgui_impl_dx12.cpp338-341 backends/imgui_impl_dx11.cpp220-228 backends/imgui_impl_dx10.cpp220-228 backends/imgui_impl_dx9.cpp185-193
Key differences when migrating from DX11 to DX12:
ID3D12CommandQueue for texture uploadsNumFramesInFlight and manage per-frame buffersImGui_ImplDX12_InitInfo instead of function parametersSources: backends/imgui_impl_dx12.cpp726-780 backends/imgui_impl_dx11.cpp384-403
All DirectX backends follow this integration pattern:
Sources: backends/imgui_impl_dx12.cpp207-348 backends/imgui_impl_dx11.cpp161-239
Refresh this wiki