Skip to content
Snippets Groups Projects
Verified Commit 66cc857c authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Fix shady compiler output file

parent f1927bda
No related branches found
No related tags found
1 merge request!116Resolve "VCC/Shady support"
Subproject commit b270da9462d9b819fdf6b851c599a353839593bf Subproject commit 2e72e345035166d7fd2a0b94610cfc8fd603155b
...@@ -25,12 +25,11 @@ namespace vkcv::shader { ...@@ -25,12 +25,11 @@ namespace vkcv::shader {
return *this; return *this;
} }
static void shadyCompileModule(Module* module, static bool shadyCompileModule(Module* module,
ShaderStage shaderStage, ShaderStage shaderStage,
const std::filesystem::path &shaderPath, const std::filesystem::path &shaderPath,
const ShaderCompiledFunction &compiled, const ShaderCompiledFunction &compiled,
const std::filesystem::path &includePath, const std::filesystem::path &includePath) {
bool update) {
ShadyErrorCodes codes = driver_load_source_file_from_filename( ShadyErrorCodes codes = driver_load_source_file_from_filename(
shaderPath.c_str(), module shaderPath.c_str(), module
); );
...@@ -49,14 +48,19 @@ namespace vkcv::shader { ...@@ -49,14 +48,19 @@ namespace vkcv::shader {
case ClangInvocationFailed: case ClangInvocationFailed:
default: default:
vkcv_log(LogLevel::ERROR, "Unknown error while loading shader"); vkcv_log(LogLevel::ERROR, "Unknown error while loading shader");
return; return false;
} }
const std::filesystem::path tmp_path = generateTemporaryFilePath();
DriverConfig config = default_driver_config(); DriverConfig config = default_driver_config();
config.output_filename = tmp_path.c_str();
// TODO // TODO
codes = driver_compile(&config, module); codes = driver_compile(&config, module);
destroy_driver_config(&config);
switch (codes) { switch (codes) {
case NoError: case NoError:
...@@ -72,28 +76,33 @@ namespace vkcv::shader { ...@@ -72,28 +76,33 @@ namespace vkcv::shader {
case ClangInvocationFailed: case ClangInvocationFailed:
default: default:
vkcv_log(LogLevel::ERROR, "Unknown error while compiling shader"); vkcv_log(LogLevel::ERROR, "Unknown error while compiling shader");
return; return false;
} }
if (compiled) { if (compiled) {
compiled(shaderStage, shaderPath); compiled(shaderStage, tmp_path);
} }
std::filesystem::remove(tmp_path);
return true;
} }
static void shadyCompileArena(IrArena* arena, static bool shadyCompileArena(IrArena* arena,
ShaderStage shaderStage, ShaderStage shaderStage,
const std::filesystem::path &shaderPath, const std::filesystem::path &shaderPath,
const ShaderCompiledFunction &compiled, const ShaderCompiledFunction &compiled,
const std::filesystem::path &includePath, const std::filesystem::path &includePath) {
bool update) { Module* module = new_module(arena, "main");
Module* module = new_module(arena, "NAME");
if (nullptr == module) { if (nullptr == module) {
vkcv_log(LogLevel::ERROR, "Module could not be created"); vkcv_log(LogLevel::ERROR, "Module could not be created");
return; return false;
} }
shadyCompileModule(module, shaderStage, shaderPath, compiled, includePath, update); bool result = shadyCompileModule(module, shaderStage, shaderPath, compiled, includePath);
destroy_module(module);
return result;
} }
void ShadyCompiler::compile(ShaderStage shaderStage, void ShadyCompiler::compile(ShaderStage shaderStage,
...@@ -112,8 +121,17 @@ namespace vkcv::shader { ...@@ -112,8 +121,17 @@ namespace vkcv::shader {
return; return;
} }
shadyCompileArena(arena, shaderStage, shaderPath, compiled, includePath, update); bool result = shadyCompileArena(arena, shaderStage, shaderPath, compiled, includePath);
destroy_ir_arena(arena); destroy_ir_arena(arena);
if (!result) {
vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)", shaderPath.string().c_str());
}
if (update) {
// TODO: Shader hot compilation during runtime
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment