Skip to content

Commit bb85a58

Browse files
authored
Minimal invasive fix for the memory leak in the performance sample multi_draw_indirect. (#1444)
1 parent 4edb9fd commit bb85a58

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

framework/core/command_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CommandPool : private vkb::core::CommandPoolBase
6868
uint32_t queue_family_index,
6969
vkb::rendering::RenderFrame<bindingType> *render_frame = nullptr,
7070
size_t thread_index = 0,
71-
vkb::CommandBufferResetMode reset_mode = vkb::CommandBufferResetMode::ResetPool);
71+
vkb::CommandBufferResetMode reset_mode = vkb::CommandBufferResetMode::ResetIndividually);
7272
CommandPool(CommandPool<bindingType> const &) = delete;
7373
CommandPool(CommandPool<bindingType> &&other) = default;
7474
CommandPool &operator=(CommandPool<bindingType> const &) = delete;

samples/performance/multi_draw_indirect/multi_draw_indirect.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ void MultiDrawIndirect::on_update_ui_overlay(vkb::Drawer &drawer)
198198
assert(!!indirect_call_buffer && !!cpu_staging_buffer && indirect_call_buffer->get_size() == cpu_staging_buffer->get_size());
199199
assert(cpu_commands.size() * sizeof(cpu_commands[0]) == cpu_staging_buffer->get_size());
200200

201-
auto cmd = get_device().get_command_pool().request_command_buffer();
202-
cmd->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
203-
cmd->copy_buffer(*indirect_call_buffer, *cpu_staging_buffer, cpu_staging_buffer->get_size());
204-
cmd->end();
201+
ui_overlay_command_buffer->reset(vkb::CommandBufferResetMode::ResetIndividually);
202+
ui_overlay_command_buffer->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
203+
ui_overlay_command_buffer->copy_buffer(*indirect_call_buffer, *cpu_staging_buffer, cpu_staging_buffer->get_size());
204+
ui_overlay_command_buffer->end();
205205

206206
auto &queue = get_device().get_queue_by_flags(VK_QUEUE_COMPUTE_BIT, 0);
207-
queue.submit(*cmd, get_device().get_fence_pool().request_fence());
207+
queue.submit(*ui_overlay_command_buffer, get_device().get_fence_pool().request_fence());
208208
get_device().get_fence_pool().wait();
209209

210210
memcpy(cpu_commands.data(), cpu_staging_buffer->get_data(), cpu_staging_buffer->get_size());
@@ -278,6 +278,8 @@ bool MultiDrawIndirect::prepare(const vkb::ApplicationOptions &options)
278278
}
279279
}
280280

281+
ui_overlay_command_buffer = get_device().get_command_pool().request_command_buffer();
282+
281283
create_samplers();
282284
load_scene();
283285
initialize_resources();

samples/performance/multi_draw_indirect/multi_draw_indirect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class MultiDrawIndirect : public ApiVulkanSample
128128
const vkb::Queue *compute_queue{nullptr};
129129
std::vector<uint32_t> queue_families;
130130

131+
std::shared_ptr<vkb::core::CommandBufferC> ui_overlay_command_buffer;
132+
131133
// CPU Draw Calls
132134
void cpu_cull();
133135
std::vector<VkDrawIndexedIndirectCommand> cpu_commands;

0 commit comments

Comments
 (0)