DescriptorHeapHandle RenderPassDescriptorHeap::GetHeapHandleBlock(uint32 count) { uint32 newHandleID = 0; uint32 blockEnd = mCurrentDescriptorIndex + count; if (blockEnd < mMaxDescriptors) { newHandleID = mCurrentDescriptorIndex; mCurrentDescriptorIndex = blockEnd; } else { Direct3DUtils::ThrowRuntimeError("Ran out of render pass descriptor heap handles, need to increase heap size."); } DescriptorHeapHandle newHandle; D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = mDescriptorHeapCPUStart; cpuHandle.ptr += newHandleID * mDescriptorSize; newHandle.SetCPUHandle(cpuHandle); D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = mDescriptorHeapGPUStart; gpuHandle.ptr += newHandleID * mDescriptorSize; newHandle.SetGPUHandle(gpuHandle); newHandle.SetHeapIndex(newHandleID); return newHandle; }
DescriptorHeapHandle StaticDescriptorHeap::GetNewHeapHandle() { uint32 newHandleID = 0; if (mCurrentDescriptorIndex < mMaxDescriptors) { newHandleID = mCurrentDescriptorIndex; mCurrentDescriptorIndex++; } else if (mFreeDescriptors.CurrentSize() > 0) { newHandleID = mFreeDescriptors.RemoveLast(); } else { Direct3DUtils::ThrowRuntimeError("Ran out of dynamic descriptor heap handles, need to increase heap size."); } DescriptorHeapHandle newHandle; D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = mDescriptorHeapCPUStart; cpuHandle.ptr += newHandleID * mDescriptorSize; newHandle.SetCPUHandle(cpuHandle); newHandle.SetHeapIndex(newHandleID); mActiveHandleCount++; return newHandle; }