NDEVR
API Documentation
VulkanComputeBuffer.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2026, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: VulkanCompute
28File: VulkanComputeBuffer
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include "VulkanComputeDevice.h"
35#include <NDEVR/Pointer.h>
36
37namespace NDEVR
38{
47 class VULKAN_COMPUTE_API VulkanComputeBuffer
48 {
49 public:
50 VulkanComputeBuffer(const ConstPointer<VulkanComputeDevice>& compute_device);
51 ~VulkanComputeBuffer();
52
59 void allocate(VkDeviceSize byte_size, bool device_local = false);
60
64 void upload(const void* data, VkDeviceSize byte_size);
65
69 void download(void* data, VkDeviceSize byte_size) const;
70
72 void cleanup();
73
75 VkBuffer buffer() const { return m_device_buffer; }
76
78 VkDeviceSize byteSize() const { return m_byte_size; }
79
81 bool isAllocated() const { return m_device_buffer != VK_NULL_HANDLE; }
82
83 private:
90 VkBuffer createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceMemory& memory) const;
95 void copyBuffer(VkBuffer src, VkBuffer dst, VkDeviceSize size) const;
96
97 private:
98 ConstPointer<VulkanComputeDevice> m_compute_device;
99 VkBuffer m_device_buffer = VK_NULL_HANDLE;
100 VkDeviceMemory m_device_memory = VK_NULL_HANDLE;
101 VkBuffer m_staging_buffer = VK_NULL_HANDLE;
102 VkDeviceMemory m_staging_memory = VK_NULL_HANDLE;
103 VkDeviceSize m_byte_size = 0;
104 bool m_device_local = false;
105 };
106}
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
void cleanup()
Free all Vulkan resources.
void allocate(VkDeviceSize byte_size, bool device_local=false)
Allocate the buffer.
VkDeviceSize byteSize() const
The allocated byte size.
bool isAllocated() const
Whether the buffer has been allocated.
void download(void *data, VkDeviceSize byte_size) const
Download data from device buffer to CPU via staging.
VkBuffer buffer() const
The device-local VkBuffer (for binding as SSBO in descriptor sets).
void upload(const void *data, VkDeviceSize byte_size)
Upload data from CPU to the device buffer via staging.
The primary namespace for the NDEVR SDK.