xref: /aosp_15_r20/external/angle/src/tests/compiler_tests/EmulateGLFragColorBroadcast_test.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2016 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 // EmulateGLFragColorBroadcast_test.cpp:
7 //   Tests for gl_FragColor broadcast behavior emulation.
8 //
9 
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "gtest/gtest.h"
13 #include "tests/test_utils/compiler_test.h"
14 
15 using namespace sh;
16 
17 namespace
18 {
19 
20 const int kMaxDrawBuffers = 2;
21 
22 class EmulateGLFragColorBroadcastTest : public MatchOutputCodeTest
23 {
24   public:
EmulateGLFragColorBroadcastTest()25     EmulateGLFragColorBroadcastTest()
26         : MatchOutputCodeTest(GL_FRAGMENT_SHADER, SH_GLSL_COMPATIBILITY_OUTPUT)
27     {
28         getResources()->MaxDrawBuffers   = kMaxDrawBuffers;
29         getResources()->EXT_draw_buffers = 1;
30     }
31 };
32 
33 // Verifies that without explicitly enabling GL_EXT_draw_buffers extension
34 // in the shader, no broadcast emulation.
TEST_F(EmulateGLFragColorBroadcastTest,FragColorNoBroadcast)35 TEST_F(EmulateGLFragColorBroadcastTest, FragColorNoBroadcast)
36 {
37     const std::string shaderString =
38         "void main()\n"
39         "{\n"
40         "    gl_FragColor = vec4(1, 0, 0, 0);\n"
41         "}\n";
42     compile(shaderString);
43     EXPECT_TRUE(foundInCode("gl_FragColor"));
44     EXPECT_FALSE(foundInCode("gl_FragData[0]"));
45     EXPECT_FALSE(foundInCode("gl_FragData[1]"));
46 }
47 
48 // Verifies that with explicitly enabling GL_EXT_draw_buffers extension
49 // in the shader, broadcast is emualted by replacing gl_FragColor with gl_FragData.
TEST_F(EmulateGLFragColorBroadcastTest,FragColorBroadcast)50 TEST_F(EmulateGLFragColorBroadcastTest, FragColorBroadcast)
51 {
52     const std::string shaderString =
53         "#extension GL_EXT_draw_buffers : require\n"
54         "void main()\n"
55         "{\n"
56         "    gl_FragColor = vec4(1, 0, 0, 0);\n"
57         "}\n";
58     compile(shaderString);
59     EXPECT_FALSE(foundInCode("gl_FragColor"));
60     EXPECT_TRUE(foundInCode("gl_FragData[0]"));
61     EXPECT_TRUE(foundInCode("gl_FragData[1]"));
62 }
63 
64 // Verifies that with explicitly enabling GL_EXT_draw_buffers extension
65 // in the shader with an empty main(), anothing happens.
TEST_F(EmulateGLFragColorBroadcastTest,EmptyMain)66 TEST_F(EmulateGLFragColorBroadcastTest, EmptyMain)
67 {
68     const std::string shaderString =
69         "#extension GL_EXT_draw_buffers : require\n"
70         "void main()\n"
71         "{\n"
72         "}\n";
73     compile(shaderString);
74     EXPECT_FALSE(foundInCode("gl_FragColor"));
75     EXPECT_FALSE(foundInCode("gl_FragData[0]"));
76     EXPECT_FALSE(foundInCode("gl_FragData[1]"));
77 }
78 
79 }  // namespace
80