/* Copyright (c) 2019-2025, Arm Limited and Contributors * Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 the "License"; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "core/command_pool_base.h" #include "core/device.h" #include namespace vkb { namespace rendering { template class RenderFrame; using RenderFrameC = RenderFrame; using RenderFrameCpp = RenderFrame; } // namespace rendering namespace core { template class CommandBuffer; using CommandBufferC = CommandBuffer; using CommandBufferCpp = CommandBuffer; namespace { // type trait to get the default value for request_command_buffer template struct DefaultCommandBufferLevelValue; template <> struct DefaultCommandBufferLevelValue { static constexpr vk::CommandBufferLevel value = vk::CommandBufferLevel::ePrimary; }; template <> struct DefaultCommandBufferLevelValue { static constexpr VkCommandBufferLevel value = VK_COMMAND_BUFFER_LEVEL_PRIMARY; }; } // namespace template class CommandPool : private vkb::core::CommandPoolBase { public: using CommandBufferLevelType = typename std::conditional::type; using CommandPoolType = typename std::conditional::type; public: CommandPool(vkb::core::Device &device, uint32_t queue_family_index, vkb::rendering::RenderFrame *render_frame = nullptr, size_t thread_index = 0, vkb::CommandBufferResetMode reset_mode = vkb::CommandBufferResetMode::ResetPool); CommandPool(CommandPool const &) = delete; CommandPool(CommandPool &&other) = default; CommandPool &operator=(CommandPool const &) = delete; CommandPool &operator=(CommandPool &&other) = default; ~CommandPool() = default; vkb::core::Device &get_device(); CommandPoolType get_handle() const; uint32_t get_queue_family_index() const; vkb::rendering::RenderFrame *get_render_frame(); vkb::CommandBufferResetMode get_reset_mode() const; size_t get_thread_index() const; std::shared_ptr> request_command_buffer(CommandBufferLevelType level = DefaultCommandBufferLevelValue::value); void reset_pool(); }; using CommandPoolC = CommandPool; using CommandPoolCpp = CommandPool; template inline vkb::core::CommandPool::CommandPool(vkb::core::Device &device, uint32_t queue_family_index, vkb::rendering::RenderFrame *render_frame, size_t thread_index, vkb::CommandBufferResetMode reset_mode) : CommandPoolBase(reinterpret_cast(device), queue_family_index, reinterpret_cast(render_frame), thread_index, reset_mode) {} template inline typename vkb::core::Device &CommandPool::get_device() { if constexpr (bindingType == vkb::BindingType::Cpp) { return CommandPoolBase::get_device(); } else { return reinterpret_cast(CommandPoolBase::get_device()); } } template inline typename vkb::core::CommandPool::CommandPoolType CommandPool::get_handle() const { if constexpr (bindingType == vkb::BindingType::Cpp) { return CommandPoolBase::get_handle(); } else { return static_cast(CommandPoolBase::get_handle()); } } template inline uint32_t CommandPool::get_queue_family_index() const { return CommandPoolBase::get_queue_family_index(); } template inline vkb::rendering::RenderFrame *CommandPool::get_render_frame() { if constexpr (bindingType == vkb::BindingType::Cpp) { return CommandPoolBase::get_render_frame(); } else { return reinterpret_cast(CommandPoolBase::get_render_frame()); } } template inline vkb::CommandBufferResetMode CommandPool::get_reset_mode() const { return CommandPoolBase::get_reset_mode(); } template inline size_t CommandPool::get_thread_index() const { return CommandPoolBase::get_thread_index(); } template std::shared_ptr> CommandPool::request_command_buffer(CommandBufferLevelType level) { if constexpr (bindingType == vkb::BindingType::Cpp) { return CommandPoolBase::request_command_buffer(*this, level); } else { std::shared_ptr command_buffer = CommandPoolBase::request_command_buffer(reinterpret_cast(*this), static_cast(level)); return *reinterpret_cast *>(&command_buffer); } } template inline void CommandPool::reset_pool() { CommandPoolBase::reset_pool(); } } // namespace core } // namespace vkb