Created
May 8, 2016 01:53
-
-
Save yorung/b1b5b9d36569539366eae47deec36371 to your computer and use it in GitHub Desktop.
A helper function to create descriptor heap from array of ID3D12Resource.
This file contains hidden or 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> afCreateDescriptorHeap(int numSrvs, ComPtr<ID3D12Resource> srvs[]) | |
| { | |
| ComPtr<ID3D12DescriptorHeap> heap; | |
| D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {}; | |
| srvHeapDesc.NumDescriptors = numSrvs; | |
| srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; | |
| srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; | |
| HRESULT hr = deviceMan.GetDevice()->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(&heap)); | |
| assert(hr == S_OK); | |
| for (int i = 0; i < numSrvs; i++) { | |
| D3D12_RESOURCE_DESC desc = srvs[i]->GetDesc(); | |
| auto ptr = heap->GetCPUDescriptorHandleForHeapStart(); | |
| ptr.ptr += deviceMan.GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * i; | |
| if (desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { | |
| D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {}; | |
| cbvDesc.BufferLocation = srvs[i]->GetGPUVirtualAddress(); | |
| cbvDesc.SizeInBytes = (UINT)desc.Width; | |
| assert((cbvDesc.SizeInBytes & 0xff) == 0); | |
| deviceMan.GetDevice()->CreateConstantBufferView(&cbvDesc, ptr); | |
| } else { | |
| deviceMan.GetDevice()->CreateShaderResourceView(srvs[i].Get(), nullptr, ptr); | |
| } | |
| } | |
| return heap; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment