From c9425c6ea4ed54925cb10d31a8d4bb0aca9aa866 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 16 Mar 2021 20:00:51 +0200 Subject: [PATCH] Always show shader compiler diagnostics in debug builds --- source/core/module.cpp | 22 +++++++++++++++------- source/core/module.h | 4 ++++ source/core/program.cpp | 5 +++++ tools/glslcompiler.cpp | 3 +++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/source/core/module.cpp b/source/core/module.cpp index 406b4739..009733a9 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -1,6 +1,6 @@ +#include #include "module.h" #include "resources.h" -#include "glsl/compiler.h" using namespace std; @@ -14,18 +14,14 @@ void Module::set_source(const string &src) { SL::Compiler compiler; compiler.set_source(src); - compiler.compile(SL::Compiler::MODULE); - prepared_source = compiler.get_combined_glsl(); - source_map = compiler.get_source_map(); + compile(compiler); } void Module::load_source(IO::Base &io, Resources *res, const string &name) { SL::Compiler compiler; compiler.load_source(io, res, name); - compiler.compile(SL::Compiler::MODULE); - prepared_source = compiler.get_combined_glsl(); - source_map = compiler.get_source_map(); + compile(compiler); } void Module::load_source(IO::Base &io, const string &name) @@ -33,5 +29,17 @@ void Module::load_source(IO::Base &io, const string &name) load_source(io, 0, name); } +void Module::compile(SL::Compiler &compiler) +{ + compiler.compile(SL::Compiler::MODULE); + prepared_source = compiler.get_combined_glsl(); + source_map = compiler.get_source_map(); +#ifdef DEBUG + string diagnostics = compiler.get_diagnostics(); + if(!diagnostics.empty()) + IO::print("Module diagnostics:\n%s\n", diagnostics); +#endif +} + } // namespace GL } // namespace Msp diff --git a/source/core/module.h b/source/core/module.h index b1c0f8ab..f65f739a 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -3,6 +3,7 @@ #include #include +#include "glsl/compiler.h" #include "glsl/sourcemap.h" namespace Msp { @@ -22,7 +23,10 @@ public: void set_source(const std::string &); void load_source(IO::Base &, Resources *, const std::string &); void load_source(IO::Base &, const std::string &); +private: + void compile(SL::Compiler &); +public: const std::string &get_prepared_source() const { return prepared_source; } const SL::SourceMap &get_source_map() const { return source_map; } }; diff --git a/source/core/program.cpp b/source/core/program.cpp index 9ef5d6d7..fa9a5ded 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -86,6 +86,11 @@ void Program::add_stages(const Module &mod, const map &spec_values) compiler.set_source(module->get_prepared_source(), ""); compiler.specialize(spec_values); compiler.compile(SL::Compiler::PROGRAM); +#ifdef DEBUG + string diagnostics = compiler.get_diagnostics(); + if(!diagnostics.empty()) + IO::print("Program diagnostics:\n%s\n", diagnostics); +#endif vector stages = compiler.get_stages(); for(vector::const_iterator i=stages.begin(); i!=stages.end(); ++i) diff --git a/tools/glslcompiler.cpp b/tools/glslcompiler.cpp index 4a166ba6..24df1f2b 100644 --- a/tools/glslcompiler.cpp +++ b/tools/glslcompiler.cpp @@ -85,6 +85,9 @@ int GlslCompiler::main() try { compiler.compile(GL::SL::Compiler::PROGRAM); + string diag = compiler.get_diagnostics(); + if(!diag.empty()) + IO::print("Diagnostic messages from compiler:\n%s\n", diag); } catch(const GL::SL::invalid_shader_source &exc) { -- 2.45.2