Path: blob/main_old/src/tests/compiler_tests/Pack_Unpack_test.cpp
1693 views
//1// Copyright 2015 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// Pack_Unpack_test.cpp:6// Tests for the emulating pack_unpack functions for GLSL.7//89#include "GLSLANG/ShaderLang.h"10#include "angle_gl.h"11#include "gtest/gtest.h"12#include "tests/test_utils/compiler_test.h"1314using namespace sh;1516namespace17{1819class PackUnpackTest : public MatchOutputCodeTest20{21public:22PackUnpackTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_GLSL_400_CORE_OUTPUT) {}23};2425// Check if PackSnorm2x16 Emulation for GLSL < 4.2 compile correctly.26TEST_F(PackUnpackTest, PackSnorm2x16Emulation)27{28const std::string &shaderString =29R"(#version 300 es30precision mediump float;31layout(location = 0) out mediump vec4 fragColor;32void main()33{34vec2 v;35uint u = packSnorm2x16(v);36fragColor = vec4(u);37})";38compile(shaderString);39ASSERT_TRUE(foundInCode("uint packSnorm2x16_emu(vec2 v)"));40}4142// Check if UnpackSnorm2x16 Emulation for GLSL < 4.2 compile correctly.43TEST_F(PackUnpackTest, UnpackSnorm2x16Emulation)44{45const std::string &shaderString =46R"(#version 300 es47precision mediump float;48layout(location = 0) out mediump vec4 fragColor;49void main()50{51uint u;52vec2 v = unpackSnorm2x16(u);53fragColor = vec4(v, 0.0, 0.0);54})";55compile(shaderString);56ASSERT_TRUE(foundInCode("vec2 unpackSnorm2x16_emu(uint u)"));57}5859// Check if PackUnorm2x16 Emulation for GLSL < 4.1 compiles correctly.60TEST_F(PackUnpackTest, PackUnorm2x16Emulation)61{62const std::string &shaderString =63R"(#version 300 es64precision mediump float;65layout(location = 0) out mediump vec4 fragColor;66void main()67{68vec2 v;69uint u = packUnorm2x16(v);70fragColor = vec4(u);71})";72compile(shaderString);73ASSERT_TRUE(foundInCode("uint packUnorm2x16_emu(vec2 v)"));74}7576// Check if UnpackSnorm2x16 Emulation for GLSL < 4.1 compiles correctly.77TEST_F(PackUnpackTest, UnpackUnorm2x16Emulation)78{79const std::string &shaderString =80R"(#version 300 es81precision mediump float;82layout(location = 0) out mediump vec4 fragColor;83void main()84{85uint u;86vec2 v = unpackUnorm2x16(u);87fragColor = vec4(v, 0.0, 0.0);88})";89compile(shaderString);90ASSERT_TRUE(foundInCode("vec2 unpackUnorm2x16_emu(uint u)"));91}9293// Check if PackHalf2x16 Emulation for GLSL < 4.2 compiles correctly.94TEST_F(PackUnpackTest, PackHalf2x16Emulation)95{96const std::string &shaderString =97R"(#version 300 es98precision mediump float;99layout(location = 0) out mediump vec4 fragColor;100void main()101{102vec2 v;103uint u = packHalf2x16(v);104fragColor = vec4(u);105})";106compile(shaderString);107ASSERT_TRUE(foundInCode("uint packHalf2x16_emu(vec2 v)"));108}109110// Check if UnpackHalf2x16 Emulation for GLSL < 4.2 compiles correctly.111TEST_F(PackUnpackTest, UnpackHalf2x16Emulation)112{113const std::string &shaderString =114R"(#version 300 es115precision mediump float;116layout(location = 0) out mediump vec4 fragColor;117void main()118{119uint u;120vec2 v = unpackHalf2x16(u);121fragColor = vec4(v, 0.0, 0.0);122})";123compile(shaderString);124ASSERT_TRUE(foundInCode("vec2 unpackHalf2x16_emu(uint u)"));125}126127} // namespace128129130