Path: blob/main_old/src/tests/compiler_tests/FragDepth_test.cpp
1693 views
//1// Copyright 2015 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// FragDepth_test.cpp:6// Test for GLES SL 3.0 gl_FragDepth variable implementation.7//89#include "GLSLANG/ShaderLang.h"10#include "angle_gl.h"11#include "gtest/gtest.h"1213namespace14{15const char ESSLVersion100[] = "#version 100\n";16const char ESSLVersion300[] = "#version 300 es\n";17const char EXTFDPragma[] = "#extension GL_EXT_frag_depth : require\n";18} // namespace1920class FragDepthTest : public testing::TestWithParam<bool>21{22protected:23void SetUp() override24{25sh::InitBuiltInResources(&mResources);26mCompiler = nullptr;27mResources.EXT_frag_depth = GetParam();28}2930void TearDown() override { DestroyCompiler(); }31void DestroyCompiler()32{33if (mCompiler)34{35sh::Destruct(mCompiler);36mCompiler = nullptr;37}38}3940void InitializeCompiler()41{42DestroyCompiler();43mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, SH_GLES3_SPEC,44SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);45ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";46}4748testing::AssertionResult TestShaderCompile(const char *version,49const char *pragma,50const char *shader)51{52const char *shaderStrings[] = {version, pragma, shader};53bool success = sh::Compile(mCompiler, shaderStrings, 3, 0);54if (success)55{56return ::testing::AssertionSuccess() << "Compilation success";57}58return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);59}6061protected:62ShBuiltInResources mResources;63ShHandle mCompiler;64};6566// The GLES SL 3.0 built-in variable gl_FragDepth fails to compile with GLES SL 1.0.67TEST_P(FragDepthTest, CompileFailsESSL100)68{69static const char shaderString[] =70"precision mediump float;\n"71"void main() { \n"72" gl_FragDepth = 1.0;\n"73"}\n";7475InitializeCompiler();76EXPECT_FALSE(TestShaderCompile(ESSLVersion100, "", shaderString));77EXPECT_FALSE(TestShaderCompile("", "", shaderString));78EXPECT_FALSE(TestShaderCompile("", EXTFDPragma, shaderString));79}8081// The GLES SL 3.0 built-in variable gl_FragDepth compiles with GLES SL 3.0.82TEST_P(FragDepthTest, CompileSucceedsESSL300)83{84static const char shaderString[] =85"precision mediump float;\n"86"void main() { \n"87" gl_FragDepth = 1.0;\n"88"}\n";89InitializeCompiler();90EXPECT_TRUE(TestShaderCompile(ESSLVersion300, "", shaderString));91}9293// Using #extension GL_EXT_frag_depth in GLSL ES 3.0 shader fails to compile.94TEST_P(FragDepthTest, ExtensionFDFailsESSL300)95{96static const char shaderString[] =97"precision mediump float;\n"98"out vec4 fragColor;\n"99"void main() { \n"100" fragColor = vec4(1.0);\n"101"}\n";102InitializeCompiler();103if (mResources.EXT_frag_depth == 1)104{105// TODO(kkinnunen, geofflang): this should fail. Extensions need to have similar level106// system to SymbolTable. The biggest task is to implement version-aware preprocessor, so107// that the extension defines can be defined depending on the version that the preprocessor108// saw or did not see.109EXPECT_TRUE(TestShaderCompile(ESSLVersion300, EXTFDPragma, shaderString));110}111else112{113EXPECT_FALSE(TestShaderCompile(ESSLVersion300, EXTFDPragma, shaderString));114}115}116117// The tests should pass regardless whether the EXT_frag_depth is on or not.118INSTANTIATE_TEST_SUITE_P(FragDepthTests, FragDepthTest, testing::Values(false, true));119120121