diff --git a/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp b/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp index 5718fc1..d661f95 100644 --- a/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12CommandList.cpp @@ -388,7 +388,7 @@ namespace Juliet::D3D12 viewHeap = commandList->Driver->BindlessDescriptorHeap; - samplerHeap = AcquireDescriptorHeapFromPool(commandList->Driver, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + samplerHeap = AcquireSamplerHeapFromPool(commandList->Driver); commandList->CRB_SRV_UAV_Heap = viewHeap; commandList->RTV_Heap = samplerHeap; @@ -437,7 +437,7 @@ namespace Juliet::D3D12 // Return heap descriptor to pool // 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->RTV_Heap = nullptr; diff --git a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp index a03ff74..f0a6f89 100644 --- a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.cpp @@ -105,22 +105,11 @@ namespace Juliet::D3D12::Internal heap->FreeIndicesCount++; } - D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr d3d12Driver, D3D12_DESCRIPTOR_HEAP_TYPE type) + D3D12DescriptorHeap* AcquireSamplerHeapFromPool(NonNullPtr d3d12Driver) { - D3D12DescriptorHeapPool* pool = nullptr; - uint32 count = 0; - 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); - + D3D12DescriptorHeapPool* pool = &d3d12Driver->SamplerHeapPool; + uint32 count = GPUDriver::kSampler_HeapDescriptorCount; + D3D12DescriptorHeap* result = nullptr; if (pool->Count > 0) { @@ -129,34 +118,27 @@ namespace Juliet::D3D12::Internal } else { - result = CreateDescriptorHeap(d3d12Driver, type, count, false); + result = CreateDescriptorHeap(d3d12Driver, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, count, false); } return result; } - void ReturnDescriptorHeapToPool(NonNullPtr d3d12Driver, D3D12DescriptorHeap* heap) + void ReturnSamplerHeapToPool(NonNullPtr d3d12Driver, D3D12DescriptorHeap* heap) { if (heap == nullptr) { return; } - D3D12DescriptorHeapPool* pool = nullptr; - if (heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) - { - pool = &d3d12Driver->CRB_SRV_UAV_HeapPool; - } - else if (heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) - { - pool = &d3d12Driver->RTV_HeapPool; - } - Assert(pool != nullptr); + Assert(heap->HeapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + D3D12DescriptorHeapPool* pool = &d3d12Driver->SamplerHeapPool; + heap->CurrentDescriptorIndex = 0; if (pool->Count >= pool->Capacity) { - pool->Capacity *= 2; + pool->Capacity = pool->Capacity == 0 ? 1 : pool->Capacity * 2; pool->Heaps = static_cast(Realloc(pool->Heaps, pool->Capacity * sizeof(D3D12DescriptorHeap*))); } diff --git a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h index 0d28c13..c91dcac 100644 --- a/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h +++ b/Juliet/src/Graphics/D3D12/D3D12DescriptorHeap.h @@ -48,9 +48,8 @@ namespace Juliet::D3D12::Internal D3D12_DESCRIPTOR_HEAP_TYPE type, uint32 count, bool isStaging); extern void DestroyDescriptorHeap(NonNullPtr heap); - extern D3D12DescriptorHeap* AcquireDescriptorHeapFromPool(NonNullPtr commandList, - D3D12_DESCRIPTOR_HEAP_TYPE type); - extern void ReturnDescriptorHeapToPool(NonNullPtr d3d12Driver, D3D12DescriptorHeap* heap); + extern D3D12DescriptorHeap* AcquireSamplerHeapFromPool(NonNullPtr d3d12Driver); + extern void ReturnSamplerHeapToPool(NonNullPtr d3d12Driver, D3D12DescriptorHeap* heap); extern bool AssignDescriptor(D3D12DescriptorHeap* heap, D3D12Descriptor& outDescriptor); extern void ReleaseDescriptor(const D3D12Descriptor& descriptor); diff --git a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp index 9f8437d..3feb46f 100644 --- a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp +++ b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.cpp @@ -496,8 +496,7 @@ namespace Juliet::D3D12 SafeFree(heapPool.Heaps); } }; - DestroyDescriptorHeapPool(driver->CRB_SRV_UAV_HeapPool); - DestroyDescriptorHeapPool(driver->RTV_HeapPool); + DestroyDescriptorHeapPool(driver->SamplerHeapPool); // Release command buffers for (uint32 i = 0; i < driver->AvailableCommandListCount; i += 1) @@ -950,14 +949,7 @@ namespace Juliet::D3D12 return true; }; - if (!CreateDescriptorPool(driver->CRB_SRV_UAV_HeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, - GPUDriver::kCBV_SRV_UAV_HeapDescriptorCount)) - { - DestroyDriver_Internal(driver); - return nullptr; - } - - if (!CreateDescriptorPool(driver->RTV_HeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, GPUDriver::kSampler_HeapDescriptorCount)) + if (!CreateDescriptorPool(driver->SamplerHeapPool, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, GPUDriver::kSampler_HeapDescriptorCount)) { DestroyDriver_Internal(driver); return nullptr; @@ -1029,7 +1021,7 @@ namespace Juliet::D3D12 driver->GraphicsDevice = device; // 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; } diff --git a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h index 3f0f075..54d130d 100644 --- a/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h +++ b/Juliet/src/Graphics/D3D12/D3D12GraphicsDevice.h @@ -99,8 +99,7 @@ namespace Juliet::D3D12 D3D12StagingDescriptorPool* StagingDescriptorPools[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES]; Internal::D3D12DescriptorHeap* BindlessDescriptorHeap; - Internal::D3D12DescriptorHeapPool CRB_SRV_UAV_HeapPool; - Internal::D3D12DescriptorHeapPool RTV_HeapPool; + Internal::D3D12DescriptorHeapPool SamplerHeapPool; String Semantic;