D3D12: Add helper for offsetting descriptors
This commit is contained in:
parent
cb1e15da58
commit
aff9f1c25f
|
@ -51,7 +51,7 @@ void DescriptorHeapManager::Destroy()
|
|||
m_free_slots.clear();
|
||||
}
|
||||
|
||||
bool DescriptorHeapManager::Allocate(DescriptorHandle* handle)
|
||||
bool DescriptorHeapManager::Allocate(DescriptorHandle* handle, u32 count /* = 1 */)
|
||||
{
|
||||
// Start past the temporary slots, no point in searching those.
|
||||
for (u32 group = 0; group < m_free_slots.size(); group++)
|
||||
|
@ -64,11 +64,22 @@ bool DescriptorHeapManager::Allocate(DescriptorHandle* handle)
|
|||
for (; bit < BITSET_SIZE; bit++)
|
||||
{
|
||||
if (bs[bit])
|
||||
{
|
||||
u32 offset;
|
||||
for (offset = 0; offset < count; offset++)
|
||||
{
|
||||
if (!bs[bit + offset])
|
||||
break;
|
||||
}
|
||||
|
||||
if (offset == count)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
u32 index = group * BITSET_SIZE + bit;
|
||||
bs[bit] = false;
|
||||
for (u32 offset = 0; offset < count; offset++)
|
||||
bs[bit + offset] = false;
|
||||
|
||||
handle->index = index;
|
||||
handle->cpu_handle.ptr = m_heap_base_cpu.ptr + index * m_descriptor_increment_size;
|
||||
|
@ -80,21 +91,24 @@ bool DescriptorHeapManager::Allocate(DescriptorHandle* handle)
|
|||
return false;
|
||||
}
|
||||
|
||||
void DescriptorHeapManager::Free(u32 index)
|
||||
void DescriptorHeapManager::Free(u32 index, u32 count /* = 1 */)
|
||||
{
|
||||
Assert(index < m_num_descriptors);
|
||||
|
||||
for (u32 i = 0; i < count; i++, index++)
|
||||
{
|
||||
u32 group = index / BITSET_SIZE;
|
||||
u32 bit = index % BITSET_SIZE;
|
||||
m_free_slots[group][bit] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DescriptorHeapManager::Free(DescriptorHandle* handle)
|
||||
void DescriptorHeapManager::Free(DescriptorHandle* handle, u32 count /* = 1 */)
|
||||
{
|
||||
if (handle->index == DescriptorHandle::INVALID_INDEX)
|
||||
return;
|
||||
|
||||
Free(handle->index);
|
||||
Free(handle->index, count);
|
||||
handle->Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,15 +44,29 @@ public:
|
|||
DescriptorHeapManager();
|
||||
~DescriptorHeapManager();
|
||||
|
||||
ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.Get(); }
|
||||
u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; }
|
||||
ALWAYS_INLINE ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.Get(); }
|
||||
ALWAYS_INLINE u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; }
|
||||
|
||||
ALWAYS_INLINE D3D12_CPU_DESCRIPTOR_HANDLE OffsetCPUHandle(D3D12_CPU_DESCRIPTOR_HANDLE handle, u32 count) const
|
||||
{
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE ret;
|
||||
ret.ptr = handle.ptr + m_descriptor_increment_size * count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE D3D12_GPU_DESCRIPTOR_HANDLE OffsetGPUHandle(D3D12_GPU_DESCRIPTOR_HANDLE handle, u32 count) const
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE ret;
|
||||
ret.ptr = handle.ptr + m_descriptor_increment_size * count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors, bool shader_visible);
|
||||
void Destroy();
|
||||
|
||||
bool Allocate(DescriptorHandle* handle);
|
||||
void Free(DescriptorHandle* handle);
|
||||
void Free(u32 index);
|
||||
bool Allocate(DescriptorHandle* handle, u32 count = 1);
|
||||
void Free(DescriptorHandle* handle, u32 count = 1);
|
||||
void Free(u32 index, u32 count = 1);
|
||||
|
||||
private:
|
||||
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> m_descriptor_heap;
|
||||
|
|
Loading…
Reference in New Issue