Skip to content

Instantly share code, notes, and snippets.

@yorung
Created July 9, 2016 09:56
Show Gist options
  • Save yorung/2d4d75f828bf5993c989b74cf065f400 to your computer and use it in GitHub Desktop.
Save yorung/2d4d75f828bf5993c989b74cf065f400 to your computer and use it in GitHub Desktop.
[DX12] Allocate, assign SRV and bind descriptor heap
int DeviceManDX12::AssignDescriptorHeap(int numRequired)
{
if (numAssignedSrvs + numRequired > maxSrvs) {
assert(0);
return -1;
}
int head = numAssignedSrvs;
numAssignedSrvs = numAssignedSrvs + numRequired;
return head;
}
void DeviceManDX12::AssignSRV(int descriptorHeapIndex, ComPtr<ID3D12Resource> res)
{
D3D12_CPU_DESCRIPTOR_HANDLE ptr = srvHeap->GetCPUDescriptorHandleForHeapStart();
ptr.ptr += device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * descriptorHeapIndex;
device->CreateShaderResourceView(res.Get(), nullptr, ptr);
}
void DeviceManDX12::SetAssignedDescriptorHeap(int descriptorHeapIndex)
{
ID3D12DescriptorHeap* ppHeaps[] = { srvHeap.Get() };
deviceMan.GetCommandList()->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
D3D12_GPU_DESCRIPTOR_HANDLE addr = srvHeap->GetGPUDescriptorHandleForHeapStart();
addr.ptr += descriptorHeapIndex * device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
deviceMan.GetCommandList()->SetGraphicsRootDescriptorTable(0, addr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment