UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
VulkanBuffer.h
1#pragma once
2#include <UnCompute/Backend/BufferBase.h>
3#include <UnCompute/Backend/IDeviceMemory.h>
4#include <UnCompute/Memory/Memory.h>
5#include <UnCompute/VulkanBackend/VulkanInclude.h>
6
7namespace UN
8{
9 class VulkanDeviceMemory;
10
11 class VulkanBuffer final : public BufferBase
12 {
13 VkBuffer m_NativeBuffer = VK_NULL_HANDLE;
14 VkMemoryRequirements m_MemoryRequirements = {};
15 Ptr<VulkanDeviceMemory> m_MemoryOwner = {}; // !!! must be here to not free the memory before ~DeviceMemorySlice()
16 DeviceMemorySlice m_Memory = {};
17
18 protected:
19 ResultCode InitInternal(const BufferDesc& desc) override;
20
21 public:
22 explicit VulkanBuffer(IComputeDevice* pDevice);
23 ~VulkanBuffer() override;
24
25 ResultCode BindMemory(const DeviceMemorySlice& deviceMemory) override;
26 ResultCode BindMemory(IDeviceMemory* pDeviceMemory) override;
27 void Reset() override;
28
29 [[nodiscard]] inline VkBuffer GetNativeBuffer() const
30 {
31 return m_NativeBuffer;
32 }
33
34 [[nodiscard]] inline const VkMemoryRequirements& GetMemoryRequirements() const
35 {
36 return m_MemoryRequirements;
37 }
38
39 inline static ResultCode Create(IComputeDevice* pDevice, IBuffer** ppBuffer)
40 {
41 *ppBuffer = AllocateObject<VulkanBuffer>(pDevice);
42 (*ppBuffer)->AddRef();
43 return ResultCode::Success;
44 }
45 };
46} // namespace UN
Definition: BufferBase.h:8
A slice of device memory.
Definition: IDeviceMemory.h:89
An interface for backend-specific buffers that store the data on the device.
Definition: IBuffer.h:26
Interface for all backend-specific compute devices.
Definition: IComputeDevice.h:38
This class holds a handle to backend-specific memory.
Definition: IDeviceMemory.h:31
Shared smart pointer implementation that uses reference counting.
Definition: Ptr.h:44
Definition: VulkanBuffer.h:12
ResultCode BindMemory(const DeviceMemorySlice &deviceMemory) override
Bind device memory to the buffer.
Definition: VulkanBuffer.cpp:12
void Reset() override
Reset the object to uninitialized state.
Definition: VulkanBuffer.cpp:34
Buffer descriptor.
Definition: IBuffer.h:8