> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dispatch

> Executes a compute shader on a thread group.

Executes a command list from a thread group.

## Syntax

```cpp theme={null}
void Dispatch(
    UINT ThreadGroupCountX,
    UINT ThreadGroupCountY,
    UINT ThreadGroupCountZ
)
```

### Parameters

*ThreadGroupCountX \[in]*\
Type: UINT

The number of groups dispatched in the x direction. <i>ThreadGroupCountX</i> must be less than or equal to D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535).

*ThreadGroupCountY \[in]*\
Type: UINT

The number of groups dispatched in the y direction. <i>ThreadGroupCountY</i> must be less than or equal to D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535).

*ThreadGroupCountZ \[in]*\
Type: UINT

The number of groups dispatched in the z direction.  <i>ThreadGroupCountZ</i> must be less than or equal to D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535).
In feature level 10 the value for <i>ThreadGroupCountZ</i> must be 1.

### Return value

Type: void

None.

## Remarks

You call the **Dispatch** method to execute commands in a compute shader. A compute shader can be run on many threads in parallel, within a thread group. Index a particular thread, within a thread group using a 3D vector
given by (x,y,z).

#### Examples

The [D3D12nBodyGravity](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) sample uses **ID3D12GraphicsCommandList::Dispatch** as follows:

```cpp theme={null}
// Run the particle simulation using the compute shader.
void D3D12nBodyGravity::Simulate(UINT threadIndex)
{
ID3D12GraphicsCommandList* pCommandList = m_computeCommandList[threadIndex].Get();

UINT srvIndex;
UINT uavIndex;
ID3D12Resource *pUavResource;
if (m_srvIndex[threadIndex] == 0)
{
srvIndex = SrvParticlePosVelo0;
uavIndex = UavParticlePosVelo1;
pUavResource = m_particleBuffer1[threadIndex].Get();
}
else
{
srvIndex = SrvParticlePosVelo1;
uavIndex = UavParticlePosVelo0;
pUavResource = m_particleBuffer0[threadIndex].Get();
}

pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(pUavResource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_UNORDERED_ACCESS));

pCommandList->SetPipelineState(m_computeState.Get());
pCommandList->SetComputeRootSignature(m_computeRootSignature.Get());

ID3D12DescriptorHeap* ppHeaps[] = { m_srvUavHeap.Get() };
pCommandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);

CD3DX12_GPU_DESCRIPTOR_HANDLE srvHandle(m_srvUavHeap->GetGPUDescriptorHandleForHeapStart(), srvIndex + threadIndex, m_srvUavDescriptorSize);
CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandle(m_srvUavHeap->GetGPUDescriptorHandleForHeapStart(), uavIndex + threadIndex, m_srvUavDescriptorSize);

pCommandList->SetComputeRootConstantBufferView(RootParameterCB, m_constantBufferCS->GetGPUVirtualAddress());
pCommandList->SetComputeRootDescriptorTable(RootParameterSRV, srvHandle);
pCommandList->SetComputeRootDescriptorTable(RootParameterUAV, uavHandle);

pCommandList->Dispatch(static_cast<int>(ceil(ParticleCount / 128.0f)), 1, 1);

pCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE));
}

```

See [Example Code in the D3D12 Reference](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code).

<div class="code" />

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h\
**Library:** d3d12\_xs.lib or d3d12\_x.lib\
**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

[ID3D12GraphicsCommandList](/reference/graphics/d3d12_xs/interfaces/ID3D12GraphicsCommandList/id3d12graphicscommandlist_xs)


## Related topics

- [XTaskQueueDispatch](/reference/system/xtaskqueue/functions/xtaskqueuedispatch.md)
- [Dispatch task queue example](/build/core-features/common/async/async-libraries/async-library-xtaskqueue-example-dispatch-task-queue.md)
- [IGameInputDispatcher::Dispatch](/reference/input/gameinput/interfaces/IGameInputDispatcher/methods/igameinputdispatcher_dispatch.md)
- [XTaskQueueDispatchMode](/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode.md)
- [D3D12_DISPATCH_ARGUMENTS](/reference/graphics/d3d12/structs/d3d12_dispatch_arguments_public.md)
