Add more profier events to Vulkan backed

This commit is contained in:
Wojtek Figat
2024-01-30 18:45:34 +01:00
parent fa58b171ec
commit 7fd6c43f84
7 changed files with 22 additions and 24 deletions

View File

@@ -6,8 +6,11 @@
#include "RenderToolsVulkan.h"
#include "QueueVulkan.h"
#include "GPUContextVulkan.h"
#if VULKAN_USE_QUERIES
#include "GPUTimerQueryVulkan.h"
#endif
#include "DescriptorSetVulkan.h"
#include "Engine/Profiler/ProfilerCPU.h"
void CmdBufferVulkan::AddWaitSemaphore(VkPipelineStageFlags waitFlags, SemaphoreVulkan* waitSemaphore)
{
@@ -18,6 +21,7 @@ void CmdBufferVulkan::AddWaitSemaphore(VkPipelineStageFlags waitFlags, Semaphore
void CmdBufferVulkan::Begin()
{
PROFILE_CPU();
ASSERT(_state == State::ReadyForBegin);
VkCommandBufferBeginInfo beginInfo;
@@ -41,6 +45,7 @@ void CmdBufferVulkan::Begin()
void CmdBufferVulkan::End()
{
PROFILE_CPU();
ASSERT(IsOutsideRenderPass());
#if GPU_ALLOW_PROFILE_EVENTS && VK_EXT_debug_utils
@@ -242,13 +247,13 @@ CmdBufferManagerVulkan::CmdBufferManagerVulkan(GPUDeviceVulkan* device, GPUConte
void CmdBufferManagerVulkan::SubmitActiveCmdBuffer(SemaphoreVulkan* signalSemaphore)
{
PROFILE_CPU();
ASSERT(_activeCmdBuffer);
if (!_activeCmdBuffer->IsSubmitted() && _activeCmdBuffer->HasBegun())
{
if (_activeCmdBuffer->IsInsideRenderPass())
_activeCmdBuffer->EndRenderPass();
#if VULKAN_USE_QUERIES
// Pause all active queries
for (int32 i = 0; i < _queriesInProgress.Count(); i++)
@@ -268,12 +273,12 @@ void CmdBufferManagerVulkan::SubmitActiveCmdBuffer(SemaphoreVulkan* signalSemaph
_queue->Submit(_activeCmdBuffer);
}
}
_activeCmdBuffer = nullptr;
}
void CmdBufferManagerVulkan::WaitForCmdBuffer(CmdBufferVulkan* cmdBuffer, float timeInSecondsToWait)
{
PROFILE_CPU();
ASSERT(cmdBuffer->IsSubmitted());
const bool failed = _device->FenceManager.WaitForFence(cmdBuffer->GetFence(), (uint64)(timeInSecondsToWait * 1e9));
ASSERT(!failed);
@@ -282,6 +287,7 @@ void CmdBufferManagerVulkan::WaitForCmdBuffer(CmdBufferVulkan* cmdBuffer, float
void CmdBufferManagerVulkan::PrepareForNewActiveCommandBuffer()
{
PROFILE_CPU();
for (int32 i = 0; i < _pool._cmdBuffers.Count(); i++)
{
auto cmdBuffer = _pool._cmdBuffers[i];

View File

@@ -199,7 +199,7 @@ public:
return _queriesInProgress.Count() != 0;
}
CmdBufferVulkan* GetCmdBuffer()
FORCE_INLINE CmdBufferVulkan* GetCmdBuffer()
{
if (!_activeCmdBuffer)
PrepareForNewActiveCommandBuffer();

View File

@@ -312,7 +312,6 @@ DescriptorPoolsManagerVulkan::~DescriptorPoolsManagerVulkan()
DescriptorPoolSetContainerVulkan& DescriptorPoolsManagerVulkan::AcquirePoolSetContainer()
{
ScopeLock lock(_locker);
for (auto* poolSet : _poolSets)
{
if (poolSet->IsUnused())
@@ -322,7 +321,6 @@ DescriptorPoolSetContainerVulkan& DescriptorPoolsManagerVulkan::AcquirePoolSetCo
return *poolSet;
}
}
const auto poolSet = New<DescriptorPoolSetContainerVulkan>(_device);
_poolSets.Add(poolSet);
return *poolSet;

View File

@@ -126,12 +126,12 @@ public:
~GPUContextVulkan();
public:
QueueVulkan* GetQueue() const
FORCE_INLINE QueueVulkan* GetQueue() const
{
return _queue;
}
CmdBufferManagerVulkan* GetCmdBufferManager() const
FORCE_INLINE CmdBufferManagerVulkan* GetCmdBufferManager() const
{
return _cmdBufferManager;
}

View File

@@ -2020,6 +2020,7 @@ void GPUDeviceVulkan::WaitForGPU()
{
if (Device != VK_NULL_HANDLE)
{
PROFILE_CPU();
VALIDATE_VULKAN_RESULT(vkDeviceWaitIdle(Device));
}
}

View File

@@ -11,6 +11,7 @@
#include "Engine/Core/Log.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Scripting/Enums.h"
#include "Engine/Profiler/ProfilerCPU.h"
void BackBufferVulkan::Setup(GPUSwapChainVulkan* window, VkImage backbuffer, PixelFormat format, VkExtent3D extent)
{
@@ -103,6 +104,7 @@ GPUTextureView* GPUSwapChainVulkan::GetBackBufferView()
{
if (_acquiredImageIndex == -1)
{
PROFILE_CPU();
if (TryPresent(DoAcquireImageIndex) < 0)
{
LOG(Fatal, "Swapchain acquire image index failed!");
@@ -125,7 +127,6 @@ GPUTextureView* GPUSwapChainVulkan::GetBackBufferView()
cmdBufferManager->PrepareForNewActiveCommandBuffer();
ASSERT(cmdBufferManager->HasPendingActiveCmdBuffer() && cmdBufferManager->GetActiveCmdBuffer()->GetState() == CmdBufferVulkan::State::IsInsideBegin);
}
return &_backBuffers[_acquiredImageIndex].Handle;
}
@@ -174,7 +175,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
auto windowHandle = _window->GetNativePtr();
if (!windowHandle)
return false;
PROFILE_CPU();
GPUDeviceLock lock(_device);
const auto device = _device->Device;
@@ -411,9 +412,7 @@ bool GPUSwapChainVulkan::CreateSwapChain(int32 width, int32 height)
GPUSwapChainVulkan::Status GPUSwapChainVulkan::Present(QueueVulkan* presentQueue, SemaphoreVulkan* backBufferRenderingDoneSemaphore)
{
if (_currentImageIndex == -1)
{
return Status::Ok;
}
VkPresentInfoKHR presentInfo;
RenderToolsVulkan::ZeroStruct(presentInfo, VK_STRUCTURE_TYPE_PRESENT_INFO_KHR);
@@ -429,7 +428,6 @@ GPUSwapChainVulkan::Status GPUSwapChainVulkan::Present(QueueVulkan* presentQueue
presentInfo.pImageIndices = (uint32*)&_currentImageIndex;
const VkResult presentResult = vkQueuePresentKHR(presentQueue->GetHandle(), &presentInfo);
if (presentResult == VK_ERROR_OUT_OF_DATE_KHR)
{
return Status::Outdated;
@@ -450,7 +448,7 @@ GPUSwapChainVulkan::Status GPUSwapChainVulkan::Present(QueueVulkan* presentQueue
int32 GPUSwapChainVulkan::DoAcquireImageIndex(GPUSwapChainVulkan* viewport, void* customData)
{
return viewport->_acquiredImageIndex = viewport->AcquireNextImage(&viewport->_acquiredSemaphore);
return viewport->_acquiredImageIndex = viewport->AcquireNextImage(viewport->_acquiredSemaphore);
}
int32 GPUSwapChainVulkan::DoPresent(GPUSwapChainVulkan* viewport, void* customData)
@@ -462,7 +460,6 @@ int32 GPUSwapChainVulkan::TryPresent(Function<int32(GPUSwapChainVulkan*, void*)>
{
int32 attemptsPending = 4;
int32 status = job(this, customData);
while (status < 0 && attemptsPending > 0)
{
if (status == (int32)Status::Outdated)
@@ -491,18 +488,17 @@ int32 GPUSwapChainVulkan::TryPresent(Function<int32(GPUSwapChainVulkan*, void*)>
_device->WaitForGPU();
status = job(this, customData);
attemptsPending--;
}
return status;
}
int32 GPUSwapChainVulkan::AcquireNextImage(SemaphoreVulkan** outSemaphore)
int32 GPUSwapChainVulkan::AcquireNextImage(SemaphoreVulkan*& outSemaphore)
{
PROFILE_CPU();
ASSERT(_swapChain && _backBuffers.HasItems());
uint32 imageIndex = 0;
uint32 imageIndex = _currentImageIndex;
const int32 prevSemaphoreIndex = _semaphoreIndex;
_semaphoreIndex = (_semaphoreIndex + 1) % _backBuffers.Count();
const auto semaphore = _backBuffers[_semaphoreIndex].ImageAcquiredSemaphore;
@@ -514,21 +510,17 @@ int32 GPUSwapChainVulkan::AcquireNextImage(SemaphoreVulkan** outSemaphore)
semaphore->GetHandle(),
VK_NULL_HANDLE,
&imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR)
{
_semaphoreIndex = prevSemaphoreIndex;
return (int32)Status::Outdated;
}
if (result == VK_ERROR_SURFACE_LOST_KHR)
{
_semaphoreIndex = prevSemaphoreIndex;
return (int32)Status::LostSurface;
}
*outSemaphore = semaphore;
outSemaphore = semaphore;
if (result == VK_ERROR_VALIDATION_FAILED_EXT)
{
LOG(Fatal, "vkAcquireNextImageKHR failed with validation error");
@@ -549,6 +541,7 @@ void GPUSwapChainVulkan::Present(bool vsync)
// Skip if there was no rendering to the backbuffer
if (_acquiredImageIndex == -1)
return;
PROFILE_CPU();
// Ensure that backbuffer has been acquired before presenting it to the window
const auto backBuffer = (GPUTextureViewVulkan*)GetBackBufferView();

View File

@@ -98,7 +98,7 @@ public:
static int32 DoAcquireImageIndex(GPUSwapChainVulkan* viewport, void* customData);
static int32 DoPresent(GPUSwapChainVulkan* viewport, void* customData);
int32 TryPresent(Function<int32(GPUSwapChainVulkan*, void*)> job, void* customData = nullptr, bool skipOnOutOfDate = false);
int32 AcquireNextImage(SemaphoreVulkan** outSemaphore);
int32 AcquireNextImage(SemaphoreVulkan*& outSemaphore);
private:
void ReleaseBackBuffer();