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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
//
// 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.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
class BlendIntegerTest : public ANGLETest<>
{
protected:
BlendIntegerTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
template <typename T, GLuint components>
void compareValue(const T *value, const char *name, GLenum attachment)
{
T pixel[4];
glReadBuffer(attachment);
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER,
std::is_same<T, int32_t>::value ? GL_INT : GL_UNSIGNED_INT, pixel);
for (size_t componentIdx = 0; componentIdx < components; componentIdx++)
{
EXPECT_EQ(value[componentIdx], pixel[componentIdx])
<< " componentIdx=" << componentIdx << std::endl
<< " " << name << "[0]=" << value[0] << " pixel[0]=" << pixel[0] << std::endl
<< " " << name << "[1]=" << value[1] << " pixel[1]=" << pixel[1] << std::endl
<< " " << name << "[2]=" << value[2] << " pixel[2]=" << pixel[2] << std::endl
<< " " << name << "[3]=" << value[3] << " pixel[3]=" << pixel[3];
}
}
template <GLenum internalformat, GLuint components, bool isSigned>
void runTest()
{
constexpr char kFsui[] =
"#version 300 es\n"
"out highp uvec4 o_drawBuffer0;\n"
"void main(void)\n"
"{\n"
" o_drawBuffer0 = uvec4(1, 1, 1, 1);\n"
"}\n";
constexpr char kFssi[] =
"#version 300 es\n"
"out highp ivec4 o_drawBuffer0;\n"
"void main(void)\n"
"{\n"
" o_drawBuffer0 = ivec4(-1, -1, -1, -1);\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), isSigned ? kFssi : kFsui);
glUseProgram(program);
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLRenderbuffer colorRenderbuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, internalformat, getWindowWidth(), getWindowHeight());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
colorRenderbuffer);
if (isSigned)
{
const int32_t clearValueSigned[4] = {-128, -128, -128, -128};
glClearBufferiv(GL_COLOR, 0, clearValueSigned);
ASSERT_GL_NO_ERROR();
compareValue<int32_t, components>(clearValueSigned, "clearValueSigned",
GL_COLOR_ATTACHMENT0);
}
else
{
const uint32_t clearValueUnsigned[4] = {127, 127, 127, 3};
glClearBufferuiv(GL_COLOR, 0, clearValueUnsigned);
ASSERT_GL_NO_ERROR();
compareValue<uint32_t, components>(clearValueUnsigned, "clearValueUnsigned",
GL_COLOR_ATTACHMENT0);
}
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
// Enabled blending must be ignored for integer color attachment.
if (isSigned)
{
const int32_t colorValueSigned[4] = {-1, -1, -1, -1};
compareValue<int32_t, components>(colorValueSigned, "colorValueSigned",
GL_COLOR_ATTACHMENT0);
}
else
{
const uint32_t colorValueUnsigned[4] = {1, 1, 1, 1};
compareValue<uint32_t, components>(colorValueUnsigned, "colorValueUnsigned",
GL_COLOR_ATTACHMENT0);
}
}
template <bool isSigned>
void runTestMRT()
{
constexpr char kFragmentSigned[] = R"(#version 300 es
layout(location = 1) out highp vec4 o_drawBuffer1;
layout(location = 2) out highp ivec4 o_drawBuffer2;
layout(location = 3) out highp vec4 o_drawBuffer3;
void main(void)
{
o_drawBuffer1 = vec4(0, 0, 0, 0);
o_drawBuffer2 = ivec4(0, 0, 0, 0);
o_drawBuffer3 = vec4(0, 0, 0, 0);
})";
constexpr char kFragmentUnsigned[] = R"(#version 300 es
layout(location = 1) out highp vec4 o_drawBuffer1;
layout(location = 2) out highp uvec4 o_drawBuffer2;
layout(location = 3) out highp vec4 o_drawBuffer3;
void main(void)
{
o_drawBuffer1 = vec4(0, 0, 0, 0);
o_drawBuffer2 = uvec4(0, 0, 0, 0);
o_drawBuffer3 = vec4(0, 0, 0, 0);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(),
isSigned ? kFragmentSigned : kFragmentUnsigned);
glUseProgram(program);
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLRenderbuffer colorRenderbuffer1;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer1);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER,
colorRenderbuffer1);
GLRenderbuffer colorRenderbuffer2;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer2);
glRenderbufferStorage(GL_RENDERBUFFER, isSigned ? GL_RGBA32I : GL_RGBA32UI,
getWindowWidth(), getWindowHeight());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER,
colorRenderbuffer2);
GLRenderbuffer colorRenderbuffer3;
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer3);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, getWindowWidth(), getWindowHeight());
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER,
colorRenderbuffer3);
GLenum drawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2,
GL_COLOR_ATTACHMENT3};
glDrawBuffers(4, drawBuffers);
if (isSigned)
{
const int32_t clearValue[4] = {-1, 2, -3, 4};
glClearBufferiv(GL_COLOR, 2, clearValue);
ASSERT_GL_NO_ERROR();
compareValue<int32_t, 4>(clearValue, "clearValue", GL_COLOR_ATTACHMENT2);
}
else
{
const uint32_t clearValue[4] = {1, 2, 3, 4};
glClearBufferuiv(GL_COLOR, 2, clearValue);
ASSERT_GL_NO_ERROR();
compareValue<uint32_t, 4>(clearValue, "clearValue", GL_COLOR_ATTACHMENT2);
}
glBlendEquation(GL_MAX);
glEnable(GL_BLEND);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
if (isSigned)
{
const int32_t drawValue[4] = {0, 0, 0, 0};
compareValue<int32_t, 4>(drawValue, "drawValue", GL_COLOR_ATTACHMENT2);
}
else
{
const uint32_t drawValue[4] = {0, 0, 0, 0};
compareValue<uint32_t, 4>(drawValue, "drawValue", GL_COLOR_ATTACHMENT2);
}
}
};
// Test that blending is not applied to signed integer attachments.
TEST_P(BlendIntegerTest, R8I)
{
runTest<GL_R8I, 1, true>();
}
TEST_P(BlendIntegerTest, R16I)
{
runTest<GL_R16I, 1, true>();
}
TEST_P(BlendIntegerTest, R32I)
{
runTest<GL_R32I, 1, true>();
}
TEST_P(BlendIntegerTest, RG8I)
{
runTest<GL_RG8I, 2, true>();
}
TEST_P(BlendIntegerTest, RG16I)
{
runTest<GL_RG16I, 2, true>();
}
TEST_P(BlendIntegerTest, RG32I)
{
runTest<GL_RG32I, 2, true>();
}
TEST_P(BlendIntegerTest, RGBA8I)
{
runTest<GL_RGBA8I, 4, true>();
}
TEST_P(BlendIntegerTest, RGBA16I)
{
runTest<GL_RGBA16I, 4, true>();
}
TEST_P(BlendIntegerTest, RGBA32I)
{
runTest<GL_RGBA32I, 4, true>();
}
// Test that blending is not applied to unsigned integer attachments.
TEST_P(BlendIntegerTest, R8UI)
{
runTest<GL_R8UI, 1, false>();
}
TEST_P(BlendIntegerTest, R16UI)
{
runTest<GL_R16UI, 1, false>();
}
TEST_P(BlendIntegerTest, R32UI)
{
runTest<GL_R32UI, 1, false>();
}
TEST_P(BlendIntegerTest, RG8UI)
{
runTest<GL_RG8UI, 2, false>();
}
TEST_P(BlendIntegerTest, RG16UI)
{
runTest<GL_RG16UI, 2, false>();
}
TEST_P(BlendIntegerTest, RG32UI)
{
runTest<GL_RG32UI, 2, false>();
}
TEST_P(BlendIntegerTest, RGBA8UI)
{
runTest<GL_RGBA8UI, 4, false>();
}
TEST_P(BlendIntegerTest, RGBA16UI)
{
runTest<GL_RGBA16UI, 4, false>();
}
TEST_P(BlendIntegerTest, RGBA32UI)
{
runTest<GL_RGBA32UI, 4, false>();
}
TEST_P(BlendIntegerTest, RGB10_A2UI)
{
runTest<GL_RGB10_A2UI, 4, false>();
}
// Test that blending does not cancel draws on signed integer attachments.
TEST_P(BlendIntegerTest, MRTSigned)
{
// http://anglebug.com/42263640
ANGLE_SKIP_TEST_IF(IsVulkan() && IsWindows() && IsIntel());
// http://anglebug.com/42263688
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsMac() && IsIntel());
// http://anglebug.com/42263689
ANGLE_SKIP_TEST_IF(IsVulkan() && IsAdreno());
runTestMRT<true>();
}
// Test that blending does not cancel draws on unsigned integer attachments.
TEST_P(BlendIntegerTest, MRTUnsigned)
{
// http://anglebug.com/42263640
ANGLE_SKIP_TEST_IF(IsVulkan() && IsWindows() && IsIntel());
// http://anglebug.com/42263688
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsMac() && IsIntel());
// http://anglebug.com/42263689
ANGLE_SKIP_TEST_IF(IsVulkan() && IsAdreno());
runTestMRT<false>();
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BlendIntegerTest);
ANGLE_INSTANTIATE_TEST_ES3(BlendIntegerTest);