Metodo ID3D12GraphicsCommandList::SetDescriptorHeaps (d3d12.h)

Modifica l'heaps descrittore attualmente associato a un elenco di comandi.

Sintassi

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

Parametri

NumDescriptorHeaps

Tipo: [in] UINT

Numero di heaps descrittori da associare.

ppDescriptorHeaps

Tipo: [in] ID3D12DescriptorHeap*

Puntatore a una matrice di oggetti ID3D12DescriptorHeap per l'heaps da impostare nell'elenco dei comandi.

È possibile associare solo gli heaps del descrittore di tipo D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV e D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER.

Solo un heap descrittore di ogni tipo può essere impostato contemporaneamente, il che significa un massimo di 2 heaps (un sampler, un cbV/SRV/UAV) può essere impostato alla volta.

Valore restituito

nessuno

Osservazioni

SetDescriptorHeaps può essere chiamato in un bundle, ma il descrittore di bundle deve corrispondere all'heap dell'heap dell'elenco comandi chiamante. Per altre informazioni sulle restrizioni del bundle, vedere Creazione e registrazione dei comandi Elenchi e bundle.

Tutti gli heaps impostati in precedenza non vengono impostati dalla chiamata. Al massimo un heap di ogni tipo visibile dello shader può essere impostato nella chiamata.

La modifica degli heaps del descrittore può comportare uno scaricamento della pipeline su un hardware. A causa di questo, è consigliabile usare un singolo heap visibile shader di ogni tipo e impostarlo una volta per fotogramma, anziché modificare regolarmente l'heaps descrittore associato. Usare invece ID3D12Device::CopyDescriptors e ID3D12Device::CopyDescriptorsSimple per copiare i descrittori necessari dall'heap shader-opaco al singolo heap visibile shader come richiesto durante il rendering.

Esempio

L'esempio D3D12Bundles usa ID3D12GraphicsCommandList::SetDescriptorHeaps come indicato di seguito:

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

Vedere Codice di esempio nel riferimento D3D12.

Requisiti

Requisito Valore
Piattaforma di destinazione Windows
Intestazione d3d12.h
Libreria D3d12.lib
DLL D3d12.dll

Vedi anche

Descrittore Heaps

ID3D12GraphicsCommandList