Rework tracing system and enum creators
- Rework tracing system, now using "{}" for formatting instead of the
standard %s,%d,%f formatting that C++ uses.
- Rework enums creators to not take in namespace
- Fix single use CommandBuffers sometimes failing due to indexing them
with the current frame in flight
- Add DropEvent to Window
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "copium/buffer/CommandBuffer.h"
|
||||
|
||||
#include "copium/core/Vulkan.h"
|
||||
#include "copium/util/Trace.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
@@ -16,7 +17,7 @@ namespace Copium
|
||||
commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
break;
|
||||
default:
|
||||
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
||||
CP_ABORT("Unreachable switch case: {}", type);
|
||||
}
|
||||
|
||||
VkCommandBufferAllocateInfo allocateInfo{};
|
||||
@@ -49,33 +50,46 @@ namespace Copium
|
||||
beginInfo.flags = 0;
|
||||
beginInfo.pInheritanceInfo = nullptr;
|
||||
|
||||
int index = Vulkan::GetSwapChain().GetFlightIndex();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CommandBufferType::SingleUse:
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
index = 0;
|
||||
break;
|
||||
case CommandBufferType::Dynamic:
|
||||
break;
|
||||
default:
|
||||
CP_ABORT("Unreachable switch case: %s", ToString(type).c_str());
|
||||
CP_ABORT("Unreachable switch case: {}", type);
|
||||
}
|
||||
|
||||
vkResetCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], 0);
|
||||
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()], &beginInfo),
|
||||
"Failed to begin command buffer");
|
||||
vkResetCommandBuffer(commandBuffers[index], 0);
|
||||
CP_VK_ASSERT(vkBeginCommandBuffer(commandBuffers[index], &beginInfo), "Failed to begin command buffer");
|
||||
}
|
||||
|
||||
void CommandBuffer::End()
|
||||
{
|
||||
vkEndCommandBuffer(commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()]);
|
||||
int index = Vulkan::GetSwapChain().GetFlightIndex();
|
||||
if (type == CommandBufferType::SingleUse)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
vkEndCommandBuffer(commandBuffers[index]);
|
||||
}
|
||||
|
||||
void CommandBuffer::Submit()
|
||||
{
|
||||
int index = Vulkan::GetSwapChain().GetFlightIndex();
|
||||
if (type == CommandBufferType::SingleUse)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
|
||||
submitInfo.pCommandBuffers = &commandBuffers[index];
|
||||
|
||||
vkQueueSubmit(Vulkan::GetDevice().GetGraphicsQueue(), 1, &submitInfo, VK_NULL_HANDLE);
|
||||
// TODO: if singleUse?
|
||||
@@ -84,6 +98,11 @@ namespace Copium
|
||||
|
||||
CommandBuffer::operator VkCommandBuffer() const
|
||||
{
|
||||
return commandBuffers[Vulkan::GetSwapChain().GetFlightIndex()];
|
||||
int index = Vulkan::GetSwapChain().GetFlightIndex();
|
||||
if (type == CommandBufferType::SingleUse)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
return commandBuffers[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
#include "copium/util/Common.h"
|
||||
#include "copium/util/Enum.h"
|
||||
|
||||
#define CP_COMMAND_BUFFER_TYPE_ENUMS SingleUse, Dynamic
|
||||
CP_ENUM_CREATOR(Copium, CommandBufferType, CP_COMMAND_BUFFER_TYPE_ENUMS);
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
CP_ENUM_CREATOR(CommandBufferType, SingleUse, Dynamic);
|
||||
|
||||
class CommandBuffer
|
||||
{
|
||||
CP_DELETE_COPY_AND_MOVE_CTOR(CommandBuffer);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "copium/buffer/Framebuffer.h"
|
||||
|
||||
#include "copium/asset/AssetManager.h"
|
||||
#include "copium/buffer/CommandBuffer.h"
|
||||
#include "copium/core/Vulkan.h"
|
||||
#include "copium/sampler/Image.h"
|
||||
@@ -15,8 +14,8 @@ namespace Copium
|
||||
|
||||
width = attachment.GetWidth();
|
||||
height = attachment.GetHeight();
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: {}", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: {}", height);
|
||||
|
||||
InitializeDepthBuffer();
|
||||
InitializeRenderPass();
|
||||
@@ -27,8 +26,8 @@ namespace Copium
|
||||
: width{width},
|
||||
height{height}
|
||||
{
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: {}", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: {}", height);
|
||||
|
||||
InitializeImage(samplerCreator);
|
||||
InitializeDepthBuffer();
|
||||
@@ -51,8 +50,8 @@ namespace Copium
|
||||
|
||||
void Framebuffer::Resize(int width, int height)
|
||||
{
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: %d", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: %d", height);
|
||||
CP_ASSERT(width > 0, "Width of framebuffer is less than 1: {}", width);
|
||||
CP_ASSERT(height > 0, "Height of framebuffer is less than 1: {}", height);
|
||||
|
||||
Vulkan::GetDevice().WaitIdle();
|
||||
this->width = width;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "copium/util/Trace.h"
|
||||
|
||||
namespace Copium
|
||||
{
|
||||
IndexBuffer::IndexBuffer(int indexCount)
|
||||
|
||||
@@ -20,4 +20,4 @@ namespace Copium
|
||||
void Draw(const CommandBuffer& commandBuffer);
|
||||
void Draw(const CommandBuffer& commandBuffer, int indices);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Copium
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, const glm::mat3& data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat3, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat3, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
// memcpy(buffer.data() + offset, &data[0], sizeof(glm::vec3));
|
||||
// memcpy(buffer.data() + offset + 16, &data[1], sizeof(glm::vec3));
|
||||
@@ -36,42 +36,42 @@ namespace Copium
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, const glm::mat4& data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat4, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Mat4, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(glm::mat4));
|
||||
}
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, const glm::vec2& data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec2, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec2, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(glm::vec2));
|
||||
}
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, const glm::vec3& data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec3, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec3, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(glm::vec3));
|
||||
}
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, const glm::vec4& data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec4, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Vec4, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(glm::vec4));
|
||||
}
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, float data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Float, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Float, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(float));
|
||||
}
|
||||
|
||||
void UniformBuffer::Set(const std::string& str, int data)
|
||||
{
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Int, "Uniform type missmatch = %s", str.c_str());
|
||||
CP_ASSERT(binding.GetUniformType(str) == UniformType::Int, "Uniform type missmatch = {}", str);
|
||||
uint32_t offset = binding.GetUniformOffset(str);
|
||||
memcpy(buffer.data() + offset, &data, sizeof(int));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user