Hash :
0d5c0bd1
Author :
Date :
2024-04-25T10:26:08
ANGLE end2end test to check const expressions are handled correctly Bug: b/337046547 Change-Id: I1bd368f8c95a9676aba13fe91313d0eaba32db03 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5490170 Commit-Queue: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Tests for shader interpolation qualifiers
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
constexpr int kPixelColorThreshhold = 8;
class ShaderOpTest : public ANGLETest<>
{
protected:
ShaderOpTest() : ANGLETest()
{
setWindowWidth(256);
setWindowHeight(256);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
setConfigStencilBits(8);
setMultisampleEnabled(0);
}
};
// Simplified test from dEQP-GLES2.functional.fragment_ops.interaction.basic_shader.22
// Test that vulkan drivers correctly handle the constant expression spirv generated by ANGLE
TEST_P(ShaderOpTest, ConstantExpression)
{
const char *vertSrc = R"(
attribute vec4 pos;
void main()
{
gl_Position = pos;
}
)";
// ANGLE and glslang translate below expression in fragment shader differently
// vec4 c = vec4(1.0, 0.5, 0.5, 0.75)
// ANGLE:
// %constVec4 = OpConstantComposite %vec4 %const1 %const2 %const2 %const3
// %var = OpVariable %PrivateVec4Pointer Private %constVec4
// %loadedVal = OpLoad %vec4 %var
// OpStore %gl_fragColor %loadedVal
// glslang:
// %constVec4 = OpConstantComposite %vec4 %const1 %const2 %const2 %const3
// %var = OpVariable %PrivateVec4Pointer Private
// OpStore %var %constVec4
// %loadedVal = OpLoad %vec4 %var
// OpStore %gl_fragColor %loadedVal
// Both are valid spirv instructions.
// Tests should pass with spirv generated by ANGLE.
// Note: setting forceDeferNonConstGlobalInitializers to true will make ANGLE generate the same
// spirv instruction for the constant expression as glslang.
const char *fragSrc = R"(
precision mediump float;
vec4 c = vec4(1.0, 0.5, 0.5, 0.75);
void main()
{
gl_FragColor = c;
}
)";
ANGLE_GL_PROGRAM(program, vertSrc, fragSrc);
glUseProgram(program);
std::array<GLfloat, 16> attribPosData = {1, 1, 0.5, 1, -1, 1, 0.5, 1,
1, -1, 0.5, 1, -1, -1, 0.5, 1};
GLint attribPosLoc = glGetAttribLocation(1, "pos");
ASSERT(attribPosLoc >= 0);
glEnableVertexAttribArray(attribPosLoc);
glVertexAttribPointer(attribPosLoc, 4, GL_FLOAT, GL_FALSE, 0, attribPosData.data());
const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(255, 125, 125, 190), kPixelColorThreshhold);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShaderOpTest);
ANGLE_INSTANTIATE_TEST_ES2(ShaderOpTest);