mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40: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
55
include/rendering/vk_buffer.hpp
Normal file
55
include/rendering/vk_buffer.hpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
#include "rendering/vk_utils.hpp"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering {
|
||||
|
||||
class VkContext;
|
||||
|
||||
// RAII wrapper for a Vulkan buffer with VMA allocation.
|
||||
// Supports vertex, index, uniform, and storage buffer usage.
|
||||
class VkBuffer {
|
||||
public:
|
||||
VkBuffer() = default;
|
||||
~VkBuffer();
|
||||
|
||||
VkBuffer(const VkBuffer&) = delete;
|
||||
VkBuffer& operator=(const VkBuffer&) = delete;
|
||||
VkBuffer(VkBuffer&& other) noexcept;
|
||||
VkBuffer& operator=(VkBuffer&& other) noexcept;
|
||||
|
||||
// Create a GPU-local buffer and upload data via staging
|
||||
bool uploadToGPU(VkContext& ctx, const void* data, VkDeviceSize size,
|
||||
VkBufferUsageFlags usage);
|
||||
|
||||
// Create a host-visible buffer (for uniform/dynamic data updated each frame)
|
||||
bool createMapped(VmaAllocator allocator, VkDeviceSize size,
|
||||
VkBufferUsageFlags usage);
|
||||
|
||||
// Update mapped buffer contents (only valid for mapped buffers)
|
||||
void updateMapped(const void* data, VkDeviceSize size, VkDeviceSize offset = 0);
|
||||
|
||||
void destroy();
|
||||
|
||||
::VkBuffer getBuffer() const { return buf_.buffer; }
|
||||
VkDeviceSize getSize() const { return size_; }
|
||||
void* getMappedData() const { return buf_.info.pMappedData; }
|
||||
bool isValid() const { return buf_.buffer != VK_NULL_HANDLE; }
|
||||
|
||||
// Descriptor info for uniform/storage buffer binding
|
||||
VkDescriptorBufferInfo descriptorInfo(VkDeviceSize offset = 0,
|
||||
VkDeviceSize range = VK_WHOLE_SIZE) const;
|
||||
|
||||
private:
|
||||
AllocatedBuffer buf_{};
|
||||
VmaAllocator allocator_ = VK_NULL_HANDLE;
|
||||
VkDeviceSize size_ = 0;
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue