17#ifndef _FGE_VULKAN_C_GARBAGECOLLECTOR_HPP_INCLUDED
18#define _FGE_VULKAN_C_GARBAGECOLLECTOR_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
22#include "FastEngine/vulkan/vulkanGlobal.hpp"
35 GARBAGE_DESCRIPTOR_SET,
36 GARBAGE_VERTEX_BUFFER,
37 GARBAGE_GRAPHIC_PIPELINE,
38 GARBAGE_PIPELINE_LAYOUT,
40 GARBAGE_COMMAND_BUFFER,
51struct GarbageDescriptorSet
53 constexpr GarbageDescriptorSet(VkDescriptorSet descriptorSet,
54 VkDescriptorPool descriptorPool,
55 VkDevice logicalDevice) :
56 _type(GarbageType::GARBAGE_DESCRIPTOR_SET),
57 _descriptorSet(descriptorSet),
58 _descriptorPool(descriptorPool),
59 _logicalDevice(logicalDevice)
63 VkDescriptorSet _descriptorSet;
64 VkDescriptorPool _descriptorPool;
65 VkDevice _logicalDevice;
69 constexpr GarbageBuffer(
BufferInfo bufferInfo, VmaAllocator allocator) :
70 _type(GarbageType::GARBAGE_VERTEX_BUFFER),
71 _bufferInfo(bufferInfo),
77 VmaAllocator _allocator;
79struct GarbageGraphicPipeline
81 constexpr GarbageGraphicPipeline(VkPipeline pipeline, VkDevice logicalDevice) :
82 _type(GarbageType::GARBAGE_GRAPHIC_PIPELINE),
84 _logicalDevice(logicalDevice)
89 VkDevice _logicalDevice;
91struct GarbagePipelineLayout
93 constexpr GarbagePipelineLayout(VkPipelineLayout pipelineLayout, VkDevice logicalDevice) :
94 _type(GarbageType::GARBAGE_PIPELINE_LAYOUT),
95 _pipelineLayout(pipelineLayout),
96 _logicalDevice(logicalDevice)
100 VkPipelineLayout _pipelineLayout;
101 VkDevice _logicalDevice;
103struct GarbageCommandPool
105 constexpr GarbageCommandPool(VkCommandPool commandPool, VkDevice logicalDevice) :
106 _type(GarbageType::GARBAGE_COMMAND_POOL),
107 _commandPool(commandPool),
108 _logicalDevice(logicalDevice)
112 VkCommandPool _commandPool;
113 VkDevice _logicalDevice;
115struct GarbageCommandBuffer
117 constexpr GarbageCommandBuffer(VkCommandPool commandPool, VkCommandBuffer commandBuffer, VkDevice logicalDevice) :
118 _type(GarbageType::GARBAGE_COMMAND_BUFFER),
119 _commandPool(commandPool),
120 _commandBuffer(commandBuffer),
121 _logicalDevice(logicalDevice)
125 VkCommandPool _commandPool;
126 VkCommandBuffer _commandBuffer;
127 VkDevice _logicalDevice;
129struct GarbageFramebuffer
131 constexpr GarbageFramebuffer(VkFramebuffer framebuffer, VkDevice logicalDevice) :
132 _type(GarbageType::GARBAGE_FRAMEBUFFER),
133 _framebuffer(framebuffer),
134 _logicalDevice(logicalDevice)
138 VkFramebuffer _framebuffer;
139 VkDevice _logicalDevice;
141struct GarbageRenderPass
143 constexpr GarbageRenderPass(VkRenderPass renderPass, VkDevice logicalDevice) :
144 _type(GarbageType::GARBAGE_RENDERPASS),
145 _renderPass(renderPass),
146 _logicalDevice(logicalDevice)
150 VkRenderPass _renderPass;
151 VkDevice _logicalDevice;
155 constexpr GarbageSampler(VkSampler sampler, VkDevice logicalDevice) :
156 _type(GarbageType::GARBAGE_SAMPLER),
158 _logicalDevice(logicalDevice)
163 VkDevice _logicalDevice;
167 constexpr GarbageImage(VkImage image,
168 VmaAllocation bufferAllocation,
169 VkImageView imageView,
171 _type(GarbageType::GARBAGE_IMAGE),
173 _allocation(bufferAllocation),
174 _imageView(imageView),
180 VmaAllocation _allocation;
181 VkImageView _imageView;
192class FGE_API Garbage final
195 constexpr Garbage() :
196 g_data(GarbageType::GARBAGE_EMPTY)
230 Garbage(Garbage
const& r) =
delete;
231 Garbage(Garbage&& r) noexcept :
234 r.g_data._generic._type = GarbageType::GARBAGE_EMPTY;
238 Garbage& operator=(Garbage
const& r) =
delete;
239 Garbage& operator=(Garbage&& r)
noexcept =
delete;
244 explicit constexpr Data(GarbageType type) :
254 _graphicPipeline{data}
257 _pipelineLayout{data}
303class FGE_API GarbageCollector
306 using ContainerType = std::vector<Garbage>;
308 GarbageCollector() =
default;
309 GarbageCollector(GarbageCollector
const& r) =
delete;
310 GarbageCollector(GarbageCollector&& r)
noexcept;
311 ~GarbageCollector() =
default;
313 GarbageCollector& operator=(GarbageCollector
const& r) =
delete;
314 GarbageCollector& operator=(GarbageCollector&& r)
noexcept =
delete;
326 [[nodiscard]] uint32_t getCurrentFrame()
const;
364 [[nodiscard]]
bool isEnabled()
const;
367 mutable std::array<ContainerType, FGE_MAX_FRAMES_IN_FLIGHT> g_containers;
368 uint32_t g_currentFrame = 0;
369 bool g_enabled =
false;
Vulkan context.
Definition C_context.hpp:70
void free()
Free all the garbage objects in the current frame.
void enable(bool stat)
Enable or disable the garbage collector.
void setCurrentFrame(uint32_t frame)
Set the current frame.
void freeAll()
Free all the garbage objects.
void push(Garbage garbage) const
Push a garbage object.
A class that holds a garbage object.
Definition C_garbageCollector.hpp:193
Definition vulkanGlobal.hpp:44
Definition C_garbageCollector.hpp:68
Definition C_garbageCollector.hpp:116
Definition C_garbageCollector.hpp:104
Definition C_garbageCollector.hpp:52
Definition C_garbageCollector.hpp:130
Definition C_garbageCollector.hpp:48
Definition C_garbageCollector.hpp:80
Definition C_garbageCollector.hpp:166
Definition C_garbageCollector.hpp:92
Definition C_garbageCollector.hpp:142
Definition C_garbageCollector.hpp:154