]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/commands_backend.cpp
Check if render target is swapchain and set to_present accordingly
[libs/gl.git] / source / backends / vulkan / commands_backend.cpp
index 0134474b932d060e6a97eb8a4bd6d97f1fb0eadb..1634863b49e227057ccf3ceb29435600dcb00704 100644 (file)
@@ -9,6 +9,7 @@
 #include "pipelinestate.h"
 #include "rect.h"
 #include "semaphore.h"
+#include "swapchaintexture.h"
 #include "vulkan.h"
 
 using namespace std;
@@ -55,7 +56,7 @@ void VulkanCommands::begin_buffer()
        vk.BeginCommandBuffer(current_buffer, begin_info);
 }
 
-void VulkanCommands::begin_render_pass(const ClearValue *clear_values)
+void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_values)
 {
        const Framebuffer *target = pipeline_state->get_framebuffer();
        if(!target)
@@ -68,8 +69,12 @@ void VulkanCommands::begin_render_pass(const ClearValue *clear_values)
 
        device.get_transfer_queue().dispatch_transfers(current_buffer);
 
-       // TODO Use proper value for to_present
-       render_pass = device.get_pipeline_cache().get_render_pass(target->get_format(), clear_values, true);
+       bool to_present = false;
+       unsigned n_attachments = target->get_format().size();
+       for(unsigned i=0; i<n_attachments; ++i)
+               if(dynamic_cast<const SwapChainTexture *>(target->VulkanFramebuffer::get_attachment(i)))
+                       to_present = true;
+       VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(target->get_format(), clear, !clear_values, to_present);
 
        target->refresh();
 
@@ -194,7 +199,7 @@ void VulkanCommands::clear(const ClearValue *values)
        if(render_pass)
                throw invalid_operation("VulkanCommands::clear");
 
-       begin_render_pass(values);
+       begin_render_pass(true, values);
 }
 
 void VulkanCommands::draw(const Batch &batch)
@@ -210,7 +215,7 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count)
        const VulkanFunctions &vk = device.get_functions();
 
        if(!render_pass)
-                begin_render_pass(0);
+                begin_render_pass(false, 0);
 
        pipeline_state->apply(current_buffer);
        unsigned first_index = batch.get_offset()/batch.get_index_size();