Added buffer.
This commit is contained in:
parent
0ca2779014
commit
c338c34337
|
|
@ -21,7 +21,8 @@ set(HEADER_FILES
|
||||||
device.h
|
device.h
|
||||||
swapchain.h
|
swapchain.h
|
||||||
"pipeline.h"
|
"pipeline.h"
|
||||||
queue_allocation.h)
|
queue_allocation.h
|
||||||
|
buffer.h)
|
||||||
|
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
logger.cpp
|
logger.cpp
|
||||||
|
|
@ -31,7 +32,8 @@ set(SOURCE_FILES
|
||||||
physical_device.cpp
|
physical_device.cpp
|
||||||
device.cpp
|
device.cpp
|
||||||
swapchain.cpp
|
swapchain.cpp
|
||||||
pipeline.cpp)
|
pipeline.cpp
|
||||||
|
buffer.cpp)
|
||||||
|
|
||||||
add_library(aster_core STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
add_library(aster_core STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||||
set_property(TARGET aster_core PROPERTY CXX_STANDARD 20)
|
set_property(TARGET aster_core PROPERTY CXX_STANDARD 20)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
// =============================================
|
||||||
|
// Aster: buffer.cpp
|
||||||
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
Buffer::Destroy(const Device *device)
|
||||||
|
{
|
||||||
|
if (!m_Buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
vmaDestroyBuffer(device->m_Allocator, m_Buffer, m_Allocation);
|
||||||
|
m_Buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UniformBuffer::Init(const Device *device, usize size, cstr name)
|
||||||
|
{
|
||||||
|
vk::BufferCreateInfo bufferCreateInfo = {
|
||||||
|
.size = size,
|
||||||
|
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
|
||||||
|
.sharingMode = vk::SharingMode::eExclusive,
|
||||||
|
};
|
||||||
|
constexpr VmaAllocationCreateInfo allocationCreateInfo = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
|
||||||
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkBuffer buffer;
|
||||||
|
VmaAllocation allocation;
|
||||||
|
auto result = Cast<vk::Result>(vmaCreateBuffer(device->m_Allocator, Recast<VkBufferCreateInfo *>(&bufferCreateInfo),
|
||||||
|
&allocationCreateInfo, &buffer, &allocation, nullptr));
|
||||||
|
ERROR_IF(Failed(result), "Could not allocate buffer. Cause: {}", result) THEN_ABORT(result);
|
||||||
|
|
||||||
|
m_Buffer = buffer;
|
||||||
|
m_Size = size;
|
||||||
|
m_Allocation = allocation;
|
||||||
|
|
||||||
|
device->SetName(m_Buffer, name);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
// =============================================
|
||||||
|
// Aster: buffer.h
|
||||||
|
// Copyright (c) 2020-2024 Anish Bhobe
|
||||||
|
// =============================================
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
struct Device;
|
||||||
|
|
||||||
|
struct Buffer
|
||||||
|
{
|
||||||
|
vk::Buffer m_Buffer = nullptr;
|
||||||
|
VmaAllocation m_Allocation = nullptr;
|
||||||
|
usize m_Size = 0;
|
||||||
|
|
||||||
|
void Destroy(const Device *device);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UniformBuffer : Buffer
|
||||||
|
{
|
||||||
|
void Init(const Device *device, usize size, cstr name = nullptr);
|
||||||
|
};
|
||||||
|
|
@ -43,6 +43,8 @@ template <typename T>
|
||||||
void
|
void
|
||||||
Device::SetName(const T &object, cstr name) const
|
Device::SetName(const T &object, cstr name) const
|
||||||
{
|
{
|
||||||
|
if (!name)
|
||||||
|
return;
|
||||||
auto handle = Recast<u64>(Cast<typename T::NativeType>(object));
|
auto handle = Recast<u64>(Cast<typename T::NativeType>(object));
|
||||||
const vk::DebugUtilsObjectNameInfoEXT objectNameInfo = {
|
const vk::DebugUtilsObjectNameInfoEXT objectNameInfo = {
|
||||||
.objectType = object.objectType,
|
.objectType = object.objectType,
|
||||||
|
|
|
||||||
|
|
@ -76,33 +76,26 @@ main(int, char **)
|
||||||
.extent = swapchain.m_Extent,
|
.extent = swapchain.m_Extent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vk::ImageSubresourceRange subresourceRange = {
|
||||||
|
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
};
|
||||||
vk::ImageMemoryBarrier topOfThePipeBarrier = {
|
vk::ImageMemoryBarrier topOfThePipeBarrier = {
|
||||||
.oldLayout = vk::ImageLayout::eUndefined,
|
.oldLayout = vk::ImageLayout::eUndefined,
|
||||||
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||||
.srcQueueFamilyIndex = queueAllocation.m_Family,
|
.srcQueueFamilyIndex = queueAllocation.m_Family,
|
||||||
.dstQueueFamilyIndex = queueAllocation.m_Family,
|
.dstQueueFamilyIndex = queueAllocation.m_Family,
|
||||||
.subresourceRange =
|
.subresourceRange = subresourceRange,
|
||||||
{
|
|
||||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
vk::ImageMemoryBarrier renderToPresentBarrier = {
|
vk::ImageMemoryBarrier renderToPresentBarrier = {
|
||||||
.oldLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
.oldLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||||
.newLayout = vk::ImageLayout::ePresentSrcKHR,
|
.newLayout = vk::ImageLayout::ePresentSrcKHR,
|
||||||
.srcQueueFamilyIndex = queueAllocation.m_Family,
|
.srcQueueFamilyIndex = queueAllocation.m_Family,
|
||||||
.dstQueueFamilyIndex = queueAllocation.m_Family,
|
.dstQueueFamilyIndex = queueAllocation.m_Family,
|
||||||
.subresourceRange =
|
.subresourceRange = subresourceRange,
|
||||||
{
|
|
||||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Frames
|
// Frames
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue