Skip to content

D3D11 Backend

github-actions[bot] edited this page Sep 6, 2026 · 3 revisions

D3D11 Backend

DirectX 11 is SparkEngine's primary Windows implementation and the renderer candidate in the blocked, uncertified stable-v1 Windows 11 x64 profile. Auto-selection prefers it on Windows when compiled in. The implementation contains the major rendering paths described below, but their stable-v1 certification gates remain open; this page does not claim production or known-stable status.

Overview

  • Namespace: Spark::RHI::D3D11
  • Files: Graphics/RHI/D3D11/D3D11Device.{h,cpp} (~360 LOC header)
  • Guard: #ifdef _WIN32 — compiled only on Windows builds.
  • Links against: d3d11.dll, dxgi.dll, d3dcompiler_47.dll, dxguid.lib (automatic via MSVC #pragma comment).
  • Feature level: 11_0 (Shader Model 5.0) is the hard floor; 11_1 is preferred. Device creation fails on adapters below 11_0 instead of degrading.

Architecture

Class Purpose RHI interface
D3D11Device Adapter + device + immediate context owner IRHIDevice
D3D11Buffer GPU buffer backed by ID3D11Buffer IRHIBuffer
D3D11Texture 1D/2D/3D/Cube texture + SRV/RTV/DSV views IRHITexture
D3D11Shader Any shader stage + compiled bytecode IRHIShader
D3D11Sampler Sampler state IRHISampler
D3D11PipelineState Aggregate rasterizer / depth / blend / VS+PS IRHIPipelineState
D3D11SwapChain DXGI 1.2+ flip-model swap chain IRHISwapChain
D3D11CommandList Immediate-context translation of RHI calls; deferred lists record via FinishCommandList and replay on ExecuteCommandList IRHICommandList

Resources use Microsoft::WRL::ComPtr (RAII for COM objects). No raw AddRef / Release calls in user code.

Transient bump allocator

Each D3D11Device owns a TransientBufferAllocator used for per-frame CPU-visible vertex/index data — debug draw, particle batches, and UI geometry all use it instead of allocating fresh buffers every frame. The allocator resets on swap-chain present.

Features

  • Debug layer — auto-enabled on Debug builds (D3D11_CREATE_DEVICE_DEBUG + info-queue breakpoints).
  • WARP fallback — if no hardware adapter matches, the engine retries with D3D_DRIVER_TYPE_WARP; see RHI Abstraction Layer for the broader fallback chain. RHIBridge::Initialize no longer degrades a windowed request to NullRHI unless allowHeadlessFallback is passed.
  • Structured / indirect buffers — created with the matching D3D11_RESOURCE_MISC_* flags plus SRV/UAV views; no IRHICommandList overload binds an IRHIBuffer as a shader resource yet.
  • Deferred deletion queue — RHI/DeferredDeletionQueue.h is header-only with test coverage (Tests/TestDeferredDeletionReal.cpp) but no production caller: D3D11Device holds no such member and no backend calls Enqueue/ProcessQueue (D3D12 has its own fence-based queue). D3D11 is immediate-mode, so frame-delayed deletion is not required there.
  • Tearing / flip-discard — swap chain opts into DXGI_SWAP_EFFECT_FLIP_DISCARD and DXGI_FEATURE_PRESENT_ALLOW_TEARING when the adapter reports support.
  • MSAA / sRGB / HDR formats — supported; per-texture MSAA sample count is validated via CheckMultisampleQualityLevels.

Adapter / capability detection

D3D11Device::Initialize calls IDXGIFactory1::EnumAdapters1, picks the one with the largest dedicated video memory, and records:

caps.maxTextureSize         // 16384 on FL11, 2048 on FL10
caps.computeShaderSupport   // true on FL10+
caps.tessellationSupport    // true on FL11+
caps.maxMSAASamples         // 1/2/4/8 based on format checks

These land on IRHIDevice::GetCapabilities() and feed the engine's feature gates (e.g. TAA disables itself if MSAA > 1 is forced elsewhere).

Shader compilation

Shaders compile through D3DCompile (d3dcompiler_47.dll). Entry points: vs_5_0, ps_5_0, cs_5_0, etc. For the offline shader cook path, see Shader Pipeline.

Factory registration

// RHIFactory.cpp
case GraphicsBackend::D3D11:
    device = std::make_unique<D3D11::D3D11Device>();
    break;

Selected automatically by RHIFactory::GetRecommendedBackend() on Windows.

Limitations

  • No bindless — binding model is CBV / SRV / UAV slots. Use D3D12 if your workload needs descriptor-heap bindless.
  • No mesh shaders — requires D3D12 + SM 6.5.
  • No DXR — ray tracing requires D3D12. Hybrid Ray Tracing falls back to screen-space techniques on D3D11.
  • No timeline semaphores — synchronization is fence-based.

Related

SparkEngine Wiki

Website Entry Points

Getting Started

Engine Subsystems

Gameplay & Tools

Platform Support

Graphics

Advanced

Development & Process

Research & Analysis

Engineering Notes & Audits

Specifications

Reference

Clone this wiki locally