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
Library D3d12.lib
DLL D3d12.dll

另请参阅

ID3D12GraphicsCommandList