Last active
June 10, 2017 17:23
-
-
Save yorung/07a14088b62f0ff4eee27dfc932f7029 to your computer and use it in GitHub Desktop.
An example of CPU side descriptor heap.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ComPtr<ID3D12DescriptorHeap> rtvHeap, dsvHeap; | |
ID3D12GraphicsCommandList* commandList; | |
ID3D12Device* device; | |
void CreateHeaps() | |
{ | |
D3D12_DESCRIPTOR_HEAP_DESC rtvDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1 }; | |
device->CreateDescriptorHeap(&rtvDesc, IID_PPV_ARGS(&rtvHeap)); | |
D3D12_DESCRIPTOR_HEAP_DESC dsvDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1 }; | |
device->CreateDescriptorHeap(&dsvDesc, IID_PPV_ARGS(&rtvHeap)); | |
} | |
void SetRenderTarget(ComPtr<ID3D12Resource> color, ComPtr<ID3D12Resource> depthStencil) | |
{ | |
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = dsvHeap->GetCPUDescriptorHandleForHeapStart(); | |
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = rtvHeap->GetCPUDescriptorHandleForHeapStart(); | |
// this overwrites descriptor heaps in every single call of SetRenderTarget, but it's no problem. | |
// because, the descriptor heap for RTV or DSV is in CPU side, not in VRAM like SRV and CBV. | |
// refer https://youtu.be/Uwhhdktaofg for more detail. | |
device->CreateRenderTargetView(color.Get(), nullptr, rtvHandle); | |
device->CreateDepthStencilView(depthStencil.Get(), nullptr, dsvHandle); | |
commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr); | |
commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr); | |
commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment