Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
VulkanStagedBuffer.h
Go to the documentation of this file.
1#pragma once
2#include <optional>
3#include <vector>
4#include "VulkanBuffer.h"
6
7namespace EngineCore {
9 VkBufferMemoryBarrier2 releaseBarrier;
10 VkBufferMemoryBarrier2 acquireBarrier;
12 };
13
15 public:
17
26 void create(ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping = false);
27 void destroy();
28
29 VulkanStagedBufferSyncObjects upload(const ApplicationContext *context, const void *data, VkDeviceSize size);
30
39 VulkanStagedBufferSyncObjects uploadPartial(const ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset);
40
48 bool ensureSize(VkDeviceSize requiredSize, VkBufferUsageFlags usage);
49
55
60 [[nodiscard]] bool hasPendingDeletions() const { return !pendingDeletions.empty(); }
61
62 [[nodiscard]] const VulkanBuffer& getBuffer() const { return buffer.value(); }
63 [[nodiscard]] VulkanBuffer& getBufferRef() { return buffer.value(); }
64 [[nodiscard]] const VulkanBuffer& getStagingBuffer() const { return stagingBuffer.value(); }
65 [[nodiscard]] VulkanBuffer& getStagingBufferRef() { return stagingBuffer.value(); }
66
71 [[nodiscard]] VkDeviceSize getSize() const;
72
73 void setDebugName(const std::string &name, std::optional<uint32_t> index = std::nullopt);
74
75 private:
77 std::optional<VulkanBuffer> buffer;
78 std::optional<VulkanBuffer> stagingBuffer;
79 std::string debugName_;
81
88 std::vector<PendingDeletion> pendingDeletions;
89
93 static constexpr uint32_t DELETION_DELAY_FRAMES = 6;
94 };
95}
The application context is the core class which stores the basic openxr and vulkan objects.
RAII wrapper for Vulkan buffer and device memory.
VulkanStagedBufferSyncObjects uploadPartial(const ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset)
Upload data to a specific offset in the buffer (for incremental updates)
const VulkanBuffer & getStagingBuffer() const
VkDeviceSize getSize() const
Gets the current size of the device buffer.
std::vector< PendingDeletion > pendingDeletions
bool ensureSize(VkDeviceSize requiredSize, VkBufferUsageFlags usage)
Ensures the buffer is at least the required size. If resizing is needed, the old buffers are moved to...
static constexpr uint32_t DELETION_DELAY_FRAMES
std::optional< VulkanBuffer > stagingBuffer
std::optional< VulkanBuffer > buffer
void setDebugName(const std::string &name, std::optional< uint32_t > index=std::nullopt)
VulkanStagedBufferSyncObjects upload(const ApplicationContext *context, const void *data, VkDeviceSize size)
void processPendingDeletions()
Destroys all buffers that were pending deletion. Call this after all frames that might reference old ...
bool hasPendingDeletions() const
Checks if there are buffers pending deletion.
void create(ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping=false)
Creates the staged buffer with device and staging buffers.
const VulkanBuffer & getBuffer() const
Log category system implementation.
Old buffers waiting to be deleted after all frames complete.
uint32_t framesRemaining
Number of frames to wait before deletion.