Path: blob/main_old/src/tests/compiler_tests/ExtensionDirective_test.cpp
1693 views
//1// Copyright 2017 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ExtensionDirective_test.cpp:6// Miscellaneous tests for extension directives toggling functionality correctly.7//89#include "GLSLANG/ShaderLang.h"10#include "angle_gl.h"11#include "compiler/translator/ExtensionBehavior.h"12#include "gtest/gtest.h"13#include "tests/test_utils/ShaderCompileTreeTest.h"1415using namespace sh;1617class FragmentShaderExtensionDirectiveTest : public ShaderCompileTreeTest18{19public:20FragmentShaderExtensionDirectiveTest() {}2122protected:23::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }24ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }2526void testCompileNeedsExtensionDirective(const std::string &shader, const std::string &extension)27{28testCompileNeedsExtensionDirective(shader, extension, "");29}3031void testCompileNeedsExtensionDirective(const std::string &shader,32const std::string &extension,33const std::string &versionDirective)34{35if (compile(versionDirective + shader))36{37FAIL()38<< "Shader compilation without extension directive succeeded, expecting failure:\n"39<< mInfoLog;40}41if (compile(versionDirective + getExtensionDirective(extension, sh::EBhDisable) + shader))42{43FAIL() << "Shader compilation with extension disable directive succeeded, expecting "44"failure:\n"45<< mInfoLog;46}47if (!compile(versionDirective + getExtensionDirective(extension, sh::EBhEnable) + shader))48{49FAIL()50<< "Shader compilation with extension enable directive failed, expecting success:\n"51<< mInfoLog;52}5354if (!compile(versionDirective + getExtensionDirective(extension, sh::EBhWarn) + shader))55{56FAIL()57<< "Shader compilation with extension warn directive failed, expecting success:\n"58<< mInfoLog;59}60else if (!hasWarning())61{62FAIL() << "Expected compilation to succeed with warning, but warning not present:\n"63<< mInfoLog;64}65}6667private:68std::string getExtensionDirective(const std::string &extension, sh::TBehavior behavior)69{70std::string extensionDirective("#extension ");71extensionDirective += extension + " : ";72switch (behavior)73{74case EBhRequire:75extensionDirective += "require";76break;77case EBhEnable:78extensionDirective += "enable";79break;80case EBhWarn:81extensionDirective += "warn";82break;83case EBhDisable:84extensionDirective += "disable";85break;86default:87break;88}89extensionDirective += "\n";90return extensionDirective;91}92};9394class OESEGLImageExternalTest : public FragmentShaderExtensionDirectiveTest95{96public:97OESEGLImageExternalTest() {}9899protected:100void initResources(ShBuiltInResources *resources) override101{102resources->OES_EGL_image_external = 1;103}104};105106// OES_EGL_image_external needs to be enabled in GLSL to be able to use samplerExternalOES.107TEST_F(OESEGLImageExternalTest, SamplerExternalOESUsageNeedsExtensionDirective)108{109const std::string &shaderString =110R"(111precision mediump float;112113uniform samplerExternalOES s;114void main()115{})";116testCompileNeedsExtensionDirective(shaderString, "GL_OES_EGL_image_external");117}118119class NVEGLStreamConsumerExternalTest : public FragmentShaderExtensionDirectiveTest120{121public:122NVEGLStreamConsumerExternalTest() {}123124protected:125void initResources(ShBuiltInResources *resources) override126{127resources->NV_EGL_stream_consumer_external = 1;128}129};130131// NV_EGL_stream_consumer_external needs to be enabled in GLSL to be able to use samplerExternalOES.132TEST_F(NVEGLStreamConsumerExternalTest, SamplerExternalOESUsageNeedsExtensionDirective)133{134const std::string &shaderString =135R"(136precision mediump float;137138uniform samplerExternalOES s;139void main()140{})";141testCompileNeedsExtensionDirective(shaderString, "GL_NV_EGL_stream_consumer_external");142}143144class EXTYUVTargetTest : public FragmentShaderExtensionDirectiveTest145{146public:147EXTYUVTargetTest() {}148149protected:150void initResources(ShBuiltInResources *resources) override { resources->EXT_YUV_target = 1; }151};152153// GL_EXT_YUV_target needs to be enabled in GLSL to be able to use samplerExternal2DY2YEXT.154TEST_F(EXTYUVTargetTest, SamplerExternal2DY2YEXTUsageNeedsExtensionDirective)155{156const std::string &shaderString =157R"(158precision mediump float;159160uniform __samplerExternal2DY2YEXT s;161void main()162{})";163testCompileNeedsExtensionDirective(shaderString, "GL_EXT_YUV_target", "#version 300 es\n");164}165166// GL_EXT_YUV_target needs to be enabled in GLSL to be able to use samplerExternal2DY2YEXT.167TEST_F(EXTYUVTargetTest, YUVLayoutNeedsExtensionDirective)168{169const std::string &shaderString =170R"(171precision mediump float;172173layout(yuv) out vec4 color;174void main()175{})";176testCompileNeedsExtensionDirective(shaderString, "GL_EXT_YUV_target", "#version 300 es\n");177}178179180