Create memory::Buffer & Implement StagingBuffer as derivative

A `Buffer` class was created to hold any generic Vulkan buffer object with `span` semantics, `StagingBuffer` was implemented atop it as a wrapper for `Buffer` that inherits from `FenceCycleDependency` and can be used as such.
This commit is contained in:
PixelyIon
2021-12-02 01:21:18 +05:30
parent a55aca76c6
commit 8f3887c56a
2 changed files with 42 additions and 8 deletions

View File

@ -11,29 +11,36 @@ namespace skyline::gpu::memory {
* @brief A view into a CPU mapping of a Vulkan buffer
* @note The mapping **should not** be used after the lifetime of the object has ended
*/
struct StagingBuffer : public span<u8>, public FenceCycleDependency {
struct Buffer : public span<u8> {
VmaAllocator vmaAllocator;
VmaAllocation vmaAllocation;
vk::Buffer vkBuffer;
constexpr StagingBuffer(u8 *pointer, size_t size, VmaAllocator vmaAllocator, vk::Buffer vkBuffer, VmaAllocation vmaAllocation)
constexpr Buffer(u8 *pointer, size_t size, VmaAllocator vmaAllocator, vk::Buffer vkBuffer, VmaAllocation vmaAllocation)
: vmaAllocator(vmaAllocator),
vkBuffer(vkBuffer),
vmaAllocation(vmaAllocation),
span(pointer, size) {}
StagingBuffer(const StagingBuffer &) = delete;
Buffer(const Buffer &) = delete;
constexpr StagingBuffer(StagingBuffer &&other)
constexpr Buffer(Buffer &&other)
: vmaAllocator(std::exchange(other.vmaAllocator, nullptr)),
vmaAllocation(std::exchange(other.vmaAllocation, nullptr)),
vkBuffer(std::exchange(other.vkBuffer, {})) {}
StagingBuffer &operator=(const StagingBuffer &) = delete;
Buffer &operator=(const Buffer &) = delete;
StagingBuffer &operator=(StagingBuffer &&) = default;
Buffer &operator=(Buffer &&) = default;
~StagingBuffer();
~Buffer();
};
/**
* @brief A Buffer that can be independently attached to a fence cycle
*/
class StagingBuffer : public Buffer, public FenceCycleDependency {
using Buffer::Buffer;
};
/**
@ -99,6 +106,11 @@ namespace skyline::gpu::memory {
*/
std::shared_ptr<StagingBuffer> AllocateStagingBuffer(vk::DeviceSize size);
/**
* @brief Creates a buffer with a CPU mapping and all usage flags
*/
Buffer AllocateBuffer(vk::DeviceSize size);
/**
* @brief Creates an image which is allocated and deallocated using RAII
*/