Hash :
a1dea207
Author :
Date :
2024-06-13T11:40:39
Implement KHR_blend_equation_advanced_coherent * Updated the validation for glBlendBarrier() and ~KHR(). * GL state now includes mBlendAdvancedCoherent. * Updated glEnable() to accept GL_BLEND_ADVANCED_COHERENT_KHR. * It can be queried via glGetIntegerv(), etc. * EXTENDED_DIRTY_BIT_BLEND_ADVANCED_COHERENT added. * Added a corresponding bit to ExternalContextState. * If coherence is supported, there should be no need to use blend barriers, as, based on the spec, the advanced blend ops should then follow order like the basic blend ops. * Relevant tests: *GLES31.functional.blend_equation_advanced.coherent* * On Linux/NVIDIA: From "Not supported" to "Passed" Bug: angleproject:42262258 Change-Id: I7e0e43bdc71524eec111c2d3b024fe73c9795e55 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5634381 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Geoff Lang <geofflang@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
//
// 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.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
constexpr int kPixelColorThreshhold = 8;
class AdvancedBlendTest : public ANGLETest<>
{
protected:
AdvancedBlendTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Test that when blending is disabled, advanced blend is not applied.
// Regression test for a bug in the emulation path in the Vulkan backend.
TEST_P(AdvancedBlendTest, AdvancedBlendNotAppliedWhenBlendIsDisabled)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_blend_equation_advanced"));
const char *vertSrc = R"(#version 320 es
in highp vec4 a_position;
in mediump vec4 a_color;
out mediump vec4 v_color;
void main()
{
gl_Position = a_position;
v_color = a_color;
}
)";
const char *fragSrc = R"(#version 320 es
in mediump vec4 v_color;
layout(blend_support_colorburn) out;
layout(location = 0) out mediump vec4 o_color;
void main()
{
o_color = v_color;
}
)";
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, "a_position");
ASSERT(attribPosLoc >= 0);
glEnableVertexAttribArray(attribPosLoc);
glVertexAttribPointer(attribPosLoc, 4, GL_FLOAT, GL_FALSE, 0, attribPosData.data());
std::array<GLfloat, 16> attribColorData1 = {1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1,
1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1};
GLint attribColorLoc = glGetAttribLocation(1, "a_color");
ASSERT(attribColorLoc >= 0);
glEnableVertexAttribArray(attribColorLoc);
glVertexAttribPointer(attribColorLoc, 4, GL_FLOAT, GL_FALSE, 0, attribColorData1.data());
glBlendEquation(GL_COLORBURN);
const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Disable the blend. The next glDrawElements() should not blend the a_color with clear color
glDisable(GL_BLEND);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(255, 51, 128, 255), kPixelColorThreshhold);
}
// Test that when blending is disabled, advanced blend is not applied, but is applied after
// it is enabled.
// Regression test for a bug in the emulation path in the Vulkan backend.
TEST_P(AdvancedBlendTest, AdvancedBlendDisabledAndThenEnabled)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_blend_equation_advanced"));
const char *vertSrc = R"(#version 320 es
in highp vec4 a_position;
in mediump vec4 a_color;
out mediump vec4 v_color;
void main()
{
gl_Position = a_position;
v_color = a_color;
}
)";
const char *fragSrc = R"(#version 320 es
in mediump vec4 v_color;
layout(blend_support_colorburn) out;
layout(location = 0) out mediump vec4 o_color;
void main()
{
o_color = v_color;
}
)";
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, "a_position");
ASSERT(attribPosLoc >= 0);
glEnableVertexAttribArray(attribPosLoc);
glVertexAttribPointer(attribPosLoc, 4, GL_FLOAT, GL_FALSE, 0, attribPosData.data());
std::array<GLfloat, 16> attribColorData1 = {1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1,
1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1};
GLint attribColorLoc = glGetAttribLocation(1, "a_color");
ASSERT(attribColorLoc >= 0);
glEnableVertexAttribArray(attribColorLoc);
glVertexAttribPointer(attribColorLoc, 4, GL_FLOAT, GL_FALSE, 0, attribColorData1.data());
glBlendEquation(GL_COLORBURN);
const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Disable the blend. The next glDrawElements() should not blend the a_color with clear color
glDisable(GL_BLEND);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
// Enable the blend. The next glDrawElements() should blend a_color
// with the the existing framebuffer output with GL_COLORBURN blend mode
glEnable(GL_BLEND);
// Test the blend with coherent blend disabled. This make the test cover both devices that
// support / do not support GL_KHR_blend_equation_advanced_coherent
if (IsGLExtensionEnabled("GL_KHR_blend_equation_advanced_coherent"))
{
glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
}
glBlendBarrier();
std::array<GLfloat, 16> attribColorData2 = {0.5, 0.5, 0, 1, 0.5, 0.5, 0, 1,
0.5, 0.5, 0, 1, 0.5, 0.5, 0, 1};
glEnableVertexAttribArray(attribColorLoc);
glVertexAttribPointer(attribColorLoc, 4, GL_FLOAT, GL_FALSE, 0, attribColorData2.data());
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(255, 0, 0, 255), kPixelColorThreshhold);
}
// Test that when blending is enabled, advanced blend is applied, but is not applied after
// it is disabled.
// Regression test for a bug in the emulation path in the Vulkan backend.
TEST_P(AdvancedBlendTest, AdvancedBlendEnabledAndThenDisabled)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_blend_equation_advanced"));
const char *vertSrc = R"(#version 320 es
in highp vec4 a_position;
in mediump vec4 a_color;
out mediump vec4 v_color;
void main()
{
gl_Position = a_position;
v_color = a_color;
}
)";
const char *fragSrc = R"(#version 320 es
in mediump vec4 v_color;
layout(blend_support_colorburn) out;
layout(location = 0) out mediump vec4 o_color;
void main()
{
o_color = v_color;
}
)";
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, "a_position");
ASSERT(attribPosLoc >= 0);
glEnableVertexAttribArray(attribPosLoc);
glVertexAttribPointer(attribPosLoc, 4, GL_FLOAT, GL_FALSE, 0, attribPosData.data());
std::array<GLfloat, 16> attribColorData1 = {1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1,
1, 0.2, 0.5, 1, 1, 0.2, 0.5, 1};
GLint attribColorLoc = glGetAttribLocation(1, "a_color");
ASSERT(attribColorLoc >= 0);
glEnableVertexAttribArray(attribColorLoc);
glVertexAttribPointer(attribColorLoc, 4, GL_FLOAT, GL_FALSE, 0, attribColorData1.data());
glBlendEquation(GL_COLORBURN);
const uint16_t indices[] = {0, 1, 2, 2, 1, 3};
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// Enable the blend. The next glDrawElements() should blend the a_color with clear color
// using the GL_COLORBURN blend mode
glEnable(GL_BLEND);
// Test the blend with coherent blend disabled. This make the test cover both devices that
// support / do not support GL_KHR_blend_equation_advanced_coherent
if (IsGLExtensionEnabled("GL_KHR_blend_equation_advanced_coherent"))
{
glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
}
glBlendBarrier();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
// Disable the blend. The next glDrawElements() should not blend the a_color with
// the existing framebuffer output with GL_COLORBURN blend mode
glDisable(GL_BLEND);
std::array<GLfloat, 16> attribColorData2 = {0.5, 0.5, 0, 1, 0.5, 0.5, 0, 1,
0.5, 0.5, 0, 1, 0.5, 0.5, 0, 1};
glEnableVertexAttribArray(attribColorLoc);
glVertexAttribPointer(attribColorLoc, 4, GL_FLOAT, GL_FALSE, 0, attribColorData2.data());
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0]);
EXPECT_PIXEL_COLOR_NEAR(64, 64, GLColor(128, 128, 0, 255), kPixelColorThreshhold);
}
// Test querying advanced blend equation coherent on supported devices (enabled by default).
TEST_P(AdvancedBlendTest, AdvancedBlendCoherentQuery)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_KHR_blend_equation_advanced_coherent"));
GLint status = -1;
glGetIntegerv(GL_BLEND_ADVANCED_COHERENT_KHR, &status);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(status, 1);
glDisable(GL_BLEND_ADVANCED_COHERENT_KHR);
glGetIntegerv(GL_BLEND_ADVANCED_COHERENT_KHR, &status);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(status, 0);
glEnable(GL_BLEND_ADVANCED_COHERENT_KHR);
glGetIntegerv(GL_BLEND_ADVANCED_COHERENT_KHR, &status);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(status, 1);
}
// Test that querying advanced blend equation coherent results in an error as if this enum does not
// exist.
TEST_P(AdvancedBlendTest, AdvancedBlendCoherentQueryFailsIfNotSupported)
{
ANGLE_SKIP_TEST_IF(IsGLExtensionEnabled("GL_KHR_blend_equation_advanced_coherent"));
GLint status = -1;
glGetIntegerv(GL_BLEND_ADVANCED_COHERENT_KHR, &status);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AdvancedBlendTest);
ANGLE_INSTANTIATE_TEST_ES32(AdvancedBlendTest);