From a08464eb77a478f4b2bfa1c5558d3bf9be91298b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 16 Mar 2018 14:57:41 +0100 Subject: [PATCH] Vulkan: Also check for empty clearing renderpasses later in the frame. --- ext/native/thin3d/VulkanQueueRunner.cpp | 53 ++++++++++++++----------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/ext/native/thin3d/VulkanQueueRunner.cpp b/ext/native/thin3d/VulkanQueueRunner.cpp index fdeafcd6b2..2e4fd93f7d 100644 --- a/ext/native/thin3d/VulkanQueueRunner.cpp +++ b/ext/native/thin3d/VulkanQueueRunner.cpp @@ -260,30 +260,37 @@ void VulkanQueueRunner::RunSteps(VkCommandBuffer cmd, const std::vector 1 && steps[0]->stepType == VKRStepType::RENDER && - steps[0]->render.numDraws == 0 && - steps[0]->render.color == VKRRenderPassAction::CLEAR && - steps[0]->render.stencil == VKRRenderPassAction::CLEAR && - steps[0]->render.depth == VKRRenderPassAction::CLEAR) { - // Drop the first step, and merge it into the next step that touches the same framebuffer. - for (size_t i = 1; i < steps.size(); i++) { - if (steps[i]->stepType == VKRStepType::RENDER && - steps[i]->render.framebuffer == steps[0]->render.framebuffer) { - if (steps[i]->render.color != VKRRenderPassAction::CLEAR) { - steps[i]->render.color = VKRRenderPassAction::CLEAR; - steps[i]->render.clearColor = steps[0]->render.clearColor; + for (int j = 0; j < (int)steps.size() - 1; j++) { + if (steps.size() > 1 && steps[j]->stepType == VKRStepType::RENDER && + steps[j]->render.numDraws == 0 && + steps[j]->render.color == VKRRenderPassAction::CLEAR && + steps[j]->render.stencil == VKRRenderPassAction::CLEAR && + steps[j]->render.depth == VKRRenderPassAction::CLEAR) { + + //if (j != 0) + // __debugbreak(); + + // Drop the first step, and merge it into the next step that touches the same framebuffer. + for (size_t i = j + 1; i < steps.size(); i++) { + if (steps[i]->stepType == VKRStepType::RENDER && + steps[i]->render.framebuffer == steps[j]->render.framebuffer) { + if (steps[i]->render.color != VKRRenderPassAction::CLEAR) { + steps[i]->render.color = VKRRenderPassAction::CLEAR; + steps[i]->render.clearColor = steps[j]->render.clearColor; + } + if (steps[i]->render.depth != VKRRenderPassAction::CLEAR) { + steps[i]->render.depth = VKRRenderPassAction::CLEAR; + steps[i]->render.clearDepth = steps[j]->render.clearDepth; + } + if (steps[i]->render.stencil != VKRRenderPassAction::CLEAR) { + steps[i]->render.stencil = VKRRenderPassAction::CLEAR; + steps[i]->render.clearStencil = steps[j]->render.clearStencil; + } + // Cheaply skip the first step. + steps[j]->stepType = VKRStepType::RENDER_SKIP; + ILOG("Avoided a lone clear at step %d, merged it with step %d", (int)j, (int)i); + break; } - if (steps[i]->render.depth != VKRRenderPassAction::CLEAR) { - steps[i]->render.depth = VKRRenderPassAction::CLEAR; - steps[i]->render.clearDepth = steps[0]->render.clearDepth; - } - if (steps[i]->render.stencil != VKRRenderPassAction::CLEAR) { - steps[i]->render.stencil = VKRRenderPassAction::CLEAR; - steps[i]->render.clearStencil = steps[0]->render.clearStencil; - } - // Cheaply skip the first step. - steps[0]->stepType = VKRStepType::RENDER_SKIP; - break; } } }