X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fcommands_backend.cpp;h=643710d5aefeb103d7e3380f5c9f50423ce4ed4f;hb=9ccf2b0f97cc6c39571a15c82a3f00bcbee748ba;hp=1752e9dad68cf37422ab4dfdc07c0d23f708cfc1;hpb=b9b6fb7c5e59f662b011857140cea5e6be0c4309;p=libs%2Fgl.git diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index 1752e9da..643710d5 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -41,13 +41,20 @@ void VulkanCommands::begin_buffer() current_pool->in_use = true; } - VkCommandBufferAllocateInfo alloc_info = { }; - alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - alloc_info.commandPool = handle_cast<::VkCommandPool>(current_pool->pool); - alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - alloc_info.commandBufferCount = 1; + if(current_pool->next_buffer>=current_pool->buffers.size()) + { + VkCommandBufferAllocateInfo alloc_info = { }; + alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + alloc_info.commandPool = handle_cast<::VkCommandPool>(current_pool->pool); + alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + alloc_info.commandBufferCount = 1; + + VkCommandBuffer buffer; + vk.AllocateCommandBuffers(alloc_info, &buffer); + current_pool->buffers.push_back(buffer); + } - vk.AllocateCommandBuffers(alloc_info, ¤t_buffer); + current_buffer = current_pool->buffers[current_pool->next_buffer++]; VkCommandBufferBeginInfo begin_info = { }; begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; @@ -62,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) @@ -69,25 +78,31 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value device.get_transfer_queue().dispatch_transfers(current_buffer); + Synchronizer &sync = device.get_synchronizer(); + sync.reset(); + bool to_present = false; unsigned n_attachments = framebuffer->get_format().size(); for(unsigned i=0; i(framebuffer->VulkanFramebuffer::get_attachment(i))) + if(dynamic_cast(framebuffer->get_attachment(i))) to_present = true; - VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, !clear_values, to_present); + if(!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(); + sync.barrier(current_buffer); + VkRenderPassBeginInfo begin_info = { }; begin_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; 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; - begin_info.renderArea.offset.y = viewport->bottom; + begin_info.renderArea.offset.y = framebuffer->get_height()-(viewport->bottom+viewport->height); begin_info.renderArea.extent.width = viewport->width; begin_info.renderArea.extent.height = viewport->height; } @@ -151,6 +166,7 @@ void VulkanCommands::begin_frame(unsigned index) current_pool->fence.wait(); vk.ResetCommandPool(current_pool->pool, 0); current_pool->in_use = false; + current_pool->next_buffer = 0; } } @@ -191,8 +207,6 @@ void VulkanCommands::use_pipeline(const PipelineState *ps) end_render_pass(); pipeline_state = ps; - if(pipeline_state) - pipeline_state->refresh(); } void VulkanCommands::clear(const ClearValue *values) @@ -218,6 +232,7 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count) if(!framebuffer) begin_render_pass(false, 0); + pipeline_state->refresh(); pipeline_state->apply(current_buffer); unsigned first_index = batch.get_offset()/batch.get_index_size(); vk.CmdDrawIndexed(current_buffer, batch.size(), count, first_index, 0, 0);