From d98d835a6359844efcbc13b18ea6c93ace117359 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 12 Dec 2021 11:49:19 +0200 Subject: [PATCH] Discard render target contents only if the entire mip level is used --- source/backends/vulkan/commands_backend.cpp | 7 ++++--- source/backends/vulkan/framebuffer_backend.cpp | 2 +- source/backends/vulkan/pipelinecache.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index d55a4dfd..8243b58f 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -69,6 +69,8 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value if(!framebuffer) throw invalid_operation("VulkanCommands::begin_render_pass"); + viewport = pipeline_state->get_viewport(); + const VulkanFunctions &vk = device.get_functions(); if(!current_buffer) @@ -85,8 +87,8 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value if(dynamic_cast(framebuffer->get_attachment(i))) to_present = true; if(!to_present) - framebuffer->prepare_image_layouts(clear); - VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, !clear_values, to_present); + framebuffer->prepare_image_layouts(clear && !viewport); + VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, (!clear_values && !viewport), to_present); framebuffer->refresh(); @@ -97,7 +99,6 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value begin_info.renderPass = handle_cast<::VkRenderPass>(render_pass); begin_info.framebuffer = handle_cast<::VkFramebuffer>(framebuffer->handle); - viewport = pipeline_state->get_viewport(); if(viewport) { begin_info.renderArea.offset.x = viewport->left; diff --git a/source/backends/vulkan/framebuffer_backend.cpp b/source/backends/vulkan/framebuffer_backend.cpp index 16894a58..48b25f2a 100644 --- a/source/backends/vulkan/framebuffer_backend.cpp +++ b/source/backends/vulkan/framebuffer_backend.cpp @@ -131,7 +131,7 @@ void VulkanFramebuffer::update(unsigned mask) const void VulkanFramebuffer::prepare_image_layouts(bool discard) const { for(const Framebuffer::Attachment &a: static_cast(this)->attachments) - a.tex->change_layout(a.level, get_vulkan_attachment_layout(get_components(a.tex->get_format())), discard); + a.tex->change_layout(a.level, get_vulkan_attachment_layout(get_components(a.tex->get_format())), (discard && a.layer<0)); } void VulkanFramebuffer::set_debug_name(const string &name) diff --git a/source/backends/vulkan/pipelinecache.cpp b/source/backends/vulkan/pipelinecache.cpp index 8cc447ae..1568e643 100644 --- a/source/backends/vulkan/pipelinecache.cpp +++ b/source/backends/vulkan/pipelinecache.cpp @@ -76,7 +76,7 @@ VkRenderPass PipelineCache::get_render_pass(const FrameFormat &format, bool clea attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; - attachments[i].initialLayout = (clear ? VK_IMAGE_LAYOUT_UNDEFINED : external_layout); + attachments[i].initialLayout = ((clear && discard) ? VK_IMAGE_LAYOUT_UNDEFINED : external_layout); attachments[i].finalLayout = external_layout; if(subpass_layout==VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) -- 2.45.2