Path: blob/main_old/src/tests/compiler_tests/QualificationOrderESSL31_test.cpp
1693 views
//1// Copyright 2016 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// QualificationOrderESSL31_test.cpp:6// OpenGL ES 3.1 removes the strict order of qualifiers imposed by the grammar.7// This file contains tests for invalid order and usage of qualifiers in GLSL ES 3.10.89#include "gtest/gtest.h"1011#include "GLSLANG/ShaderLang.h"12#include "angle_gl.h"13#include "tests/test_utils/ShaderCompileTreeTest.h"14#include "tests/test_utils/compiler_test.h"1516using namespace sh;1718class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest19{20public:21QualificationVertexShaderTestESSL31() {}2223protected:24::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }25ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }2627const TIntermSymbol *findSymbolInAST(const ImmutableString &symbolName)28{29return FindSymbolNode(mASTRoot, symbolName);30}31};3233// GLSL ES 3.10 has relaxed checks on qualifier order. Any order is correct.34TEST_F(QualificationVertexShaderTestESSL31, CentroidOut)35{36const std::string &shaderString =37"#version 310 es\n"38"precision lowp float;\n"39"out centroid float something;\n"40"void main(){\n"41" something = 1.0;\n"42"}\n";43if (!compile(shaderString))44{45FAIL() << "Shader compilation failed, expecting success" << mInfoLog;46}47else48{49const TIntermSymbol *node = findSymbolInAST(ImmutableString("something"));50ASSERT_NE(nullptr, node);5152const TType &type = node->getType();53EXPECT_EQ(EvqCentroidOut, type.getQualifier());54}55}5657// GLSL ES 3.10 has relaxed checks on qualifier order. Any order is correct.58TEST_F(QualificationVertexShaderTestESSL31, AllQualifiersMixed)59{60const std::string &shaderString =61"#version 310 es\n"62"precision lowp float;\n"63"highp out invariant centroid flat vec4 something;\n"64"void main(){\n"65"}\n";66if (!compile(shaderString))67{68FAIL() << "Shader compilation failed, expecting success" << mInfoLog;69}70else71{72const TIntermSymbol *node = findSymbolInAST(ImmutableString("something"));73ASSERT_NE(nullptr, node);7475const TType &type = node->getType();76EXPECT_TRUE(type.isInvariant());77EXPECT_EQ(EvqFlatOut, type.getQualifier());78EXPECT_EQ(EbpHigh, type.getPrecision());79}80}8182// GLSL ES 3.10 allows multiple layout qualifiers to be specified.83TEST_F(QualificationVertexShaderTestESSL31, MultipleLayouts)84{85const std::string &shaderString =86"#version 310 es\n"87"precision lowp float;\n"88"in layout(location=1) layout(location=2) vec4 something;\n"89"void main(){\n"90"}\n";91if (!compile(shaderString))92{93FAIL() << "Shader compilation failed, expecting success" << mInfoLog;94}95else96{97const TIntermSymbol *node = findSymbolInAST(ImmutableString("something"));98ASSERT_NE(nullptr, node);99100const TType &type = node->getType();101EXPECT_EQ(EvqVertexIn, type.getQualifier());102EXPECT_EQ(2, type.getLayoutQualifier().location);103}104}105106// The test checks layout qualifier overriding when multiple layouts are specified.107TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock)108{109const std::string &shaderString =110"#version 310 es\n"111"precision lowp float;\n"112"out float someValue;\n"113"layout(shared) layout(std140) layout(column_major) uniform MyInterface\n"114"{ vec4 something; } MyInterfaceName;\n"115"void main(){\n"116" someValue = MyInterfaceName.something.r;\n"117"}\n";118if (!compile(shaderString))119{120FAIL() << "Shader compilation failed, expecting success" << mInfoLog;121}122else123{124const TIntermSymbol *node = findSymbolInAST(ImmutableString("MyInterfaceName"));125ASSERT_NE(nullptr, node);126127const TType &type = node->getType();128TLayoutQualifier layoutQualifier = type.getLayoutQualifier();129EXPECT_EQ(EbsStd140, layoutQualifier.blockStorage);130EXPECT_EQ(EmpColumnMajor, layoutQualifier.matrixPacking);131}132}133134// The test checks layout qualifier overriding when multiple layouts are specified.135TEST_F(QualificationVertexShaderTestESSL31, MultipleLayoutsInterfaceBlock2)136{137const std::string &shaderString =138"#version 310 es\n"139"precision lowp float;\n"140"out float someValue;\n"141"layout(row_major) layout(std140) layout(shared) uniform MyInterface\n"142"{ vec4 something; } MyInterfaceName;\n"143"void main(){\n"144" someValue = MyInterfaceName.something.r;\n"145"}\n";146if (!compile(shaderString))147{148FAIL() << "Shader compilation failed, expecting success" << mInfoLog;149}150else151{152const TIntermSymbol *node = findSymbolInAST(ImmutableString("MyInterfaceName"));153ASSERT_NE(nullptr, node);154155const TType &type = node->getType();156TLayoutQualifier layoutQualifier = type.getLayoutQualifier();157EXPECT_EQ(EbsShared, layoutQualifier.blockStorage);158EXPECT_EQ(EmpRowMajor, layoutQualifier.matrixPacking);159}160}161162163