68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
// =============================================
|
|
// Aster: buffer.h
|
|
// Copyright (c) 2020-2024 Anish Bhobe
|
|
// =============================================
|
|
|
|
#pragma once
|
|
|
|
#include "global.h"
|
|
|
|
struct Device;
|
|
|
|
struct Buffer
|
|
{
|
|
vk::Buffer m_Buffer = nullptr;
|
|
VmaAllocation m_Allocation = nullptr;
|
|
void *m_Mapped = nullptr;
|
|
|
|
[[nodiscard]] usize GetSize() const;
|
|
[[nodiscard]] bool IsHostVisible() const;
|
|
[[nodiscard]] bool IsMapped() const;
|
|
|
|
void Destroy(const Device *device);
|
|
void Write(const Device *device, usize offset, usize size, void *data);
|
|
|
|
protected:
|
|
void Allocate(const Device *device, usize size, vk::BufferUsageFlags bufferUsage,
|
|
VmaAllocationCreateFlags allocationFlags, VmaMemoryUsage memoryUsage, cstr name);
|
|
|
|
usize m_Size = 0;
|
|
|
|
constexpr static usize HOST_ACCESSIBLE_BIT = 1llu << 63;
|
|
constexpr static usize SIZE_MASK = ~HOST_ACCESSIBLE_BIT;
|
|
};
|
|
|
|
struct UniformBuffer : Buffer
|
|
{
|
|
void Init(const Device *device, usize size, cstr name = nullptr);
|
|
};
|
|
|
|
struct VertexBuffer : Buffer
|
|
{
|
|
void Init(const Device *device, usize size, cstr name = nullptr);
|
|
void Write(const Device *device, void *data, usize size, usize offset) const = delete;
|
|
};
|
|
|
|
struct StagingBuffer : Buffer
|
|
{
|
|
void Init(const Device *device, usize size, cstr name = nullptr);
|
|
};
|
|
|
|
inline usize
|
|
Buffer::GetSize() const
|
|
{
|
|
return m_Size & SIZE_MASK;
|
|
}
|
|
|
|
inline bool
|
|
Buffer::IsHostVisible() const
|
|
{
|
|
return m_Size & HOST_ACCESSIBLE_BIT;
|
|
}
|
|
|
|
inline bool
|
|
Buffer::IsMapped() const
|
|
{
|
|
return m_Mapped;
|
|
}
|