Microsoft DirectCompute is an application programming interface (API) that supports running compute kernels on general-purpose computing on graphics processing units on Microsoft's Windows Vista, Windows 7 and later versions. DirectCompute is part of the Microsoft DirectX collection of APIs, and was initially released with the DirectX 11 API but runs on graphics processing units that use either DirectX 10 or DirectX 11.[1] The DirectCompute architecture shares a range of computational interfaces with its competitors: OpenCL from Khronos Group, compute shaders in OpenGL, and CUDA from NVIDIA.
The DirectCompute API brings enhanced multi-threading capabilities to leverage the emerging advanced compute resources.[2] The API is designed for non-graphical applications to access and use GPU resources.[3]
The Compute pipeline is a type of graphics pipeline used for dispatching and executing compute shaders. Compute pipelines are run through compute command lists, which are restricted to recording only copy and compute commands. Compute shaders are used for general-purpose algorithms and computations, and are run through parallel processors on the GPU. This parallel execution model done by the compute pipeline is organized into a dispatch, thread groups, and threads. The dispatch is a 3-dimensional container of thread groups, and a thread group is a 3-dimensional container of threads.[4] Thread groups are ran on the GPU in waves.[5]
This pipeline allows for workloads to be easily sent to the GPU without the need for restructuring all of a program's code.[6]
A typical compute pipeline contains a read-only shader resource view as an input, constant buffer views for additional resource constants, and an unordered access view for an output. It is important to set the resource states of these resources in order to improve performance.[7]
The initialization of the compute pipeline involves creating the root signature, reading the compute shader, and creating the pipeline state object.
// Serialize the root signatureMicrosoft::WRL::ComPtr
// Create the root signatureMicrosoft::WRL::ComPtr
// Read the compute shaderWindows::WRL::ComPtr
// Create the compute pipeline state object (PSO)struct PipelineStateStream pipeline_state_stream;
// Setting the root signature and the compute shader to the PSOpipeline_state_stream.root_signature = root_signature.Get;pipeline_state_stream.compute_shader = CD3DX12_SHADER_BYTECODE;
D3D12_PIPELINE_STATE_STREAM_DESC pipeline_state_stream_desc; // Create pipeline statedevice->CreatePipelineState(&pipeline_state_stream_desc, IID_PPV_ARGS(pipeline_state_stream.GetAddressOf));After the initialization of the compute pipeline, every frame, the pipeline state must be set, the compute root signature must be set, and the dispatch is run.