> ## 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

> スレッド グループ上でコンピュート シェーダーを実行します。

スレッド グループからコマンド リストを実行します。

## 構文

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

### パラメーター

*ThreadGroupCountX \[in]*\
型: UINT

x 方向にディスパッチされるグループの数。<i>ThreadGroupCountX</i> は D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535) 以下でなければなりません。

*ThreadGroupCountY \[in]*\
型: UINT

y 方向にディスパッチされるグループの数。<i>ThreadGroupCountY</i> は D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535) 以下でなければなりません。

*ThreadGroupCountZ \[in]*\
型: UINT

z 方向にディスパッチされるグループの数。<i>ThreadGroupCountZ</i> は D3D11\_CS\_DISPATCH\_MAX\_THREAD\_GROUPS\_PER\_DIMENSION (65535) 以下でなければなりません。
機能レベル 10 では、<i>ThreadGroupCountZ</i> の値は 1 でなければなりません。

### 戻り値

型: void

なし。

## 解説

コンピュート シェーダー内のコマンドを実行するには、**Dispatch** メソッドを呼び出します。コンピュート シェーダーは、スレッド グループ内で多数のスレッドで並列に実行できます。スレッド グループ内の特定のスレッドは、(x,y,z) で与えられる 3D ベクトルを使用してインデックス付けします。

#### 例

[D3D12nBodyGravity](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) サンプルでは、**ID3D12GraphicsCommandList::Dispatch** を次のように使用しています。

```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));
}

```

[D3D12 リファレンスのサンプル コード](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code) を参照してください。

<div class="code" />

## 要件

**ヘッダー:** d3d12\_xs.h または d3d12\_x.h\
**ライブラリ:** d3d12\_xs.lib または d3d12\_x.lib\
**サポートされるプラットフォーム**: XBOX Series 本体および XBOX One ファミリ

## 関連項目

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


## Related topics

- [XTaskQueueDispatch](/ja-jp/reference/system/xtaskqueue/functions/xtaskqueuedispatch.md)
- [IGameInputDispatcher::Dispatch](/ja-jp/reference/input/gameinput/interfaces/IGameInputDispatcher/methods/igameinputdispatcher_dispatch.md)
- [XTaskQueueDispatchMode](/ja-jp/reference/system/xtaskqueue/enums/xtaskqueuedispatchmode.md)
- [DispatchRays (XBOX Series 本体)](/ja-jp/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist4/methods/id3d12graphicscommandlist4_dispatchrays_public.md)
- [D3D12_DISPATCH_ARGUMENTS](/ja-jp/reference/graphics/d3d12/structs/d3d12_dispatch_arguments_public.md)
