> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SetDescriptorHeaps

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

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

## 構文

```cpp theme={null}
void SetDescriptorHeaps(
    UINT NumDescriptorHeaps,
     ID3D12DescriptorHeap* ppDescriptorHeaps
)
```

### パラメーター

*NumDescriptorHeaps*\
型: UINT

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

*ppDescriptorHeaps*\
型: \[in] **[ID3D12DescriptorHeap](/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public)**\*

コマンド リストに設定するヒープ用の [ID3D12DescriptorHeap](/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public) オブジェクトの配列へのポインター。

バインドできる記述子ヒープのタイプは [**D3D12\_DESCRIPTOR\_HEAP\_TYPE\_CBV\_SRV\_UAV**](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_setdescriptorheaps_public) および [**D3D12\_DESCRIPTOR\_HEAP\_TYPE\_SAMPLER**](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_setdescriptorheaps_public) のみです。

各タイプの記述子ヒープを一度に設定できるのは 1 つだけであるため、一度に設定できるのは最大 2 つのヒープ (サンプラー 1 つ、CBV/SRV/UAV 1 つ) となります。

### 戻り値

型: void

なし。

## 解説

**SetDescriptorHeaps** はバンドルでも呼び出せますが、バンドルの記述子ヒープは呼び出し元のコマンド リストの記述子ヒープと一致する必要があります。バンドルの制限の詳細については、[コマンド リストとバンドルの作成と記録](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/recording-command-lists-and-bundles) を参照してください。

以前に設定されたヒープはすべて、この呼び出しによって解除されます。呼び出し内でシェーダーから可視な各タイプについて、最大 1 つのヒープを設定できます。

記述子ヒープの変更は、一部のハードウェアでパイプライン フラッシュを引き起こすことがあります。このため、頻繁にバインドされる記述子ヒープを変更するのではなく、各タイプについて 1 つのシェーダー可視ヒープを使用し、フレームごとに 1 回設定することが推奨されます。代わりに、[**ID3D12Device::CopyDescriptors**](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_copydescriptors_public) および [**ID3D12Device::CopyDescriptorsSimple**](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_copydescriptorssimple_public) を使用して、レンダリング時に必要に応じてシェーダー不透明ヒープから単一のシェーダー可視ヒープに必要な記述子をコピーしてください。

## 例

[D3D12Bundles](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) サンプルでは、**ID3D12GraphicsCommandList::SetDescriptorHeaps** を次のように使用しています。

```cpp theme={null}
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 リファレンスのサンプル コード](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code) を参照してください。

## 要件

**ヘッダー:** d3d12\_xs.h または d3d12\_x.h\
**ライブラリ:** d3d12\_xs.lib または d3d12\_x.lib\
**サポートされるプラットフォーム**: XBOX Series 本体および XBOX One ファミリ

## 関連項目

[記述子ヒープ](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/descriptor-heaps)

[ID3D12GraphicsCommandList](/reference/graphics/d3d12_xs/interfaces/ID3D12GraphicsCommandList/id3d12graphicscommandlist_xs)


## Related topics

- [ClearUnorderedAccessViewFloat](/ja-jp/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_clearunorderedaccessviewfloat_public.md)
- [ClearUnorderedAccessViewUint](/ja-jp/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_clearunorderedaccessviewuint_public.md)
- [CreateDescriptorHeap](/ja-jp/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createdescriptorheap_public.md)
- [D3D12_DESCRIPTOR_HEAP_TYPE](/ja-jp/reference/graphics/d3d12/enums/d3d12_descriptor_heap_type_public.md)
- [ID3D12DescriptorHeap](/ja-jp/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public.md)
