]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/commands_backend.cpp
Multiplex streaming buffer contents on Vulkan
[libs/gl.git] / source / backends / vulkan / commands_backend.cpp
index b7a342defb5ab741eb16f3b9c3bc06af6f8d7555..bf8ee3f13d5652c21a14db09ff1e077e016740cc 100644 (file)
@@ -31,11 +31,12 @@ VulkanCommands::~VulkanCommands()
 
 void VulkanCommands::begin_buffer(VkRenderPass render_pass)
 {
-       if(!current_pool)
+       if(frame_index>=command_pools.size())
                throw invalid_operation("VulkanCommands::begin_buffer");
 
        const VulkanFunctions &vk = device.get_functions();
 
+       CommandPool *current_pool = &command_pools[frame_index];
        if(!current_pool->in_use)
        {
                current_pool->fence.reset();
@@ -176,15 +177,15 @@ void VulkanCommands::begin_frame(unsigned index)
 {
        const VulkanFunctions &vk = device.get_functions();
 
-       unsigned pool_index = index%device.get_n_frames_in_flight();
-       if(pool_index>=command_pools.size())
+       frame_index = index%device.get_n_frames_in_flight();
+       if(frame_index>=command_pools.size())
        {
-               command_pools.reserve(pool_index+1);
-               for(unsigned i=command_pools.size(); i<pool_index+1; ++i)
+               command_pools.reserve(frame_index+1);
+               for(unsigned i=command_pools.size(); i<frame_index+1; ++i)
                        command_pools.emplace_back(device);
        }
 
-       current_pool = &command_pools[pool_index];
+       CommandPool *current_pool = &command_pools[frame_index];
        if(current_pool->in_use)
        {
                current_pool->fence.wait();
@@ -220,7 +221,7 @@ void VulkanCommands::submit_frame(Semaphore *wait_sem, Semaphore *signal_sem)
        submit_info.signalSemaphoreCount = (signal_sem ? 1 : 0);
        submit_info.pSignalSemaphores = &vk_signal_sem;
 
-       vk.QueueSubmit(1, &submit_info, current_pool->fence.handle);
+       vk.QueueSubmit(1, &submit_info, command_pools[frame_index].fence.handle);
 
        primary_buffer = 0;
 }
@@ -258,7 +259,7 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count)
                 begin_render_pass(false, 0);
 
        pipeline_state->refresh();
-       pipeline_state->apply(pass_buffer, fb_is_swapchain);
+       pipeline_state->apply(pass_buffer, frame_index, fb_is_swapchain);
        unsigned first_index = batch.get_offset()/batch.get_index_size();
        vk.CmdDrawIndexed(pass_buffer, batch.size(), count, first_index, 0, 0);
 }