diff --git a/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp b/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp index eee66a26bb0d4fed805695726b17535e47811890..181d30da783ab45602cde6b39decea617c10eccc 100644 --- a/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp +++ b/modules/shader_compiler/include/vkcv/shader/ShadyCompiler.hpp @@ -27,6 +27,6 @@ namespace vkcv::shader { const std::filesystem::path& includePath = "", bool update = false) override; - } + }; } diff --git a/modules/shader_compiler/lib/shady b/modules/shader_compiler/lib/shady index 6ab5f5fc520de70e6f19d1e7312a70aea71020fd..b270da9462d9b819fdf6b851c599a353839593bf 160000 --- a/modules/shader_compiler/lib/shady +++ b/modules/shader_compiler/lib/shady @@ -1 +1 @@ -Subproject commit 6ab5f5fc520de70e6f19d1e7312a70aea71020fd +Subproject commit b270da9462d9b819fdf6b851c599a353839593bf diff --git a/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp index e582bb2963b40db3eb45cb66119fe1ec22eaaaf3..da6680e5a037d05dabb77422db82d31ffb657777 100644 --- a/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp +++ b/modules/shader_compiler/src/vkcv/shader/ShadyCompiler.cpp @@ -4,6 +4,8 @@ #include <vkcv/File.hpp> #include <vkcv/Logger.hpp> +#include <shady/driver.h> + namespace vkcv::shader { ShadyCompiler::ShadyCompiler() : Compiler() { @@ -22,13 +24,96 @@ namespace vkcv::shader { // TODO return *this; } - - void ShadyCompiler::compile(ShaderStage shaderStage, + + static void shadyCompileModule(Module* module, + ShaderStage shaderStage, + const std::filesystem::path &shaderPath, + const ShaderCompiledFunction &compiled, + const std::filesystem::path &includePath, + bool update) { + ShadyErrorCodes codes = driver_load_source_file_from_filename( + shaderPath.c_str(), module + ); + + switch (codes) { + case NoError: + break; + case MissingInputArg: + case MissingOutputArg: + case InputFileDoesNotExist: + case InputFileIOError: + case MissingDumpCfgArg: + case MissingDumpIrArg: + case IncorrectLogLevel: + case InvalidTarget: + case ClangInvocationFailed: + default: + vkcv_log(LogLevel::ERROR, "Unknown error while loading shader"); + return; + } + + DriverConfig config = default_driver_config(); + + // TODO + + codes = driver_compile(&config, module); + + switch (codes) { + case NoError: + break; + case MissingInputArg: + case MissingOutputArg: + case InputFileDoesNotExist: + case InputFileIOError: + case MissingDumpCfgArg: + case MissingDumpIrArg: + case IncorrectLogLevel: + case InvalidTarget: + case ClangInvocationFailed: + default: + vkcv_log(LogLevel::ERROR, "Unknown error while compiling shader"); + return; + } + + if (compiled) { + compiled(shaderStage, shaderPath); + } + } + + static void shadyCompileArena(IrArena* arena, + ShaderStage shaderStage, const std::filesystem::path &shaderPath, const ShaderCompiledFunction &compiled, const std::filesystem::path &includePath, bool update) { + Module* module = new_module(arena, "NAME"); + + if (nullptr == module) { + vkcv_log(LogLevel::ERROR, "Module could not be created"); + return; + } + + shadyCompileModule(module, shaderStage, shaderPath, compiled, includePath, update); + } + + void ShadyCompiler::compile(ShaderStage shaderStage, + const std::filesystem::path &shaderPath, + const ShaderCompiledFunction &compiled, + const std::filesystem::path &includePath, + bool update) { + ArenaConfig config {}; + // TODO + + IrArena* arena = new_ir_arena(config); + + if (nullptr == arena) { + vkcv_log(LogLevel::ERROR, "IR Arena could not be created"); + return; + } + + shadyCompileArena(arena, shaderStage, shaderPath, compiled, includePath, update); + destroy_ir_arena(arena); } }