From 2bc9777c3bd0c91e708504781533104ee0ca6629 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sun, 7 Apr 2024 09:48:54 -0300 Subject: [PATCH] vulkan: limit render pass layout transitions to the active mipmap/layer. --- src/modules/graphics/vulkan/Graphics.cpp | 22 +++++++++++++++------- src/modules/graphics/vulkan/Graphics.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index e8c4c6785..720435bef 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -2408,23 +2408,31 @@ void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, b FramebufferConfiguration configuration{}; - std::vector> transitionImages; + std::vector> transitionImages; for (const auto &color : rts.colors) { auto tex = (Texture*)color.texture; configuration.colorViews.push_back(tex->getRenderTargetView(color.mipmap, color.slice)); + const Texture::ViewInfo &viewinfo = tex->getRootViewInfo(); VkImageLayout imagelayout = tex->getImageLayout(); if (imagelayout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) - transitionImages.push_back({ (VkImage)tex->getHandle(), tex->getPixelFormat(), imagelayout, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }); + { + transitionImages.push_back({ (VkImage)tex->getHandle(), tex->getPixelFormat(), imagelayout, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + viewinfo.startMipmap + color.mipmap, viewinfo.startLayer + color.slice }); + } } if (rts.depthStencil.texture != nullptr) { auto tex = (Texture*)rts.depthStencil.texture; configuration.staticData.depthView = tex->getRenderTargetView(rts.depthStencil.mipmap, rts.depthStencil.slice); + const Texture::ViewInfo &viewinfo = tex->getRootViewInfo(); VkImageLayout imagelayout = tex->getImageLayout(); if (imagelayout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) - transitionImages.push_back({ (VkImage)tex->getHandle(), tex->getPixelFormat(), imagelayout, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL }); + { + transitionImages.push_back({ (VkImage)tex->getHandle(), tex->getPixelFormat(), imagelayout, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + viewinfo.startMipmap + rts.depthStencil.mipmap, viewinfo.startLayer + rts.depthStencil.slice }); + } } configuration.staticData.width = static_cast(pixelw); @@ -2475,8 +2483,8 @@ void Graphics::startRenderPass() renderPassState.framebufferConfiguration.staticData.renderPass = renderPassState.beginInfo.renderPass; renderPassState.beginInfo.framebuffer = getFramebuffer(renderPassState.framebufferConfiguration); - for (const auto &[image, format, imageLayout, renderLayout] : renderPassState.transitionImages) - Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, format, imageLayout, renderLayout); + for (const auto &[image, format, imageLayout, renderLayout, rootmip, rootlayer] : renderPassState.transitionImages) + Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, format, imageLayout, renderLayout, rootmip, 1, rootlayer, 1); vkCmdBeginRenderPass(commandBuffers.at(currentFrame), &renderPassState.beginInfo, VK_SUBPASS_CONTENTS_INLINE); } @@ -2487,8 +2495,8 @@ void Graphics::endRenderPass() vkCmdEndRenderPass(commandBuffers.at(currentFrame)); - for (const auto &[image, format, imageLayout, renderLayout] : renderPassState.transitionImages) - Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, format, renderLayout, imageLayout); + for (const auto &[image, format, imageLayout, renderLayout, rootmip, rootlayer] : renderPassState.transitionImages) + Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, format, renderLayout, imageLayout, rootmip, 1, rootlayer, 1); for (auto &colorAttachment : renderPassState.renderPassConfiguration.colorAttachments) colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index df8f80b24..8ff82d690 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -236,7 +236,7 @@ struct RenderpassState RenderPassConfiguration renderPassConfiguration{}; FramebufferConfiguration framebufferConfiguration{}; VkPipeline pipeline = VK_NULL_HANDLE; - std::vector> transitionImages; + std::vector> transitionImages; uint32_t numColorAttachments = 0; float width = 0.0f; float height = 0.0f;