diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f9d35ef4efa5fda1cac41ad3a6ffb82c44ee1299..9c88d409b7d5f220128306d483730c2215b4bdf5 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -24,8 +24,8 @@ jobs: - name: Install dependencies run: | sudo apt-get -qq update - sudo apt-get -qq install ninja-build cmake g++ - sudo apt-get -qq install libvulkan-dev xorg-dev + sudo apt-get -qq install ninja-build cmake extra-cmake-modules g++ + sudo apt-get -qq install libvulkan-dev xorg-dev libwayland-dev libxkbcommon-dev - name: Build framework run: | diff --git a/.gitmodules b/.gitmodules index 0f788015915ea014037a674cd19deccaea0279f2..e5bea176875b4e249c8d21c99b248299cf353e67 100644 --- a/.gitmodules +++ b/.gitmodules @@ -94,3 +94,16 @@ [submodule "modules/shader_compiler/lib/json-c"] path = modules/shader_compiler/lib/json-c url = https://github.com/json-c/json-c.git +[submodule "modules/shader_compiler/lib/slang"] + path = modules/shader_compiler/lib/slang + url = https://github.com/TheJackiMonster/slang.git + branch = master +[submodule "modules/shader_compiler/lib/unordered_dense"] + path = modules/shader_compiler/lib/unordered_dense + url = https://github.com/martinus/unordered_dense.git +[submodule "modules/shader_compiler/lib/lz4"] + path = modules/shader_compiler/lib/lz4 + url = https://github.com/lz4/lz4.git +[submodule "modules/shader_compiler/lib/miniz"] + path = modules/shader_compiler/lib/miniz + url = https://github.com/richgel999/miniz.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c80a2bc8ec940f3fbe09415eb02e133d77cc16f8..9b2a6176348e4ec9ac1532d89387c31fe77a3778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.25) project(vkcv) # cmake options diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp index 3f32d61e9c95ccb51207a3795a590230e9d95b36..c6421b8ef69d153821e3424e08a748694623bb82 100644 --- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -16,8 +16,10 @@ namespace vkcv::asset { * @param e The exception being thrown * @param path The path to the file that was responsible for the exception */ - static void recurseExceptionPrint(const std::exception& e, const std::string &path) { - vkcv_log(LogLevel::ERROR, "Loading file %s: %s", path.c_str(), e.what()); + static void recurseExceptionPrint(const std::exception& e, + const std::filesystem::path& path) { + vkcv_log(LogLevel::ERROR, "Loading file %s: %s", + path.string().c_str(), e.what()); try { std::rethrow_if_nested(e); @@ -537,10 +539,10 @@ namespace vkcv::asset { ); } } catch (const std::system_error& err) { - recurseExceptionPrint(err, path.string()); + recurseExceptionPrint(err, path); return ASSET_ERROR; } catch (const std::exception& e) { - recurseExceptionPrint(e, path.string()); + recurseExceptionPrint(e, path); return ASSET_ERROR; } @@ -554,7 +556,7 @@ namespace vkcv::asset { // file has to contain at least one mesh if (sceneObjects.meshes.empty()) { - vkcv_log(LogLevel::ERROR, "No meshes found! (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "No meshes found! (%s)", path.string().c_str()); return ASSET_ERROR; } else { scene.meshes.reserve(sceneObjects.meshes.size()); @@ -565,7 +567,7 @@ namespace vkcv::asset { if (loadVertexGroups(sceneObjects.meshes[i], sceneObjects, scene, mesh) != ASSET_SUCCESS) { vkcv_log(LogLevel::ERROR, "Failed to load vertex groups of '%s'! (%s)", - mesh.name.c_str(), path.c_str()); + mesh.name.c_str(), path.string().c_str()); return ASSET_ERROR; } @@ -625,7 +627,8 @@ namespace vkcv::asset { } if (sceneObjects.samplers.empty()) { - vkcv_log(LogLevel::WARNING, "No samplers found! (%s)", path.c_str()); + vkcv_log(LogLevel::WARNING, "No samplers found! (%s)", + path.string().c_str()); } else { scene.samplers.reserve(sceneObjects.samplers.size()); @@ -635,7 +638,8 @@ namespace vkcv::asset { } if (sceneObjects.textures.empty()) { - vkcv_log(LogLevel::WARNING, "No textures found! (%s)", path.c_str()); + vkcv_log(LogLevel::WARNING, "No textures found! (%s)", + path.string().c_str()); } else { scene.textures.reserve(sceneObjects.textures.size()); @@ -647,7 +651,7 @@ namespace vkcv::asset { } else if (static_cast<size_t>(textureObject.sampler) >= scene.samplers.size()) { vkcv_log(LogLevel::ERROR, "Sampler of texture '%s' missing (%s)", - textureObject.name.c_str(), path.c_str()); + textureObject.name.c_str(), path.string().c_str()); return ASSET_ERROR; } else { texture.sampler = textureObject.sampler; @@ -656,7 +660,7 @@ namespace vkcv::asset { if ((textureObject.source < 0) || (static_cast<size_t>(textureObject.source) >= sceneObjects.images.size())) { vkcv_log(LogLevel::ERROR, "Failed to load texture '%s' (%s)", - textureObject.name.c_str(), path.c_str()); + textureObject.name.c_str(), path.string().c_str()); return ASSET_ERROR; } @@ -679,7 +683,8 @@ namespace vkcv::asset { } if (sceneObjects.materials.empty()) { - vkcv_log(LogLevel::WARNING, "No materials found! (%s)", path.c_str()); + vkcv_log(LogLevel::WARNING, "No materials found! (%s)", + path.string().c_str()); } else { scene.materials.reserve(sceneObjects.materials.size()); @@ -746,7 +751,7 @@ namespace vkcv::asset { if (!data) { vkcv_log(LogLevel::ERROR, "Texture could not be loaded from '%s'", - texture.path.c_str()); + texture.path.string().c_str()); texture.width = 0; texture.height = 0; @@ -777,7 +782,7 @@ namespace vkcv::asset { const int result = loadTextureData(scene.textures[material.baseColor]); if (ASSET_SUCCESS != result) { vkcv_log(LogLevel::ERROR, "Failed loading baseColor texture of mesh '%s'", - mesh.name.c_str()) + mesh.name.c_str()) return result; } } @@ -786,7 +791,7 @@ namespace vkcv::asset { const int result = loadTextureData(scene.textures[material.metalRough]); if (ASSET_SUCCESS != result) { vkcv_log(LogLevel::ERROR, "Failed loading metalRough texture of mesh '%s'", - mesh.name.c_str()) + mesh.name.c_str()) return result; } } @@ -795,7 +800,7 @@ namespace vkcv::asset { const int result = loadTextureData(scene.textures[material.normal]); if (ASSET_SUCCESS != result) { vkcv_log(LogLevel::ERROR, "Failed loading normal texture of mesh '%s'", - mesh.name.c_str()) + mesh.name.c_str()) return result; } } @@ -804,7 +809,7 @@ namespace vkcv::asset { const int result = loadTextureData(scene.textures[material.occlusion]); if (ASSET_SUCCESS != result) { vkcv_log(LogLevel::ERROR, "Failed loading occlusion texture of mesh '%s'", - mesh.name.c_str()) + mesh.name.c_str()) return result; } } @@ -813,7 +818,7 @@ namespace vkcv::asset { const int result = loadTextureData(scene.textures[material.emissive]); if (ASSET_SUCCESS != result) { vkcv_log(LogLevel::ERROR, "Failed loading emissive texture of mesh '%s'", - mesh.name.c_str()) + mesh.name.c_str()) return result; } } @@ -828,7 +833,7 @@ namespace vkcv::asset { if (result != ASSET_SUCCESS) { vkcv_log(LogLevel::ERROR, "Loading scene failed '%s'", - path.c_str()); + path.string().c_str()); return result; } @@ -843,7 +848,7 @@ namespace vkcv::asset { if (result != ASSET_SUCCESS) { vkcv_log(LogLevel::ERROR, "Loading mesh with index %d failed '%s'", - static_cast<int>(i), path.c_str()); + static_cast<int>(i), path.string().c_str()); return result; } } diff --git a/modules/gui/src/vkcv/gui/GUI.cpp b/modules/gui/src/vkcv/gui/GUI.cpp index 7978b10a4a515b022868fb357b6aa3f123a3d7e0..df30951afee81a97c403d5f860676a9d0e361f22 100644 --- a/modules/gui/src/vkcv/gui/GUI.cpp +++ b/modules/gui/src/vkcv/gui/GUI.cpp @@ -15,7 +15,8 @@ namespace vkcv::gui { const auto result = vk::Result(resultCode); - vkcv_log(LogLevel::ERROR, "ImGui has a problem with Vulkan! (%s)", vk::to_string(result).c_str()); + vkcv_log(LogLevel::ERROR, "ImGui has a problem with Vulkan! (%s)", + vk::to_string(result).c_str()); } GUI::GUI(Core& core, WindowHandle& windowHandle) : diff --git a/modules/scene/src/vkcv/scene/Scene.cpp b/modules/scene/src/vkcv/scene/Scene.cpp index b2b65a4a405d5adc9cf1e7933bd096ab61652a52..76b7de782f6d44ed927d4a88b4f323b9871a19f3 100644 --- a/modules/scene/src/vkcv/scene/Scene.cpp +++ b/modules/scene/src/vkcv/scene/Scene.cpp @@ -364,7 +364,8 @@ namespace vkcv::scene { asset::Scene asset_scene; if (!asset::loadScene(path.string(), asset_scene)) { - vkcv_log(LogLevel::ERROR, "Scene could not be loaded (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "Scene could not be loaded (%s)", + path.string().c_str()); return create(core); } diff --git a/modules/shader_compiler/CMakeLists.txt b/modules/shader_compiler/CMakeLists.txt index a00a896d500647b7ed38768f26235d36c8df6d29..b7452fe1ae8ca93d40b402bd820443d874c31d16 100644 --- a/modules/shader_compiler/CMakeLists.txt +++ b/modules/shader_compiler/CMakeLists.txt @@ -30,6 +30,9 @@ set(vkcv_shader_compiler_sources ${vkcv_shader_compiler_include}/vkcv/shader/LLVMCompiler.hpp ${vkcv_shader_compiler_source}/vkcv/shader/LLVMCompiler.cpp + + ${vkcv_shader_compiler_include}/vkcv/shader/SlangCompiler.hpp + ${vkcv_shader_compiler_source}/vkcv/shader/SlangCompiler.cpp ) filter_headers(vkcv_shader_compiler_sources ${vkcv_shader_compiler_include} vkcv_shader_compiler_headers) @@ -53,6 +56,12 @@ include(config/GLSLANG.cmake) include(config/Murmur3.cmake) include(config/Shady.cmake) +# Check and load SLANG +include(config/MINIZ.cmake) +include(config/LZ4.cmake) +include(config/UNORDERED_DENSE.cmake) +include(config/SLANG.cmake) + # link the required libraries to the module target_link_libraries(vkcv_shader_compiler ${vkcv_shader_compiler_libraries} vkcv) diff --git a/modules/shader_compiler/config/LZ4.cmake b/modules/shader_compiler/config/LZ4.cmake new file mode 100644 index 0000000000000000000000000000000000000000..87b2c906e9206efdc65383be328cbeb46fb7be16 --- /dev/null +++ b/modules/shader_compiler/config/LZ4.cmake @@ -0,0 +1,16 @@ + +use_git_submodule("${vkcv_shader_compiler_lib_path}/lz4" lz4_status) + +if (${lz4_status}) + set(LZ4_BUNDLED_MODE ON) + add_subdirectory(${vkcv_shader_compiler_lib}/lz4/build/cmake SYSTEM) + + if(MSVC) + target_compile_options( + lz4_static + PRIVATE /wd5045 /wd4820 /wd4711 /wd6385 /wd6262 + ) + endif() + + set(lz4_include ${vkcv_shader_compiler_lib}/lz4/lib) +endif () diff --git a/modules/shader_compiler/config/MINIZ.cmake b/modules/shader_compiler/config/MINIZ.cmake new file mode 100644 index 0000000000000000000000000000000000000000..0b32ea3667862cb4fb07bb4daa7ebb001aed4bd4 --- /dev/null +++ b/modules/shader_compiler/config/MINIZ.cmake @@ -0,0 +1,14 @@ + +use_git_submodule("${vkcv_shader_compiler_lib_path}/miniz" miniz_status) + +if (${miniz_status}) + add_subdirectory(${vkcv_shader_compiler_lib}/miniz SYSTEM) + + set_property(TARGET miniz PROPERTY POSITION_INDEPENDENT_CODE ON) + # Work around https://github.com/richgel999/miniz/pull/292 + get_target_property(miniz_c_launcher miniz C_COMPILER_LAUNCHER) + if(MSVC AND miniz_c_launcher MATCHES "ccache") + set_property(TARGET miniz PROPERTY C_COMPILER_LAUNCHER) + set_property(TARGET miniz PROPERTY MSVC_DEBUG_INFORMATION_FORMAT "") + endif() +endif () diff --git a/modules/shader_compiler/config/SLANG.cmake b/modules/shader_compiler/config/SLANG.cmake new file mode 100644 index 0000000000000000000000000000000000000000..a9bd071fa00293a5e28e011ee51bad4569188053 --- /dev/null +++ b/modules/shader_compiler/config/SLANG.cmake @@ -0,0 +1,64 @@ + +use_git_submodule("${vkcv_shader_compiler_lib_path}/slang" slang_status) + +if (${slang_status}) + set(EXTERNAL_MINIZ ON CACHE INTERNAL "") + set(EXTERNAL_LZ4 ON CACHE INTERNAL "") + set(EXTERNAL_VULKAN_HEADERS ON CACHE INTERNAL "") + set(EXTERNAL_SPIRV_HEADERS ON CACHE INTERNAL "") + set(EXTERNAL_UNORDERED_DENSE ON CACHE INTERNAL "") + + set(SLANG_ENABLE_CUDA OFF CACHE INTERNAL "") + set(SLANG_ENABLE_OPTIX OFF CACHE INTERNAL "") + set(SLANG_ENABLE_NVAPI OFF CACHE INTERNAL "") + set(SLANG_ENABLE_XLIB OFF CACHE INTERNAL "") + set(SLANG_ENABLE_AFTERMATH OFF CACHE INTERNAL "") + set(SLANG_ENABLE_DX_ON_VK OFF CACHE INTERNAL "") + set(SLANG_EMBED_STDLIB_SOURCE OFF CACHE INTERNAL "") + set(SLANG_EMBED_STDLIB ON CACHE INTERNAL "") + set(SLANG_ENABLE_FULL_IR_VALIDATION OFF CACHE INTERNAL "") + set(SLANG_ENABLE_IR_BREAK_ALLOC OFF CACHE INTERNAL "") + set(SLANG_ENABLE_ASAN OFF CACHE INTERNAL "") + set(SLANG_ENABLE_PREBUILT_BINARIES OFF CACHE INTERNAL "") + set(SLANG_ENABLE_GFX OFF CACHE INTERNAL "") + set(SLANG_ENABLE_SLANGD OFF CACHE INTERNAL "") + set(SLANG_ENABLE_SLANGC OFF CACHE INTERNAL "") + set(SLANG_ENABLE_SLANGRT OFF CACHE INTERNAL "") + set(SLANG_ENABLE_SLANG_GLSLANG OFF CACHE INTERNAL "") + set(SLANG_ENABLE_TESTS OFF CACHE INTERNAL "") + set(SLANG_ENABLE_EXAMPLES OFF CACHE INTERNAL "") + set(SLANG_LIB_TYPE ${vkcv_build_attribute} CACHE INTERNAL "") + set(SLANG_SPIRV_HEADERS_INCLUDE_DIR ${spirv_headers_include} CACHE INTERNAL "") + + add_subdirectory(${vkcv_shader_compiler_lib}/slang) + + set(slang_system_includes "") + list(APPEND slang_system_includes ${spirv_headers_include}) + list(APPEND slang_system_includes ${unordered_dense_include}) + list(APPEND slang_system_includes ${lz4_include}) + + target_include_directories(core SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(compiler-core SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-cpp-extractor SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-embed SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-generate SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-lookup-generator SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-capability-generator SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-spirv-embed-generator SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-bootstrap SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(prelude SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-capability-defs SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-capability-lookup SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-lookup-tables SYSTEM BEFORE PRIVATE ${slang_system_includes}) + target_include_directories(slang-no-embedded-stdlib SYSTEM BEFORE PRIVATE ${slang_system_includes}) + + set(SLANG_STDLIB_META_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${vkcv_shader_compiler_lib}/slang/source/slang/stdlib-meta) + + target_include_directories(slang BEFORE PUBLIC ${SLANG_STDLIB_META_OUTPUT_DIR}) + + message(WARNING ${SLANG_STDLIB_META_OUTPUT_DIR}) + + list(APPEND vkcv_shader_compiler_libraries slang lz4_static miniz unordered_dense::unordered_dense) + list(APPEND vkcv_shader_compiler_includes ${vkcv_shader_compiler_lib}/slang/include ${slang_system_includes}) +endif () diff --git a/modules/shader_compiler/config/SPIRV-Headers.cmake b/modules/shader_compiler/config/SPIRV-Headers.cmake index b5f47dbe91d3da73f585a55765514bcb3a7412c9..5ef39caa39344c459d90883674beae176c8d1c68 100644 --- a/modules/shader_compiler/config/SPIRV-Headers.cmake +++ b/modules/shader_compiler/config/SPIRV-Headers.cmake @@ -2,8 +2,10 @@ use_git_submodule("${vkcv_shader_compiler_lib_path}/SPIRV-Headers" spriv_headers_status) if (${spriv_headers_status}) - add_subdirectory(${vkcv_shader_compiler_lib}/SPIRV-Headers) + add_subdirectory(${vkcv_shader_compiler_lib}/SPIRV-Headers SYSTEM) + + set(spirv_headers_include ${vkcv_shader_compiler_lib_path}/SPIRV-Headers/include) list(APPEND vkcv_shader_compiler_libraries SPIRV-Headers) - list(APPEND vkcv_shader_compiler_includes ${vkcv_shader_compiler_lib}/SPIRV-Headers/include) + list(APPEND vkcv_shader_compiler_includes ${spirv_headers_include}) endif () diff --git a/modules/shader_compiler/config/Shady.cmake b/modules/shader_compiler/config/Shady.cmake index 56da131a23e3680e487c678260de6af2c9c3aba6..3156521dbc200ff202f48f3994caa783801f3af5 100644 --- a/modules/shader_compiler/config/Shady.cmake +++ b/modules/shader_compiler/config/Shady.cmake @@ -3,8 +3,8 @@ use_git_submodule("${vkcv_shader_compiler_lib_path}/shady" shady_status) if (${shady_status}) set(EXTERNAL_JSON_C ON CACHE INTERNAL "") - set(EXTERNAL_SPIRV_HEADERS ON CACHE INTERNAL "") - set(EXTERNAL_MURMUR3 ON CACHE INTERNAL "") + set(EXTERNAL_SPIRV_HEADERS ON CACHE INTERNAL "") + set(EXTERNAL_MURMUR3 ON CACHE INTERNAL "") set(EXTERNAL_JSON_C_INCLUDE ${JSON_C_INCLUDE_DIR} CACHE INTERNAL "") diff --git a/modules/shader_compiler/config/UNORDERED_DENSE.cmake b/modules/shader_compiler/config/UNORDERED_DENSE.cmake new file mode 100644 index 0000000000000000000000000000000000000000..8c2e60aa129dbe2248b1691b7b07b09d66da0eb8 --- /dev/null +++ b/modules/shader_compiler/config/UNORDERED_DENSE.cmake @@ -0,0 +1,8 @@ + +use_git_submodule("${vkcv_shader_compiler_lib_path}/unordered_dense" unordered_dense_status) + +if (${unordered_dense_status}) + add_subdirectory(${vkcv_shader_compiler_lib}/unordered_dense SYSTEM) + + set(unordered_dense_include ${vkcv_shader_compiler_lib_path}/unordered_dense/include) +endif () diff --git a/modules/shader_compiler/include/vkcv/shader/Compiler.hpp b/modules/shader_compiler/include/vkcv/shader/Compiler.hpp index 2fdda591644dc10ba35af21a00d3d429abbd8b7e..4fc7c5990623dcfad8d818f598077718e274f817 100644 --- a/modules/shader_compiler/include/vkcv/shader/Compiler.hpp +++ b/modules/shader_compiler/include/vkcv/shader/Compiler.hpp @@ -94,11 +94,11 @@ namespace vkcv::shader { * @param[in] includePath Include path for shaders * @param[in] update Flag to update shaders during runtime */ - virtual void compile(ShaderStage shaderStage, + void compile(ShaderStage shaderStage, const std::filesystem::path& shaderPath, const ShaderCompiledFunction& compiled, - const std::filesystem::path& includePath, - bool update) = 0; + const std::filesystem::path& includePath = "", + bool update = false); /** * Compile a shader program from a specific map of given file paths for diff --git a/modules/shader_compiler/include/vkcv/shader/GlslangCompiler.hpp b/modules/shader_compiler/include/vkcv/shader/GlslangCompiler.hpp index 161c796ec8cd7fbb1a74ad673c25fc07804b9c97..443290de52d858a59eca5954c0a427b3fb0fef27 100644 --- a/modules/shader_compiler/include/vkcv/shader/GlslangCompiler.hpp +++ b/modules/shader_compiler/include/vkcv/shader/GlslangCompiler.hpp @@ -1,7 +1,5 @@ #pragma once -#include <filesystem> - #include <vkcv/ShaderStage.hpp> #include "Compiler.hpp" @@ -57,23 +55,6 @@ namespace vkcv::shader { */ GlslangCompiler& operator=(GlslangCompiler&& other) = default; - /** - * Compile a shader from a specific file path for a target stage with - * a custom shader include path and an event function called if the - * compilation completes. - * - * @param[in] shaderStage Shader pipeline stage - * @param[in] shaderPath Filepath of shader - * @param[in] compiled Shader compilation event - * @param[in] includePath Include path for shaders - * @param[in] update Flag to update shaders during runtime - */ - void compile(ShaderStage shaderStage, - const std::filesystem::path& shaderPath, - const ShaderCompiledFunction& compiled, - const std::filesystem::path& includePath = "", - bool update = false) override; - }; /** @} */ diff --git a/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp b/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp index 65e732f021d80d60a653962c82b51e44b4ab887b..f9278329d9278d51bfa36649bafe924bdd1936c7 100644 --- a/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp +++ b/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp @@ -57,23 +57,6 @@ namespace vkcv::shader { */ ShadyCompiler& operator=(ShadyCompiler&& other) = default; - /** - * Compile a shader from a specific file path for a target stage with - * a custom shader include path and an event function called if the - * compilation completes. - * - * @param[in] shaderStage Shader pipeline stage - * @param[in] shaderPath Filepath of shader - * @param[in] compiled Shader compilation event - * @param[in] includePath Include path for shaders - * @param[in] update Flag to update shaders during runtime - */ - void compile(ShaderStage shaderStage, - const std::filesystem::path& shaderPath, - const ShaderCompiledFunction& compiled, - const std::filesystem::path& includePath = "", - bool update = false) override; - }; /** @} */ diff --git a/modules/shader_compiler/include/vkcv/shader/SlangCompiler.hpp b/modules/shader_compiler/include/vkcv/shader/SlangCompiler.hpp new file mode 100644 index 0000000000000000000000000000000000000000..556627e97b90f5312bc21535fcf30d39629a5bab --- /dev/null +++ b/modules/shader_compiler/include/vkcv/shader/SlangCompiler.hpp @@ -0,0 +1,91 @@ +#pragma once + +#include <filesystem> + +#include <vkcv/ShaderStage.hpp> +#include "Compiler.hpp" + +namespace vkcv::shader { + + /** + * @addtogroup vkcv_shader + * @{ + */ + + enum class SlangCompileProfile { + GLSL, + HLSL, + SPIRV, + UNKNOWN + }; + + /** + * An abstract class to handle Slang runtime shader compilation. + */ + class SlangCompiler : public Compiler { + private: + SlangCompileProfile m_profile; + + public: + /** + * The constructor of a runtime Slang shader compiler instance. + * + * @param[in] profile Compile profile (optional) + */ + SlangCompiler(SlangCompileProfile profile = SlangCompileProfile::UNKNOWN); + + /** + * The copy-constructor of a runtime Slang shader compiler instance. + * + * @param[in] other Other instance of a Slang shader compiler instance + */ + SlangCompiler(const SlangCompiler& other); + + /** + * The move-constructor of a runtime Slang shader compiler instance. + * + * @param[out] other Other instance of a Slang shader compiler instance + */ + SlangCompiler(SlangCompiler&& other) = default; + + /** + * The destructor of a runtime Slang shader compiler instance. + */ + ~SlangCompiler(); + + /** + * The copy-operator of a runtime Slang shader compiler instance. + * + * @param[in] other Other instance of a Slang shader compiler instance + * @return Reference to this instance + */ + SlangCompiler& operator=(const SlangCompiler& other); + + /** + * The copy-operator of a runtime Slang shader compiler instance. + * + * @param[out] other Other instance of a Slang shader compiler instance + * @return Reference to this instance + */ + SlangCompiler& operator=(SlangCompiler&& other) = default; + + /** + * Compile a shader from source for a target stage with a custom shader + * include path and an event function called if the compilation completes. + * + * @param[in] shaderStage Shader pipeline stage + * @param[in] shaderSource Source of shader + * @param[in] compiled Shader compilation event + * @param[in] includePath Include path for shaders + * @return Result if the compilation succeeds + */ + bool compileSource(ShaderStage shaderStage, + const std::string& shaderSource, + const ShaderCompiledFunction& compiled, + const std::filesystem::path& includePath) override; + + }; + + /** @} */ + +} diff --git a/modules/shader_compiler/lib/lz4 b/modules/shader_compiler/lib/lz4 new file mode 160000 index 0000000000000000000000000000000000000000..68959d27c3ec37b339b3b8ecfea155faf0ef94f2 --- /dev/null +++ b/modules/shader_compiler/lib/lz4 @@ -0,0 +1 @@ +Subproject commit 68959d27c3ec37b339b3b8ecfea155faf0ef94f2 diff --git a/modules/shader_compiler/lib/miniz b/modules/shader_compiler/lib/miniz new file mode 160000 index 0000000000000000000000000000000000000000..bf7a1f0a5aa1deae9cab2d73b5ef9edec41b877c --- /dev/null +++ b/modules/shader_compiler/lib/miniz @@ -0,0 +1 @@ +Subproject commit bf7a1f0a5aa1deae9cab2d73b5ef9edec41b877c diff --git a/modules/shader_compiler/lib/slang b/modules/shader_compiler/lib/slang new file mode 160000 index 0000000000000000000000000000000000000000..e1734897a3681f7685b4768fd8d40f446134d483 --- /dev/null +++ b/modules/shader_compiler/lib/slang @@ -0,0 +1 @@ +Subproject commit e1734897a3681f7685b4768fd8d40f446134d483 diff --git a/modules/shader_compiler/lib/unordered_dense b/modules/shader_compiler/lib/unordered_dense new file mode 160000 index 0000000000000000000000000000000000000000..d911053e390816ecc5dedd5a9d6b4bb5ed92b4c9 --- /dev/null +++ b/modules/shader_compiler/lib/unordered_dense @@ -0,0 +1 @@ +Subproject commit d911053e390816ecc5dedd5a9d6b4bb5ed92b4c9 diff --git a/modules/shader_compiler/src/vkcv/shader/Compiler.cpp b/modules/shader_compiler/src/vkcv/shader/Compiler.cpp index 25d1b0d46653f7fda07430a1d03cef91bd174a56..c38b6a584affc44f5d09c41f588140af7dbf81fa 100644 --- a/modules/shader_compiler/src/vkcv/shader/Compiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/Compiler.cpp @@ -18,7 +18,8 @@ namespace vkcv::shader { const std::filesystem::path directory = generateTemporaryDirectoryPath(); if (!std::filesystem::create_directory(directory)) { - vkcv_log(LogLevel::ERROR, "The directory could not be created (%s)", directory.c_str()); + vkcv_log(LogLevel::ERROR, "The directory could not be created (%s)", + directory.string().c_str()); return false; } @@ -45,6 +46,35 @@ namespace vkcv::shader { }, directory ); } + + void Compiler::compile(ShaderStage shaderStage, + const std::filesystem::path &shaderPath, + const ShaderCompiledFunction &compiled, + const std::filesystem::path &includePath, + bool update) { + std::string shaderCode; + bool result = readTextFromFile(shaderPath, shaderCode); + + if (!result) { + vkcv_log(LogLevel::ERROR, "Loading shader failed: (%s)", + shaderPath.string().c_str()); + } + + if (!includePath.empty()) { + result = compileSource(shaderStage, shaderCode, compiled, includePath); + } else { + result = compileSource(shaderStage, shaderCode, compiled, shaderPath.parent_path()); + } + + if (!result) { + vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)", + shaderPath.string().c_str()); + } + + if (update) { + // TODO: Shader hot compilation during runtime + } + } void Compiler::compileProgram(ShaderProgram& program, const Dictionary<ShaderStage, const std::filesystem::path>& stages, diff --git a/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp index 5c2a74f0fd5f177783ce148bd24f24540b7c5459..84a936ced2efa4e5d66d1f429dfe71ac969d0d7b 100644 --- a/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp @@ -236,7 +236,7 @@ namespace vkcv::shader { false, false, messages, &preprocessedGLSL, includer)) { vkcv_log(LogLevel::ERROR, "Shader preprocessing failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } @@ -245,7 +245,7 @@ namespace vkcv::shader { if (!shader.parse(&resources, 100, false, messages)) { vkcv_log(LogLevel::ERROR, "Shader parsing failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } @@ -253,7 +253,7 @@ namespace vkcv::shader { if (!program.link(messages)) { vkcv_log(LogLevel::ERROR, "Shader linking failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } diff --git a/modules/shader_compiler/src/vkcv/shader/GlslangCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/GlslangCompiler.cpp index 2a2847ada699364c025f957b204b58b3190a8ed2..b749f9501989ab20fd239086ba4e66e18ed30f54 100644 --- a/modules/shader_compiler/src/vkcv/shader/GlslangCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/GlslangCompiler.cpp @@ -36,31 +36,4 @@ namespace vkcv::shader { return *this; } - void GlslangCompiler::compile(ShaderStage shaderStage, - const std::filesystem::path &shaderPath, - const ShaderCompiledFunction &compiled, - const std::filesystem::path &includePath, - bool update) { - std::string shaderCode; - bool result = readTextFromFile(shaderPath, shaderCode); - - if (!result) { - vkcv_log(LogLevel::ERROR, "Loading shader failed: (%s)", shaderPath.string().c_str()); - } - - if (!includePath.empty()) { - result = compileSource(shaderStage, shaderCode, compiled, includePath); - } else { - result = compileSource(shaderStage, shaderCode, compiled, shaderPath.parent_path()); - } - - if (!result) { - vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)", shaderPath.string().c_str()); - } - - if (update) { - // TODO: Shader hot compilation during runtime - } - } - } diff --git a/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp index 934993a7ef840a46fa0c6ad0f222dd3e98e4cf91..3e45e38a7d99b1eeeac64c7115c070c6298c9b8f 100644 --- a/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp @@ -232,7 +232,7 @@ namespace vkcv::shader { false, false, messages, &preprocessedHLSL, includer)) { vkcv_log(LogLevel::ERROR, "Shader preprocessing failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } @@ -241,7 +241,7 @@ namespace vkcv::shader { if (!shader.parse(&resources, 100, false, messages)) { vkcv_log(LogLevel::ERROR, "Shader parsing failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } @@ -249,7 +249,7 @@ namespace vkcv::shader { if (!program.link(messages)) { vkcv_log(LogLevel::ERROR, "Shader linking failed {\n%s\n%s\n}", - shader.getInfoLog(), shader.getInfoDebugLog()); + shader.getInfoLog(), shader.getInfoDebugLog()); return false; } diff --git a/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp index 6168fcfa2baa04b8a7f261db8828bfab8c2ed018..80b44a3626f2238cebaae5d2cc23ed5fb9f98681 100644 --- a/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp @@ -9,31 +9,4 @@ namespace vkcv::shader { ShadyCompiler::ShadyCompiler() : Compiler() {} - void ShadyCompiler::compile(ShaderStage shaderStage, - const std::filesystem::path &shaderPath, - const ShaderCompiledFunction &compiled, - const std::filesystem::path &includePath, - bool update) { - std::string shaderCode; - bool result = readTextFromFile(shaderPath, shaderCode); - - if (!result) { - vkcv_log(LogLevel::ERROR, "Loading shader failed: (%s)", shaderPath.string().c_str()); - } - - if (!includePath.empty()) { - result = compileSource(shaderStage, shaderCode, compiled, includePath); - } else { - result = compileSource(shaderStage, shaderCode, compiled, shaderPath.parent_path()); - } - - if (!result) { - vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)", shaderPath.string().c_str()); - } - - if (update) { - // TODO: Shader hot compilation during runtime - } - } - } diff --git a/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e610bb7a796c7fc908cfbffe0be2b8bce048ac2 --- /dev/null +++ b/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp @@ -0,0 +1,187 @@ + +#include "vkcv/shader/SlangCompiler.hpp" + +#include <cstdint> +#include <vkcv/File.hpp> +#include <vkcv/Logger.hpp> + +#include <slang.h> +#include <slang-com-ptr.h> +#include <slang-com-helper.h> +#include <vkcv/ShaderStage.hpp> + +namespace vkcv::shader { + + static uint32_t s_CompilerCount = 0; + static Slang::ComPtr<slang::IGlobalSession> s_GlobalSession; + + SlangCompiler::SlangCompiler(SlangCompileProfile profile) + : Compiler(), m_profile(profile) { + if (s_CompilerCount == 0) { + slang::createGlobalSession(s_GlobalSession.writeRef()); + } + + s_CompilerCount++; + } + + SlangCompiler::SlangCompiler(const SlangCompiler &other) + : Compiler(other), m_profile(other.m_profile) { + s_CompilerCount++; + } + + SlangCompiler::~SlangCompiler() { + s_CompilerCount--; + } + + SlangCompiler &SlangCompiler::operator=(const SlangCompiler &other) { + m_profile = other.m_profile; + s_CompilerCount++; + return *this; + } + + constexpr SlangStage findShaderLanguage(ShaderStage shaderStage) { + switch (shaderStage) { + case ShaderStage::VERTEX: + return SlangStage::SLANG_STAGE_VERTEX; + case ShaderStage::TESS_CONTROL: + return SlangStage::SLANG_STAGE_HULL; + case ShaderStage::TESS_EVAL: + return SlangStage::SLANG_STAGE_DOMAIN; + case ShaderStage::GEOMETRY: + return SlangStage::SLANG_STAGE_GEOMETRY; + case ShaderStage::FRAGMENT: + return SlangStage::SLANG_STAGE_FRAGMENT; + case ShaderStage::COMPUTE: + return SlangStage::SLANG_STAGE_COMPUTE; + case ShaderStage::TASK: + return SlangStage::SLANG_STAGE_AMPLIFICATION; + case ShaderStage::MESH: + return SlangStage::SLANG_STAGE_MESH; + case ShaderStage::RAY_GEN: + return SlangStage::SLANG_STAGE_RAY_GENERATION; + case ShaderStage::RAY_CLOSEST_HIT: + return SlangStage::SLANG_STAGE_CLOSEST_HIT; + case ShaderStage::RAY_MISS: + return SlangStage::SLANG_STAGE_MISS; + case ShaderStage::RAY_INTERSECTION: + return SlangStage::SLANG_STAGE_INTERSECTION; + case ShaderStage::RAY_ANY_HIT: + return SlangStage::SLANG_STAGE_ANY_HIT; + case ShaderStage::RAY_CALLABLE: + return SlangStage::SLANG_STAGE_CALLABLE; + default: + return SlangStage::SLANG_STAGE_NONE; + } + } + + bool SlangCompiler::compileSource(ShaderStage shaderStage, + const std::string& shaderSource, + const ShaderCompiledFunction& compiled, + const std::filesystem::path& includePath) { + slang::SessionDesc sessionDesc = {}; + slang::TargetDesc targetDesc = {}; + SlangSourceLanguage lang; + + targetDesc.format = SLANG_SPIRV; + + switch (m_profile) { + case SlangCompileProfile::GLSL: + targetDesc.profile = s_GlobalSession->findProfile("glsl_460"); + sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; + sessionDesc.allowGLSLSyntax = true; + lang = SLANG_SOURCE_LANGUAGE_GLSL; + break; + case SlangCompileProfile::HLSL: + targetDesc.profile = s_GlobalSession->findProfile("sm_5_0"); + sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_ROW_MAJOR; + lang = SLANG_SOURCE_LANGUAGE_HLSL; + break; + case SlangCompileProfile::SPIRV: + targetDesc.profile = s_GlobalSession->findProfile("spirv_1_5"); + targetDesc.flags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; + lang = SLANG_SOURCE_LANGUAGE_SPIRV; + break; + default: + lang = SLANG_SOURCE_LANGUAGE_UNKNOWN; + break; + } + + sessionDesc.targets = &targetDesc; + sessionDesc.targetCount = 1; + + const char *searchPath = includePath.string().c_str(); + sessionDesc.searchPaths = &searchPath; + sessionDesc.searchPathCount = 1; + + std::vector<slang::PreprocessorMacroDesc> macros; + macros.reserve(m_defines.size()); + + for (const auto& define : m_defines) { + const slang::PreprocessorMacroDesc macro = { + define.first.c_str(), + define.second.c_str() + }; + + macros.push_back(macro); + } + + sessionDesc.preprocessorMacros = macros.data(); + sessionDesc.preprocessorMacroCount = macros.size(); + + Slang::ComPtr<slang::ISession> session; + if (SLANG_FAILED(s_GlobalSession->createSession(sessionDesc, session.writeRef()))) { + vkcv_log(LogLevel::ERROR, "Compiler session could not be created"); + return false; + } + + Slang::ComPtr<slang::ICompileRequest> request; + if (SLANG_FAILED(session->createCompileRequest(request.writeRef()))) { + vkcv_log(LogLevel::ERROR, "Compilation request could not be created"); + return false; + } + + const int translationUnit = request->addTranslationUnit(lang, nullptr); + request->addTranslationUnitSourceString(translationUnit, nullptr, shaderSource.c_str()); + + const int entryPoint = request->addEntryPoint( + translationUnit, "main", findShaderLanguage(shaderStage) + ); + + if (SLANG_FAILED(request->compile())) { + vkcv_log(LogLevel::ERROR, "Compilation process failed"); + return false; + } + + size_t size; + const void *code = request->getEntryPointCode(entryPoint, &size); + + if (0 == size) { + code = request->getCompileRequestCode(&size); + } + + if ((0 == size) || (!code)) { + vkcv_log(LogLevel::ERROR, "Entry point could not be found\n%s", + request->getDiagnosticOutput()); + return false; + } + + std::vector<uint32_t> spirv; + spirv.resize(size / sizeof(uint32_t)); + memcpy(spirv.data(), code, spirv.size() * sizeof(uint32_t)); + + const std::filesystem::path tmp_path = generateTemporaryFilePath(); + + if (!writeBinaryToFile(tmp_path, spirv)) { + vkcv_log(LogLevel::ERROR, "Spir-V could not be written to disk"); + return false; + } + + if (compiled) { + compiled(shaderStage, tmp_path); + } + + std::filesystem::remove(tmp_path); + return true; + } + +} diff --git a/modules/shader_compiler/src/vkcv/shader/SlimCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/SlimCompiler.cpp index 028d0618940d27cf00af920653e87d89f3ff7025..6270bb8efa245617da4c7f8f5a7e8663ccd282d1 100644 --- a/modules/shader_compiler/src/vkcv/shader/SlimCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/SlimCompiler.cpp @@ -14,15 +14,15 @@ namespace vkcv::shader { : ShadyCompiler(), m_target(target) {} static bool shadyCompileModule(Module* module, - ShaderStage shaderStage, - const std::string& shaderSource, - const ShaderCompiledFunction &compiled, - const std::filesystem::path &includePath) { + ShaderStage shaderStage, + const std::string& shaderSource, + const ShaderCompiledFunction &compiled, + const std::filesystem::path &includePath) { ShadyErrorCodes codes = driver_load_source_file( - SrcSlim, - shaderSource.length(), + SrcSlim, + shaderSource.length(), shaderSource.c_str(), - module + module ); switch (codes) { @@ -46,7 +46,7 @@ namespace vkcv::shader { DriverConfig config = default_driver_config(); - config.target = TgtSPV; + config.target = TgtSPV; config.output_filename = tmp_path.string().c_str(); codes = driver_compile(&config, module); @@ -78,10 +78,10 @@ namespace vkcv::shader { } static bool shadyCompileArena(IrArena* arena, - ShaderStage shaderStage, - const std::string& shaderSource, - const ShaderCompiledFunction &compiled, - const std::filesystem::path &includePath) { + ShaderStage shaderStage, + const std::string& shaderSource, + const ShaderCompiledFunction &compiled, + const std::filesystem::path &includePath) { Module* module = new_module(arena, "slim_module"); if (nullptr == module) { @@ -92,11 +92,11 @@ namespace vkcv::shader { return shadyCompileModule(module, shaderStage, shaderSource, compiled, includePath); } - bool SlimCompiler::compileSource(ShaderStage shaderStage, - const std::string& shaderSource, - const ShaderCompiledFunction& compiled, - const std::filesystem::path& includePath) { - if (ShaderStage::COMPUTE != shaderStage) { + bool SlimCompiler::compileSource(ShaderStage shaderStage, + const std::string& shaderSource, + const ShaderCompiledFunction& compiled, + const std::filesystem::path& includePath) { + if (ShaderStage::COMPUTE != shaderStage) { vkcv_log(LogLevel::ERROR, "Shader stage not supported"); return false; } @@ -112,7 +112,7 @@ namespace vkcv::shader { bool result = shadyCompileArena(arena, shaderStage, shaderSource, compiled, includePath); destroy_ir_arena(arena); - return result; - } + return result; + } } diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 3cefdab895e1f5fb4fc34c2c1f4332f62e86464b..a402067d1d1d76d9791cae7e865a69a3354f9875 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -896,7 +896,7 @@ namespace vkcv { if ((result != vk::Result::eSuccess) && (result != vk::Result::eSuboptimalKHR)) { vkcv_log(LogLevel::ERROR, "Swapchain presentation failed (%s)", - vk::to_string(result).c_str()); + vk::to_string(result).c_str()); } else if (result == vk::Result::eSuboptimalKHR) { vkcv_log(LogLevel::WARNING, "Swapchain presentation is suboptimal"); m_SwapchainManager->signalRecreation(swapchainHandle); diff --git a/src/vkcv/DescriptorSetManager.cpp b/src/vkcv/DescriptorSetManager.cpp index d4ffce7480853bbd907ef3dc61ed317ae04e9220..74b4b291d309bbc0c8b50e5e35ca1e30acad30f6 100644 --- a/src/vkcv/DescriptorSetManager.cpp +++ b/src/vkcv/DescriptorSetManager.cpp @@ -165,7 +165,7 @@ namespace vkcv { if (result != vk::Result::eSuccess) { vkcv_log(LogLevel::ERROR, "Failed to create descriptor set (%s)", - vk::to_string(result).c_str()); + vk::to_string(result).c_str()); return {}; } }; diff --git a/src/vkcv/FeatureManager.cpp b/src/vkcv/FeatureManager.cpp index fe7537beae0640afba91ee0150e1aa5bd8b3abb9..e18598e06d60d482d09eccab9ab9674f52e21ab9 100644 --- a/src/vkcv/FeatureManager.cpp +++ b/src/vkcv/FeatureManager.cpp @@ -627,13 +627,17 @@ namespace vkcv { const char* clone = strclone(extension.c_str()); if (!clone) { - vkcv_log(LogLevel::WARNING, "Extension '%s' is not valid", extension.c_str()); + vkcv_log(LogLevel::WARNING, "Extension '%s' is not valid", + extension.c_str()); return false; } if (!isExtensionSupported(extension)) { - vkcv_log((required ? LogLevel::ERROR : LogLevel::WARNING), - "Extension '%s' is not supported", extension.c_str()); + vkcv_log( + (required ? LogLevel::ERROR : LogLevel::WARNING), + "Extension '%s' is not supported", + extension.c_str() + ); delete [] clone; if (required) { diff --git a/src/vkcv/File.cpp b/src/vkcv/File.cpp index 702ae899b77a963719e7921ba2625704c205ba81..0b1328f4f790b34f5a2cd6cfbd6a2eb5c6890e8d 100644 --- a/src/vkcv/File.cpp +++ b/src/vkcv/File.cpp @@ -62,7 +62,8 @@ namespace vkcv { std::ofstream file (path.string(), std::ios::out); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } @@ -78,7 +79,8 @@ namespace vkcv { std::ofstream file (path.string(), std::ios::out); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } @@ -97,7 +99,8 @@ namespace vkcv { std::ofstream file (path.string(), std::ios::out); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } @@ -113,7 +116,8 @@ namespace vkcv { std::ifstream file (path.string(), std::ios::ate); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } @@ -132,14 +136,16 @@ namespace vkcv { std::ifstream file (path.string(), std::ios::ate); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } const std::streamsize fileSize = file.tellg(); if (fileSize % sizeof(uint32_t) != 0) { - vkcv_log(LogLevel::ERROR, "The file is not a valid binary: %s", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file is not a valid binary: %s", + path.string().c_str()); return false; } @@ -160,7 +166,8 @@ namespace vkcv { std::ifstream file (path.string(), std::ios::ate); if (!file.is_open()) { - vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str()); + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", + path.string().c_str()); return false; } diff --git a/src/vkcv/SwapchainManager.cpp b/src/vkcv/SwapchainManager.cpp index 03dbdc0175b393565bc4235e99f5cb02dd176db5..008d2d1d03c0d751776d34e0d741365116680180 100644 --- a/src/vkcv/SwapchainManager.cpp +++ b/src/vkcv/SwapchainManager.cpp @@ -176,8 +176,12 @@ namespace vkcv { static bool createVulkanSwapchain(const Context &context, const Window &window, SwapchainEntry &entry) { if (!context.getFeatureManager().isExtensionActive(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { - vkcv_log(LogLevel::WARNING, "Extension required to create a swapchain: '%s'", - VK_KHR_SWAPCHAIN_EXTENSION_NAME); + vkcv_log( + LogLevel::WARNING, + "Extension required to create a swapchain: '%s'", + VK_KHR_SWAPCHAIN_EXTENSION_NAME + ); + return false; } diff --git a/src/vkcv/TypeGuard.cpp b/src/vkcv/TypeGuard.cpp index 742071bb7b8d055ff1e3037a825052b0f24ae84a..91d6358e02765feff5ceb65ba2aba74e369f7d84 100644 --- a/src/vkcv/TypeGuard.cpp +++ b/src/vkcv/TypeGuard.cpp @@ -16,17 +16,21 @@ namespace vkcv { } if (m_typeHash != hash) { - vkcv_log(LogLevel::WARNING, - "Hash (%lu) does not match the specified hash of the type guard (%lu)", hash, - m_typeHash); + vkcv_log( + LogLevel::WARNING, + "Hash (%lu) does not match the specified hash of the type guard (%lu)", + hash, m_typeHash + ); return false; } if (strcmp(m_typeName, name) != 0) { - vkcv_log(LogLevel::WARNING, - "Name (%s) does not match the specified name of the type guard (%s)", name, - m_typeName); + vkcv_log( + LogLevel::WARNING, + "Name (%s) does not match the specified name of the type guard (%s)", + name, m_typeName + ); return false; } else { @@ -37,9 +41,11 @@ namespace vkcv { bool TypeGuard::checkTypeSize(size_t size) const { if (m_typeSize != size) { - vkcv_log(LogLevel::WARNING, - "Size (%lu) does not match the specified size of the type guard (%lu)", size, - m_typeSize); + vkcv_log( + LogLevel::WARNING, + "Size (%lu) does not match the specified size of the type guard (%lu)", + size, m_typeSize + ); return false; } else {