]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/commands_backend.cpp
Rename VulkanFramebuffer::prepare_image_layouts to synchronize_resources
[libs/gl.git] / source / backends / vulkan / commands_backend.cpp
index ff9e6cf62da0ae0b851e11f572dd416cabddd968..4791122f3528ff47110618aa19996bee1a8ef9e6 100644 (file)
@@ -10,7 +10,6 @@
 #include "rect.h"
 #include "renderpass.h"
 #include "semaphore.h"
-#include "swapchaintexture.h"
 #include "vulkan.h"
 
 using namespace std;
@@ -92,12 +91,7 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value
        if(!primary_buffer)
                begin_buffer(0);
 
-       fb_is_swapchain = false;
-       unsigned n_attachments = framebuffer->get_format().size();
-       for(unsigned i=0; (!fb_is_swapchain && i<n_attachments); ++i)
-               if(dynamic_cast<const SwapChainTexture *>(framebuffer->get_attachment(i)))
-                       fb_is_swapchain = true;
-
+       fb_is_swapchain = framebuffer->is_presentable();
        framebuffer->refresh();
 
        RenderPass render_pass;
@@ -126,7 +120,7 @@ void VulkanCommands::end_render_pass()
        Synchronizer &sync = device.get_synchronizer();
        sync.reset();
        if(!fb_is_swapchain)
-               framebuffer->prepare_image_layouts(discard_fb_contents);
+               framebuffer->synchronize_resources(discard_fb_contents);
        sync.barrier(vkCmd);
 
        const VkRenderPassBeginInfo &begin_info = *reinterpret_cast<const VkRenderPassBeginInfo *>(pass_begin_info.data());
@@ -233,9 +227,29 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count)
        vkCmd.DrawIndexed(batch.size(), count, first_index, 0, 0);
 }
 
-void VulkanCommands::resolve_multisample(Framebuffer &)
+void VulkanCommands::dispatch(unsigned count_x, unsigned count_y, unsigned count_z)
 {
-       throw logic_error("VulkanCommands::resolve_multisample is unimplemented");
+       if(!pipeline_state)
+               throw invalid_operation("VulkanCommands::draw_instanced");
+
+       if(framebuffer)
+               end_render_pass();
+
+       VulkanCommandRecorder vkCmd(device.get_functions(), primary_buffer);
+
+       pipeline_state->refresh();
+       pipeline_state->synchronize_resources();
+       device.get_synchronizer().barrier(vkCmd);
+       pipeline_state->apply(vkCmd, 0, frame_index, false);
+       vkCmd.Dispatch(count_x, count_y, count_z);
+}
+
+void VulkanCommands::resolve_multisample()
+{
+       if(!framebuffer || !framebuffer->has_resolve_attachments())
+               throw invalid_operation("VulkanCommands::resolve_multisample");
+
+       end_render_pass();
 }
 
 void VulkanCommands::begin_query(const QueryPool &, unsigned)