X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fcommands_backend.cpp;h=777d1a6b8b3a17a7ca882c2e9f0a4ea5f82433bf;hb=1b4d387b74b2108f3926796d8115bee134fbf7f1;hp=d655134d032fdf95cf05fe6a5d7941868cd2c341;hpb=016f0f0dd51511f98d0bf398d99199d7dec1543c;p=libs%2Fgl.git diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index d655134d..777d1a6b 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -36,20 +36,20 @@ void VulkanCommands::begin_buffer(VkRenderPass render_pass) const VulkanFunctions &vk = device.get_functions(); - CommandPool *current_pool = &command_pools[frame_index]; - if(!current_pool->in_use) + CommandPool ¤t_pool = command_pools[frame_index]; + if(!current_pool.in_use) { - current_pool->fence.reset(); - current_pool->in_use = true; + current_pool.fence.reset(); + current_pool.in_use = true; } - CommandBuffers &buffers = (render_pass ? current_pool->secondary : current_pool->primary); + CommandBuffers &buffers = (render_pass ? current_pool.secondary : current_pool.primary); if(buffers.next_buffer>=buffers.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.commandPool = handle_cast<::VkCommandPool>(current_pool.pool); alloc_info.level = (render_pass ? VK_COMMAND_BUFFER_LEVEL_SECONDARY : VK_COMMAND_BUFFER_LEVEL_PRIMARY); alloc_info.commandBufferCount = 1; @@ -78,6 +78,7 @@ void VulkanCommands::begin_buffer(VkRenderPass render_pass) } vk.BeginCommandBuffer(buffer, begin_info); + last_pipeline = 0; } void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_values) @@ -109,8 +110,8 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value begin_buffer(render_pass); StructureBuilder sb(pass_begin_info, 2); - VkRenderPassBeginInfo *&begin_info = sb.add(1); - VkClearValue *&vk_clear_values = sb.add(FrameFormat::MAX_ATTACHMENTS); + VkRenderPassBeginInfo *const &begin_info = sb.add(1); + VkClearValue *const &vk_clear_values = sb.add(FrameFormat::MAX_ATTACHMENTS); begin_info->sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; begin_info->renderPass = handle_cast<::VkRenderPass>(render_pass); @@ -148,21 +149,22 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value void VulkanCommands::end_render_pass() { const VulkanFunctions &vk = device.get_functions(); + VulkanCommandRecorder vkCmd(vk, primary_buffer); vk.EndCommandBuffer(pass_buffer); - device.get_transfer_queue().dispatch_transfers(primary_buffer); + device.get_transfer_queue().dispatch_transfers(vkCmd); Synchronizer &sync = device.get_synchronizer(); sync.reset(); if(!fb_is_swapchain) framebuffer->prepare_image_layouts(discard_fb_contents); - sync.barrier(primary_buffer); + sync.barrier(vkCmd); const VkRenderPassBeginInfo &begin_info = *reinterpret_cast(pass_begin_info.data()); - vk.CmdBeginRenderPass(primary_buffer, begin_info, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); - vk.CmdExecuteCommands(primary_buffer, 1, &pass_buffer); - vk.CmdEndRenderPass(primary_buffer); + vkCmd.BeginRenderPass(begin_info, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); + vkCmd.ExecuteCommands(1, &pass_buffer); + vkCmd.EndRenderPass(); framebuffer = 0; viewport = Rect::max(); @@ -181,15 +183,17 @@ void VulkanCommands::begin_frame(unsigned index) command_pools.emplace_back(device); } - CommandPool *current_pool = &command_pools[frame_index]; - if(current_pool->in_use) + CommandPool ¤t_pool = command_pools[frame_index]; + if(current_pool.in_use) { - current_pool->fence.wait(); - vk.ResetCommandPool(current_pool->pool, 0); - current_pool->in_use = false; - current_pool->primary.next_buffer = 0; - current_pool->secondary.next_buffer = 0; + current_pool.fence.wait(); + vk.ResetCommandPool(current_pool.pool, 0); + current_pool.in_use = false; + current_pool.primary.next_buffer = 0; + current_pool.secondary.next_buffer = 0; } + + device.get_descriptor_pool().begin_frame(); } void VulkanCommands::submit_frame(Semaphore *wait_sem, Semaphore *signal_sem) @@ -249,15 +253,16 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count) if(!pipeline_state) throw invalid_operation("VulkanCommands::draw_instanced"); - const VulkanFunctions &vk = device.get_functions(); - if(!framebuffer) begin_render_pass(false, 0); + VulkanCommandRecorder vkCmd(device.get_functions(), pass_buffer); + pipeline_state->refresh(); - pipeline_state->apply(pass_buffer, frame_index, fb_is_swapchain); + pipeline_state->apply(vkCmd, last_pipeline, frame_index, fb_is_swapchain); + last_pipeline = pipeline_state; unsigned first_index = batch.get_offset()/batch.get_index_size(); - vk.CmdDrawIndexed(pass_buffer, batch.size(), count, first_index, 0, 0); + vkCmd.DrawIndexed(batch.size(), count, first_index, 0, 0); } void VulkanCommands::resolve_multisample(Framebuffer &)