| 551 | } |
| 552 | |
| 553 | bool create_thread_command_pool(const bool is_secondary) { |
| 554 | auto& cmd_pool = (!is_secondary ? thread_primary_cmd_pool : thread_secondary_cmd_pool); |
| 555 | if (cmd_pool) { |
| 556 | return true; |
| 557 | } |
| 558 | cmd_pool = vulkan_command_pool_storage::create_cmd_pool(dev, queue, is_secondary); |
| 559 | |
| 560 | // register in per-thread destructor |
| 561 | if (!is_secondary) { |
| 562 | vulkan_command_pool_destructor.primary_pool = cmd_pool; |
| 563 | } else { |
| 564 | vulkan_command_pool_destructor.secondary_pool = cmd_pool; |
| 565 | } |
| 566 | |
| 567 | MULTI_GUARD(cmd_pool->cmd_buffers_lock, cmd_pool->fence_lock); |
| 568 | |
| 569 | // create command pool for this queue + device |
| 570 | const VkCommandPoolCreateInfo cmd_pool_info { |
| 571 | .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, |
| 572 | .pNext = nullptr, |
| 573 | // always short-lived + need individual reset |
| 574 | .flags = (VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT), |
| 575 | .queueFamilyIndex = family_index, |
| 576 | }; |
| 577 | VK_CALL_RET(vkCreateCommandPool(dev.device, &cmd_pool_info, nullptr, &cmd_pool->cmd_pool), |
| 578 | "failed to create command pool", false) |
| 579 | |
| 580 | #if defined(FLOOR_DEBUG) |
| 581 | auto thread_name = core::get_current_thread_name(); |
| 582 | if (thread_name.empty()) { |
| 583 | stringstream sstr; |
| 584 | sstr << this_thread::get_id(); |
| 585 | thread_name = sstr.str(); |
| 586 | } |
| 587 | ((const vulkan_compute*)dev.context)->set_vulkan_debug_label(dev, VK_OBJECT_TYPE_COMMAND_POOL, uint64_t(cmd_pool->cmd_pool), |
| 588 | "command_pool:" + thread_name); |
| 589 | #endif |
| 590 | |
| 591 | // allocate initial command buffers |
| 592 | const VkCommandBufferAllocateInfo cmd_buffer_info { |
| 593 | .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, |
| 594 | .pNext = nullptr, |
| 595 | .commandPool = cmd_pool->cmd_pool, |
| 596 | .level = (!is_secondary ? VK_COMMAND_BUFFER_LEVEL_PRIMARY : VK_COMMAND_BUFFER_LEVEL_SECONDARY), |
| 597 | .commandBufferCount = vulkan_command_pool_t::cmd_buffer_count, |
| 598 | }; |
| 599 | VK_CALL_RET(vkAllocateCommandBuffers(dev.device, &cmd_buffer_info, &cmd_pool->cmd_buffers[0]), |
| 600 | "failed to create command buffers", false) |
| 601 | cmd_pool->cmd_buffers_in_use.reset(); |
| 602 | |
| 603 | #if defined(FLOOR_DEBUG) |
| 604 | const auto cmd_buf_prefix = (is_secondary ? "sec_"s : ""s) + "command_buffer:" + thread_name + ":"; |
| 605 | for (uint32_t cmd_buf_idx = 0; cmd_buf_idx < vulkan_command_pool_t::cmd_buffer_count; ++cmd_buf_idx) { |
| 606 | ((const vulkan_compute*)dev.context)->set_vulkan_debug_label(dev, VK_OBJECT_TYPE_COMMAND_BUFFER, uint64_t(cmd_pool->cmd_buffers[cmd_buf_idx]), |
| 607 | cmd_buf_prefix + to_string(cmd_buf_idx)); |
| 608 | } |
| 609 | #endif |
| 610 |
no test coverage detected