Path: blob/main_old/src/tests/compiler_tests/AtomicCounter_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// AtomicCounter_test.cpp:6// Tests for validating ESSL 3.10 section 4.4.6.7//89#include "gtest/gtest.h"1011#include "GLSLANG/ShaderLang.h"12#include "angle_gl.h"13#include "gtest/gtest.h"14#include "tests/test_utils/ShaderCompileTreeTest.h"1516using namespace sh;1718class AtomicCounterTest : public ShaderCompileTreeTest19{20public:21AtomicCounterTest() {}2223protected:24::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }25ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }26void initResources(ShBuiltInResources *resources) override27{28resources->MaxAtomicCounterBindings = 8;29}30};3132// Test that layout qualifiers described in ESSL 3.10 section 4.4.6 can be successfully compiled,33// and the values of offset are properly assigned to counter variables.34TEST_F(AtomicCounterTest, BasicAtomicCounterDeclaration)35{36mExtraCompileOptions |= SH_VARIABLES;37const std::string &source =38"#version 310 es\n"39"layout(binding = 2, offset = 4) uniform atomic_uint a;\n"40"layout(binding = 2) uniform atomic_uint b;\n"41"layout(binding = 2, offset = 12) uniform atomic_uint c, d;\n"42"layout(binding = 1, offset = 4) uniform atomic_uint e;\n"43"void main()\n"44"{\n"45"}\n";46if (!compile(source))47{48FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;49}5051std::vector<sh::ShaderVariable> counters = getUniforms();5253EXPECT_EQ(std::string("a"), counters[0].name);54EXPECT_EQ(2, counters[0].binding);55EXPECT_EQ(4, counters[0].offset);5657EXPECT_EQ(std::string("b"), counters[1].name);58EXPECT_EQ(2, counters[1].binding);59EXPECT_EQ(8, counters[1].offset);6061EXPECT_EQ(std::string("c"), counters[2].name);62EXPECT_EQ(2, counters[2].binding);63EXPECT_EQ(12, counters[2].offset);6465EXPECT_EQ(std::string("d"), counters[3].name);66EXPECT_EQ(2, counters[3].binding);67EXPECT_EQ(16, counters[3].offset);6869EXPECT_EQ(std::string("e"), counters[4].name);70EXPECT_EQ(1, counters[4].binding);71EXPECT_EQ(4, counters[4].offset);72}7374// Test that ESSL 3.00 doesn't support atomic_uint.75TEST_F(AtomicCounterTest, InvalidShaderVersion)76{77const std::string &source =78"#version 300 es\n"79"layout(binding = 2, offset = 4) uniform atomic_uint a;\n"80"void main()\n"81"{\n"82"}\n";83if (compile(source))84{85FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;86}87}8889// Test that any qualifier other than uniform leads to compile-time error.90TEST_F(AtomicCounterTest, InvalidQualifier)91{92const std::string &source =93"#version 310 es\n"94"layout(binding = 2, offset = 4) in atomic_uint a;\n"95"void main()\n"96"{\n"97"}\n";98if (compile(source))99{100FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;101}102}103104// Test that uniform must be specified for declaration.105TEST_F(AtomicCounterTest, UniformMustSpecifiedForDeclaration)106{107const std::string &source =108"#version 310 es\n"109"atomic_uint a;\n"110"void main()\n"111"{\n"112"}\n";113if (compile(source))114{115FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;116}117}118119// Test that offset overlapping leads to compile-time error(ESSL 3.10 section 4.4.6).120TEST_F(AtomicCounterTest, BindingOffsetOverlapping)121{122const std::string &source =123"#version 310 es\n"124"layout(binding = 2, offset = 4) uniform atomic_uint a;\n"125"layout(binding = 2, offset = 6) uniform atomic_uint b;\n"126"void main()\n"127"{\n"128"}\n";129if (compile(source))130{131FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;132}133}134135// Test offset inheritance for multiple variables in one same declaration.136TEST_F(AtomicCounterTest, MultipleVariablesDeclaration)137{138const std::string &source =139"#version 310 es\n"140"layout(binding = 2, offset = 4) uniform atomic_uint a, b;\n"141"layout(binding = 2, offset = 8) uniform atomic_uint c;\n"142"void main()\n"143"{\n"144"}\n";145if (compile(source))146{147FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;148}149}150151// Test that subsequent declarations inherit the globally specified offset.152TEST_F(AtomicCounterTest, GlobalBindingOffsetOverlapping)153{154const std::string &source =155"#version 310 es\n"156"layout(binding = 2, offset = 4) uniform atomic_uint;\n"157"layout(binding = 2) uniform atomic_uint b;\n"158"layout(binding = 2, offset = 4) uniform atomic_uint c;\n"159"void main()\n"160"{\n"161"}\n";162if (compile(source))163{164FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;165}166}167168// The spec only demands offset unique and non-overlapping. So this should be allowed.169TEST_F(AtomicCounterTest, DeclarationSequenceWithDecrementalOffsetsSpecified)170{171const std::string &source =172"#version 310 es\n"173"layout(binding = 2, offset = 4) uniform atomic_uint a;\n"174"layout(binding = 2, offset = 0) uniform atomic_uint b;\n"175"void main()\n"176"{\n"177"}\n";178if (!compile(source))179{180FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;181}182}183184// Test that image format qualifiers are not allowed for atomic counters.185TEST_F(AtomicCounterTest, ImageFormatMustNotSpecified)186{187const std::string &source =188"#version 310 es\n"189"layout(binding = 2, offset = 4, rgba32f) uniform atomic_uint a;\n"190"void main()\n"191"{\n"192"}\n";193if (compile(source))194{195FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;196}197}198199// Test that global layout qualifiers must not use 'offset'.200TEST_F(AtomicCounterTest, OffsetMustNotSpecifiedForGlobalLayoutQualifier)201{202const std::string &source =203"#version 310 es\n"204"layout(offset = 4) in;\n"205"void main()\n"206"{\n"207"}\n";208if (compile(source))209{210FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;211}212}213214// Test that offset overlapping leads to compile-time error (ESSL 3.10 section 4.4.6).215// Note that there is some vagueness in the spec when it comes to this test.216TEST_F(AtomicCounterTest, BindingOffsetOverlappingForArrays)217{218const std::string &source =219"#version 310 es\n"220"layout(binding = 2, offset = 4) uniform atomic_uint[2] a;\n"221"layout(binding = 2, offset = 8) uniform atomic_uint b;\n"222"void main()\n"223"{\n"224"}\n";225if (compile(source))226{227FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;228}229}230231232