-
Notifications
You must be signed in to change notification settings - Fork 0
Graphics Module
The Graphics Module provides a convenient wrapper around the D3D12 API. This module actively uses Graphics.Heaps and allows easy interaction with buffers and textures, creating descriptors for them. It implements code for SwapChain creation, shader compilation, and supports two graphics queues: Direct and Compute.
Below is the hierarchy of classes responsible for resource management.
The base class for all resources is ResourceD3D12. It takes a reference to the source ID3D12Resource in the constructor and enqueues this resource for deletion in the destructor. It also accepts a QueueID to determine which queue the resource was used in, ensuring that it is deleted only when the GPU no longer needs it. Essentially, ResourceD3D12 implements automatic resource management: when a resource is created, it is stored in this class. Once the class is freed, the resource is automatically placed in the deletion queue.
This class creates a resource in the DEFAULT heap, allows buffer initialization with initial data, and provides CBV, SRV, and UAV creation.
Convenient wrappers for creating vertex and index buffers. These classes provide functions to obtain D3D12_VERTEX_BUFFER_VIEW and D3D12_INDEX_BUFFER_VIEW.
Creates a resource in the DEFAULT heap. It can load a texture into memory using void* data or a file path to a .dds texture. The .dds texture loading is handled using DDSTextureLoader. Additionally, it provides convenient functions for creating SRV, RTV, and DSV.
A wrapper for creating resources in the UPLOAD heap. Useful, for example, for initializing a buffer with empty data using CopyBufferRegion.
Allocates memory in the DynamicUploadHeap (reference) and provides functions for data upload. Supports CBV and SRV creation. Lifetime: one frame. Useful for creating constant buffers or structured buffers that update every frame.
Below is a simplified diagram of the classes responsible for command creation and execution on the GPU.
Inspired by the implementation in DiligentEngine. This class efficiently reuses ID3D12CommandAllocator. More details: Resource Management.
A wrapper around ID3D12GraphicsCommandList. It uses CommandListManager for handling ID3D12CommandAllocator. Additionally, it implements a queue of D3D12_RESOURCE_BARRIER and a FlushResourceBarriers function, which applies all pending barriers for optimization.
Represents a command queue of a specific type: Direct or Compute. It contains a DynamicUploadHeap for creating dynamic resources. This class also manages a queue for safe GPU resource deletion and provides functionality for submitting command lists and handling Fence synchronization.
The main class encapsulating multiple subsystems. It stores:
-
Two
CommandContextinstances -
Two
CommandQueueD3D12instances (Direct and Compute) -
Four
CPUDescriptorHeap -
Two
GPUDescriptorHeap -
Two
DynamicSuballocationManager
As illustrated in this diagram. It maintains its own resource release queue for cases where a resource is used in both Direct and Compute queues simultaneously. Provides functions for allocating resources in the appropriate queues and accessing CommandContext and CommandQueueD3D12.
Several additional classes simplify working with DirectX 12.
Creates IDXGISwapChain4 in the constructor. It supports transparent window swap chains using DirectComposition. The approach described in this article was used when implementing the swap chain.
Takes an .hlsl file path and compiles the shader into bytecode. Supports Vertex, Geometry, Pixel, and Compute shaders.
A wrapper for GBuffer resource creation. It generates the necessary buffers and includes an Accumulation Buffer.
A convenient wrapper for ID3D12RootSignature creation. Each root signature also generates static samplers for easy shader use.
A wrapper for ID3D12CommandSignature, enabling Indirect Drawing.
A wrapper for graphics ID3D12PipelineState creation.
A wrapper for compute ID3D12PipelineState creation.

