Add lightmap stats to stat gpu

This commit is contained in:
Magnus Norddahl 2023-09-21 02:07:50 +02:00 committed by Christoph Oelckers
parent 0020ab5758
commit cf6f349943
4 changed files with 29 additions and 9 deletions

View file

@ -79,11 +79,15 @@ void VkLightmap::Raytrace(const TArray<LevelMeshSurface*>& surfaces)
SelectSurfaces(surfaces);
if (selectedSurfaces.Size() > 0)
{
fb->GetCommands()->PushGroup(fb->GetCommands()->GetTransferCommands(), "lightmap.total");
UploadUniforms();
RenderBakeImage();
ResolveBakeImage();
BlurBakeImage();
CopyBakeImageResult();
fb->GetCommands()->PopGroup(fb->GetCommands()->GetTransferCommands());
}
lightmapRaytrace.Unclock();
@ -129,6 +133,8 @@ void VkLightmap::RenderBakeImage()
{
auto cmdbuffer = fb->GetCommands()->GetTransferCommands();
fb->GetCommands()->PushGroup(cmdbuffer, "lightmap.raytrace");
RenderPassBegin()
.RenderPass(raytrace.renderPass.get())
.RenderArea(0, 0, bakeImageSize, bakeImageSize)
@ -241,6 +247,8 @@ void VkLightmap::RenderBakeImage()
}
cmdbuffer->endRenderPass();
fb->GetCommands()->PopGroup(cmdbuffer);
}
void VkLightmap::UploadUniforms()
@ -265,6 +273,8 @@ void VkLightmap::ResolveBakeImage()
{
auto cmdbuffer = fb->GetCommands()->GetTransferCommands();
fb->GetCommands()->PushGroup(cmdbuffer, "lightmap.resolve");
PipelineBarrier()
.AddImage(bakeImage.raytrace.Image.get(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT)
.Execute(cmdbuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
@ -287,12 +297,16 @@ void VkLightmap::ResolveBakeImage()
cmdbuffer->draw(3, 1, 0, 0);
cmdbuffer->endRenderPass();
fb->GetCommands()->PopGroup(cmdbuffer);
}
void VkLightmap::BlurBakeImage()
{
auto cmdbuffer = fb->GetCommands()->GetTransferCommands();
fb->GetCommands()->PushGroup(cmdbuffer, "lightmap.blur");
PipelineBarrier()
.AddImage(bakeImage.resolve.Image.get(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT)
.Execute(cmdbuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
@ -344,6 +358,8 @@ void VkLightmap::BlurBakeImage()
cmdbuffer->endRenderPass();
}
fb->GetCommands()->PopGroup(cmdbuffer);
}
void VkLightmap::CopyBakeImageResult()
@ -386,6 +402,8 @@ void VkLightmap::CopyBakeImageResult()
{
auto cmdbuffer = fb->GetCommands()->GetTransferCommands();
fb->GetCommands()->PushGroup(cmdbuffer, "lightmap.copy");
PipelineBarrier barrier0;
barrier0.AddImage(bakeImage.resolve.Image.get(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
for (int pageIndex : seenPages)
@ -398,6 +416,8 @@ void VkLightmap::CopyBakeImageResult()
for (int pageIndex : seenPages)
barrier1.AddImage(fb->GetTextureManager()->Lightmap.Image.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, pageIndex, 1);
barrier1.Execute(cmdbuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
fb->GetCommands()->PopGroup(cmdbuffer);
}
}

View file

@ -113,7 +113,7 @@ void VkCommandBufferManager::BeginFrame()
{
if (mNextTimestampQuery > 0)
{
GetDrawCommands()->resetQueryPool(mTimestampQueryPool.get(), 0, mNextTimestampQuery);
GetTransferCommands()->resetQueryPool(mTimestampQueryPool.get(), 0, mNextTimestampQuery);
mNextTimestampQuery = 0;
}
}
@ -234,7 +234,7 @@ void VkCommandBufferManager::DeleteFrameObjects(bool uploadOnly)
DrawDeleteList = std::make_unique<DeleteList>();
}
void VkCommandBufferManager::PushGroup(const FString& name)
void VkCommandBufferManager::PushGroup(VulkanCommandBuffer* cmdbuffer, const FString& name)
{
if (!gpuStatActive)
return;
@ -245,13 +245,13 @@ void VkCommandBufferManager::PushGroup(const FString& name)
q.name = name;
q.startIndex = mNextTimestampQuery++;
q.endIndex = 0;
GetDrawCommands()->writeTimestamp(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, mTimestampQueryPool.get(), q.startIndex);
cmdbuffer->writeTimestamp(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, mTimestampQueryPool.get(), q.startIndex);
mGroupStack.push_back(timeElapsedQueries.size());
timeElapsedQueries.push_back(q);
}
}
void VkCommandBufferManager::PopGroup()
void VkCommandBufferManager::PopGroup(VulkanCommandBuffer* cmdbuffer)
{
if (!gpuStatActive || mGroupStack.empty())
return;
@ -262,7 +262,7 @@ void VkCommandBufferManager::PopGroup()
if (mNextTimestampQuery < MaxTimestampQueries && fb->GetDevice()->GraphicsTimeQueries)
{
q.endIndex = mNextTimestampQuery++;
GetDrawCommands()->writeTimestamp(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, mTimestampQueryPool.get(), q.endIndex);
cmdbuffer->writeTimestamp(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, mTimestampQueryPool.get(), q.endIndex);
}
}

View file

@ -25,8 +25,8 @@ public:
void WaitForCommands(bool finish) { WaitForCommands(finish, false); }
void WaitForCommands(bool finish, bool uploadOnly);
void PushGroup(const FString& name);
void PopGroup();
void PushGroup(VulkanCommandBuffer* cmdbuffer, const FString& name);
void PopGroup(VulkanCommandBuffer* cmdbuffer);
void UpdateGpuStats();
class DeleteList

View file

@ -43,12 +43,12 @@ VkPPRenderState::VkPPRenderState(VulkanRenderDevice* fb) : fb(fb)
void VkPPRenderState::PushGroup(const FString &name)
{
fb->GetCommands()->PushGroup(name);
fb->GetCommands()->PushGroup(fb->GetCommands()->GetDrawCommands(), name);
}
void VkPPRenderState::PopGroup()
{
fb->GetCommands()->PopGroup();
fb->GetCommands()->PopGroup(fb->GetCommands()->GetDrawCommands());
}
void VkPPRenderState::Draw()