ID3D12GraphicsCommandList::D ispatch 方法 (d3d12.h)

從線程群組執行命令清單。

語法

void Dispatch(
  [in] UINT ThreadGroupCountX,
  [in] UINT ThreadGroupCountY,
  [in] UINT ThreadGroupCountZ
);

參數

[in] ThreadGroupCountX

類型: UINT

以 x 方向分派的群組數目。 ThreadGroupCountX 必須小於或等於 D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION (65535) 。

[in] ThreadGroupCountY

類型: UINT

以 Y 方向分派的群組數目。 ThreadGroupCountY 必須小於或等於 D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION (65535) 。

[in] ThreadGroupCountZ

類型: UINT

以 z 方向分派的群組數目。 ThreadGroupCountZ 必須小於或等於 D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION (65535) 。 在功能層級 10 中, ThreadGroupCountZ 的值必須是 1。

傳回值

備註

您可以呼叫 Dispatch 方法,以在計算著色器中執行命令。 計算著色器可以在線程群組內的許多線程上平行執行。 使用 (x,y,z) 指定的 3D 向量,為線程群組內的特定線程編製索引。

範例

D3D12nBodyGravity 範例使用 ID3D12GraphicsCommandList::D ispatch,如下所示:

// 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 參考中的範例程式代碼

規格需求

需求
目標平台 Windows
標頭 d3d12.h
程式庫 D3d12.lib
Dll D3d12.dll

另請參閱

ID3D12GraphicsCommandList