From: Mikko Rasa Date: Fri, 19 Nov 2021 22:42:00 +0000 (+0200) Subject: Cache framebuffer and viewport in VulkanCommands X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b9b6fb7c5e59f662b011857140cea5e6be0c4309;p=libs%2Fgl.git Cache framebuffer and viewport in VulkanCommands Since PipelineState is not immutable, this is necessary to detect when they have changed. --- diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index 1634863b..1752e9da 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -58,8 +58,8 @@ void VulkanCommands::begin_buffer() void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_values) { - const Framebuffer *target = pipeline_state->get_framebuffer(); - if(!target) + framebuffer = pipeline_state->get_framebuffer(); + if(!framebuffer) throw invalid_operation("VulkanCommands::begin_render_pass"); const VulkanFunctions &vk = device.get_functions(); @@ -70,20 +70,20 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value device.get_transfer_queue().dispatch_transfers(current_buffer); bool to_present = false; - unsigned n_attachments = target->get_format().size(); + unsigned n_attachments = framebuffer->get_format().size(); for(unsigned i=0; i(target->VulkanFramebuffer::get_attachment(i))) + if(dynamic_cast(framebuffer->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); + VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, !clear_values, to_present); - target->refresh(); + framebuffer->refresh(); 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>(target->handle); + begin_info.framebuffer = handle_cast<::VkFramebuffer>(framebuffer->handle); - const Rect *viewport = pipeline_state->get_viewport(); + viewport = pipeline_state->get_viewport(); if(viewport) { begin_info.renderArea.offset.x = viewport->left; @@ -93,15 +93,15 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value } else { - begin_info.renderArea.extent.width = target->get_width(); - begin_info.renderArea.extent.height = target->get_height(); + begin_info.renderArea.extent.width = framebuffer->get_width(); + begin_info.renderArea.extent.height = framebuffer->get_height(); } VkClearValue vk_clear_values[7]; if(clear_values) { unsigned i = 0; - for(FrameAttachment a: target->get_format()) + for(FrameAttachment a: framebuffer->get_format()) { if(get_attach_point(a)==get_attach_point(DEPTH_ATTACHMENT)) vk_clear_values[i].depthStencil.depth = clear_values[i].depth_stencil.depth; @@ -117,7 +117,7 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value ++i; } - begin_info.clearValueCount = target->get_format().size(); + begin_info.clearValueCount = framebuffer->get_format().size(); begin_info.pClearValues = vk_clear_values; } @@ -129,7 +129,8 @@ void VulkanCommands::end_render_pass() const VulkanFunctions &vk = device.get_functions(); vk.CmdEndRenderPass(current_buffer); - render_pass = 0; + framebuffer = 0; + viewport = 0; } void VulkanCommands::begin_frame(unsigned index) @@ -163,7 +164,7 @@ void VulkanCommands::submit_frame(Semaphore *wait_sem, Semaphore *signal_sem) ::VkSemaphore vk_signal_sem = (signal_sem ? handle_cast<::VkSemaphore>(signal_sem->handle) : 0); VkPipelineStageFlags wait_stages = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT; - if(render_pass) + if(framebuffer) end_render_pass(); vk.EndCommandBuffer(current_buffer); @@ -185,8 +186,8 @@ void VulkanCommands::submit_frame(Semaphore *wait_sem, Semaphore *signal_sem) void VulkanCommands::use_pipeline(const PipelineState *ps) { - if(!pipeline_state || !ps || ps->get_framebuffer()!=pipeline_state->get_framebuffer() || ps->get_viewport()!=pipeline_state->get_viewport()) - if(render_pass) + if(!pipeline_state || !ps || ps->get_framebuffer()!=framebuffer || ps->get_viewport()!=viewport) + if(framebuffer) end_render_pass(); pipeline_state = ps; @@ -196,7 +197,7 @@ void VulkanCommands::use_pipeline(const PipelineState *ps) void VulkanCommands::clear(const ClearValue *values) { - if(render_pass) + if(framebuffer) throw invalid_operation("VulkanCommands::clear"); begin_render_pass(true, values); @@ -214,7 +215,7 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count) const VulkanFunctions &vk = device.get_functions(); - if(!render_pass) + if(!framebuffer) begin_render_pass(false, 0); pipeline_state->apply(current_buffer); diff --git a/source/backends/vulkan/commands_backend.h b/source/backends/vulkan/commands_backend.h index 4de712f5..b87d73e0 100644 --- a/source/backends/vulkan/commands_backend.h +++ b/source/backends/vulkan/commands_backend.h @@ -14,6 +14,7 @@ class Device; class Framebuffer; class PipelineState; class QueryPool; +struct Rect; class Semaphore; class SwapChain; @@ -37,7 +38,8 @@ protected: CommandPool *current_pool = 0; VkCommandBuffer current_buffer = 0; const PipelineState *pipeline_state = 0; - VkRenderPass render_pass = 0; + const Framebuffer *framebuffer = 0; + const Rect *viewport = 0; VulkanCommands(); ~VulkanCommands();