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 // Pack_Unpack_test.cpp:
7 // Tests for the emulating pack_unpack functions for GLSL.
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 class PackUnpackTest : public MatchOutputCodeTest
21 {
22 public:
PackUnpackTest()23 PackUnpackTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_GLSL_400_CORE_OUTPUT) {}
24 };
25
26 // Check if PackSnorm2x16 Emulation for GLSL < 4.2 compile correctly.
TEST_F(PackUnpackTest,PackSnorm2x16Emulation)27 TEST_F(PackUnpackTest, PackSnorm2x16Emulation)
28 {
29 const std::string &shaderString =
30 R"(#version 300 es
31 precision mediump float;
32 layout(location = 0) out mediump vec4 fragColor;
33 void main()
34 {
35 vec2 v;
36 uint u = packSnorm2x16(v);
37 fragColor = vec4(u);
38 })";
39 compile(shaderString);
40 ASSERT_TRUE(foundInCode("uint packSnorm2x16_emu(vec2 v)"));
41 }
42
43 // Check if UnpackSnorm2x16 Emulation for GLSL < 4.2 compile correctly.
TEST_F(PackUnpackTest,UnpackSnorm2x16Emulation)44 TEST_F(PackUnpackTest, UnpackSnorm2x16Emulation)
45 {
46 const std::string &shaderString =
47 R"(#version 300 es
48 precision mediump float;
49 layout(location = 0) out mediump vec4 fragColor;
50 void main()
51 {
52 uint u;
53 vec2 v = unpackSnorm2x16(u);
54 fragColor = vec4(v, 0.0, 0.0);
55 })";
56 compile(shaderString);
57 ASSERT_TRUE(foundInCode("vec2 unpackSnorm2x16_emu(uint u)"));
58 }
59
60 // Check if PackUnorm2x16 Emulation for GLSL < 4.1 compiles correctly.
TEST_F(PackUnpackTest,PackUnorm2x16Emulation)61 TEST_F(PackUnpackTest, PackUnorm2x16Emulation)
62 {
63 const std::string &shaderString =
64 R"(#version 300 es
65 precision mediump float;
66 layout(location = 0) out mediump vec4 fragColor;
67 void main()
68 {
69 vec2 v;
70 uint u = packUnorm2x16(v);
71 fragColor = vec4(u);
72 })";
73 compile(shaderString);
74 ASSERT_TRUE(foundInCode("uint packUnorm2x16_emu(vec2 v)"));
75 }
76
77 // Check if UnpackSnorm2x16 Emulation for GLSL < 4.1 compiles correctly.
TEST_F(PackUnpackTest,UnpackUnorm2x16Emulation)78 TEST_F(PackUnpackTest, UnpackUnorm2x16Emulation)
79 {
80 const std::string &shaderString =
81 R"(#version 300 es
82 precision mediump float;
83 layout(location = 0) out mediump vec4 fragColor;
84 void main()
85 {
86 uint u;
87 vec2 v = unpackUnorm2x16(u);
88 fragColor = vec4(v, 0.0, 0.0);
89 })";
90 compile(shaderString);
91 ASSERT_TRUE(foundInCode("vec2 unpackUnorm2x16_emu(uint u)"));
92 }
93
94 // Check if PackHalf2x16 Emulation for GLSL < 4.2 compiles correctly.
TEST_F(PackUnpackTest,PackHalf2x16Emulation)95 TEST_F(PackUnpackTest, PackHalf2x16Emulation)
96 {
97 const std::string &shaderString =
98 R"(#version 300 es
99 precision mediump float;
100 layout(location = 0) out mediump vec4 fragColor;
101 void main()
102 {
103 vec2 v;
104 uint u = packHalf2x16(v);
105 fragColor = vec4(u);
106 })";
107 compile(shaderString);
108 ASSERT_TRUE(foundInCode("uint packHalf2x16_emu(vec2 v)"));
109 }
110
111 // Check if UnpackHalf2x16 Emulation for GLSL < 4.2 compiles correctly.
TEST_F(PackUnpackTest,UnpackHalf2x16Emulation)112 TEST_F(PackUnpackTest, UnpackHalf2x16Emulation)
113 {
114 const std::string &shaderString =
115 R"(#version 300 es
116 precision mediump float;
117 layout(location = 0) out mediump vec4 fragColor;
118 void main()
119 {
120 uint u;
121 vec2 v = unpackHalf2x16(u);
122 fragColor = vec4(v, 0.0, 0.0);
123 })";
124 compile(shaderString);
125 ASSERT_TRUE(foundInCode("vec2 unpackHalf2x16_emu(uint u)"));
126 }
127
128 } // namespace
129