NDEVR
API Documentation
VulkanStagingRing.h
1#pragma once
2#include "VulkanDevice.h"
3namespace NDEVR
4{
18
22 {
26 void add(bool is_src, VkBufferCopy item);
28 };
29
35 {
37 enum CMDBufferState
38 {
39 e_has_pending
40 , e_is_running
41 , e_empty
42 };
43 public:
51 void ensureSize(VkDeviceSize size);
54 void setSize(VkDeviceSize size);
58 void* mapData(VkDeviceSize size);
63 void setData(const void* data, VkDeviceSize byte_size, VkDeviceSize alignment = 1);
66 VkCommandBuffer getCommandBuffer();
68 void cleanup();
70 void begin();
74 void end();
78 void sendData(VkBuffer dst, VkDeviceSize dst_offset_bytes);
85 void sendData(VkImage dst, Vector<2, uint04> image_size, uint04 mip_level, uint04 image_layer, VkCommandBuffer command_buffer);
88 void removePending(VkBuffer buffer);
94 void moveData(VkBuffer target, VkDeviceSize src_offset, VkDeviceSize dst_offset, VkDeviceSize size);
97 private:
98 void record(uint04 idx);
99 void submit();
100 void waitForComplete();
101 private:
102 void* m_ptr = nullptr;
103 VkCommandPool m_command_pool = VK_NULL_HANDLE;
104 VkBuffer m_local_buffer = VK_NULL_HANDLE;
105 VkDeviceMemory m_memory = VK_NULL_HANDLE;
106 VkDeviceSize m_size = 0;
107 VkDeviceSize m_head = 0;
108 VkDeviceSize m_atom = 1;
109 VkDeviceSize m_pending_size = 0;
110 Dictionary<VkBuffer, CopyOperations> m_regions_to_copy;
111 Dictionary<VkBuffer, CopyOperations> m_regions_copying;
112 Buffer<VkCommandBuffer> m_command_buffers;
113 Buffer<CMDBufferState> m_cmd_buffer_states;
114 VkFence m_fence = VK_NULL_HANDLE;
115 uint04 m_next_cmd_buffer = 0;
116 const VulkanDevice* m_device;
117 bool m_coherent = true;
118 bool m_needs_fence_wait = false;
119 bool m_is_running = false;
120#ifdef _DEBUG
121 uint04 m_start_thread = Constant<uint04>::Invalid;
122#endif
123 };
124}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A GraphicsDevice for managing Vulkan limitations and actions.
void sendData(VkBuffer dst, VkDeviceSize dst_offset_bytes)
Queues a copy from the staging buffer to a destination buffer.
void setData(const void *data, VkDeviceSize byte_size, VkDeviceSize alignment=1)
Writes data into the staging buffer.
void moveData(VkBuffer target, VkDeviceSize src_offset, VkDeviceSize dst_offset, VkDeviceSize size)
Moves data within a buffer using a transfer command.
void end()
Ends the current staging cycle and submits pending transfers.
void setSize(VkDeviceSize size)
Sets the staging buffer to the given size.
void * mapData(VkDeviceSize size)
Maps a region of the staging buffer for writing.
~VulkanStagingRing()
Destructor.
VkCommandBuffer getCommandBuffer()
Returns a command buffer for recording transfer commands.
void begin()
Begins a new staging cycle.
VulkanStagingRing(const VulkanDevice *device)
Constructs a staging ring for the given device.
void removePending(VkBuffer buffer)
Removes all pending copy operations targeting the given buffer.
void cleanup()
Releases all staging ring resources.
void setDeviceLost()
Handles device lost by resetting internal state.
void ensureComplete()
Ensures all pending transfers are complete before returning.
void ensureSize(VkDeviceSize size)
Ensures the staging buffer is at least the given size.
void sendData(VkImage dst, Vector< 2, uint04 > image_size, uint04 mip_level, uint04 image_layer, VkCommandBuffer command_buffer)
Queues a copy from the staging buffer to a destination image.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
A collection of buffer copy steps for batched copy operations.
Buffer< CopyStep > ops
The ordered list of copy steps.
void add(bool is_src, VkBufferCopy item)
Adds a copy region to the operation.
Buffer< VkBufferCopy > regions
The buffer copy regions for this step.
bool is_src
Whether this step represents the source side.
CopyStep(bool is_src)
Constructs a copy step.