Commit 262bb32a authored by Lukas Tietze's avatar Lukas Tietze

Fixe für shaderc-Implementierung!

parent 3a9c77c9
......@@ -18,7 +18,7 @@ add_subdirectory(./src/submodules/glfw)
set(SHADERC_SKIP_TESTS on)
set(SHADERC_ENABLE_SHARED_CRT on)
add_subdirectory(./src/submodules/shaderc/src)
add_subdirectory(./src/submodules/shaderc/)
# set(ASSIMP_NO_EXPORT on)
set(ASSIMP_BUILD_TESTS off)
......@@ -88,7 +88,8 @@ target_include_directories(Lib
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/.shaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
......@@ -128,7 +129,8 @@ target_include_directories(App
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/src/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
......@@ -161,7 +163,8 @@ target_include_directories(Playground
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/src/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
......
#version 450
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
// #extension GL_GOOGLE_include_directive : enable
// #extension GL_ARB_separate_shader_objects : enable
layout(location = 0) out vec2 texCoord;
......
......@@ -276,7 +276,7 @@ lib::AppCreateInfo app::VkrtApp::CreateInitInfo() const
info.shaderTable.postProcessingFragmentShader.path = "./assets/shaders/post-processing/default.frag.glsl";
info.shaderTable.postProcessingFragmentShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
info.shaderTable.postProcessingVertexShader.type = lib::ShaderType::Fragment;
info.shaderTable.postProcessingVertexShader.type = lib::ShaderType::Vertex;
info.shaderTable.postProcessingVertexShader.fileType = lib::ShaderFileType::Glsl;
info.shaderTable.postProcessingVertexShader.path = "./assets/shaders/post-processing/default.vert.glsl";
info.shaderTable.postProcessingVertexShader.compileOptions.optimizationLevel = lib::ShaderOptimizationLevel::Performance;
......
......@@ -22,4 +22,17 @@ namespace lib
inline const glm::vec3 y = {0, 1, 0};
inline const glm::vec3 z = {0, 0, 1};
} // namespace axis
namespace ansiColors
{
constexpr auto Black = "\u001b[30m";
constexpr auto Red = "\u001b[31m";
constexpr auto Green = "\u001b[32m";
constexpr auto Yellow = "\u001b[33m";
constexpr auto Blue = "\u001b[34m";
constexpr auto Magenta = "\u001b[35m";
constexpr auto Cyan = "\u001b[36m";
constexpr auto White = "\u001b[37m";
constexpr auto Reset = "\u001b[0m";
} // namespace ansiColors
} // namespace lib
......@@ -7,63 +7,98 @@
namespace lib
{
namespace log
{
void SetLoggingStatus(bool debugEnabled, bool infoEnabled, bool warningEnabled, bool errorEnabled);
bool IsDebugEnabled();
bool IsInfoEnabled();
bool IsWarningEnabled();
bool IsErrorEnabled();
void LogDebug(const std::string &text);
void Log(const std::string &text);
void LogWarning(const std::string &text);
void LogError(const std::string &text);
template <class TFirst, class... TArgs>
void LogDebug(const std::string &format, const TFirst &first, const TArgs &... args)
{
if constexpr (IsDebug)
namespace log
{
if (!lib::log::IsDebugEnabled())
struct ChannelState
{
return;
}
bool enabled;
bool flush;
std::string prefix;
std::string suffix;
lib::log::LogDebug(Format(format, first, args...));
}
}
inline ChannelState(
bool enabled,
std::string prefix,
std::string suffix,
bool flush)
: enabled(enabled),
flush(flush),
prefix(prefix),
suffix(suffix) {}
};
template <class TFirst, class... TArgs>
void Log(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::IsInfoEnabled())
{
return;
}
struct State
{
ChannelState debug;
ChannelState info;
ChannelState warning;
ChannelState error;
lib::log::Log(Format(format, first, args...));
}
inline State(
ChannelState debug,
ChannelState info,
ChannelState warning,
ChannelState error)
: debug(debug),
info(info),
warning(warning),
error(error)
{
}
};
template <class TFirst, class... TArgs>
void LogWarning(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::IsWarningEnabled())
{
return;
}
State &GetState();
lib::log::LogWarning(Format(format, first, args...));
}
void Debug(const std::string &text);
void Info(const std::string &text);
void Warning(const std::string &text);
void Error(const std::string &text);
template <class TFirst, class... TArgs>
void LogError(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::IsErrorEnabled())
{
return;
}
template <class TFirst, class... TArgs>
void Debug(const std::string &format, const TFirst &first, const TArgs &... args)
{
if constexpr (IsDebug)
{
if (!lib::log::GetState().debug.enabled)
{
return;
}
lib::log::LogError(Format(format, first, args...));
}
} // namespace log
lib::log::Debug(Format(format, first, args...));
}
}
template <class TFirst, class... TArgs>
void Info(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::GetState().info.enabled)
{
return;
}
lib::log::Info(Format(format, first, args...));
}
template <class TFirst, class... TArgs>
void Warning(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::GetState().warning.enabled)
{
return;
}
lib::log::Warning(Format(format, first, args...));
}
template <class TFirst, class... TArgs>
void Error(const std::string &format, const TFirst &first, const TArgs &... args)
{
if (!lib::log::GetState().error.enabled)
{
return;
}
lib::log::Error(Format(format, first, args...));
}
} // namespace log
} // namespace lib
\ No newline at end of file
......@@ -8,9 +8,9 @@
#include <numeric>
#include <cmath>
using lib::log::Log;
using lib::log::LogError;
using lib::log::LogWarning;
using lib::log::Info;
using lib::log::Error;
using lib::log::Warning;
#undef CreateWindow
......@@ -145,20 +145,20 @@ lib::App::App(const AppCreateInfo &info) : appBaseName(info.appName),
{
if (!info.Validate(false))
{
LogError("Invalid create info!");
Error("Invalid create info!");
return;
}
if (!glfwInit())
{
LogError("Glfw could not be initialized!");
Error("Glfw could not be initialized!");
return;
}
if (!glfwVulkanSupported())
{
LogError("Vulkan is not supported!");
Error("Vulkan is not supported!");
return;
}
......@@ -172,22 +172,22 @@ lib::App::App(const AppCreateInfo &info) : appBaseName(info.appName),
if (this->context->IsOk())
{
Log("Successfully initialized App!");
Info("Successfully initialized App!");
}
else if (this->context->IsRecoverable())
{
LogWarning("Initialized App with recoverable errors!");
Warning("Initialized App with recoverable errors!");
}
else
{
LogError("Failed to initialize App: Failed to initialize Vulkan Context!");
Error("Failed to initialize App: Failed to initialize Vulkan Context!");
}
this->RegisterCallbacks();
}
catch (const std::exception &e)
{
LogError("Failed to initialize App: Exception occurred: %", e.what());
Error("Failed to initialize App: Exception occurred: %", e.what());
}
}
......@@ -227,21 +227,21 @@ void lib::App::Run()
{
if (!this->IsOk())
{
LogError("The App was not initialized correctly, can't run!");
Error("The App was not initialized correctly, can't run!");
return;
}
if (!this->adapter)
{
LogError("There must be an IAppAdapter attached to run!");
Error("There must be an IAppAdapter attached to run!");
return;
}
this->adapter->AfterInit(*this);
Log("Starting main loop!");
Info("Starting main loop!");
auto hasException = false;
::t0 = ::t1 = std::chrono::high_resolution_clock::now();
......@@ -261,12 +261,12 @@ void lib::App::Run()
}
catch (const std::exception &e)
{
LogError("Exception occurred: %", e.what());
Error("Exception occurred: %", e.what());
hasException = true;
}
catch (...)
{
LogError("Unidentified exception occurred");
Error("Unidentified exception occurred");
hasException = true;
}
}
......
......@@ -57,7 +57,7 @@ bool lib::AppCreateInfo::Validate(bool silent) const
{
for (const auto &error : errors)
{
lib::log::LogError(::errorMessages[error]);
lib::log::Error(::errorMessages[error]);
}
}
......
......@@ -17,10 +17,10 @@
#include "Util/Utils.hpp"
#include "VkUtil/VkUtil.hpp"
using lib::log::Log;
using lib::log::LogDebug;
using lib::log::LogError;
using lib::log::LogWarning;
using lib::log::Debug;
using lib::log::Error;
using lib::log::Info;
using lib::log::Warning;
#undef min
#undef max
......@@ -29,11 +29,11 @@ void lib::CgContext::QueryExtensions()
{
this->availableExtensions = vk::enumerateInstanceExtensionProperties();
if (lib::log::IsDebugEnabled())
if (lib::log::GetState().debug.enabled)
{
for (const auto &availableExtension : this->availableExtensions)
{
LogDebug("Available extension %", availableExtension.extensionName);
Debug("Available extension %", availableExtension.extensionName);
}
}
}
......@@ -52,11 +52,11 @@ bool lib::CgContext::CheckAndAdd(const char *name, NameList &buf, bool required)
if (required)
{
LogError("Could not find required extension %", name);
Error("Could not find required extension %", name);
}
else
{
LogWarning("Could not find optional extension %", name);
Warning("Could not find optional extension %", name);
}
return false;
......@@ -78,11 +78,11 @@ void lib::CgContext::QueryLayers()
{
this->availableLayers = vk::enumerateInstanceLayerProperties();
if (lib::log::IsDebugEnabled())
if (lib::log::GetState().debug.enabled)
{
for (const auto &availableLayer : this->availableLayers)
{
LogDebug("Available extension %", availableLayer.layerName);
Debug("Available extension %", availableLayer.layerName);
}
}
}
......@@ -97,7 +97,7 @@ bool lib::CgContext::CheckLayer(const char *name)
}
}
LogError("Could not find layer %", name);
Error("Could not find layer %", name);
return false;
}
......
......@@ -26,10 +26,10 @@
#include "imgui_impl_vulkan.h"
#include "imgui_impl_glfw.h"
using lib::log::Log;
using lib::log::LogDebug;
using lib::log::LogError;
using lib::log::LogWarning;
using lib::log::Debug;
using lib::log::Error;
using lib::log::Info;
using lib::log::Warning;
bool lib::CgContext::TryCreateRasterizerPipeline()
{
......@@ -73,6 +73,7 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
viewport.maxDepth = 1.f;
vk::Rect2D scissor;
scissor.offset = {0, 0};
scissor.extent = this->swapChainExtent;
vk::PipelineViewportStateCreateInfo viewportStateCreateInfo;
......@@ -122,7 +123,17 @@ bool lib::CgContext::TryCreateRasterizerPipeline()
createInfo.layout = this->rasterizationStep.pipelineLayout;
const auto result = this->logicalDevice.createGraphicsPipeline(nullptr, createInfo);
this->rasterizationStep.pipeline = result.value;
if (result.result == vk::Result::eSuccess)
{
this->rasterizationStep.pipeline = result.value;
}
else
{
Error("Failed to create Graphicspipeline!");
success = false;
}
}
if (vertexModule)
......
......@@ -26,10 +26,10 @@
#include "imgui_impl_vulkan.h"
#include "imgui_impl_glfw.h"
using lib::log::Log;
using lib::log::LogDebug;
using lib::log::LogError;
using lib::log::LogWarning;
using lib::log::Info;
using lib::log::Debug;
using lib::log::Error;
using lib::log::Warning;
void lib::CgContext::CreateAccelerationStructures()
{
......@@ -51,7 +51,7 @@ void lib::CgContext::CreateAccelerationStructures()
commandBuffer.Run();
Log("Successfully created acceleration structures!");
Info("Successfully created acceleration structures!");
}
void lib::CgContext::CreateRaytracingDescriptorSetLayout()
......@@ -131,7 +131,7 @@ void lib::CgContext::CreateRaytracingDescriptorSetLayout()
this->raytracingStep.descriptorSetLayout = this->logicalDevice.createDescriptorSetLayout(createInfo);
Log("Successfully created descriptor set layout!");
Info("Successfully created descriptor set layout!");
}
void lib::CgContext::CreateRaytracingDescriptorPool()
......@@ -298,7 +298,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
{});
}
Log("Successfully created raytracing descriptor set!");
Info("Successfully created raytracing descriptor set!");
}
bool lib::CgContext::TryCreateRayTracingPipeline()
......@@ -414,13 +414,13 @@ bool lib::CgContext::TryCreateRayTracingPipeline()
const auto result = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo);
this->raytracingStep.pipeline = result.value[0];
Log("Successfully created raytracing pipeline!");
Info("Successfully created raytracing pipeline!");
success = true;
}
else
{
LogError("Failed to load shaders required for raytracing!");
Error("Failed to load shaders required for raytracing!");
}
if (raygenModule)
......@@ -463,5 +463,5 @@ void lib::CgContext::CreateShaderBindingTable()
this->shaderBindingTableBuffer.reset(new lib::Buffer(std::move(finalBuffer)));
Log("Successfully created shader binding table!");
Info("Successfully created shader binding table!");
}
......@@ -26,39 +26,38 @@
#include "imgui_impl_vulkan.h"
#include "imgui_impl_glfw.h"
using lib::log::Log;
using lib::log::LogDebug;
using lib::log::LogError;
using lib::log::LogWarning;
using lib::log::Debug;
using lib::log::Error;
using lib::log::Info;
using lib::log::Warning;
#undef min
#undef max
namespace
{
VKAPI_ATTR vk::Bool32 VKAPI_CALL debugCallback(vk::DebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
vk::DebugUtilsMessageTypeFlagsEXT messageType,
const vk::DebugUtilsMessengerCallbackDataEXT &pCallbackData,
void *pUserData)
bool debugCallback(vk::DebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
vk::DebugUtilsMessageTypeFlagsEXT messageType,
const vk::DebugUtilsMessengerCallbackDataEXT &pCallbackData,
void *pUserData)
{
switch (messageSeverity)
{
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose:
lib::log::LogDebug("[ValidationLayer] %", pCallbackData.pMessage);
lib::log::Debug("[ValidationLayer] %", pCallbackData.pMessage);
break;
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo:
lib::log::Log("[ValidationLayer] %", pCallbackData.pMessage);
lib::log::Info("[ValidationLayer] %", pCallbackData.pMessage);
break;
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning:
lib::log::LogWarning("[ValidationLayer] %", pCallbackData.pMessage);
lib::log::Warning("[ValidationLayer] %", pCallbackData.pMessage);
break;
case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError:
lib::log::LogError("[ValidationLayer] %", pCallbackData.pMessage);
lib::log::Error("[ValidationLayer] %", pCallbackData.pMessage);
break;
}
return VK_FALSE;
return false;
}
/**
......@@ -88,11 +87,11 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
Log("Starting %\nVersion: %.%.%\nTimeStamp: %\nBuildType: %",
this->appInfo.appName,
version::Major, version::Minor, version::Patch,
version::TimeStamp,
version::Type);
Info("Starting %\nVersion: %.%.%\nTimeStamp: %\nBuildType: %",
this->appInfo.appName,
version::Major, version::Minor, version::Patch,
version::TimeStamp,
version::Type);
try
{
......@@ -127,15 +126,15 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
this->CreateSyncObjects();
this->InitializeImGui();
this->frameIndex = 0;
Log("Successfully initialized Vulkan!");
Info("Successfully initialized Vulkan!");
}
catch (CoreInitException &e)
{
LogError("Failed to initialize Vulkan!\nReason: %", e.what());
Error("Failed to initialize Vulkan!\nReason: %", e.what());
}
catch (std::exception &e)
{
LogError("Failed to initialize Vulkan after unhandled exception!\n What: %!", e.what());
Error("Failed to initialize Vulkan after unhandled exception!\n What: %!", e.what());
}
}
......@@ -415,7 +414,7 @@ void lib::CgContext::CreateInstance()
}
else
{
LogWarning("Not all required Layers are available!");
Warning("Not all required Layers are available!");
}
}
......@@ -429,7 +428,7 @@ void lib::CgContext::CreateInstance()
this->instance = vk::createInstance(createInfo);
Log("Successfully created vulkan instance!");
Info("Successfully created vulkan instance!");
VULKAN_HPP_DEFAULT_DISPATCHER.init(this->instance);
......@@ -443,10 +442,20 @@ void lib::CgContext::SetupDebugCallbacks()
{
vk::DebugUtilsMessengerCreateInfoEXT createInfo;
lib::log::SetLoggingStatus(this->appInfo.loggingInfo.debugEnabled,
this->appInfo.loggingInfo.infosEnabled,
this->appInfo.loggingInfo.warningsEnabled,
this->appInfo.loggingInfo.errorsEnabled);
auto log = lib::log::GetState();
log.debug.enabled = this->appInfo.loggingInfo.debugEnabled;
log.debug.prefix = lib::ansiColors::White + log.debug.prefix;
log.debug.suffix = lib::ansiColors::Reset;
log.info.enabled = this->appInfo.loggingInfo.infosEnabled;
log.info.prefix = lib::ansiColors::Green + log.info.prefix;
log.info.suffix = lib::ansiColors::Reset;
log.warning.enabled = this->appInfo.loggingInfo.warningsEnabled;
log.warning.prefix = lib::ansiColors::Yellow + log.warning.prefix;
log.warning.suffix = lib::ansiColors::Reset;
log.error.enabled = this->appInfo.loggingInfo.errorsEnabled;
log.error.prefix = lib::ansiColors::Red + log.error.prefix;
log.error.suffix = lib::ansiColors::Reset;
if (this->appInfo.loggingInfo.debugEnabled)
{
......@@ -476,7 +485,7 @@ void lib::CgContext::SetupDebugCallbacks()
this->debugMessenger = this->instance.createDebugUtilsMessengerEXT(createInfo, nullptr);