@@ -2292,6 +2292,19 @@ bool RenderingDeviceDriverD3D12::command_pool_reset(CommandPoolID p_cmd_pool) {
2292
2292
2293
2293
void RenderingDeviceDriverD3D12::command_pool_free (CommandPoolID p_cmd_pool) {
2294
2294
CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id );
2295
+
2296
+ // Destroy all command buffers associated with this command pool, mirroring Vulkan's behavior.
2297
+ SelfList<CommandBufferInfo> *cmd_buf_elem = command_pool->command_buffers .first ();
2298
+ while (cmd_buf_elem != nullptr ) {
2299
+ CommandBufferInfo *cmd_buf_info = cmd_buf_elem->self ();
2300
+ cmd_buf_elem = cmd_buf_elem->next ();
2301
+
2302
+ cmd_buf_info->cmd_list .Reset ();
2303
+ cmd_buf_info->cmd_allocator .Reset ();
2304
+
2305
+ VersatileResource::free (resources_allocator, cmd_buf_info);
2306
+ }
2307
+
2295
2308
memdelete (command_pool);
2296
2309
}
2297
2310
@@ -2300,7 +2313,7 @@ void RenderingDeviceDriverD3D12::command_pool_free(CommandPoolID p_cmd_pool) {
2300
2313
RDD::CommandBufferID RenderingDeviceDriverD3D12::command_buffer_create (CommandPoolID p_cmd_pool) {
2301
2314
DEV_ASSERT (p_cmd_pool);
2302
2315
2303
- const CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id );
2316
+ CommandPoolInfo *command_pool = (CommandPoolInfo *)(p_cmd_pool.id );
2304
2317
D3D12_COMMAND_LIST_TYPE list_type;
2305
2318
if (command_pool->buffer_type == COMMAND_BUFFER_TYPE_SECONDARY) {
2306
2319
list_type = D3D12_COMMAND_LIST_TYPE_BUNDLE;
@@ -2336,6 +2349,9 @@ RDD::CommandBufferID RenderingDeviceDriverD3D12::command_buffer_create(CommandPo
2336
2349
cmd_buf_info->cmd_allocator = cmd_allocator;
2337
2350
cmd_buf_info->cmd_list = cmd_list;
2338
2351
2352
+ // Add this command buffer to the command pool's list of command buffers.
2353
+ command_pool->command_buffers .add (&cmd_buf_info->command_buffer_info_elem );
2354
+
2339
2355
return CommandBufferID (cmd_buf_info);
2340
2356
}
2341
2357
0 commit comments