ID3D12DescriptorHeap interface
A descriptor heap is a collection of contiguous allocations of descriptors, one allocation for every descriptor. Descriptor heaps contain many object types that are not part of a Pipeline State Object (PSO), such as Shader Resource Views (SRVs), Unordered Access Views (UAVs), Constant Buffer Views (CBVs), and Samplers.
Members
The ID3D12DescriptorHeap interface inherits from ID3D12Pageable. ID3D12DescriptorHeap also has these types of members:
Methods
The ID3D12DescriptorHeap interface has these methods.
| Method | Description |
|---|---|
| GetCPUDescriptorHandleForHeapStart |
Gets the CPU descriptor handle that represents the start of the heap. |
| GetDesc |
Gets the descriptor heap description. |
| GetGPUDescriptorHandleForHeapStart |
Gets the GPU descriptor handle that represents the start of the heap. |
Examples
The D3D12nBodyGravity sample uses ID3D12DescriptorHeap as follows:
Header file declarations.
// Pipeline objects.
D3D12_VIEWPORT m_viewport;
ComPtr<IDXGISwapChain3> m_swapChain;
ComPtr<ID3D12Device> m_device;
ComPtr<ID3D12Resource> m_renderTargets[FrameCount];
ComPtr<ID3D12Resource> m_depthStencil;
ComPtr<ID3D12CommandAllocator> m_commandAllocator;
ComPtr<ID3D12GraphicsCommandList> m_commandList;
ComPtr<ID3D12CommandQueue> m_commandQueue;
ComPtr<ID3D12RootSignature >m_rootSignature;
ComPtr<ID3D12DescriptorHeap> m_rtvHeap;
ComPtr<ID3D12DescriptorHeap> m_cbvSrvHeap;
ComPtr<ID3D12DescriptorHeap> m_dsvHeap;
ComPtr<ID3D12DescriptorHeap> m_samplerHeap;
ComPtr<ID3D12PipelineState> m_pipelineState1;
ComPtr<ID3D12PipelineState> m_pipelineState2;
D3D12_RECT m_scissorRect;
Populating command lists.
// Fill the command list with all the render commands and dependent state. void D3D12nBodyGravity::PopulateCommandList() { // 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_commandAllocators[m_frameIndex]->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_commandAllocators[m_frameIndex].Get(), m_pipelineState.Get())); // Set necessary state. m_commandList->SetPipelineState(m_pipelineState.Get()); m_commandList->SetGraphicsRootSignature(m_rootSignature.Get()); m_commandList->SetGraphicsRootConstantBufferView(RootParameterCB, m_constantBufferGS->GetGPUVirtualAddress() + m_frameIndex * sizeof(ConstantBufferGS)); ID3D12DescriptorHeap* ppHeaps[] = { m_srvUavHeap.Get() }; m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps); m_commandList->IASetVertexBuffers(0, 1, &m_vertexBufferView); m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); 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); m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr); // Record commands. const float clearColor[] = { 0.0f, 0.0f, 0.1f, 0.0f }; m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr); // Render the particles. float viewportHeight = static_cast<float>(static_cast<UINT>(m_viewport.Height) / m_heightInstances); float viewportWidth = static_cast<float>(static_cast<UINT>(m_viewport.Width) / m_widthInstances); for (UINT n = 0; n < ThreadCount; n++) { const UINT srvIndex = n + (m_srvIndex[n] == 0 ? SrvParticlePosVelo0 : SrvParticlePosVelo1); D3D12_VIEWPORT viewport; viewport.TopLeftX = (n % m_widthInstances) * viewportWidth; viewport.TopLeftY = (n / m_widthInstances) * viewportHeight; viewport.Width = viewportWidth; viewport.Height = viewportHeight; viewport.MinDepth = D3D12_MIN_DEPTH; viewport.MaxDepth = D3D12_MAX_DEPTH; m_commandList->RSSetViewports(1, &viewport); CD3DX12_GPU_DESCRIPTOR_HANDLE srvHandle(m_srvUavHeap->GetGPUDescriptorHandleForHeapStart(), srvIndex, m_srvUavDescriptorSize); m_commandList->SetGraphicsRootDescriptorTable(RootParameterSRV, srvHandle); m_commandList->DrawInstanced(ParticleCount, 1, 0, 0); } m_commandList->RSSetViewports(1, &m_viewport); // 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()); }
Refer to the Example Code in the D3D12 Reference.
Requirements
|
Header |
|
|---|---|
|
Library |
|
|
DLL |
|
See also