1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // WorkGroupSize_test.cpp:
7 // tests for local group size in a compute shader
8 //
9
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "compiler/translator/glsl/TranslatorESSL.h"
13 #include "gtest/gtest.h"
14 #include "tests/test_utils/compiler_test.h"
15
16 using namespace sh;
17
18 class WorkGroupSizeTest : public testing::Test
19 {
20 public:
WorkGroupSizeTest()21 WorkGroupSizeTest() {}
22
23 protected:
SetUp()24 void SetUp() override
25 {
26 ShBuiltInResources resources;
27 InitBuiltInResources(&resources);
28
29 mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
30 ASSERT_TRUE(mTranslator->Init(resources));
31 }
32
TearDown()33 void TearDown() override { SafeDelete(mTranslator); }
34
35 // Return true when compilation succeeds
compile(const std::string & shaderString)36 bool compile(const std::string &shaderString)
37 {
38 ShCompileOptions compileOptions = {};
39 compileOptions.intermediateTree = true;
40
41 const char *shaderStrings[] = {shaderString.c_str()};
42 bool status = mTranslator->compile(shaderStrings, 1, compileOptions);
43 TInfoSink &infoSink = mTranslator->getInfoSink();
44 mInfoLog = infoSink.info.c_str();
45 return status;
46 }
47
48 protected:
49 std::string mInfoLog;
50 TranslatorESSL *mTranslator = nullptr;
51 };
52
53 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,OnlyLocalSizeXSpecified)54 TEST_F(WorkGroupSizeTest, OnlyLocalSizeXSpecified)
55 {
56 const std::string &shaderString =
57 "#version 310 es\n"
58 "layout(local_size_x=5) in;\n"
59 "void main() {\n"
60 "}\n";
61
62 compile(shaderString);
63
64 const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
65 ASSERT_EQ(5, localSize[0]);
66 ASSERT_EQ(1, localSize[1]);
67 ASSERT_EQ(1, localSize[2]);
68 }
69
70 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,LocalSizeXandZ)71 TEST_F(WorkGroupSizeTest, LocalSizeXandZ)
72 {
73 const std::string &shaderString =
74 "#version 310 es\n"
75 "layout(local_size_x=5, local_size_z=10) in;\n"
76 "void main() {\n"
77 "}\n";
78
79 compile(shaderString);
80
81 const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
82 ASSERT_EQ(5, localSize[0]);
83 ASSERT_EQ(1, localSize[1]);
84 ASSERT_EQ(10, localSize[2]);
85 }
86
87 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,LocalSizeAll)88 TEST_F(WorkGroupSizeTest, LocalSizeAll)
89 {
90 const std::string &shaderString =
91 "#version 310 es\n"
92 "layout(local_size_x=5, local_size_z=10, local_size_y=15) in;\n"
93 "void main() {\n"
94 "}\n";
95
96 compile(shaderString);
97
98 const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
99 ASSERT_EQ(5, localSize[0]);
100 ASSERT_EQ(15, localSize[1]);
101 ASSERT_EQ(10, localSize[2]);
102 }
103