Hash :
9c17232a
Author :
Date :
2022-09-02T16:05:48
Vulkan: Make robustness affect all of share group Since contexts in a share group can share their program, if any context in the share group is robust, programs in all contexts in the share group need to be created with robustness in mind. This fixes the situation when the programs are created after a robust context has been created. However, if programs are created first, then a robust context is added to a share group, there remains a bug where the old programs aren't recreated to have robust behavior. Bug: angleproject:7629 Change-Id: I4922091962a32ca75a6107343df0cd87e5e9592d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3872506 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> 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 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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
//
// Copyright 2016 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.
//
// EGLRobustnessTest.cpp: tests for EGL_EXT_create_context_robustness
//
// Tests causing GPU resets are disabled, use the following args to run them:
// --gtest_also_run_disabled_tests --gtest_filter=EGLRobustnessTest\*
#include <gtest/gtest.h>
#include "common/debug.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/OSWindow.h"
using namespace angle;
class EGLRobustnessTest : public ANGLETest<>
{
public:
void testSetUp() override
{
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLRobustnessTest", 500, 500);
setWindowVisible(mOSWindow, true);
const auto &platform = GetParam().eglParameters;
std::vector<EGLint> displayAttributes;
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
displayAttributes.push_back(platform.renderer);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
displayAttributes.push_back(platform.majorVersion);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
displayAttributes.push_back(platform.minorVersion);
if (platform.deviceType != EGL_DONT_CARE)
{
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
displayAttributes.push_back(platform.deviceType);
}
displayAttributes.push_back(EGL_NONE);
mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
&displayAttributes[0]);
ASSERT_NE(EGL_NO_DISPLAY, mDisplay);
ASSERT_TRUE(eglInitialize(mDisplay, nullptr, nullptr) == EGL_TRUE);
const char *extensions = eglQueryString(mDisplay, EGL_EXTENSIONS);
if (strstr(extensions, "EGL_EXT_create_context_robustness") == nullptr)
{
std::cout << "Test skipped due to missing EGL_EXT_create_context_robustness"
<< std::endl;
return;
}
int nConfigs = 0;
ASSERT_TRUE(eglGetConfigs(mDisplay, nullptr, 0, &nConfigs) == EGL_TRUE);
ASSERT_LE(1, nConfigs);
std::vector<EGLConfig> allConfigs(nConfigs);
int nReturnedConfigs = 0;
ASSERT_TRUE(eglGetConfigs(mDisplay, allConfigs.data(), nConfigs, &nReturnedConfigs) ==
EGL_TRUE);
ASSERT_EQ(nConfigs, nReturnedConfigs);
for (const EGLConfig &config : allConfigs)
{
EGLint surfaceType;
eglGetConfigAttrib(mDisplay, config, EGL_SURFACE_TYPE, &surfaceType);
if ((surfaceType & EGL_WINDOW_BIT) != 0)
{
mConfig = config;
mInitialized = true;
break;
}
}
if (mInitialized)
{
mWindow =
eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(), nullptr);
ASSERT_EGL_SUCCESS();
}
}
void testTearDown() override
{
eglDestroySurface(mDisplay, mWindow);
eglDestroyContext(mDisplay, mContext);
eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(mDisplay);
EXPECT_EGL_SUCCESS();
OSWindow::Delete(&mOSWindow);
}
void createContext(EGLint resetStrategy)
{
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
resetStrategy, EGL_NONE};
mContext = eglCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, contextAttribs);
ASSERT_NE(EGL_NO_CONTEXT, mContext);
eglMakeCurrent(mDisplay, mWindow, mWindow, mContext);
ASSERT_EGL_SUCCESS();
const char *extensionString = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
ASSERT_NE(nullptr, strstr(extensionString, "GL_ANGLE_instanced_arrays"));
}
void createRobustContext(EGLint resetStrategy, EGLContext shareContext)
{
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION,
3,
EGL_CONTEXT_MINOR_VERSION_KHR,
0,
EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT,
EGL_TRUE,
EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
resetStrategy,
EGL_NONE};
mContext = eglCreateContext(mDisplay, mConfig, shareContext, contextAttribs);
ASSERT_NE(EGL_NO_CONTEXT, mContext);
eglMakeCurrent(mDisplay, mWindow, mWindow, mContext);
ASSERT_EGL_SUCCESS();
}
void forceContextReset()
{
// Cause a GPU reset by drawing 100,000,000 fullscreen quads
GLuint program = CompileProgram(
"attribute vec4 pos;\n"
"void main() {gl_Position = pos;}\n",
"precision mediump float;\n"
"void main() {gl_FragColor = vec4(1.0);}\n");
ASSERT_NE(0u, program);
glUseProgram(program);
GLfloat vertices[] = {
-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
};
const int kNumQuads = 10000;
std::vector<GLushort> indices(6 * kNumQuads);
for (size_t i = 0; i < kNumQuads; i++)
{
indices[i * 6 + 0] = 0;
indices[i * 6 + 1] = 1;
indices[i * 6 + 2] = 2;
indices[i * 6 + 3] = 1;
indices[i * 6 + 4] = 2;
indices[i * 6 + 5] = 3;
}
glBindAttribLocation(program, 0, "pos");
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glViewport(0, 0, mOSWindow->getWidth(), mOSWindow->getHeight());
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawElementsInstancedANGLE(GL_TRIANGLES, kNumQuads * 6, GL_UNSIGNED_SHORT, indices.data(),
10000);
glFinish();
}
const char *getInvalidShaderLocalVariableAccessFS()
{
static constexpr char kFS[] = R"(#version 300 es
layout(location = 0) out highp vec4 fragColor;
uniform highp int u_index;
uniform mediump float u_color;
void main (void)
{
highp vec4 color = vec4(0.0f);
color[u_index] = u_color;
fragColor = color;
})";
return kFS;
}
void testInvalidShaderLocalVariableAccess(GLuint program)
{
glUseProgram(program);
EXPECT_GL_NO_ERROR();
GLint indexLocation = glGetUniformLocation(program, "u_index");
ASSERT_NE(-1, indexLocation);
GLint colorLocation = glGetUniformLocation(program, "u_color");
ASSERT_NE(-1, colorLocation);
// delibrately pass in -1 to u_index to test robustness extension protects write out of
// bound
constexpr GLint kInvalidIndex = -1;
glUniform1i(indexLocation, kInvalidIndex);
EXPECT_GL_NO_ERROR();
glUniform1f(colorLocation, 1.0f);
drawQuad(program, essl31_shaders::PositionAttrib(), 0);
EXPECT_GL_NO_ERROR();
// When command buffers are submitted to GPU, if robustness is working properly, the
// fragment shader will not suffer from write out-of-bounds issue, which resulted in context
// reset and context loss.
glFinish();
EXPECT_GL_NO_ERROR();
}
protected:
EGLDisplay mDisplay = EGL_NO_DISPLAY;
EGLSurface mWindow = EGL_NO_SURFACE;
EGLContext mContext = EGL_NO_CONTEXT;
bool mInitialized = false;
private:
EGLConfig mConfig = 0;
OSWindow *mOSWindow = nullptr;
};
class EGLRobustnessTestES3 : public EGLRobustnessTest
{};
// Check glGetGraphicsResetStatusEXT returns GL_NO_ERROR if we did nothing
TEST_P(EGLRobustnessTest, NoErrorByDefault)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ASSERT_TRUE(glGetGraphicsResetStatusEXT() == GL_NO_ERROR);
}
// Checks that the application gets no loss with NO_RESET_NOTIFICATION
TEST_P(EGLRobustnessTest, DISABLED_NoResetNotification)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
createContext(EGL_NO_RESET_NOTIFICATION_EXT);
if (!IsWindows())
{
std::cout << "Test disabled on non Windows platforms because drivers can't recover. "
<< "See " << __FILE__ << ":" << __LINE__ << std::endl;
return;
}
std::cout << "Causing a GPU reset, brace for impact." << std::endl;
forceContextReset();
ASSERT_TRUE(glGetGraphicsResetStatusEXT() == GL_NO_ERROR);
}
// Checks that resetting the ANGLE display allows to get rid of the context loss.
// Also checks that the application gets notified of the loss of the display.
// We coalesce both tests to reduce the number of TDRs done on Windows: by default
// having more than 5 TDRs in a minute will cause Windows to disable the GPU until
// the computer is rebooted.
TEST_P(EGLRobustnessTest, DISABLED_ResettingDisplayWorks)
{
// Note that on Windows the OpenGL driver fails hard (popup that closes the application)
// on a TDR caused by D3D. Don't run D3D tests at the same time as the OpenGL tests.
ANGLE_SKIP_TEST_IF(IsWindows() && isGLRenderer());
ANGLE_SKIP_TEST_IF(!mInitialized);
createContext(EGL_LOSE_CONTEXT_ON_RESET_EXT);
if (!IsWindows())
{
std::cout << "Test disabled on non Windows platforms because drivers can't recover. "
<< "See " << __FILE__ << ":" << __LINE__ << std::endl;
return;
}
std::cout << "Causing a GPU reset, brace for impact." << std::endl;
forceContextReset();
ASSERT_TRUE(glGetGraphicsResetStatusEXT() != GL_NO_ERROR);
recreateTestFixture();
ASSERT_TRUE(glGetGraphicsResetStatusEXT() == GL_NO_ERROR);
}
// Test to reproduce the crash when running
// dEQP-EGL.functional.robustness.reset_context.shaders.out_of_bounds.reset_status.writes.uniform_block.fragment
// on Pixel 6
TEST_P(EGLRobustnessTestES3, ContextResetOnInvalidLocalShaderVariableAccess)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createRobustContext(EGL_LOSE_CONTEXT_ON_RESET, EGL_NO_CONTEXT);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
testInvalidShaderLocalVariableAccess(program);
}
// Similar to ContextResetOnInvalidLocalShaderVariableAccess, but the program is created on a
// context that's not robust, but used on one that is.
TEST_P(EGLRobustnessTestES3,
ContextResetOnInvalidLocalShaderVariableAccess_ShareGroupBeforeProgramCreation)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createContext(EGL_LOSE_CONTEXT_ON_RESET);
EGLContext shareContext = mContext;
createRobustContext(EGL_LOSE_CONTEXT_ON_RESET, shareContext);
eglMakeCurrent(mDisplay, mWindow, mWindow, shareContext);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
eglMakeCurrent(mDisplay, mWindow, mWindow, mContext);
testInvalidShaderLocalVariableAccess(program);
eglDestroyContext(mDisplay, shareContext);
}
// Similar to ContextResetOnInvalidLocalShaderVariableAccess, but the program is created on a
// context that's not robust, but used on one that is.
TEST_P(EGLRobustnessTestES3,
ContextResetOnInvalidLocalShaderVariableAccess_ShareGroupAfterProgramCreation)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createContext(EGL_LOSE_CONTEXT_ON_RESET);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
EGLContext shareContext = mContext;
createRobustContext(EGL_LOSE_CONTEXT_ON_RESET, shareContext);
testInvalidShaderLocalVariableAccess(program);
eglDestroyContext(mDisplay, shareContext);
}
// Test to ensure shader local variable write out of bound won't crash
// when the context has robustness enabled, and EGL_NO_RESET_NOTIFICATION_EXT
// is set as the value for attribute EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEFY_EXT
TEST_P(EGLRobustnessTestES3, ContextNoResetOnInvalidLocalShaderVariableAccess)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createRobustContext(EGL_NO_RESET_NOTIFICATION_EXT, EGL_NO_CONTEXT);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
testInvalidShaderLocalVariableAccess(program);
}
// Similar to ContextNoResetOnInvalidLocalShaderVariableAccess, but the program is created on a
// context that's not robust, but used on one that is.
TEST_P(EGLRobustnessTestES3,
ContextNoResetOnInvalidLocalShaderVariableAccess_ShareGroupBeforeProgramCreation)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createContext(EGL_NO_RESET_NOTIFICATION_EXT);
EGLContext shareContext = mContext;
createRobustContext(EGL_NO_RESET_NOTIFICATION_EXT, shareContext);
eglMakeCurrent(mDisplay, mWindow, mWindow, shareContext);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
eglMakeCurrent(mDisplay, mWindow, mWindow, mContext);
testInvalidShaderLocalVariableAccess(program);
eglDestroyContext(mDisplay, shareContext);
}
// Similar to ContextNoResetOnInvalidLocalShaderVariableAccess, but the program is created on a
// context that's not robust, but used on one that is.
TEST_P(EGLRobustnessTestES3,
ContextNoResetOnInvalidLocalShaderVariableAccess_ShareGroupAfterProgramCreation)
{
ANGLE_SKIP_TEST_IF(!mInitialized);
ANGLE_SKIP_TEST_IF(
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_KHR_create_context") ||
!IsEGLDisplayExtensionEnabled(mDisplay, "EGL_EXT_create_context_robustness"));
createContext(EGL_NO_RESET_NOTIFICATION_EXT);
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), getInvalidShaderLocalVariableAccessFS());
EGLContext shareContext = mContext;
createRobustContext(EGL_NO_RESET_NOTIFICATION_EXT, shareContext);
testInvalidShaderLocalVariableAccess(program);
eglDestroyContext(mDisplay, shareContext);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLRobustnessTest);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLRobustnessTestES3);
ANGLE_INSTANTIATE_TEST(EGLRobustnessTest,
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES2_D3D9()),
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES2_OPENGLES()));
ANGLE_INSTANTIATE_TEST(EGLRobustnessTestES3,
WithNoFixture(ES3_VULKAN()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_OPENGL()),
WithNoFixture(ES3_OPENGLES()));