evan 2026.1.4
Evan
Loading...
Searching...
No Matches
TransferManager.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** TransferManager
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11
12#include <cstdint>
13#include <vector>
14
15namespace evan
16{
28 {
29 public:
30 TransferManager() = default;
32
33 TransferManager(const TransferManager &) = delete;
34 TransferManager &operator=(const TransferManager &) = delete;
35
48 VkQueue graphicsQueue, uint32_t graphicsFamily);
49
53 void destroy();
54
59 void uploadBuffer(const void *data, VkDeviceSize size, VkBuffer dst,
61
66 void uploadBufferToImage(const void *data, VkDeviceSize size,
69
77
83
87 void flush();
88
93 void waitIdle();
94
95 private:
96 struct PendingBatch {
97 VkFence fence = VK_NULL_HANDLE;
98 VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
99 };
100
101 void ensureBegan();
102 void recycle();
103 void createStagingBuffer(VkDeviceSize size);
104
105 VkDevice _device = VK_NULL_HANDLE;
106 VkPhysicalDevice _physicalDevice = VK_NULL_HANDLE;
107 VkQueue _transferQueue = VK_NULL_HANDLE;
108 uint32_t _transferFamily = 0;
109 VkCommandPool _commandPool = VK_NULL_HANDLE;
110 VkCommandBuffer _commandBuffer = VK_NULL_HANDLE;
111 bool _recording = false;
112 bool _dirty = false;
113
114 VkBuffer _stagingBuffer = VK_NULL_HANDLE;
115 VkDeviceMemory _stagingMemory = VK_NULL_HANDLE;
116 void *_stagingMapped = nullptr;
117 VkDeviceSize _stagingSize = 0;
118 VkDeviceSize _stagingOffset = 0;
119
120 std::vector<PendingBatch> _pending;
121 };
122} // namespace evan
Owns staging memory and command buffers used to upload data to device-local resources without drainin...
void destroy()
Releases every Vulkan resource owned by this manager.
void uploadBuffer(const void *data, VkDeviceSize size, VkBuffer dst, VkDeviceSize dstOffset=0)
Copies host data into the staging ring and records a vkCmdCopyBuffer from the ring slot into dst.
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels)
Records an image layout transition into the current batch.
void flush()
Submits the pending transfer command buffer, if any.
void waitIdle()
Flushes pending work and blocks until every submitted batch has completed on the GPU.
void init(VkDevice device, VkPhysicalDevice physicalDevice, VkQueue graphicsQueue, uint32_t graphicsFamily)
Initializes the transfer queue and command pool.
void generateMipmaps(VkImage image, VkFormat format, uint32_t width, uint32_t height, uint32_t mipLevels)
Records a mipmap generation chain into the current batch.
void uploadBufferToImage(const void *data, VkDeviceSize size, VkImage dst, const VkBufferImageCopy &region)
Copies host data into the staging ring and records a vkCmdCopyBufferToImage from the ring slot into d...
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89