From d3309dd8e9b1edcd2e4c2b9971996e4b5c20a163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 3 Sep 2022 22:04:01 +0200 Subject: [PATCH] Minor refactor with pipelines in QueueRunner (makes more information available for easier debugging) --- Common/GPU/Vulkan/VulkanQueueRunner.cpp | 53 ++++++++++++----------- Common/GPU/Vulkan/VulkanQueueRunner.h | 4 +- Common/GPU/Vulkan/VulkanRenderManager.cpp | 3 ++ Common/GPU/Vulkan/VulkanRenderManager.h | 15 +++---- GPU/Common/FramebufferManagerCommon.cpp | 5 ++- 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index 92b7fb7e83..9b7ae11ea5 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -1144,8 +1144,8 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c VKRFramebuffer *fb = step.render.framebuffer; - VkPipeline lastGraphicsPipeline = VK_NULL_HANDLE; - VkPipeline lastComputePipeline = VK_NULL_HANDLE; + VKRGraphicsPipeline *lastGraphicsPipeline = nullptr; + VKRComputePipeline *lastComputePipeline = nullptr; auto &commands = step.commands; @@ -1168,40 +1168,43 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c case VKRRenderCommand::BIND_PIPELINE: { VkPipeline pipeline = c.pipeline.pipeline; - if (pipeline != lastGraphicsPipeline) { - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - pipelineLayout = c.pipeline.pipelineLayout; - lastGraphicsPipeline = pipeline; - // Reset dynamic state so it gets refreshed with the new pipeline. - lastStencilWriteMask = -1; - lastStencilCompareMask = -1; - lastStencilReference = -1; - } + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); + pipelineLayout = c.pipeline.pipelineLayout; + // Reset dynamic state so it gets refreshed with the new pipeline. + lastStencilWriteMask = -1; + lastStencilCompareMask = -1; + lastStencilReference = -1; break; } case VKRRenderCommand::BIND_GRAPHICS_PIPELINE: { - VkPipeline pipeline = c.graphics_pipeline.pipeline->BlockUntilReady(); - if (pipeline != lastGraphicsPipeline && pipeline != VK_NULL_HANDLE) { - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - pipelineLayout = c.pipeline.pipelineLayout; - lastGraphicsPipeline = pipeline; - // Reset dynamic state so it gets refreshed with the new pipeline. - lastStencilWriteMask = -1; - lastStencilCompareMask = -1; - lastStencilReference = -1; + VKRGraphicsPipeline *graphicsPipeline = c.graphics_pipeline.pipeline; + if (graphicsPipeline != lastGraphicsPipeline) { + VkPipeline pipeline = graphicsPipeline->pipeline->BlockUntilReady(); + if (pipeline != VK_NULL_HANDLE) { + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); + pipelineLayout = c.pipeline.pipelineLayout; + lastGraphicsPipeline = graphicsPipeline; + // Reset dynamic state so it gets refreshed with the new pipeline. + lastStencilWriteMask = -1; + lastStencilCompareMask = -1; + lastStencilReference = -1; + } } break; } case VKRRenderCommand::BIND_COMPUTE_PIPELINE: { - VkPipeline pipeline = c.graphics_pipeline.pipeline->BlockUntilReady(); - if (pipeline != lastComputePipeline && pipeline != VK_NULL_HANDLE) { - vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); - pipelineLayout = c.pipeline.pipelineLayout; - lastComputePipeline = pipeline; + VKRComputePipeline *computePipeline = c.compute_pipeline.pipeline; + if (computePipeline != lastComputePipeline) { + VkPipeline pipeline = computePipeline->pipeline->BlockUntilReady(); + if (pipeline != VK_NULL_HANDLE) { + vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); + pipelineLayout = c.pipeline.pipelineLayout; + lastComputePipeline = computePipeline; + } } break; } diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.h b/Common/GPU/Vulkan/VulkanQueueRunner.h index 1d1c4efe8f..ce6dc9f5eb 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.h +++ b/Common/GPU/Vulkan/VulkanQueueRunner.h @@ -55,11 +55,11 @@ struct VkRenderData { VkPipelineLayout pipelineLayout; } pipeline; struct { - Promise *pipeline; + VKRGraphicsPipeline *pipeline; VkPipelineLayout pipelineLayout; } graphics_pipeline; struct { - Promise *pipeline; + VKRComputePipeline *pipeline; VkPipelineLayout pipelineLayout; } compute_pipeline; struct { diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 7741fb2e44..a4e14a1b8d 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -80,8 +80,11 @@ bool VKRGraphicsPipeline::Create(VulkanContext *vulkan) { pipeline->Post(vkpipeline); } + // Having the desc stick around can be useful for debugging. +#ifndef _DEBUG delete desc; desc = nullptr; +#endif return success; } diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 4b69247525..67dff36880 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -141,20 +141,19 @@ struct VKRComputePipelineDesc { VkComputePipelineCreateInfo pipe{ VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO }; }; -// Wrapped pipeline, which will later allow for background compilation while emulating the rest of the frame. +// Wrapped pipeline. struct VKRGraphicsPipeline { VKRGraphicsPipeline() { pipeline = Promise::CreateEmpty(); } + ~VKRGraphicsPipeline() { + delete desc; + } - VKRGraphicsPipelineDesc *desc = nullptr; // While non-zero, is pending and pipeline isn't valid. - + VKRGraphicsPipelineDesc *desc = nullptr; Promise *pipeline; bool Create(VulkanContext *vulkan); - bool Pending() const { - return pipeline == VK_NULL_HANDLE && desc != nullptr; - } }; struct VKRComputePipeline { @@ -263,7 +262,7 @@ public: _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER); _dbg_assert_(pipeline != nullptr); VkRenderData data{ VKRRenderCommand::BIND_GRAPHICS_PIPELINE }; - data.graphics_pipeline.pipeline = pipeline->pipeline; + data.graphics_pipeline.pipeline = pipeline; data.graphics_pipeline.pipelineLayout = pipelineLayout; curPipelineFlags_ |= flags; curRenderStep_->commands.push_back(data); @@ -273,7 +272,7 @@ public: _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER); _dbg_assert_(pipeline != nullptr); VkRenderData data{ VKRRenderCommand::BIND_COMPUTE_PIPELINE }; - data.compute_pipeline.pipeline = pipeline->pipeline; + data.compute_pipeline.pipeline = pipeline; data.compute_pipeline.pipelineLayout = pipelineLayout; curPipelineFlags_ |= flags; curRenderStep_->commands.push_back(data); diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 00f5df9b07..5a74382fb6 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -808,7 +808,8 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra } if (dst != currentRenderVfb_ && tookActions) { - draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, Draw::RPAction::KEEP }, "After FakeReinterpret"); + // Will probably just change the name of the current renderpass, since one was started by the reinterpret itself. + draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, Draw::RPAction::KEEP }, "After Reinterpret"); } shaderManager_->DirtyLastShader(); @@ -2791,7 +2792,7 @@ void FramebufferManagerCommon::BlitFramebuffer(VirtualFramebuffer *dst, int dstX draw_->InvalidateCachedState(); - gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_RASTER_STATE); + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE); } // The input is raw pixel coordinates, scale not taken into account.