Make Vulkan class a global instance

This commit is contained in:
Thraix
2023-04-04 21:14:01 +02:00
parent 9faec15fd6
commit 431ad9c573
56 changed files with 333 additions and 424 deletions
+24 -25
View File
@@ -1,12 +1,11 @@
#include "copium/buffer/Buffer.h"
#include "copium/core/Device.h"
#include "copium/core/Instance.h"
#include "copium/core/Vulkan.h"
namespace Copium
{
Buffer::Buffer(Vulkan& vulkan, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
: vulkan{vulkan}, size{size}, count{count}
Buffer::Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count)
: size{size}, count{count}
{
VkBufferCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@@ -14,25 +13,25 @@ namespace Copium
createInfo.usage = usage;
createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
CP_VK_ASSERT(vkCreateBuffer(vulkan.GetDevice(), &createInfo, nullptr, &handle), "Buffer : Failed to initialize buffer");
CP_VK_ASSERT(vkCreateBuffer(Vulkan::GetDevice(), &createInfo, nullptr, &handle), "Buffer : Failed to initialize buffer");
VkMemoryRequirements memoryRequirements;
vkGetBufferMemoryRequirements(vulkan.GetDevice(), handle, &memoryRequirements);
vkGetBufferMemoryRequirements(Vulkan::GetDevice(), handle, &memoryRequirements);
VkMemoryAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = vulkan.GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
allocateInfo.memoryTypeIndex = Vulkan::GetDevice().FindMemoryType(memoryRequirements.memoryTypeBits, properties);
CP_VK_ASSERT(vkAllocateMemory(vulkan.GetDevice(), &allocateInfo, nullptr, &memory), "Buffer : Failed to allocate buffer memory");
CP_VK_ASSERT(vkAllocateMemory(Vulkan::GetDevice(), &allocateInfo, nullptr, &memory), "Buffer : Failed to allocate buffer memory");
vkBindBufferMemory(vulkan.GetDevice(), handle, memory, 0);
vkBindBufferMemory(Vulkan::GetDevice(), handle, memory, 0);
}
Buffer::~Buffer()
{
vkFreeMemory(vulkan.GetDevice(), memory, nullptr);
vkDestroyBuffer(vulkan.GetDevice(), handle, nullptr);
vkFreeMemory(Vulkan::GetDevice(), memory, nullptr);
vkDestroyBuffer(Vulkan::GetDevice(), handle, nullptr);
}
void Buffer::Update(void* indexData, int index)
@@ -42,9 +41,9 @@ namespace Copium
if (mappedData == nullptr)
{
void* data;
vkMapMemory(vulkan.GetDevice(), memory, index * size, size, 0, &data);
vkMapMemory(Vulkan::GetDevice(), memory, index * size, size, 0, &data);
memcpy(data, indexData, size);
vkUnmapMemory(vulkan.GetDevice(), memory);
vkUnmapMemory(Vulkan::GetDevice(), memory);
}
else
{
@@ -55,26 +54,26 @@ namespace Copium
void Buffer::UpdateStaging(void* data)
{
VkDeviceSize bufferSize = size * count;
Buffer stagingBuffer{vulkan, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1};
Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, bufferSize, 1};
stagingBuffer.Update(data, 0);
CopyBuffer(vulkan, stagingBuffer, *this, 0, bufferSize);
CopyBuffer(stagingBuffer, *this, 0, bufferSize);
}
void Buffer::UpdateStaging(void* data, VkDeviceSize offset, VkDeviceSize size)
{
Buffer stagingBuffer{vulkan, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, size, 1};
Buffer stagingBuffer{VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, size, 1};
stagingBuffer.Update(data, 0);
CopyBuffer(vulkan, stagingBuffer, *this, offset, size);
CopyBuffer(stagingBuffer, *this, offset, size);
}
void* Buffer::Map()
{
CP_ASSERT(mappedData == nullptr, "Map : Mapping an already mapped buffer");
vkMapMemory(vulkan.GetDevice(), memory, 0, size * count, 0, &mappedData);
vkMapMemory(Vulkan::GetDevice(), memory, 0, size * count, 0, &mappedData);
return mappedData;
}
@@ -82,7 +81,7 @@ namespace Copium
{
CP_ASSERT(mappedData != nullptr, "Unmap : Unmapping an already unmapped buffer");
vkUnmapMemory(vulkan.GetDevice(), memory);
vkUnmapMemory(Vulkan::GetDevice(), memory);
mappedData = nullptr;
}
@@ -102,17 +101,17 @@ namespace Copium
return size * (VkDeviceSize)index;
}
void Buffer::CopyBuffer(Vulkan& vulkan, const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size)
void Buffer::CopyBuffer(const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size)
{
VkCommandBufferAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandPool = vulkan.GetDevice().GetCommandPool();
allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
allocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer;
CP_VK_ASSERT(vkAllocateCommandBuffers(vulkan.GetDevice(), &allocateInfo, &commandBuffer), "CopyBuffer : Failed to initialize command buffer");
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, &commandBuffer), "CopyBuffer : Failed to initialize command buffer");
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -134,9 +133,9 @@ namespace Copium
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer;
vkQueueSubmit(vulkan.GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
vkQueueWaitIdle(vulkan.GetDevice().GetGraphicsQueue());
vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
vkQueueWaitIdle(Vulkan::GetDevice().GetGraphicsQueue());
vkFreeCommandBuffers(vulkan.GetDevice(), vulkan.GetDevice().GetCommandPool(), 1, &commandBuffer);
vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), 1, &commandBuffer);
}
}
+2 -5
View File
@@ -1,6 +1,5 @@
#pragma once
#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
@@ -11,8 +10,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Buffer);
protected:
Vulkan& vulkan;
VkDeviceMemory memory;
VkBuffer handle;
VkDeviceSize size;
@@ -21,7 +18,7 @@ namespace Copium
void* mappedData = nullptr;
public:
Buffer(Vulkan& vulkan, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count);
Buffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkDeviceSize size, int count);
virtual ~Buffer();
void Update(void* indexData, int index);
@@ -35,6 +32,6 @@ namespace Copium
VkDeviceSize GetSize() const;
VkDeviceSize GetPosition(int index) const;
static void CopyBuffer(Vulkan& vulkan, const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size);
static void CopyBuffer(const Buffer& srcBuffer, const Buffer& dstBuffer, VkDeviceSize offset, VkDeviceSize size);
};
}
@@ -1,13 +1,11 @@
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Device.h"
#include "copium/core/Instance.h"
#include "copium/core/SwapChain.h"
#include "copium/core/Vulkan.h"
namespace Copium
{
CommandBuffer::CommandBuffer(Vulkan& vulkan, Type type)
: vulkan{vulkan}, type{type}
CommandBuffer::CommandBuffer(Type type)
: type{type}
{
switch (type)
{
@@ -24,14 +22,14 @@ namespace Copium
VkCommandBufferAllocateInfo allocateInfo{};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandPool = vulkan.GetDevice().GetCommandPool();
allocateInfo.commandPool = Vulkan::GetDevice().GetCommandPool();
allocateInfo.commandBufferCount = commandBuffers.size();
CP_VK_ASSERT(vkAllocateCommandBuffers(vulkan.GetDevice(), &allocateInfo, commandBuffers.data()), "CommandBuffer : Failed to allocate CommandBuffer");
CP_VK_ASSERT(vkAllocateCommandBuffers(Vulkan::GetDevice(), &allocateInfo, commandBuffers.data()), "CommandBuffer : Failed to allocate CommandBuffer");
}
CommandBuffer::~CommandBuffer()
{
vkFreeCommandBuffers(vulkan.GetDevice(), vulkan.GetDevice().GetCommandPool(), commandBuffers.size(), commandBuffers.data());
vkFreeCommandBuffers(Vulkan::GetDevice(), Vulkan::GetDevice().GetCommandPool(), commandBuffers.size(), commandBuffers.data());
}
// TODO: Test as constexpr function to see if it avoids the switch case
@@ -53,13 +51,13 @@ namespace Copium
CP_ABORT("Begin : Unreachable switch case");
}
vkResetCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()], 0);
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()], &beginInfo), "Begin : Failed to begin command buffer");
vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0);
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo), "Begin : Failed to begin command buffer");
}
void CommandBuffer::End()
{
vkEndCommandBuffer(commandBuffers[vulkan.GetSwapChain().GetFlightIndex()]);
vkEndCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()]);
}
void CommandBuffer::Submit()
@@ -67,15 +65,15 @@ namespace Copium
VkSubmitInfo submitInfo{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffers[vulkan.GetSwapChain().GetFlightIndex()];
submitInfo.pCommandBuffers = &commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
vkQueueSubmit(vulkan.GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
// TODO: if singleUse?
vkQueueWaitIdle(vulkan.GetDevice().GetGraphicsQueue());
vkQueueWaitIdle(Vulkan::GetDevice().GetGraphicsQueue());
}
CommandBuffer::operator VkCommandBuffer() const
{
return commandBuffers[vulkan.GetSwapChain().GetFlightIndex()];
return commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
}
}
@@ -1,6 +1,5 @@
#pragma once
#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
#include <vulkan/vulkan.hpp>
@@ -16,13 +15,11 @@ namespace Copium
SingleUse, Dynamic
};
private:
Vulkan& vulkan;
std::vector<VkCommandBuffer> commandBuffers;
const Type type;
public:
CommandBuffer(Vulkan& vulkan, Type type);
CommandBuffer(Type type);
virtual ~CommandBuffer();
void Begin();
@@ -2,8 +2,8 @@
namespace Copium
{
CommandBufferScoped::CommandBufferScoped(Vulkan& vulkan)
: CommandBuffer{vulkan, Type::SingleUse}
CommandBufferScoped::CommandBufferScoped()
: CommandBuffer{Type::SingleUse}
{
CommandBuffer::Begin();
}
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
namespace Copium
@@ -10,7 +9,7 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBufferScoped);
public:
CommandBufferScoped(Vulkan& vulkan);
CommandBufferScoped();
~CommandBufferScoped() override;
};
+14 -15
View File
@@ -1,14 +1,13 @@
#include "copium/buffer/Framebuffer.h"
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Device.h"
#include "copium/core/SwapChain.h"
#include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h"
namespace Copium
{
Framebuffer::Framebuffer(Vulkan& vulkan, uint32_t width, uint32_t height)
: vulkan{vulkan}, width{width}, height{height}
Framebuffer::Framebuffer(uint32_t width, uint32_t height)
: width{width}, height{height}
{
InitializeImage();
InitializeDepthBuffer();
@@ -19,19 +18,19 @@ namespace Copium
Framebuffer::~Framebuffer()
{
for (auto& framebuffer : framebuffers)
vkDestroyFramebuffer(vulkan.GetDevice(), framebuffer, nullptr);
vkDestroyRenderPass(vulkan.GetDevice(), renderPass, nullptr);
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
vkDestroyRenderPass(Vulkan::GetDevice(), renderPass, nullptr);
}
void Framebuffer::Resize(uint32_t width, uint32_t height)
{
vkDeviceWaitIdle(vulkan.GetDevice());
vkDeviceWaitIdle(Vulkan::GetDevice());
this->width = width;
this->height = height;
colorAttachment.reset();
depthAttachment.reset();
for (auto&& framebuffer : framebuffers)
vkDestroyFramebuffer(vulkan.GetDevice(), framebuffer, nullptr);
vkDestroyFramebuffer(Vulkan::GetDevice(), framebuffer, nullptr);
InitializeImage();
InitializeDepthBuffer();
InitializeFramebuffers();
@@ -46,7 +45,7 @@ namespace Copium
VkRenderPassBeginInfo renderPassBeginInfo{};
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassBeginInfo.renderPass = renderPass;
renderPassBeginInfo.framebuffer = framebuffers[vulkan.GetSwapChain().GetFlightIndex()];
renderPassBeginInfo.framebuffer = framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
;
renderPassBeginInfo.renderArea.offset = {0, 0};
renderPassBeginInfo.renderArea.extent = {width, height};
@@ -80,7 +79,7 @@ namespace Copium
VkFramebuffer Framebuffer::GetFramebuffer() const
{
return framebuffers[vulkan.GetSwapChain().GetFlightIndex()];
return framebuffers[Vulkan::GetSwapChain().GetFlightIndex()];
}
const ColorAttachment& Framebuffer::GetColorAttachment() const
@@ -100,12 +99,12 @@ namespace Copium
void Framebuffer::InitializeImage()
{
colorAttachment = std::make_unique<ColorAttachment>(vulkan, width, height);
colorAttachment = std::make_unique<ColorAttachment>(width, height);
}
void Framebuffer::InitializeDepthBuffer()
{
depthAttachment = std::make_unique<DepthAttachment>(vulkan, width, height);
depthAttachment = std::make_unique<DepthAttachment>(width, height);
}
void Framebuffer::InitializeRenderPass()
@@ -121,7 +120,7 @@ namespace Copium
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
VkAttachmentDescription depthAttachment{};
depthAttachment.format = Image::SelectDepthFormat(vulkan);
depthAttachment.format = Image::SelectDepthFormat();
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
@@ -169,7 +168,7 @@ namespace Copium
renderPassCreateInfo.dependencyCount = dependencies.size();
renderPassCreateInfo.pDependencies = dependencies.data();
CP_VK_ASSERT(vkCreateRenderPass(vulkan.GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
CP_VK_ASSERT(vkCreateRenderPass(Vulkan::GetDevice(), &renderPassCreateInfo, nullptr, &renderPass), "InitializeRenderPass : Failed to initialze render pass");
}
void Framebuffer::InitializeFramebuffers()
@@ -188,7 +187,7 @@ namespace Copium
createInfo.height = height;
createInfo.layers = 1;
CP_VK_ASSERT(vkCreateFramebuffer(vulkan.GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize framebuffer");
CP_VK_ASSERT(vkCreateFramebuffer(Vulkan::GetDevice(), &createInfo, nullptr, &framebuffers[i]), "InitializeFramebuffers : Failed to initialize framebuffer");
}
}
}
+1 -4
View File
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Vulkan.h"
#include "copium/sampler/ColorAttachment.h"
#include "copium/sampler/DepthAttachment.h"
#include "copium/util/Common.h"
@@ -14,8 +13,6 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(Framebuffer);
private:
Vulkan& vulkan;
std::unique_ptr<ColorAttachment> colorAttachment;
std::unique_ptr<DepthAttachment> depthAttachment;
std::vector<VkFramebuffer> framebuffers;
@@ -24,7 +21,7 @@ namespace Copium
uint32_t width;
uint32_t height;
public:
Framebuffer(Vulkan& vulkan, uint32_t width, uint32_t height);
Framebuffer(uint32_t width, uint32_t height);
~Framebuffer();
void Resize(uint32_t width, uint32_t height);
@@ -4,8 +4,8 @@
namespace Copium
{
IndexBuffer::IndexBuffer(Vulkan& vulkan, int indexCount)
: Buffer{vulkan, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexCount * sizeof(uint16_t), 1},
IndexBuffer::IndexBuffer(int indexCount)
: Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexCount * sizeof(uint16_t), 1},
indexCount{indexCount}
{}
+1 -2
View File
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Vulkan.h"
#include "copium/util/Common.h"
namespace Copium
@@ -13,7 +12,7 @@ namespace Copium
private:
int indexCount;
public:
IndexBuffer(Vulkan& vulkan, int indexCount);
IndexBuffer(int indexCount);
void Bind(const CommandBuffer& commandBuffer);
void Draw(const CommandBuffer& commandBuffer);
@@ -1,17 +1,17 @@
#include "copium/buffer/RendererVertexBuffer.h"
#include "copium/core/SwapChain.h"
#include "copium/core/Vulkan.h"
namespace Copium
{
RendererVertexBuffer::RendererVertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount)
: Buffer{vulkan, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, descriptor.GetVertexSize() * vertexCount, SwapChain::MAX_FRAMES_IN_FLIGHT}
RendererVertexBuffer::RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
: Buffer{VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, descriptor.GetVertexSize() * vertexCount, SwapChain::MAX_FRAMES_IN_FLIGHT}
{}
void RendererVertexBuffer::Bind(const CommandBuffer& commandBuffer)
{
VkDeviceSize offset = GetPosition(vulkan.GetSwapChain().GetFlightIndex());
VkDeviceSize offset = GetPosition(Vulkan::GetSwapChain().GetFlightIndex());
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &handle, &offset);
}
}
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Vulkan.h"
#include "copium/pipeline/VertexDescriptor.h"
namespace Copium
@@ -11,7 +10,7 @@ namespace Copium
{
CP_DELETE_COPY_AND_MOVE_CTOR(RendererVertexBuffer);
public:
RendererVertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount);
RendererVertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
void Bind(const CommandBuffer& commandBuffer);
};
@@ -1,11 +1,11 @@
#include "copium/buffer/UniformBuffer.h"
#include "copium/core/SwapChain.h"
#include "copium/core/Vulkan.h"
namespace Copium
{
UniformBuffer::UniformBuffer(Vulkan& vulkan, ShaderBinding binding)
: Buffer{vulkan, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, binding.GetUniformBufferSize(), SwapChain::MAX_FRAMES_IN_FLIGHT}, binding{binding}
UniformBuffer::UniformBuffer(ShaderBinding binding)
: Buffer{VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, binding.GetUniformBufferSize(), SwapChain::MAX_FRAMES_IN_FLIGHT}, binding{binding}
{
buffer.resize(Buffer::GetSize());
}
@@ -70,6 +70,6 @@ namespace Copium
void UniformBuffer::Update()
{
Buffer::Update(buffer.data(), vulkan.GetSwapChain().GetFlightIndex());
Buffer::Update(buffer.data(), Vulkan::GetSwapChain().GetFlightIndex());
}
}
@@ -1,7 +1,6 @@
#pragma once
#include "copium/buffer/Buffer.h"
#include "copium/core/Vulkan.h"
#include "copium/pipeline/ShaderBinding.h"
#include "copium/util/Common.h"
@@ -13,12 +12,12 @@ namespace Copium
class UniformBuffer final : public Buffer
{
CP_DELETE_COPY_AND_MOVE_CTOR(UniformBuffer);
private:
ShaderBinding binding;
std::vector<uint8_t> buffer;
public:
UniformBuffer(Vulkan& vulkan, ShaderBinding binding);
UniformBuffer(ShaderBinding binding);
VkDescriptorBufferInfo GetDescriptorBufferInfo(int index) const;
@@ -2,8 +2,8 @@
namespace Copium
{
VertexBuffer::VertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount)
: Buffer{vulkan, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, descriptor.GetVertexSize() * vertexCount, 1}
VertexBuffer::VertexBuffer(const VertexDescriptor& descriptor, int vertexCount)
: Buffer{VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, descriptor.GetVertexSize() * vertexCount, 1}
{
VkDeviceSize offset = 0;
for (auto&& binding : descriptor.GetBindings())
@@ -2,7 +2,6 @@
#include "copium/buffer/Buffer.h"
#include "copium/buffer/CommandBuffer.h"
#include "copium/core/Vulkan.h"
#include "copium/pipeline/VertexDescriptor.h"
#include "copium/util/Common.h"
@@ -18,7 +17,7 @@ namespace Copium
std::vector<VkDeviceSize> bindingOffsets;
std::vector<VkDeviceSize> bindingSizes;
public:
VertexBuffer(Vulkan& vulkan, const VertexDescriptor& descriptor, int vertexCount);
VertexBuffer(const VertexDescriptor& descriptor, int vertexCount);
void Bind(const CommandBuffer& commandBuffer);
void UpdateStaging(uint32_t binding, void* data);