Refactor tracing

This commit is contained in:
Thraix
2023-04-13 22:03:06 +02:00
parent d9e7fd7019
commit 0246e89039
31 changed files with 132 additions and 130 deletions
@@ -20,7 +20,7 @@ namespace Copium
createInfo.maxSets = DESCRIPTOR_SET_COUNT * SwapChain::MAX_FRAMES_IN_FLIGHT;
createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "DescriptorPool : Failed to initialize descriptor pool");
CP_VK_ASSERT(vkCreateDescriptorPool(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorPool), "Failed to initialize descriptor pool");
}
DescriptorPool::~DescriptorPool()
@@ -38,7 +38,7 @@ namespace Copium
allocateInfo.descriptorSetCount = descriptorSets.size();
allocateInfo.pSetLayouts = layouts.data();
CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "AllocateDescriptorSets : Failed to allocate descriptor sets");
CP_VK_ASSERT(vkAllocateDescriptorSets(Vulkan::GetDevice(), &allocateInfo, descriptorSets.data()), "Failed to allocate descriptor sets");
return descriptorSets;
}
@@ -7,7 +7,7 @@ namespace Copium
DescriptorSet::DescriptorSet(DescriptorPool& descriptorPool, VkDescriptorSetLayout descriptorSetLayout, const std::set<ShaderBinding>& bindings)
: descriptorPool{descriptorPool}, descriptorSetLayout{descriptorSetLayout}, bindings{bindings}
{
CP_ASSERT(!bindings.empty(), "DescriptorSet : cannot initialize DescriptorSet with empty ShaderBindings");
CP_ASSERT(!bindings.empty(), "Cannot initialize DescriptorSet with empty ShaderBindings");
descriptorSets = descriptorPool.AllocateDescriptorSets(descriptorSetLayout);
for (auto& binding : bindings)
@@ -86,7 +86,7 @@ namespace Copium
UniformBuffer& DescriptorSet::GetUniformBuffer(const std::string& uniformBuffer)
{
auto it = uniformBuffers.find(uniformBuffer);
CP_ASSERT(it != uniformBuffers.end(), "GetUniformBuffer : UniformBuffer not found = %s", uniformBuffer.c_str());
CP_ASSERT(it != uniformBuffers.end(), "UniformBuffer not found = %s", uniformBuffer.c_str());
return *it->second;
}
@@ -30,7 +30,7 @@ namespace Copium
void Pipeline::SetDescriptorSet(const DescriptorSet& descriptorSet)
{
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "SetDescriptorSet : DescriptorSet index is out of bounds");
CP_ASSERT(descriptorSet.GetSetIndex() < boundDescriptorSets.size(), "DescriptorSet index is out of bounds");
boundDescriptorSets[descriptorSet.GetSetIndex()] = descriptorSet;
}
@@ -76,7 +76,7 @@ namespace Copium
createInfo.bindingCount = layoutBindings.size();
createInfo.pBindings = layoutBindings.data();
CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "InitializeDescriptorSetLayout : Failed to initialize descriptor set layout");
CP_VK_ASSERT(vkCreateDescriptorSetLayout(Vulkan::GetDevice(), &createInfo, nullptr, &descriptorSetLayouts[i++]), "Failed to initialize descriptor set layout");
}
}
@@ -192,7 +192,7 @@ namespace Copium
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
pipelineLayoutCreateInfo.pPushConstantRanges = nullptr;
CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "InitializePipeline : Failed to initialize pipeline layout");
CP_VK_ASSERT(vkCreatePipelineLayout(Vulkan::GetDevice(), &pipelineLayoutCreateInfo, nullptr, &pipelineLayout), "Failed to initialize pipeline layout");
const std::vector<VkPipelineShaderStageCreateInfo>& shaderStages = shader.GetShaderStages();
VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo{};
@@ -213,6 +213,6 @@ namespace Copium
graphicsPipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
graphicsPipelineCreateInfo.basePipelineIndex = -1;
CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "InitializePipeline : Failed to initialize graphics pipeline");
CP_VK_ASSERT(vkCreateGraphicsPipelines(Vulkan::GetDevice(), VK_NULL_HANDLE, 1, &graphicsPipelineCreateInfo, nullptr, &graphicsPipeline), "Failed to initialize graphics pipeline");
}
}
@@ -55,7 +55,7 @@ namespace Copium
case BindingType::UniformBuffer:
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
default:
CP_ABORT("GetDescriptorType : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
@@ -68,7 +68,7 @@ namespace Copium
case ShaderType::Fragment:
return VK_SHADER_STAGE_FRAGMENT_BIT;
default:
CP_ABORT("GetShaderStageFlags : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
}
+9 -8
View File
@@ -2,6 +2,7 @@
#include "copium/util/FileSystem.h"
#include "copium/core/Vulkan.h"
#include "copium/util/RuntimeException.h"
namespace Copium
{
@@ -26,7 +27,7 @@ namespace Copium
fragShaderModule = InitializeShaderModule(FileSystem::ReadFile(fragmentInput));
break;
default:
CP_ASSERT(false, "Shader : Unreachable switch case %d", (int)type);
CP_ASSERT(false, "Unreachable switch case %d", (int)type);
}
shaderStages.resize(2);
@@ -78,17 +79,17 @@ namespace Copium
{
if (FileSystem::DateModified(filename) < FileSystem::DateModified(spvFilename))
{
CP_DEBUG("InitializeShaderModuleFromGlslFile : Loading cached shader file: %s", filename.c_str());
CP_DEBUG("Loading cached shader file: %s", filename.c_str());
std::vector<uint32_t> data = FileSystem::ReadFile32(spvFilename);
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
}
}
}
catch (const std::runtime_error& e)
catch (const RuntimeException& e)
{
CP_WARN("InitializeShaderModuleFromGlslFile : Cached shader file is invalid, recreating it");
CP_WARN("Cached shader file is invalid, recreating it");
}
CP_DEBUG("InitializeShaderModuleFromGlslFile : Compiling shader file: %s", filename.c_str());
CP_DEBUG("Compiling shader file: %s", filename.c_str());
shaderc::Compiler compiler;
shaderc::CompileOptions options;
@@ -96,7 +97,7 @@ namespace Copium
std::vector<char> glslCode = FileSystem::ReadFile(filename);
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(glslCode.data(), glslCode.size(), type, filename.c_str(), options);
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "InitializeShaderModuleFromGlslFile : Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str());
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile shader: %s\n%s", filename.c_str(), result.GetErrorMessage().c_str());
std::vector<uint32_t> data{result.cbegin(), result.cend()};
FileSystem::WriteFile(spvFilename, (const char*)data.data(), data.size() * sizeof(uint32_t));
@@ -111,7 +112,7 @@ namespace Copium
options.SetOptimizationLevel(shaderc_optimization_level_size);
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(code.data(), type, "inline_shader_code", options);
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "InitializeShaderModuleFromGlslCode : Failed to compile inline shader code: %s", result.GetErrorMessage());
CP_ASSERT(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile inline shader code: %s", result.GetErrorMessage());
std::vector<uint32_t> data{result.cbegin(), result.cend()};
return InitializeShaderModule(data.data(), data.size() * sizeof(uint32_t));
@@ -125,7 +126,7 @@ namespace Copium
createInfo.pCode = data;
VkShaderModule shaderModule;
CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), "InitializeShaderModule : Failed to initialize shader module");
CP_VK_ASSERT(vkCreateShaderModule(Vulkan::GetDevice(), &createInfo, nullptr, &shaderModule), "Failed to initialize shader module");
return shaderModule;
}
@@ -21,7 +21,7 @@ namespace Copium
return offset;
offset += GetUniformTypeOffset(uniformElem.first);
}
CP_ABORT("GetUniformOffset : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
uint32_t ShaderBinding::GetUniformSize(const std::string& uniform) const
@@ -31,7 +31,7 @@ namespace Copium
if (uniformElem.second == uniform)
return GetUniformTypeSize(uniformElem.first);
}
CP_ABORT("GetUniformSize : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
UniformType ShaderBinding::GetUniformType(const std::string& uniform) const
@@ -41,12 +41,12 @@ namespace Copium
if (uniformElem.second == uniform)
return uniformElem.first;
}
CP_ABORT("GetUniformType : Uniform not found=%s", uniform);
CP_ABORT("Uniform not found=%s", uniform);
}
uint32_t ShaderBinding::GetUniformBufferSize() const
{
CP_ASSERT(bindingType == BindingType::UniformBuffer, "GetUniformBufferSize : BindingType is not UniformBuffer");
CP_ASSERT(bindingType == BindingType::UniformBuffer, "BindingType is not UniformBuffer");
uint32_t size = 0;
for (auto& uniform : uniforms)
@@ -79,7 +79,7 @@ namespace Copium
case UniformType::Float:
return 4; // float
default:
CP_ABORT("GetUniformBufferSize : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
@@ -102,7 +102,7 @@ namespace Copium
case UniformType::Float:
return 16; // alignas(16) glm::vec2
default:
CP_ABORT("GetUniformBufferSize : Unhandled switch case");
CP_ABORT("Unhandled switch case");
}
}
}
@@ -103,7 +103,7 @@ namespace Copium
shaderBinding.bindingType = BindingType::Sampler2D;
else
shaderBinding.bindingType = BindingType::UniformBuffer;
CP_ASSERT(bindings.emplace(shaderBinding).second, "ParseLayout : multiple layouts with the same binding");
CP_ASSERT(bindings.emplace(shaderBinding).second, "multiple layouts with the same binding");
}
std::string_view ShaderReflector::ParseWord(const std::string& str, int& index)
@@ -6,7 +6,7 @@ namespace Copium
{
void VertexDescriptor::AddAttribute(uint32_t binding, uint32_t location, VkFormat format, uint32_t offset, uint32_t size)
{
CP_ASSERT(binding <= bindings.size(), "AddAttribute : Attribute binding must less than or be equal to the amount of current bindings");
CP_ASSERT(binding <= bindings.size(), "Attribute binding must less than or be equal to the amount of current bindings");
if (binding == bindings.size())
AddLayout(binding, size);