From c9ec1f77272de8a828294d2348c4cb1d4577612c Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sat, 21 Oct 2023 11:56:37 -0300 Subject: [PATCH] Fix buffer updates going to the wrong cmd buffer if barriers were 0 From what I could see only SSAO & SSIL were affected when they both call: int zero[1] = { 0 }; RD::get_singleton()->buffer_update(ssao.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0); int zero[1] = { 0 }; RD::get_singleton()->buffer_update(ssil.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0); Also documented what setup_command_buffer & draw_command_buffer are for. --- drivers/vulkan/rendering_device_vulkan.cpp | 2 +- drivers/vulkan/rendering_device_vulkan.h | 9 +++++++-- servers/rendering/renderer_rd/effects/ss_effects.cpp | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index a9f77c9072c4..a54e5a80597c 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -5995,7 +5995,7 @@ Error RenderingDeviceVulkan::buffer_update(RID p_buffer, uint32_t p_offset, uint // No barrier should be needed here. // _buffer_memory_barrier(buffer->buffer, p_offset, p_size, dst_stage_mask, VK_PIPELINE_STAGE_TRANSFER_BIT, dst_access, VK_ACCESS_TRANSFER_WRITE_BIT, true); - Error err = _buffer_update(buffer, p_offset, (uint8_t *)p_data, p_size, p_post_barrier); + Error err = _buffer_update(buffer, p_offset, (uint8_t *)p_data, p_size, true); if (err) { return err; } diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 7c514c11f873..0ffadd163332 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -1015,8 +1015,13 @@ class RenderingDeviceVulkan : public RenderingDevice { List compute_pipelines_to_dispose_of; VkCommandPool command_pool = VK_NULL_HANDLE; - VkCommandBuffer setup_command_buffer = VK_NULL_HANDLE; // Used at the beginning of every frame for set-up. - VkCommandBuffer draw_command_buffer = VK_NULL_HANDLE; // Used at the beginning of every frame for set-up. + // Used for filling up newly created buffers with data provided on creation. + // Primarily intended to be accessed by worker threads. + // Ideally this cmd buffer should use an async transfer queue. + VkCommandBuffer setup_command_buffer = VK_NULL_HANDLE; + // The main cmd buffer for drawing and compute. + // Primarily intended to be used by the main thread to do most stuff. + VkCommandBuffer draw_command_buffer = VK_NULL_HANDLE; struct Timestamp { String description; diff --git a/servers/rendering/renderer_rd/effects/ss_effects.cpp b/servers/rendering/renderer_rd/effects/ss_effects.cpp index d123f248652d..628edc0127dd 100644 --- a/servers/rendering/renderer_rd/effects/ss_effects.cpp +++ b/servers/rendering/renderer_rd/effects/ss_effects.cpp @@ -950,7 +950,7 @@ void SSEffects::screen_space_indirect_lighting(Ref p_rende RD::get_singleton()->draw_command_end_label(); // SSIL - RD::get_singleton()->compute_list_end(RD::BARRIER_MASK_NO_BARRIER); + RD::get_singleton()->compute_list_end(RD::BARRIER_MASK_TRANSFER); // Zeroing importance_map_load_counter depends on us. int zero[1] = { 0 }; RD::get_singleton()->buffer_update(ssil.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0); //no barrier @@ -1332,7 +1332,7 @@ void SSEffects::generate_ssao(Ref p_render_buffers, SSAORe RD::get_singleton()->draw_command_end_label(); // Interleave } RD::get_singleton()->draw_command_end_label(); //SSAO - RD::get_singleton()->compute_list_end(RD::BARRIER_MASK_NO_BARRIER); //wait for upcoming transfer + RD::get_singleton()->compute_list_end(RD::BARRIER_MASK_TRANSFER); // Zeroing importance_map_load_counter depends on us. int zero[1] = { 0 }; RD::get_singleton()->buffer_update(ssao.importance_map_load_counter, 0, sizeof(uint32_t), &zero, 0); //no barrier