]> git.tdb.fi Git - libs/gl.git/commitdiff
Make it possible to specify a target API for GLSL test cases
authorMikko Rasa <tdb@tdb.fi>
Sat, 9 Apr 2022 11:43:49 +0000 (14:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 9 Apr 2022 16:05:05 +0000 (19:05 +0300)
tests/glsl/glslcompiler.cpp

index 516642727fdd5c0afd5979e675b8f8dd990b4c6d..7deeb1f35190b403f8594e159562498e522e5b9e 100644 (file)
@@ -15,6 +15,7 @@ protected:
        {
                std::string name;
                std::string source;
+               Msp::GL::GraphicsApi target_api;
                Msp::GL::SL::Compiler::Mode compile_mode;
                std::map<std::string, int> spec_values;
                std::map<Msp::GL::SL::Stage::Type, std::string> expected_output;
@@ -91,6 +92,7 @@ const GlslCompilerHelper::TestCase &GlslCompilerHelper::load_test_case(const str
        IO::BufferedFile file(fn);
        TestCase test_case;
        test_case.name = FS::basename(fn);
+       test_case.target_api = GL::OPENGL;
        test_case.compile_mode = GL::SL::Compiler::PROGRAM;
        string *target = &test_case.source;
        while(!file.eof())
@@ -127,6 +129,21 @@ const GlslCompilerHelper::TestCase &GlslCompilerHelper::load_test_case(const str
                        continue;
                }
 
+               pos = line.find("Target API:");
+               if(pos!=string::npos)
+               {
+                       string api = strip(line.substr(pos+11));
+                       if(api=="OpenGL")
+                               test_case.target_api = GL::OPENGL;
+                       else if(api=="OpenGL ES")
+                               test_case.target_api = GL::OPENGL_ES;
+                       else if(api=="Vulkan")
+                               test_case.target_api = GL::VULKAN;
+                       else
+                               throw runtime_error("Unknown API "+api);
+                       continue;
+               }
+
                pos = line.find("Compile mode:");
                if(pos!=string::npos)
                {
@@ -251,7 +268,7 @@ GlslCompilerTest::GlslCompilerTest()
 
 void GlslCompilerTest::run_test_case(const TestCase *test_case)
 {
-       GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL));
+       GL::SL::Compiler compiler(GL::SL::Features::latest(test_case->target_api));
        try
        {
                compiler.set_source(test_case->source, "<test>");
@@ -308,13 +325,13 @@ GlslCompilerIdempotence::GlslCompilerIdempotence()
 
 void GlslCompilerIdempotence::run_test_case(const TestCase *test_case)
 {
-       GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL));
+       GL::SL::Compiler compiler(GL::SL::Features::latest(test_case->target_api));
        compiler.set_source(test_case->source, "<test>");
        if(test_case->compile_mode==GL::SL::Compiler::PROGRAM)
                compiler.specialize(test_case->spec_values);
        compiler.compile(test_case->compile_mode);
 
-       GL::SL::Compiler compiler2(GL::SL::Features::latest(GL::OPENGL));
+       GL::SL::Compiler compiler2(GL::SL::Features::latest(test_case->target_api));
        compiler2.set_source(compiler.get_combined_glsl(), "<loopback>");
        compiler2.compile(test_case->compile_mode);
 
@@ -351,7 +368,7 @@ GlslCompilerSpirV::GlslCompilerSpirV():
 
 void GlslCompilerSpirV::run_test_case(const TestCase *test_case)
 {
-       GL::SL::Compiler compiler(GL::SL::Features::latest(GL::OPENGL));
+       GL::SL::Compiler compiler(GL::SL::Features::latest(test_case->target_api));
        compiler.set_source(test_case->source, "<test>");
        compiler.compile(GL::SL::Compiler::SPIRV);