mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-24 08:00:14 +00:00
Vulcan Nightmare
Experimentally bringing up vulcan support
This commit is contained in:
parent
863a786c48
commit
83b576e8d9
189 changed files with 12147 additions and 7820 deletions
91
src/rendering/vk_buffer.cpp
Normal file
91
src/rendering/vk_buffer.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include "rendering/vk_buffer.hpp"
|
||||
#include "rendering/vk_context.hpp"
|
||||
#include "core/logger.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
||||
VkBuffer::~VkBuffer() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
VkBuffer::VkBuffer(VkBuffer&& other) noexcept
|
||||
: buf_(other.buf_), allocator_(other.allocator_), size_(other.size_) {
|
||||
other.buf_ = {};
|
||||
other.allocator_ = VK_NULL_HANDLE;
|
||||
other.size_ = 0;
|
||||
}
|
||||
|
||||
VkBuffer& VkBuffer::operator=(VkBuffer&& other) noexcept {
|
||||
if (this != &other) {
|
||||
destroy();
|
||||
buf_ = other.buf_;
|
||||
allocator_ = other.allocator_;
|
||||
size_ = other.size_;
|
||||
other.buf_ = {};
|
||||
other.allocator_ = VK_NULL_HANDLE;
|
||||
other.size_ = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool VkBuffer::uploadToGPU(VkContext& ctx, const void* data, VkDeviceSize size,
|
||||
VkBufferUsageFlags usage)
|
||||
{
|
||||
destroy();
|
||||
allocator_ = ctx.getAllocator();
|
||||
size_ = size;
|
||||
|
||||
buf_ = uploadBuffer(ctx, data, size, usage);
|
||||
if (!buf_.buffer) {
|
||||
LOG_ERROR("Failed to upload buffer (size=", size, ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VkBuffer::createMapped(VmaAllocator allocator, VkDeviceSize size,
|
||||
VkBufferUsageFlags usage)
|
||||
{
|
||||
destroy();
|
||||
allocator_ = allocator;
|
||||
size_ = size;
|
||||
|
||||
buf_ = createBuffer(allocator, size, usage, VMA_MEMORY_USAGE_CPU_TO_GPU);
|
||||
if (!buf_.buffer) {
|
||||
LOG_ERROR("Failed to create mapped buffer (size=", size, ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VkBuffer::updateMapped(const void* data, VkDeviceSize size, VkDeviceSize offset) {
|
||||
if (!buf_.info.pMappedData) {
|
||||
LOG_ERROR("Attempted to update non-mapped buffer");
|
||||
return;
|
||||
}
|
||||
std::memcpy(static_cast<uint8_t*>(buf_.info.pMappedData) + offset, data, size);
|
||||
}
|
||||
|
||||
void VkBuffer::destroy() {
|
||||
if (buf_.buffer && allocator_) {
|
||||
destroyBuffer(allocator_, buf_);
|
||||
}
|
||||
buf_ = {};
|
||||
allocator_ = VK_NULL_HANDLE;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
VkDescriptorBufferInfo VkBuffer::descriptorInfo(VkDeviceSize offset, VkDeviceSize range) const {
|
||||
VkDescriptorBufferInfo info{};
|
||||
info.buffer = buf_.buffer;
|
||||
info.offset = offset;
|
||||
info.range = range;
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace rendering
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue