• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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         const char *shaderStrings[] = {shaderString.c_str()};
39         bool status = mTranslator->compile(shaderStrings, 1, SH_INTERMEDIATE_TREE | SH_VARIABLES);
40         TInfoSink &infoSink = mTranslator->getInfoSink();
41         mInfoLog            = infoSink.info.c_str();
42         return status;
43     }
44 
45   protected:
46     std::string mInfoLog;
47     TranslatorESSL *mTranslator = nullptr;
48 };
49 
50 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,OnlyLocalSizeXSpecified)51 TEST_F(WorkGroupSizeTest, OnlyLocalSizeXSpecified)
52 {
53     const std::string &shaderString =
54         "#version 310 es\n"
55         "layout(local_size_x=5) in;\n"
56         "void main() {\n"
57         "}\n";
58 
59     compile(shaderString);
60 
61     const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
62     ASSERT_EQ(5, localSize[0]);
63     ASSERT_EQ(1, localSize[1]);
64     ASSERT_EQ(1, localSize[2]);
65 }
66 
67 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,LocalSizeXandZ)68 TEST_F(WorkGroupSizeTest, LocalSizeXandZ)
69 {
70     const std::string &shaderString =
71         "#version 310 es\n"
72         "layout(local_size_x=5, local_size_z=10) in;\n"
73         "void main() {\n"
74         "}\n";
75 
76     compile(shaderString);
77 
78     const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
79     ASSERT_EQ(5, localSize[0]);
80     ASSERT_EQ(1, localSize[1]);
81     ASSERT_EQ(10, localSize[2]);
82 }
83 
84 // checks whether compiler has parsed the local size layout qualifiers qcorrectly
TEST_F(WorkGroupSizeTest,LocalSizeAll)85 TEST_F(WorkGroupSizeTest, LocalSizeAll)
86 {
87     const std::string &shaderString =
88         "#version 310 es\n"
89         "layout(local_size_x=5, local_size_z=10, local_size_y=15) in;\n"
90         "void main() {\n"
91         "}\n";
92 
93     compile(shaderString);
94 
95     const WorkGroupSize &localSize = mTranslator->getComputeShaderLocalSize();
96     ASSERT_EQ(5, localSize[0]);
97     ASSERT_EQ(15, localSize[1]);
98     ASSERT_EQ(10, localSize[2]);
99 }
100