DirectX Compute API Reference

Introduction to DirectX Compute

DirectX Compute provides a powerful and flexible framework for leveraging the parallel processing capabilities of the GPU for general-purpose computation. It allows developers to move beyond traditional graphics rendering pipelines and utilize the GPU for tasks such as physics simulations, data processing, AI computations, and more.

By utilizing compute shaders, developers can define custom kernels that execute on the GPU, processing large datasets efficiently. This section covers the core APIs, structures, and concepts related to DirectX Compute.

Core Concepts

Understanding these fundamental concepts is crucial for effective use of DirectX Compute:

Compute Shaders

Compute shaders are the primary building blocks for GPU computation. They are programmable stages that execute on the GPU, designed for arbitrary data processing rather than fixed graphics pipeline stages.

Unordered Access Views (UAVs)

UAVs provide read-and-write access to GPU resources (like buffers and textures) from compute shaders. This allows shaders to modify data in place or write results to various locations.

Shader Resource Views (SRVs)

SRVs are used to read data from GPU resources within compute shaders. They can be bound as input to a compute shader, allowing it to access textures or structured data.

Append Buffers and Consume Buffers

Special types of UAVs that allow for dynamic generation and consumption of data from buffers, useful for scenarios like generating geometry or processing variable-length data.

Thread Groups

Compute shaders execute in a grid of thread groups. Threads within a thread group can synchronize and share data through shared memory, enabling efficient parallel processing and communication.

Key API Functions

The following functions are essential for setting up and dispatching compute workloads:

Function Description
ID3D11Device::CreateComputeShader Creates a compute shader object from compiled shader code.
ID3D11DeviceContext::CSSetShader Sets the active compute shader on the device context.
ID3D11DeviceContext::CSSetUnorderedAccessViews Binds one or more unordered-access views to the compute shader pipeline.
ID3D11DeviceContext::CSSetShaderResources Binds one or more shader resource views to the compute shader pipeline.
ID3D11DeviceContext::Dispatch Dispatches one or more thread groups for the currently bound compute shader.
ID3D11DeviceContext::DispatchIndirect Dispatches thread groups based on parameters stored in a buffer.
ID3D11Device::CreateBuffer Creates various types of buffers, including those used for compute operations (e.g., structured buffers, UAVs).

Important Structures

These structures are frequently used when working with compute shaders:

Structure Description
D3D11_SHADER_DESC Describes a shader.
D3D11_INPUT_ELEMENT_DESC Describes an input element for shaders.
D3D11_UNORDERED_ACCESS_VIEW_DESC Describes an unordered-access view.
D3D11_SHADER_RESOURCE_VIEW_DESC Describes a shader resource view.
D3D11_TEXTURE2D_DESC Describes a 2D texture.
D3D11_BUFFER_DESC Describes a buffer.

Relevant Enums

Enumerations that define specific states and properties for compute operations:

Enum Description
D3D11_UAV_DIMENSION Specifies the dimension of a UAV.
D3D11_SRV_DIMENSION Specifies the dimension of an SRV.
D3D11_BIND_FLAG Flags for binding resources to pipeline stages.