diff --git a/Source/Engine/Graphics/RenderTargetPool.cpp b/Source/Engine/Graphics/RenderTargetPool.cpp index 891610ab8..6f9507d33 100644 --- a/Source/Engine/Graphics/RenderTargetPool.cpp +++ b/Source/Engine/Graphics/RenderTargetPool.cpp @@ -4,6 +4,7 @@ #include "GPUDevice.h" #include "Engine/Core/Log.h" #include "Engine/Engine/Engine.h" +#include "Engine/Profiler/ProfilerCPU.h" struct Entry { @@ -20,9 +21,11 @@ namespace void RenderTargetPool::Flush(bool force, int32 framesOffset) { + PROFILE_CPU(); if (framesOffset < 0) framesOffset = 3 * 60; // For how many frames RTs should be cached (by default) - const uint64 maxReleaseFrame = Engine::FrameCount - framesOffset; + const uint64 frameCount = Engine::FrameCount; + const uint64 maxReleaseFrame = frameCount - Math::Min(frameCount, framesOffset); force |= Engine::ShouldExit(); for (int32 i = 0; i < TemporaryRTs.Count(); i++) @@ -40,6 +43,8 @@ void RenderTargetPool::Flush(bool force, int32 framesOffset) GPUTexture* RenderTargetPool::Get(const GPUTextureDescription& desc) { + PROFILE_CPU(); + // Find free render target with the same properties const uint32 descHash = GetHash(desc); for (int32 i = 0; i < TemporaryRTs.Count(); i++) @@ -85,7 +90,6 @@ void RenderTargetPool::Release(GPUTexture* rt) { if (!rt) return; - for (int32 i = 0; i < TemporaryRTs.Count(); i++) { auto& e = TemporaryRTs[i]; @@ -98,6 +102,5 @@ void RenderTargetPool::Release(GPUTexture* rt) return; } } - LOG(Error, "Trying to release temporary render target which has not been registered in service!"); } diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp index 9c553060f..19578df89 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.cpp @@ -356,14 +356,12 @@ DeferredDeletionQueueVulkan::~DeferredDeletionQueueVulkan() void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) { - ScopeLock lock(_locker); const uint64 checkFrame = Engine::FrameCount - VULKAN_RESOURCE_DELETE_SAFE_FRAMES_COUNT; + ScopeLock lock(_locker); for (int32 i = 0; i < _entries.Count(); i++) { - Entry* e = &_entries[i]; - - if (deleteImmediately || (checkFrame > e->FrameNumber && (e->CmdBuffer == nullptr || e->FenceCounter < e->CmdBuffer->GetFenceSignaledCounter())) - ) + Entry* e = &_entries.Get()[i]; + if (deleteImmediately || (checkFrame > e->FrameNumber && (e->CmdBuffer == nullptr || e->FenceCounter < e->CmdBuffer->GetFenceSignaledCounter()))) { if (e->AllocationHandle == VK_NULL_HANDLE) { @@ -402,14 +400,15 @@ void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) { vmaDestroyBuffer(_device->Allocator, (VkBuffer)e->Handle, e->AllocationHandle); } +#if !BUILD_RELEASE else { CRASH; } +#endif } _entries.RemoveAt(i--); - if (_entries.IsEmpty()) break; } @@ -418,19 +417,17 @@ void DeferredDeletionQueueVulkan::ReleaseResources(bool deleteImmediately) void DeferredDeletionQueueVulkan::EnqueueGenericResource(Type type, uint64 handle, VmaAllocation allocation) { - ASSERT(handle != 0); - const auto queue = _device->GraphicsQueue; + ASSERT_LOW_LAYER(handle != 0); Entry entry; - queue->GetLastSubmittedInfo(entry.CmdBuffer, entry.FenceCounter); + _device->GraphicsQueue->GetLastSubmittedInfo(entry.CmdBuffer, entry.FenceCounter); entry.Handle = handle; entry.AllocationHandle = allocation; entry.StructureType = type; entry.FrameNumber = Engine::FrameCount; ScopeLock lock(_locker); - -#if BUILD_DEBUG +#if BUILD_DEBUG && 0 const Function ContainsHandle = [handle](const Entry& e) { return e.Handle == handle; diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h index d1195c5db..3daefa1f3 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUDeviceVulkan.h @@ -63,19 +63,15 @@ class FenceVulkan friend FenceManagerVulkan; private: - VkFence _handle; bool _signaled; FenceManagerVulkan* _owner; public: - FenceVulkan(GPUDeviceVulkan* device, FenceManagerVulkan* owner, bool createSignaled); - ~FenceVulkan(); public: - inline VkFence GetHandle() const { return _handle; @@ -220,7 +216,7 @@ public: EnqueueGenericResource(type, (uint64)handle, allocation); } - auto ReleaseResources(bool deleteImmediately = false) -> void; + void ReleaseResources(bool deleteImmediately = false); private: @@ -629,11 +625,9 @@ public: // Try to use pool with available space inside for (int32 i = 0; i < pools.Count(); i++) { - auto pool = pools[i]; + auto pool = pools.Get()[i]; if (pool->HasRoom()) - { return pool; - } } // Create new pool