2
3
4
5
27
28
29 VkCommandPoolCreateInfo poolInfo{};
30 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
31 poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
32 poolInfo.queueFamilyIndex = vulkanState.m_GraphicQueueFamily;
35
36
37 VK_CHECK(vkCreateCommandPool(vulkanState.m_Device, &poolInfo,
nullptr, &vulkanState.m_GraphicCommandPool))
38 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_POOL,
reinterpret_cast<uint64_t>(vulkanState.m_GraphicCommandPool), vulkanState.m_Device,
"GraphicCommandPool")
40 VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId = 0;
41 m_ThreadGraphicCommandPool.push_back(vulkanState.m_GraphicCommandPool);
43 poolInfo.queueFamilyIndex = vulkanState.m_ComputeQueueFamily;
46
47
48 VK_CHECK(vkCreateCommandPool(vulkanState.m_Device, &poolInfo,
nullptr, &vulkanState.m_ComputeCommandPool))
49 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_POOL,
reinterpret_cast<uint64_t>(vulkanState.m_ComputeCommandPool), vulkanState.m_Device,
"ComputeCommandPool")
51 VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId = 0;
52 m_ThreadComputeCommandPool.push_back(vulkanState.m_ComputeCommandPool);
62
63
64 for(
auto& pool : m_ThreadGraphicCommandPool)
68 vkDestroyCommandPool(m_VulkanState.m_Device, pool,
nullptr);
73 for(
auto& pool : m_ThreadComputeCommandPool)
77 vkDestroyCommandPool(m_VulkanState.m_Device, pool,
nullptr);
87 std::unique_lock<std::mutex> lock(m_GraphicCommandPoolMutex);
91 SPICES_CORE_ERROR(
"CommandPool is not active.")
96 for (
int i = 0; i < m_ThreadGraphicCommandPool.size(); i++)
98 if (!m_ThreadGraphicCommandPool[i]) VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId = i;
103 VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId = m_ThreadGraphicCommandPool.size();
104 m_ThreadGraphicCommandPool.push_back(
nullptr);
108 if(!m_ThreadGraphicCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId])
111
112
113 VkCommandPoolCreateInfo poolInfo{};
114 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
115 poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
116 poolInfo.queueFamilyIndex = VulkanRenderBackend::GetState().m_GraphicQueueFamily;
119
120
122 VK_CHECK(vkCreateCommandPool(VulkanRenderBackend::GetState().m_Device, &poolInfo,
nullptr, &pool))
123 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_POOL,
reinterpret_cast<uint64_t>(pool), VulkanRenderBackend::GetState().m_Device,
"ThreadGraphicCommandPool")
124 m_ThreadGraphicCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId] = std::move(pool);
127 return m_ThreadGraphicCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_GraphicThreadId];
134 std::unique_lock<std::mutex> lock(m_ComputeCommandPoolMutex);
138 SPICES_CORE_ERROR(
"CommandPool is not active.")
143 for (
int i = 0; i < m_ThreadComputeCommandPool.size(); i++)
145 if (!m_ThreadComputeCommandPool[i]) VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId = i;
150 VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId = m_ThreadComputeCommandPool.size();
151 m_ThreadComputeCommandPool.push_back(
nullptr);
155 if(m_ThreadComputeCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId])
158
159
160 VkCommandPoolCreateInfo poolInfo{};
161 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
162 poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
163 poolInfo.queueFamilyIndex = VulkanRenderBackend::GetState().m_ComputeQueueFamily;
166
167
169 VK_CHECK(vkCreateCommandPool(VulkanRenderBackend::GetState().m_Device, &poolInfo,
nullptr, &pool))
170 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_POOL,
reinterpret_cast<uint64_t>(pool), VulkanRenderBackend::GetState().m_Device,
"ThreadComputeCommandPool")
171 m_ThreadComputeCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId] = std::move(pool);
174 return m_ThreadComputeCommandPool[VulkanCommandPoolThreadWrapper::GetInst().m_ComputeThreadId];
183
184
185 VkCommandBufferAllocateInfo allocInfo{};
186 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
187 allocInfo.commandPool = vulkanState.m_GraphicCommandPool;
188 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
189 allocInfo.commandBufferCount = MaxFrameInFlight;
192
193
194 VK_CHECK(vkAllocateCommandBuffers(vulkanState.m_Device, &allocInfo, vulkanState.m_GraphicCommandBuffer.data()))
196 allocInfo.commandPool = vulkanState.m_ComputeCommandPool;
197 VK_CHECK(vkAllocateCommandBuffers(vulkanState.m_Device, &allocInfo, vulkanState.m_ComputeCommandBuffer.data()))
201 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_BUFFER,
reinterpret_cast<uint64_t>(vulkanState.m_GraphicCommandBuffer[i]), vulkanState.m_Device,
"GraphicCommandBuffer")
202 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_BUFFER,
reinterpret_cast<uint64_t>(vulkanState.m_ComputeCommandBuffer[i]), vulkanState.m_Device,
"ComputeCommandBuffer")
217 auto& pool = VulkanCommandPool::GetThreadGraphicCommandPool();
221 vkDestroyCommandPool(VulkanRenderBackend::GetState().m_Device, pool,
nullptr);
228 auto& pool = VulkanCommandPool::GetThreadComputeCommandPool();
232 vkDestroyCommandPool(VulkanRenderBackend::GetState().m_Device, pool,
nullptr);
241
242
243 static _declspec(thread) VulkanCommandPoolThreadWrapper pTLSVulkanCommandPool;
245 return pTLSVulkanCommandPool;
#define SPICES_PROFILE_ZONE
#define SPICES_PROFILE_VK_COLLECT(cmdbuf)
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
VulkanCommandBuffer(VulkanState &vulkanState)
Constructor Function. Create VkCommandBuffer.
VulkanCommandBuffer Class. This class defines the VulkanCommandBuffer behaves. This class is just a w...
int m_GraphicThreadId
Thread Unique Graphic ThreadId.
int m_ComputeThreadId
Thread Unique Compute ThreadId.
static VulkanCommandPoolThreadWrapper & GetInst()
Get this instance.
virtual ~VulkanCommandPoolThreadWrapper()
Destructor Function.
Wrapper of Instance/Delete VkCommandPool in thread.
static std::vector< VkCommandPool > m_ThreadGraphicCommandPool
Thread Graphic VkCommandPool map.
static bool m_IsPoolActive
True if this Pool is actived.
VulkanCommandPool(VulkanState &vulkanState)
Constructor Function. Create VkCommandPool.
virtual ~VulkanCommandPool() override
Destructor Function.
static std::mutex m_ComputeCommandPoolMutex
Mutex for GraphicCommandPool.
static std::mutex m_GraphicCommandPoolMutex
Mutex for GraphicCommandPool.
static std::vector< VkCommandPool > m_ThreadComputeCommandPool
Thread Compute VkCommandPool map.
VulkanCommandPool Class. This class defines the VulkanCommandPool behaves. This class is just a wrapp...
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
VulkanObject Class. This class defines the basic behaves of VulkanObject. When we create an new Vulka...
constexpr uint32_t MaxFrameInFlight
Max In Flight Frame. 2 buffers are enough in this program.
This struct contains all Vulkan object in used global.