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 "Buffer.h"
4
5#include <array>
6#include <optional>
7#include <vector>
8
9namespace Engine::Core
10{
12} // namespace Engine::Core
13
14namespace Vulkan {
22 VkBufferMemoryBarrier2 releaseBarrier;
23
27 VkBufferMemoryBarrier2 acquireBarrier;
28
33 };
34
39 public:
41 static constexpr uint32_t STAGING_BUFFER_COUNT = 2;
42
44
53 void create(
54 Engine::Core::ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping = false);
55 void destroy();
56
57 StagedBufferSyncObjects upload( const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size);
58
67 StagedBufferSyncObjects uploadPartial( const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset);
68
75
83 bool ensureSize(VkDeviceSize requiredSize, VkBufferUsageFlags usage);
84
90
95 [[nodiscard]] bool hasPendingDeletions() const { return !pendingDeletions.empty(); }
96
97 [[nodiscard]] const Vulkan::Buffer& getBuffer() const { return buffer.value(); }
98 [[nodiscard]] Vulkan::Buffer& getBufferRef() { return buffer.value(); }
99 [[nodiscard]] const Vulkan::Buffer& getStagingBuffer() const { return stagingBuffers_[currentStagingIndex_].value(); }
101
106 [[nodiscard]] VkDeviceSize getSize() const;
107
108 void setDebugName(const std::string &name, std::optional<uint32_t> index = std::nullopt);
109
110 private:
112 std::optional<Buffer> buffer;
115 std::array<std::optional<Vulkan::Buffer>, STAGING_BUFFER_COUNT> stagingBuffers_;
117 std::string debugName_;
119
123 std::array<Vulkan::Buffer, STAGING_BUFFER_COUNT> stagingBuffers;
124 uint32_t framesRemaining = 0;
125 };
126 std::vector<PendingDeletion> pendingDeletions;
127
131 static constexpr uint32_t DELETION_DELAY_FRAMES = 6;
132 };
133}
The application context is the core class which stores the basic openxr and vulkan objects.
RAII wrapper for Vulkan buffer and device memory.
Definition Buffer.h:26
std::array< std::optional< Vulkan::Buffer >, STAGING_BUFFER_COUNT > stagingBuffers_
Vulkan::Buffer & getBufferRef()
Engine::Core::ApplicationContext * context_
StagedBufferSyncObjects upload(const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size)
Vulkan::Buffer & getStagingBufferRef()
std::vector< PendingDeletion > pendingDeletions
static constexpr uint32_t STAGING_BUFFER_COUNT
Number of staging buffers for multi-buffering (matches frames in flight)
void advanceStagingBuffer()
Advance to next staging buffer for double-buffering. Call this at the start of each frame to ensure w...
VkDeviceSize getSize() const
Gets the current size of the device buffer.
bool hasPendingDeletions() const
Checks if there are buffers pending deletion.
void create(Engine::Core::ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping=false)
Creates the staged buffer with device and staging buffers.
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...
const Vulkan::Buffer & getStagingBuffer() const
const Vulkan::Buffer & getBuffer() const
StagedBufferSyncObjects uploadPartial(const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset)
Upload data to a specific offset in the buffer (for incremental updates)
void setDebugName(const std::string &name, std::optional< uint32_t > index=std::nullopt)
std::optional< Buffer > buffer
void processPendingDeletions()
Destroys all buffers that were pending deletion. Call this after all frames that might reference old ...
static constexpr uint32_t DELETION_DELAY_FRAMES
Manages IBL (Image-Based Lighting) resources for specular reflections.
Description of one buffer copy operation.
Synchronization and copy metadata returned by staged buffer uploads.
VkBufferMemoryBarrier2 releaseBarrier
Barrier that releases ownership or visibility from the staging copy source.
VkBufferMemoryBarrier2 acquireBarrier
Barrier that acquires ownership or visibility for the destination buffer.
BufferCopyObject copyObject
Buffer copy operation recorded for the upload.
Old buffers waiting to be deleted after all frames complete.
uint32_t framesRemaining
Number of frames to wait before deletion.
std::array< Vulkan::Buffer, STAGING_BUFFER_COUNT > stagingBuffers