11 #ifndef __VE_COMMANDPOOL_H__
12 #define __VE_COMMANDPOOL_H__
51 void copyBuffer(VkBuffer
src, VkBuffer
dst, uint64_t src_offset, uint64_t dst_offset, uint64_t
size);
84 *
this = std::move(rhs);
113 template <
int CB_COUNT>
116 VkCommandPool myPool;
117 VkCommandBuffer myCommandBuffers[CB_COUNT];
152 for (
int i = 0; i < CB_COUNT; ++i) {
156 return VEvoidSuccess();
169 static_assert(I < CB_COUNT);
170 return myCommandBuffers[I];
182 uint32_t exe_buf_count = 0;
183 VkCommandBuffer executable_bufs[CB_COUNT];
185 for (
int i = 0; i < CB_COUNT; ++i)
189 executable_bufs[exe_buf_count++] = myCommandBuffers[i];
193 if (exe_buf_count == 0)
194 return VEvoidSuccess();
212 return VEvoidSuccess();
217 for (
int i = 0; i < CB_COUNT; ++i)
227 for (
int i = 0; i < CB_COUNT; ++i)
238 if (!hasPendingWork())
239 return VEvoidSuccess();
247 for (int i = 0; i < CB_COUNT; ++i)
249 if (myCommandBufferStates[i] == CommandBufferState::PENDING)
250 myCommandBufferStates[i] = CommandBufferState::RETIRED;
253 return VEvoidSuccess();
257 template <int CB_COUNT>
258 class VE_API VE_CommandPoolTransient : public VE_CommandPool<CB_COUNT>
261 static VE_Result<VE_CommandPoolTransient> create(
264 VE_CommandPoolTransient pool;
265 auto r = pool.init(device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT);
273 class VE_API VE_CommandBufferSingleUse
275 using CmdPool = VE_CommandPoolTransient<1>;
279 VkDevice myDevice = nullptr;
281 VE_CommandBufferSingleUse(CmdPool &&pool, VkDevice d, VkQueue q) : myPool(pool), myDevice(d), myQueue(q) {}
283 ~VE_CommandBufferSingleUse()
288 if (myPool.hasExecutableWork())
290 auto r = submitAndWait();
293 myPool.destroy(myDevice);
296 static VE_Result<VE_CommandBufferSingleUse> create(VE_Device &device)
298 auto r = CmdPool::create(device);
302 VE_CommandBufferSingleUse buf(r.unpack(), device.handle(), device.universalQueue());
307 VE_CommandBufferHandle commandBuffer() & { return myPool.commandBuffer(); }
309 VE_VoidResult submitAndWait()
311 auto r = myPool.submitToQueue(myQueue);
315 r = myPool.waitOnInFlightCommands(myDevice);
319 return VEvoidSuccess();
322 UT_NON_COPYABLE(VE_CommandBufferSingleUse);
324 VE_CommandBufferSingleUse(VE_CommandBufferSingleUse &&rhs) noexcept
326 *this = std::move(rhs);
329 VE_CommandBufferSingleUse &operator=(VE_CommandBufferSingleUse &&rhs) noexcept
331 std::swap(myDevice, rhs.myDevice);
332 myQueue = rhs.myQueue;
VE_CommandBufferHandle(VkCommandBuffer cb, CommandBufferState &state)
uint32_t universalQueueFamilyIndex() const
VE_API VkResult VEsubmitToQueueInternal(VkQueue &, VkSubmitInfo &, VkFence &)
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFence *pFence)
VE_API VE_Result< VkCommandPool > VEcreateCommandPool(VkDevice device, uint32_t queue_family_index, VkCommandPoolCreateFlags flags)
VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator)
VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator)
VE_VoidResult init(VE_Device &device, VkCommandPoolCreateFlags flags)
VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, VkBool32 waitAll, uint64_t timeout)
bool hasPendingWork() const
VE_VoidResult waitOnInFlightCommands(VkDevice device)
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
VkFlags VkCommandPoolCreateFlags
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
VE_CommandBufferHandle(VE_CommandBufferHandle &&rhs) noexcept
~VE_CommandBufferHandle()
void beginRenderPass(const VkRenderPassBeginInfo &bi)
VE_CommandBuffer(VkCommandBuffer cb)
VE_CommandBufferHandle & operator=(VE_CommandBufferHandle &&rhs) noexcept
void beginRenderPass(const VkRenderPassBeginInfo &)
VE_VoidResult submitToQueue(VkQueue queue)
VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers)
void destroy(VkDevice device)
void VEdestroyCommandPool(VkDevice device, VkCommandPool pool)
bool hasExecutableWork() const
VE_CommandBufferHandle commandBuffer()&
VkCommandBuffer getVkCommandBuffer()
VkCommandBuffer commandBuffer()
**Note that the tasks the is the thread number *for the pool
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.