From: Mikko Rasa Date: Wed, 10 Mar 2021 10:01:33 +0000 (+0200) Subject: Support compile modes and specialization constants in the test harness X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1f870744029d50f29a060ddf68b8b7c40c6ef1ed;p=libs%2Fgl.git Support compile modes and specialization constants in the test harness --- diff --git a/tests/glsl/glslcompiler.cpp b/tests/glsl/glslcompiler.cpp index acca61d3..30805db3 100644 --- a/tests/glsl/glslcompiler.cpp +++ b/tests/glsl/glslcompiler.cpp @@ -16,6 +16,8 @@ private: { std::string name; std::string source; + Msp::GL::SL::Compiler::Mode compile_mode; + std::map spec_values; std::map expected_output; std::string expected_error; }; @@ -56,6 +58,7 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string IO::BufferedFile file(fn); TestCase test_case; test_case.name = FS::basename(fn); + test_case.compile_mode = GL::SL::Compiler::PROGRAM; string *target = &test_case.source; while(!file.eof()) { @@ -66,10 +69,10 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string if(line=="*/") continue; - string::size_type expected = line.find("Expected output:"); - if(expected!=string::npos) + string::size_type pos = line.find("Expected output:"); + if(pos!=string::npos) { - string stage = strip(line.substr(expected+16)); + string stage = strip(line.substr(pos+16)); if(stage=="vertex") target = &test_case.expected_output[GL::SL::Stage::VERTEX]; else if(stage=="geometry") @@ -81,13 +84,41 @@ const GlslCompilerTest::TestCase &GlslCompilerTest::load_test_case(const string continue; } - expected = line.find("Expected error:"); - if(expected!=string::npos) + pos = line.find("Expected error:"); + if(pos!=string::npos) { target = &test_case.expected_error; continue; } + pos = line.find("Compile mode:"); + if(pos!=string::npos) + { + string mode = strip(line.substr(pos+13)); + if(mode=="module") + test_case.compile_mode = GL::SL::Compiler::MODULE; + else if(mode=="program") + test_case.compile_mode = GL::SL::Compiler::PROGRAM; + else + throw runtime_error("Unknown compile mode "+mode); + continue; + } + + pos = line.find("Specialize:"); + if(pos!=string::npos) + { + vector parts = split(line.substr(pos+11)); + int value = 0; + if(parts[1]=="true") + value = 1; + else if(parts[1]=="false") + value = 0; + else + value = lexical_cast(parts[1]); + test_case.spec_values[parts[0]] = value; + continue; + } + *target += line; *target += '\n'; } @@ -102,7 +133,9 @@ void GlslCompilerTest::run_test_case(const TestCase *test_case) try { compiler.set_source(test_case->source, ""); - compiler.compile(GL::SL::Compiler::PROGRAM); + if(test_case->compile_mode==GL::SL::Compiler::PROGRAM) + compiler.specialize(test_case->spec_values); + compiler.compile(test_case->compile_mode); } catch(const GL::SL::invalid_shader_source &exc) {