Hash :
d193d51b
Author :
Date :
2024-06-17T22:46:08
Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
//
// Copyright 2020 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 "common/mathutil.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
constexpr int kPixelColorThreshhold = 8;
class ShaderInterpTest : public ANGLETest<>
{
protected:
ShaderInterpTest() : ANGLETest()
{
setWindowWidth(128);
setWindowHeight(128);
}
void draw(GLuint program, float skew)
{
glUseProgram(program);
std::array<Vector4, 3> vertices;
vertices[0] = {-1.0, -1.0, 0.0, 1.0};
vertices[1] = {1.0, -1.0, 0.0, 1.0};
vertices[2] = {0.0, 1.0 * skew, 0.0, skew};
std::array<Vector4, 3> colors;
colors[0] = {1.0, 0.0, 0.0, 1.0};
colors[1] = {0.0, 1.0, 0.0, 1.0};
colors[2] = {0.0, 0.0, 1.0, 1.0};
GLint positionLocation = glGetAttribLocation(program, "position");
GLint colorLocation = glGetAttribLocation(program, "vertex_color");
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, vertices.data());
glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, colors.data());
glEnableVertexAttribArray(positionLocation);
glEnableVertexAttribArray(colorLocation);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
};
// Test that regular "smooth" interpolation works correctly
TEST_P(ShaderInterpTest, Smooth)
{
const char *vertSrc = R"(#version 300 es
precision highp float;
in vec4 position;
in vec4 vertex_color;
smooth out vec4 interp_color;
void main()
{
gl_Position = position;
interp_color = vertex_color;
}
)";
const char *fragSrc = R"(#version 300 es
precision highp float;
smooth in vec4 interp_color;
out vec4 fragColor;
void main()
{
fragColor = interp_color;
}
)";
// iOS chokes on the "smooth" qualifier.
// TODO(anglebug.com/42264029): Add shader compiler workaround that omits "smooth".
ANGLE_SKIP_TEST_IF(IsIOS() && IsOpenGLES());
ANGLE_GL_PROGRAM(program, vertSrc, fragSrc);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
draw(program, 1.0);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(62, 64, 128, 255), kPixelColorThreshhold);
glClear(GL_COLOR_BUFFER_BIT);
draw(program, 2.0);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(83, 86, 86, 255), kPixelColorThreshhold);
}
// Test that uninterpolated "Flat" interpolation works correctly
TEST_P(ShaderInterpTest, Flat)
{
// TODO: anglebug.com/42262721
// No vendors currently support VK_EXT_provoking_vertex, which is necessary for conformant flat
// shading. SwiftShader does technically support this extension, but as it has not yet been
// ratified by Khronos, the vulkan validation layers do not recognize the create info struct,
// causing it to be stripped and thus causing the extension to behave as if it is disabled.
ANGLE_SKIP_TEST_IF(IsVulkan());
const char *vertSrc = R"(#version 300 es
precision highp float;
in vec4 position;
in vec4 vertex_color;
flat out vec4 interp_color;
void main()
{
gl_Position = position;
interp_color = vertex_color;
}
)";
const char *fragSrc = R"(#version 300 es
precision highp float;
flat in vec4 interp_color;
out vec4 fragColor;
void main()
{
fragColor = interp_color;
}
)";
ANGLE_GL_PROGRAM(program, vertSrc, fragSrc);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
draw(program, 1.0);
GLColor smooth_reference;
glReadPixels(64, 64, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &smooth_reference);
EXPECT_PIXEL_COLOR_EQ(64, 64, GLColor(0, 0, 255, 255));
}
// Test that "noperspective" interpolation correctly interpolates in screenspace
TEST_P(ShaderInterpTest, NoPerspective)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_NV_shader_noperspective_interpolation"));
const char *vertSrcSmooth = R"(#version 300 es
precision highp float;
in vec4 position;
in vec4 vertex_color;
smooth out vec4 interp_color;
void main()
{
gl_Position = position;
interp_color = vertex_color;
}
)";
const char *fragSrcSmooth = R"(#version 300 es
precision highp float;
smooth in vec4 interp_color;
out vec4 fragColor;
void main()
{
fragColor = interp_color;
}
)";
ANGLE_GL_PROGRAM(programSmooth, vertSrcSmooth, fragSrcSmooth);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
draw(programSmooth, 1.0);
GLColor smooth_reference;
glReadPixels(64, 64, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &smooth_reference);
const char *vertSrcNoPerspective = R"(#version 300 es
#extension GL_NV_shader_noperspective_interpolation : require
#ifndef GL_NV_shader_noperspective_interpolation
#error GL_NV_shader_noperspective_interpolation is not defined
#endif
precision highp float;
in vec4 position;
in vec4 vertex_color;
noperspective out vec4 interp_color;
void main()
{
gl_Position = position;
interp_color = vertex_color;
}
)";
const char *fragSrcNoPerspective = R"(#version 300 es
#extension GL_NV_shader_noperspective_interpolation : require
#ifndef GL_NV_shader_noperspective_interpolation
#error GL_NV_shader_noperspective_interpolation is not defined
#endif
precision highp float;
noperspective in vec4 interp_color;
out vec4 fragColor;
void main()
{
fragColor = interp_color;
}
)";
ANGLE_GL_PROGRAM(programNoPerspective, vertSrcNoPerspective, fragSrcNoPerspective);
glClear(GL_COLOR_BUFFER_BIT);
draw(programNoPerspective, 1.0);
EXPECT_PIXEL_COLOR_EQ(64, 64, smooth_reference);
glClear(GL_COLOR_BUFFER_BIT);
draw(programNoPerspective, 2.0);
EXPECT_PIXEL_COLOR_EQ(64, 64, smooth_reference);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShaderInterpTest);
ANGLE_INSTANTIATE_TEST_ES3(ShaderInterpTest);