SpiecsEngine
 
Loading...
Searching...
No Matches

◆ CustomGraphicCmd()

template<typename T >
void Spices::VulkanCommandBuffer::CustomGraphicCmd ( VulkanState & vulkanState,
T func )
inlinestatic

Create a new command buffer and record custom cmd, submit to graphic queue, execute it immediately.

Parameters
[in]funcThe function pointer of what cmd need to execute.
[in]vulkanStateThe global VulkanState.

Instanced a VkCommandBufferAllocateInfo with default value.

Allocate s new CommandBuffer from CommandPool.

Instanced a VkCommandBufferBeginInfo with default value.

Begin a CommandBuffer

Execute function pointer.

End a CommandBuffer

Fetch valid Graphic Queue.

Submit commandBuffer in queue.

Wait queue finished.

Push back to Graphic queue.

Free the CommandBuffer that created.

Definition at line 144 of file VulkanCommandBuffer.h.

145 {
147
151 VkCommandBufferAllocateInfo allocInfo{};
152 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
153 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
154 allocInfo.commandPool = VulkanCommandPool::GetThreadGraphicCommandPool();
155 allocInfo.commandBufferCount = 1;
156
160 VkCommandBuffer commandBuffer;
161 VK_CHECK(vkAllocateCommandBuffers(vulkanState.m_Device, &allocInfo, &commandBuffer));
162 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast<uint64_t>(commandBuffer), vulkanState.m_Device, "CustomCmd Command Buffer")
163
164
167 VkCommandBufferBeginInfo beginInfo{};
168 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
169 beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
170
174 VK_CHECK(vkBeginCommandBuffer(commandBuffer, &beginInfo));
175
176 SPICES_PROFILE_VK_ZONE(commandBuffer, "CustomCmd Command Buffer")
177
178
181 func(commandBuffer);
182
186 VK_CHECK(vkEndCommandBuffer(commandBuffer));
187
191 auto queue = VulkanThreadQueue::FetchGraphicQueue();
192
196 queue->Submit(commandBuffer);
197
201 queue->Wait();
202
206 VulkanThreadQueue::PushToGraphic(queue);
207
211 vkFreeCommandBuffers(vulkanState.m_Device, allocInfo.commandPool, 1, &commandBuffer);
212 }
#define SPICES_PROFILE_ZONE
#define SPICES_PROFILE_VK_ZONE(cmdbuf, name)
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
static VkCommandPool & GetThreadGraphicCommandPool()
Get Thread Graphic VkCommandPool by thread id.

References Spices::VulkanThreadQueue::FetchGraphicQueue().