#pragma once #include "vk_device.h" #include "vk_objects.h" class VulkanFrameBuffer; class VkCommandBufferManager { public: VkCommandBufferManager(VulkanFrameBuffer* fb); ~VkCommandBufferManager(); void BeginFrame(); VulkanCommandBuffer* GetTransferCommands(); VulkanCommandBuffer* GetDrawCommands(); void FlushCommands(bool finish, bool lastsubmit = false, bool uploadOnly = false); void WaitForCommands(bool finish) { WaitForCommands(finish, false); } void WaitForCommands(bool finish, bool uploadOnly); void PushGroup(const FString& name); void PopGroup(); void UpdateGpuStats(); class DeleteList { public: std::vector> Buffers; std::vector> Samplers; std::vector> Images; std::vector> ImageViews; std::vector> Framebuffers; std::vector> AccelStructs; std::vector> DescriptorPools; std::vector> Descriptors; std::vector> Shaders; std::vector> CommandBuffers; size_t TotalSize = 0; void Add(std::unique_ptr obj) { if (obj) { TotalSize += obj->size; Buffers.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { Samplers.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { Images.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { ImageViews.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { Framebuffers.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { AccelStructs.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { DescriptorPools.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { Descriptors.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { CommandBuffers.push_back(std::move(obj)); } } void Add(std::unique_ptr obj) { if (obj) { Shaders.push_back(std::move(obj)); } } }; std::unique_ptr TransferDeleteList = std::make_unique(); std::unique_ptr DrawDeleteList = std::make_unique(); void DeleteFrameObjects(bool uploadOnly = false); std::unique_ptr swapChain; uint32_t presentImageIndex = 0xffffffff; private: void FlushCommands(VulkanCommandBuffer** commands, size_t count, bool finish, bool lastsubmit); VulkanFrameBuffer* fb = nullptr; std::unique_ptr mCommandPool; std::unique_ptr mTransferCommands; std::unique_ptr mDrawCommands; enum { maxConcurrentSubmitCount = 8 }; std::unique_ptr mSubmitSemaphore[maxConcurrentSubmitCount]; std::unique_ptr mSubmitFence[maxConcurrentSubmitCount]; VkFence mSubmitWaitFences[maxConcurrentSubmitCount]; int mNextSubmit = 0; std::unique_ptr mSwapChainImageAvailableSemaphore; std::unique_ptr mRenderFinishedSemaphore; struct TimestampQuery { FString name; uint32_t startIndex; uint32_t endIndex; }; enum { MaxTimestampQueries = 100 }; std::unique_ptr mTimestampQueryPool; int mNextTimestampQuery = 0; std::vector mGroupStack; std::vector timeElapsedQueries; };