ID3D12GraphicsCommandList::SetDescriptorHeaps 方法 (d3d12.h)

更改与命令列表关联的当前绑定描述符堆。

语法

void SetDescriptorHeaps(
  UINT                 NumDescriptorHeaps,
  ID3D12DescriptorHeap * const *ppDescriptorHeaps
);

参数

NumDescriptorHeaps

类型:[in] UINT

要绑定的描述符堆数。

ppDescriptorHeaps

类型:[in] ID3D12DescriptorHeap*

指向要对命令列表设置的堆的 ID3D12DescriptorHeap 对象的数组的指针。

只能绑定 类型为 D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAVD3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER 的描述符堆。

一次只能设置每种类型的一个描述符堆,这意味着一次最多可以设置 2 个堆, (一个采样器,一次可以设置一个 CBV/SRV/UAV) 。

返回值

备注

可以针对捆绑调用 SetDescriptorHeaps,但捆绑描述符堆必须与调用方命令列表描述符堆相匹配。 有关捆绑包限制的详细信息,请参阅创建和录制命令Lists和捆绑包

调用未设置以前设置的所有堆。 调用中最多可以设置每个着色器可见类型的一个堆。

更改描述符堆可能会导致某些硬件上的管道刷新。 因此,建议使用每种类型的单个着色器可见堆,并为每个帧设置一次,而不是定期更改绑定描述符堆。 而是使用 ID3D12Device::CopyDescriptorsID3D12Device::CopyDescriptorsSimple ,根据需要将所需的描述符从着色器不透明堆复制到单个着色器可见堆。

示例

D3D12Bundles 示例使用 ID3D12GraphicsCommandList::SetDescriptorHeaps,如下所示:

void D3D12Bundles::PopulateCommandList(FrameResource* pFrameResource)
{
    // Command list allocators can only be reset when the associated
    // command lists have finished execution on the GPU; apps should use
    // fences to determine GPU execution progress.
    ThrowIfFailed(m_pCurrentFrameResource->m_commandAllocator->Reset());

    // However, when ExecuteCommandList() is called on a particular command
    // list, that command list can then be reset at any time and must be before
    // re-recording.
    ThrowIfFailed(m_commandList->Reset(m_pCurrentFrameResource->m_commandAllocator.Get(), m_pipelineState1.Get()));

    // Set necessary state.
    m_commandList->SetGraphicsRootSignature(m_rootSignature.Get());

    ID3D12DescriptorHeap* ppHeaps[] = { m_cbvSrvHeap.Get(), m_samplerHeap.Get() };
    m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);

    m_commandList->RSSetViewports(1, &m_viewport);
    m_commandList->RSSetScissorRects(1, &m_scissorRect);

    // Indicate that the back buffer will be used as a render target.
    m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

    CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart(), m_frameIndex, m_rtvDescriptorSize);
    CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle(m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
    m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);

    // Record commands.
    const float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };
    m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);
    m_commandList->ClearDepthStencilView(m_dsvHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

    if (UseBundles)
    {
        // Execute the prebuilt bundle.
        m_commandList->ExecuteBundle(pFrameResource->m_bundle.Get());
    }
    else
    {
        // Populate a new command list.
        pFrameResource->PopulateCommandList(m_commandList.Get(), m_pipelineState1.Get(), m_pipelineState2.Get(), m_currentFrameResourceIndex, m_numIndices, &m_indexBufferView,
            &m_vertexBufferView, m_cbvSrvHeap.Get(), m_cbvSrvDescriptorSize, m_samplerHeap.Get(), m_rootSignature.Get());
    }

    // Indicate that the back buffer will now be used to present.
    m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

    ThrowIfFailed(m_commandList->Close());
}

请参阅 D3D12 参考中的示例代码

要求

要求
目标平台 Windows
标头 d3d12.h
Library D3d12.lib
DLL D3d12.dll

另请参阅

描述符堆

ID3D12GraphicsCommandList