From: Mikko Rasa Date: Fri, 21 Jun 2019 11:46:34 +0000 (+0300) Subject: Translate shader compile errors to actual source file names X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=b699b811b22450828268be7ed67e35900be7bdad Translate shader compile errors to actual source file names Intel drivers appear to process the #line directives incorrectly and produce off-by-one line numbers. --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 518b31e1..bb77e0ea 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "error.h" #include "program.h" @@ -57,7 +58,7 @@ void ProgramCompiler::compile(const string &source, const string &src_name) delete module; module = new Module(); ProgramParser parser; - imported_names.insert(src_name); + imported_names.push_back(src_name); append_module(parser.parse(source, src_name, 1)); process(); } @@ -68,7 +69,7 @@ void ProgramCompiler::compile(IO::Base &io, Resources *res, const string &src_na delete module; module = new Module(); ProgramParser parser; - imported_names.insert(src_name); + imported_names.push_back(src_name); append_module(parser.parse(io, src_name, 1)); process(); } @@ -83,25 +84,64 @@ void ProgramCompiler::add_shaders(Program &program) if(!module) throw invalid_operation("ProgramCompiler::add_shaders"); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + try { - if(i->type==VERTEX) + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) { - program.attach_shader_owned(new VertexShader(apply(*i))); - for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) - program.bind_attribute(j->second, j->first); + if(i->type==VERTEX) + { + program.attach_shader_owned(new VertexShader(apply(*i))); + for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) + program.bind_attribute(j->second, j->first); + } + else if(i->type==GEOMETRY) + program.attach_shader_owned(new GeometryShader(apply(*i))); + else if(i->type==FRAGMENT) + { + program.attach_shader_owned(new FragmentShader(apply(*i))); + if(EXT_gpu_shader4) + { + for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) + program.bind_fragment_data(j->second, j->first); + } + } } - else if(i->type==GEOMETRY) - program.attach_shader_owned(new GeometryShader(apply(*i))); - else if(i->type==FRAGMENT) + } + catch(const compile_error &e) + { + static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$"); + vector lines = split(e.what(), '\n'); + string translated; + for(vector::const_iterator i=lines.begin(); i!=lines.end(); ++i) { - program.attach_shader_owned(new FragmentShader(apply(*i))); - if(EXT_gpu_shader4) + RegMatch m = r_message.match(*i); + if(m) { - for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) - program.bind_fragment_data(j->second, j->first); + unsigned index = 0; + unsigned line = 0; + if(m[2]) + { + index = lexical_cast(m[2].str); + line = lexical_cast(m[3].str); + } + else if(m[4]) + { + index = lexical_cast(m[4].str); + line = lexical_cast(m[5].str); + } + const char *src = ""; + if(index==0) + src = ""; + else if(index-1 io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn)); if(!io) diff --git a/source/programcompiler.h b/source/programcompiler.h index 697c6086..bea3faec 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -381,7 +381,7 @@ private: Resources *resources; ProgramSyntax::Module *module; - std::set imported_names; + std::vector imported_names; public: ProgramCompiler();