DirectCompute API Reference
This section provides detailed documentation for the DirectCompute API, a powerful extension of DirectX designed for general-purpose computation on the GPU.
Overview
DirectCompute allows developers to leverage the parallel processing power of graphics processing units (GPUs) for a wide range of tasks beyond traditional graphics rendering. This includes physics simulations, signal processing, machine learning, data analysis, and more. It integrates seamlessly with Direct3D 11 and later versions.
Key Components
DirectCompute provides a set of APIs for:
- Creating and managing compute shaders.
- Binding shader resources (textures, buffers) for input and output.
- Dispatching compute workloads to the GPU.
- Synchronizing CPU and GPU operations.
Core Functions
HRESULT CreateComputeShader(
[in] const void* pShaderBytecode,
[in] SIZE_T BytecodeLength,
[in, optional] ID3D11ClassLinkage* pClassLinkage,
[out, optional] ID3D11ComputeShader** ppComputeShader
);
Creates a compute shader object from compiled shader code.
Parameters:
pShaderBytecode
: Pointer to the compiled shader.BytecodeLength
: Size of the compiled shader bytecode.pClassLinkage
: Pointer to a linkage interface.ppComputeShader
: Address of a pointer to the created compute shader object.
Return Value: Returns one of the Direct3D 11 Return Codes.
void CSSetShader(
[in, optional] ID3D11ComputeShader* pComputeShader,
[in, optional] ID3D11ClassInstance* const* ppClassInstances,
[in] UINT NumClassInstances
);
Sets a compute shader to the device for use.
Parameters:
pComputeShader
: Pointer to the compute shader object.ppClassInstances
: Array of pointers to class instances.NumClassInstances
: Number of class instances.
void Dispatch(
[in] UINT ThreadGroupCountX,
[in] UINT ThreadGroupCountY,
[in] UINT ThreadGroupCountZ
);
Executes one or more compute-shader instances.
Parameters:
ThreadGroupCountX
: Number of thread groups to execute along the X axis.ThreadGroupCountY
: Number of thread groups to execute along the Y axis.ThreadGroupCountZ
: Number of thread groups to execute along the Z axis.
void CSSetShaderResources(
[in] UINT StartSlot,
[in] UINT NumViews,
[in, optional] ID3D11ShaderResourceView* const* ppShaderResourceViews
);
Sets an array of shader resource views (SRVs) to the shader pipeline.
Parameters:
StartSlot
: The first shader-stage pipeline stage slot that will receive the shader resource views.NumViews
: Number of views to set.ppShaderResourceViews
: Array of SRV pointers.
void CSSetUnorderedAccessViews(
[in] UINT StartUAV,
[in] UINT NumUAVs,
[in, optional] ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
[in, optional] const UINT* pUAVInitialCounts
);
Sets an array of unordered-access view (UAV) to the shader pipeline.
Parameters:
StartUAV
: The first UAV slot to set.NumUAVs
: Number of UAVs to set.ppUnorderedAccessViews
: Array of UAV pointers.pUAVInitialCounts
: Array of initial counts for UAVs.
Related Structures and Types
Explore the structures and types used in DirectCompute operations: