]> git.tdb.fi Git - libs/gl.git/commitdiff
Discard render target contents only if the entire mip level is used
authorMikko Rasa <tdb@tdb.fi>
Sun, 12 Dec 2021 09:49:19 +0000 (11:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 12 Dec 2021 09:49:19 +0000 (11:49 +0200)
source/backends/vulkan/commands_backend.cpp
source/backends/vulkan/framebuffer_backend.cpp
source/backends/vulkan/pipelinecache.cpp

index d55a4dfdbad3095bc253f57820f9bfa37a10c775..8243b58fe1ba66849b10a2cf2d94538f5d4450a8 100644 (file)
@@ -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<const SwapChainTexture *>(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;
index 16894a58369f8639bfcc15260505d50a7ab8b8cf..48b25f2ac456dec0e1816308cd16ac2916839804 100644 (file)
@@ -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<const Framebuffer *>(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)
index 8cc447aedbf91c2bf8f68cb302483637d2aaaa8a..1568e6431c9716bff03569417548db7849130c86 100644 (file)
@@ -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)