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 {
16 VkBufferMemoryBarrier2 releaseBarrier;
17 VkBufferMemoryBarrier2 acquireBarrier;
19 };
20
22 public:
24 static constexpr uint32_t STAGING_BUFFER_COUNT = 2;
25
27
36 void create(
37 Engine::Core::ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping = false);
38 void destroy();
39
40 StagedBufferSyncObjects upload( const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size);
41
50 StagedBufferSyncObjects uploadPartial( const Engine::Core::ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset);
51
58
66 bool ensureSize(VkDeviceSize requiredSize, VkBufferUsageFlags usage);
67
73
78 [[nodiscard]] bool hasPendingDeletions() const { return !pendingDeletions.empty(); }
79
80 [[nodiscard]] const Vulkan::Buffer& getBuffer() const { return buffer.value(); }
81 [[nodiscard]] Vulkan::Buffer& getBufferRef() { return buffer.value(); }
82 [[nodiscard]] const Vulkan::Buffer& getStagingBuffer() const { return stagingBuffers_[currentStagingIndex_].value(); }
84
89 [[nodiscard]] VkDeviceSize getSize() const;
90
91 void setDebugName(const std::string &name, std::optional<uint32_t> index = std::nullopt);
92
93 private:
95 std::optional<Buffer> buffer;
98 std::array<std::optional<Vulkan::Buffer>, STAGING_BUFFER_COUNT> stagingBuffers_;
100 std::string debugName_;
102
106 std::array<Vulkan::Buffer, STAGING_BUFFER_COUNT> stagingBuffers;
107 uint32_t framesRemaining = 0;
108 };
109 std::vector<PendingDeletion> pendingDeletions;
110
114 static constexpr uint32_t DELETION_DELAY_FRAMES = 6;
115 };
116}
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
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9
VkBufferMemoryBarrier2 releaseBarrier
VkBufferMemoryBarrier2 acquireBarrier
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