1*8975f5c5SAndroid Build Coastguard Worker // 2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2018 The ANGLE Project Authors. All rights reserved. 3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file. 5*8975f5c5SAndroid Build Coastguard Worker // 6*8975f5c5SAndroid Build Coastguard Worker // ShaderExtensionTest.cpp: 7*8975f5c5SAndroid Build Coastguard Worker // Utilities for testing that GLSL extension pragma and changing the extension flag in compiler 8*8975f5c5SAndroid Build Coastguard Worker // resources has the correct effect. 9*8975f5c5SAndroid Build Coastguard Worker // 10*8975f5c5SAndroid Build Coastguard Worker 11*8975f5c5SAndroid Build Coastguard Worker #include "GLSLANG/ShaderLang.h" 12*8975f5c5SAndroid Build Coastguard Worker #include "angle_gl.h" 13*8975f5c5SAndroid Build Coastguard Worker #include "gtest/gtest.h" 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard Worker using testing::Combine; 16*8975f5c5SAndroid Build Coastguard Worker using testing::make_tuple; 17*8975f5c5SAndroid Build Coastguard Worker using testing::Values; 18*8975f5c5SAndroid Build Coastguard Worker 19*8975f5c5SAndroid Build Coastguard Worker namespace sh 20*8975f5c5SAndroid Build Coastguard Worker { 21*8975f5c5SAndroid Build Coastguard Worker 22*8975f5c5SAndroid Build Coastguard Worker const char ESSLVersion100[] = "#version 100\n"; 23*8975f5c5SAndroid Build Coastguard Worker const char ESSLVersion300[] = "#version 300 es\n"; 24*8975f5c5SAndroid Build Coastguard Worker const char ESSLVersion310[] = "#version 310 es\n"; 25*8975f5c5SAndroid Build Coastguard Worker 26*8975f5c5SAndroid Build Coastguard Worker class ShaderExtensionTest 27*8975f5c5SAndroid Build Coastguard Worker : public testing::TestWithParam<testing::tuple<ShShaderSpec, const char *, const char *>> 28*8975f5c5SAndroid Build Coastguard Worker { 29*8975f5c5SAndroid Build Coastguard Worker protected: SetUp()30*8975f5c5SAndroid Build Coastguard Worker void SetUp() override 31*8975f5c5SAndroid Build Coastguard Worker { 32*8975f5c5SAndroid Build Coastguard Worker sh::InitBuiltInResources(&mResources); 33*8975f5c5SAndroid Build Coastguard Worker mCompiler = nullptr; 34*8975f5c5SAndroid Build Coastguard Worker mCompileOptions = {}; 35*8975f5c5SAndroid Build Coastguard Worker mCompileOptions.objectCode = true; 36*8975f5c5SAndroid Build Coastguard Worker } 37*8975f5c5SAndroid Build Coastguard Worker TearDown()38*8975f5c5SAndroid Build Coastguard Worker void TearDown() override { DestroyCompiler(); } DestroyCompiler()39*8975f5c5SAndroid Build Coastguard Worker void DestroyCompiler() 40*8975f5c5SAndroid Build Coastguard Worker { 41*8975f5c5SAndroid Build Coastguard Worker if (mCompiler) 42*8975f5c5SAndroid Build Coastguard Worker { 43*8975f5c5SAndroid Build Coastguard Worker sh::Destruct(mCompiler); 44*8975f5c5SAndroid Build Coastguard Worker mCompiler = nullptr; 45*8975f5c5SAndroid Build Coastguard Worker } 46*8975f5c5SAndroid Build Coastguard Worker } 47*8975f5c5SAndroid Build Coastguard Worker InitializeCompiler()48*8975f5c5SAndroid Build Coastguard Worker void InitializeCompiler() 49*8975f5c5SAndroid Build Coastguard Worker { 50*8975f5c5SAndroid Build Coastguard Worker DestroyCompiler(); 51*8975f5c5SAndroid Build Coastguard Worker mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()), 52*8975f5c5SAndroid Build Coastguard Worker SH_GLSL_COMPATIBILITY_OUTPUT, &mResources); 53*8975f5c5SAndroid Build Coastguard Worker ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed."; 54*8975f5c5SAndroid Build Coastguard Worker } 55*8975f5c5SAndroid Build Coastguard Worker TestShaderCompile(const char * pragma)56*8975f5c5SAndroid Build Coastguard Worker testing::AssertionResult TestShaderCompile(const char *pragma) 57*8975f5c5SAndroid Build Coastguard Worker { 58*8975f5c5SAndroid Build Coastguard Worker return TestShaderCompile(testing::get<1>(GetParam()), // Version. 59*8975f5c5SAndroid Build Coastguard Worker pragma, 60*8975f5c5SAndroid Build Coastguard Worker testing::get<2>(GetParam()) // Shader. 61*8975f5c5SAndroid Build Coastguard Worker ); 62*8975f5c5SAndroid Build Coastguard Worker } 63*8975f5c5SAndroid Build Coastguard Worker TestShaderCompile(const char * version,const char * pragma,const char * shader)64*8975f5c5SAndroid Build Coastguard Worker testing::AssertionResult TestShaderCompile(const char *version, 65*8975f5c5SAndroid Build Coastguard Worker const char *pragma, 66*8975f5c5SAndroid Build Coastguard Worker const char *shader) 67*8975f5c5SAndroid Build Coastguard Worker { 68*8975f5c5SAndroid Build Coastguard Worker const char *shaderStrings[] = {version, pragma, shader}; 69*8975f5c5SAndroid Build Coastguard Worker bool success = sh::Compile(mCompiler, shaderStrings, 3, mCompileOptions); 70*8975f5c5SAndroid Build Coastguard Worker if (success) 71*8975f5c5SAndroid Build Coastguard Worker { 72*8975f5c5SAndroid Build Coastguard Worker return ::testing::AssertionSuccess() << "Compilation success"; 73*8975f5c5SAndroid Build Coastguard Worker } 74*8975f5c5SAndroid Build Coastguard Worker return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler); 75*8975f5c5SAndroid Build Coastguard Worker } 76*8975f5c5SAndroid Build Coastguard Worker 77*8975f5c5SAndroid Build Coastguard Worker protected: 78*8975f5c5SAndroid Build Coastguard Worker ShBuiltInResources mResources; 79*8975f5c5SAndroid Build Coastguard Worker ShHandle mCompiler; 80*8975f5c5SAndroid Build Coastguard Worker ShCompileOptions mCompileOptions; 81*8975f5c5SAndroid Build Coastguard Worker }; 82*8975f5c5SAndroid Build Coastguard Worker 83*8975f5c5SAndroid Build Coastguard Worker } // namespace sh 84