Hash :
9c391154
Author :
Date :
2024-06-06T18:24:18
Vulkan: Do not apply advanced blend emulation when blend is disabled The emulateAdvancedBlendEquations code path does not check if GL_BLEND is disabled. This CL adds the check so that the blend is not applied when we disable the GL_BLEND. This CL also adds an updateAdvancedBlendEquations() when DIRTY_BIT_BLEND_ENABLED bit is set. This ensures DIRTY_BIT_DRIVER_UNIFORMS bit is set when GL_BLEND state changes, meaning we will regenerate the uniforms if GL_BLEND state changes: GL_BLEND is enabled: pass the advanced blend equations to the uniforms; GL_BLEND is disabled: do not pass the advanced blend equations to the unforms Bug: b/345581214 Change-Id: I5708a4051647bc29b5b38a027e836f5bf717d1d5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5605109 Auto-Submit: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> Commit-Queue: Yuxin Hu <yuxinhu@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 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
#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);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AdvancedBlendTest);
ANGLE_INSTANTIATE_TEST_ES32(AdvancedBlendTest);