Small refactor, now that we are bindless we only need a pool for samplers

This commit is contained in:
2026-01-11 18:49:30 -05:00
parent 8a23ae72fe
commit fa1933c169
5 changed files with 18 additions and 46 deletions

View File

@@ -388,7 +388,7 @@ namespace Juliet::D3D12
viewHeap = commandList->Driver->BindlessDescriptorHeap; viewHeap = commandList->Driver->BindlessDescriptorHeap;
samplerHeap = AcquireDescriptorHeapFromPool(commandList->Driver, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); samplerHeap = AcquireSamplerHeapFromPool(commandList->Driver);
commandList->CRB_SRV_UAV_Heap = viewHeap; commandList->CRB_SRV_UAV_Heap = viewHeap;
commandList->RTV_Heap = samplerHeap; commandList->RTV_Heap = samplerHeap;
@@ -437,7 +437,7 @@ namespace Juliet::D3D12
// Return heap descriptor to pool // Return heap descriptor to pool
// CRB_SRV_UAV_Heap is global bindless, do not return it. // CRB_SRV_UAV_Heap is global bindless, do not return it.
ReturnDescriptorHeapToPool(driver, commandList->RTV_Heap); ReturnSamplerHeapToPool(driver, commandList->RTV_Heap);
commandList->CRB_SRV_UAV_Heap = nullptr; commandList->CRB_SRV_UAV_Heap = nullptr;
commandList->RTV_Heap = nullptr; commandList->RTV_Heap = nullptr;

View File

@@ -105,22 +105,11 @@ namespace Juliet::D3D12::Internal
heap->FreeIndicesCount++; heap->FreeIndicesCount++;
} }
D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr<D3D12Driver> d3d12Driver, D3D12_DESCRIPTOR_HEAP_TYPE type) D3D12DescriptorHeap* AcquireSamplerHeapFromPool(NonNullPtr<D3D12Driver> d3d12Driver)
{ {
D3D12DescriptorHeapPool* pool = nullptr; D3D12DescriptorHeapPool* pool = &d3d12Driver->SamplerHeapPool;
uint32 count = 0; uint32 count = GPUDriver::kSampler_HeapDescriptorCount;
if (type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)
{
pool = &d3d12Driver->CRB_SRV_UAV_HeapPool;
count = GPUDriver::kCBV_SRV_UAV_HeapDescriptorCount;
}
else if (type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER)
{
pool = &d3d12Driver->RTV_HeapPool;
count = GPUDriver::kSampler_HeapDescriptorCount;
}
Assert(pool != nullptr);
D3D12DescriptorHeap* result = nullptr; D3D12DescriptorHeap* result = nullptr;
if (pool->Count > 0) if (pool->Count > 0)
{ {
@@ -129,34 +118,27 @@ namespace Juliet::D3D12::Internal
} }
else else
{ {
result = CreateDescriptorHeap(d3d12Driver, type, count, false); result = CreateDescriptorHeap(d3d12Driver, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, count, false);
} }
return result; return result;
} }
void ReturnDescriptorHeapToPool(NonNullPtr<D3D12Driver> d3d12Driver, D3D12DescriptorHeap* heap) void ReturnSamplerHeapToPool(NonNullPtr<D3D12Driver> d3d12Driver, D3D12DescriptorHeap* heap)
{ {
if (heap == nullptr) if (heap == nullptr)
{ {
return; return;
} }
D3D12DescriptorHeapPool* pool = nullptr; Assert(heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
if (heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) D3D12DescriptorHeapPool* pool = &d3d12Driver->SamplerHeapPool;
{
pool = &d3d12Driver->CRB_SRV_UAV_HeapPool;
}
else if (heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER)
{
pool = &d3d12Driver->RTV_HeapPool;
}
Assert(pool != nullptr);
heap->CurrentDescriptorIndex = 0; heap->CurrentDescriptorIndex = 0;
if (pool->Count >= pool->Capacity) if (pool->Count >= pool->Capacity)
{ {
pool->Capacity *= 2; pool->Capacity = pool->Capacity == 0 ? 1 : pool->Capacity * 2;
pool->Heaps = pool->Heaps =
static_cast<D3D12DescriptorHeap**>(Realloc(pool->Heaps, pool->Capacity * sizeof(D3D12DescriptorHeap*))); static_cast<D3D12DescriptorHeap**>(Realloc(pool->Heaps, pool->Capacity * sizeof(D3D12DescriptorHeap*)));
} }

View File

@@ -48,9 +48,8 @@ namespace Juliet::D3D12::Internal
D3D12_DESCRIPTOR_HEAP_TYPE type, uint32 count, bool isStaging); D3D12_DESCRIPTOR_HEAP_TYPE type, uint32 count, bool isStaging);
extern void DestroyDescriptorHeap(NonNullPtr<D3D12DescriptorHeap> heap); extern void DestroyDescriptorHeap(NonNullPtr<D3D12DescriptorHeap> heap);
extern D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr<D3D12Driver> commandList, extern D3D12DescriptorHeap* AcquireSamplerHeapFromPool(NonNullPtr<D3D12Driver> d3d12Driver);
D3D12_DESCRIPTOR_HEAP_TYPE type); extern void ReturnSamplerHeapToPool(NonNullPtr<D3D12Driver> d3d12Driver, D3D12DescriptorHeap* heap);
extern void ReturnDescriptorHeapToPool(NonNullPtr<D3D12Driver> d3d12Driver, D3D12DescriptorHeap* heap);
extern bool AssignDescriptor(D3D12DescriptorHeap* heap, D3D12Descriptor& outDescriptor); extern bool AssignDescriptor(D3D12DescriptorHeap* heap, D3D12Descriptor& outDescriptor);
extern void ReleaseDescriptor(const D3D12Descriptor& descriptor); extern void ReleaseDescriptor(const D3D12Descriptor& descriptor);

View File

@@ -496,8 +496,7 @@ namespace Juliet::D3D12
SafeFree(heapPool.Heaps); SafeFree(heapPool.Heaps);
} }
}; };
DestroyDescriptorHeapPool(driver->CRB_SRV_UAV_HeapPool); DestroyDescriptorHeapPool(driver->SamplerHeapPool);
DestroyDescriptorHeapPool(driver->RTV_HeapPool);
// Release command buffers // Release command buffers
for (uint32 i = 0; i < driver->AvailableCommandListCount; i += 1) for (uint32 i = 0; i < driver->AvailableCommandListCount; i += 1)
@@ -950,14 +949,7 @@ namespace Juliet::D3D12
return true; return true;
}; };
if (!CreateDescriptorPool(driver->CRB_SRV_UAV_HeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, if (!CreateDescriptorPool(driver->SamplerHeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, GPUDriver::kSampler_HeapDescriptorCount))
GPUDriver::kCBV_SRV_UAV_HeapDescriptorCount))
{
DestroyDriver_Internal(driver);
return nullptr;
}
if (!CreateDescriptorPool(driver->RTV_HeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, GPUDriver::kSampler_HeapDescriptorCount))
{ {
DestroyDriver_Internal(driver); DestroyDriver_Internal(driver);
return nullptr; return nullptr;
@@ -1029,7 +1021,7 @@ namespace Juliet::D3D12
driver->GraphicsDevice = device; driver->GraphicsDevice = device;
// Create Global Bindless Heap that stays alive for the driver whole lifetime // Create Global Bindless Heap that stays alive for the driver whole lifetime
driver->BindlessDescriptorHeap = Internal::AcquireDescriptorHeapFromPool(driver, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); driver->BindlessDescriptorHeap = Internal::CreateDescriptorHeap(driver, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, GPUDriver::kCBV_SRV_UAV_HeapDescriptorCount, false);
return device; return device;
} }

View File

@@ -99,8 +99,7 @@ namespace Juliet::D3D12
D3D12StagingDescriptorPool* StagingDescriptorPools[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES]; D3D12StagingDescriptorPool* StagingDescriptorPools[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
Internal::D3D12DescriptorHeap* BindlessDescriptorHeap; Internal::D3D12DescriptorHeap* BindlessDescriptorHeap;
Internal::D3D12DescriptorHeapPool CRB_SRV_UAV_HeapPool; Internal::D3D12DescriptorHeapPool SamplerHeapPool;
Internal::D3D12DescriptorHeapPool RTV_HeapPool;
String Semantic; String Semantic;