Fixes to Vulkan backend

This commit is contained in:
Wojtek Figat
2024-04-13 23:55:39 +02:00
parent fbfe77e386
commit 2b95f11b1f
3 changed files with 16 additions and 17 deletions

View File

@@ -10,6 +10,7 @@
#include "GPUTimerQueryVulkan.h" #include "GPUTimerQueryVulkan.h"
#endif #endif
#include "DescriptorSetVulkan.h" #include "DescriptorSetVulkan.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Profiler/ProfilerCPU.h"
void CmdBufferVulkan::AddWaitSemaphore(VkPipelineStageFlags waitFlags, SemaphoreVulkan* waitSemaphore) void CmdBufferVulkan::AddWaitSemaphore(VkPipelineStageFlags waitFlags, SemaphoreVulkan* waitSemaphore)
@@ -32,7 +33,7 @@ void CmdBufferVulkan::Begin()
// Acquire a descriptor pool set on // Acquire a descriptor pool set on
if (_descriptorPoolSetContainer == nullptr) if (_descriptorPoolSetContainer == nullptr)
{ {
_descriptorPoolSetContainer = &_device->DescriptorPoolsManager->AcquirePoolSetContainer(); _descriptorPoolSetContainer = _device->DescriptorPoolsManager->AcquirePoolSetContainer();
} }
_state = State::IsInsideBegin; _state = State::IsInsideBegin;
@@ -138,7 +139,7 @@ void CmdBufferVulkan::RefreshFenceStatus()
if (_descriptorPoolSetContainer) if (_descriptorPoolSetContainer)
{ {
_device->DescriptorPoolsManager->ReleasePoolSet(*_descriptorPoolSetContainer); _descriptorPoolSetContainer->LastFrameUsed = Engine::FrameCount;
_descriptorPoolSetContainer = nullptr; _descriptorPoolSetContainer = nullptr;
} }
} }
@@ -279,6 +280,7 @@ void CmdBufferManagerVulkan::WaitForCmdBuffer(CmdBufferVulkan* cmdBuffer, float
void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer() void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer()
{ {
PROFILE_CPU(); PROFILE_CPU();
ASSERT_LOW_LAYER(_activeCmdBuffer == nullptr)
for (int32 i = 0; i < _pool._cmdBuffers.Count(); i++) for (int32 i = 0; i < _pool._cmdBuffers.Count(); i++)
{ {
auto cmdBuffer = _pool._cmdBuffers.Get()[i]; auto cmdBuffer = _pool._cmdBuffers.Get()[i];
@@ -286,8 +288,7 @@ void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer()
if (cmdBuffer->GetState() == CmdBufferVulkan::State::ReadyForBegin) if (cmdBuffer->GetState() == CmdBufferVulkan::State::ReadyForBegin)
{ {
_activeCmdBuffer = cmdBuffer; _activeCmdBuffer = cmdBuffer;
_activeCmdBuffer->Begin(); break;
return;
} }
else else
{ {
@@ -295,8 +296,12 @@ void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer()
} }
} }
// Always begin fresh command buffer for rendering if (_activeCmdBuffer == nullptr)
_activeCmdBuffer = _pool.Create(); {
// Always begin fresh command buffer for rendering
_activeCmdBuffer = _pool.Create();
}
_activeCmdBuffer->Begin(); _activeCmdBuffer->Begin();
#if VULKAN_USE_QUERIES #if VULKAN_USE_QUERIES

View File

@@ -287,7 +287,7 @@ DescriptorPoolsManagerVulkan::~DescriptorPoolsManagerVulkan()
_poolSets.ClearDelete(); _poolSets.ClearDelete();
} }
DescriptorPoolSetContainerVulkan& DescriptorPoolsManagerVulkan::AcquirePoolSetContainer() DescriptorPoolSetContainerVulkan* DescriptorPoolsManagerVulkan::AcquirePoolSetContainer()
{ {
ScopeLock lock(_locker); ScopeLock lock(_locker);
for (auto* poolSet : _poolSets) for (auto* poolSet : _poolSets)
@@ -296,17 +296,12 @@ DescriptorPoolSetContainerVulkan& DescriptorPoolsManagerVulkan::AcquirePoolSetCo
{ {
poolSet->LastFrameUsed = Engine::FrameCount; poolSet->LastFrameUsed = Engine::FrameCount;
poolSet->Reset(); poolSet->Reset();
return *poolSet; return poolSet;
} }
} }
const auto poolSet = New<DescriptorPoolSetContainerVulkan>(_device); const auto poolSet = New<DescriptorPoolSetContainerVulkan>(_device);
_poolSets.Add(poolSet); _poolSets.Add(poolSet);
return *poolSet; return poolSet;
}
void DescriptorPoolsManagerVulkan::ReleasePoolSet(DescriptorPoolSetContainerVulkan& poolSet)
{
poolSet.LastFrameUsed = Engine::FrameCount;
} }
void DescriptorPoolsManagerVulkan::GC() void DescriptorPoolsManagerVulkan::GC()

View File

@@ -222,7 +222,7 @@ public:
void Reset(); void Reset();
mutable uint64 Refs = 0; mutable uint64 Refs = 0;
mutable uint32 LastFrameUsed; mutable uint64 LastFrameUsed;
}; };
class DescriptorPoolsManagerVulkan class DescriptorPoolsManagerVulkan
@@ -236,8 +236,7 @@ public:
DescriptorPoolsManagerVulkan(GPUDeviceVulkan* device); DescriptorPoolsManagerVulkan(GPUDeviceVulkan* device);
~DescriptorPoolsManagerVulkan(); ~DescriptorPoolsManagerVulkan();
DescriptorPoolSetContainerVulkan& AcquirePoolSetContainer(); DescriptorPoolSetContainerVulkan* AcquirePoolSetContainer();
void ReleasePoolSet(DescriptorPoolSetContainerVulkan& poolSet);
void GC(); void GC();
}; };