共用方式為


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,但套件組合描述元堆積必須符合呼叫的命令清單描述元堆積。 如需套件組合限制的詳細資訊,請參閱建立和錄製命令 清單 和套件組合

所有先前設定的堆積都會由呼叫取消設定。 呼叫中最多可以設定每個著色器可見類型的一個堆積。

變更描述項堆積可能會在某些硬體上產生管線排清。 因此,建議您使用每個類型的單一著色器可見堆積,併為每個畫面設定一次,而不是定期變更系結描述項堆積。 請改用 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
程式庫 D3d12.lib
Dll D3d12.dll

另請參閱

描述項堆積

ID3D12GraphicsCommandList