ID3D12GraphicsCommandList::SetDescriptorHeaps メソッド (d3d12.h)

コマンド リストに関連付けられている現在バインドされている記述子ヒープを変更します。

構文

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

パラメーター

NumDescriptorHeaps

型: [in] UINT

バインドする記述子ヒープの数。

ppDescriptorHeaps

種類: [入力] ID3D12DescriptorHeap*

コマンド リストに設定するヒープの ID3D12DescriptorHeap オブジェクトの配列へのポインター。

バインドできるのは、 D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV 型と D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER型の記述子ヒープのみです。

各型の記述子ヒープを一度に 1 つだけ設定できます。つまり、最大 2 つのヒープ (サンプラー 1 つ、CBV/SRV/UAV 1 つ) を一度に設定できます。

戻り値

なし

解説

SetDescriptorHeaps をバンドルに対して呼び出すことはできますが、バンドル記述子ヒープは呼び出し元のコマンド リスト記述子ヒープと一致する必要があります。 バンドルの制限の詳細については、「コマンド Listsとバンドルの作成と記録」を参照してください。

以前に設定されたすべてのヒープは、呼び出しによって設定解除されます。 呼び出しでは、シェーダーに表示される各型のヒープを最大 1 つ設定できます。

記述子ヒープを変更すると、一部のハードウェアでパイプラインのフラッシュが発生する可能性があります。 このため、バインドされた記述子ヒープを定期的に変更するのではなく、各型のシェーダーに表示されるヒープを 1 つ使用し、フレームごとに 1 回設定することをお勧めします。 代わりに、 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