Hash :
1db5581d
        
        Author :
  
        
        Date :
2024-05-21T13:07:44
        
      
Implement KHR_robustness
* Added implementation for the validation layers for the
  added functions, and updated some of the existing ones.
  * The core functions require GLES 3.2.
  * The KHR functions have been limited to GLES 2.0+.
    * KHR_robustness requires GLES 2.0 and removes support
      for GLES 1.1 for logistical reasons.
  * Some functions require GLES 3.0 with this extension, which become
    core in GLES 3.2.
    * glGetnUniformuivKHR()
* Enabled robustnessKHR on several platforms.
* Added unit tests similar to ContextLostTest.BasicUsage for the new
  cases.
  * Added ContextLostTestES32 for the core usage in GLES 3.2.
Bug: angleproject:42262244
Change-Id: Id1425c39d9a1a66ae1a90048b673cb1ae391c0ef
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5555985
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
Reviewed-by: Cody Northrop <cnorthrop@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
//
// Copyright 2015 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.
//
// BindGeneratesResourceTest.cpp : Tests of the GL_CHROMIUM_bind_generates_resource extension.
#include "test_utils/ANGLETest.h"
namespace angle
{
class ContextLostTest : public ANGLETest<>
{
  protected:
    ContextLostTest() {}
    void testSetUp() override
    {
        if (IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"))
        {
            setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT);
        }
        else
        {
            setContextResetStrategy(EGL_NO_RESET_NOTIFICATION_EXT);
        }
    }
};
// GL_CHROMIUM_lose_context is implemented in the frontend
TEST_P(ContextLostTest, ExtensionStringExposed)
{
    EXPECT_TRUE(EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
}
// Use GL_CHROMIUM_lose_context to lose a context and verify using GL_EXT_robustness
TEST_P(ContextLostTest, BasicUsageEXT)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_robustness") ||
                       !IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"));
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    EXPECT_GL_NO_ERROR();
    EXPECT_GLENUM_EQ(glGetGraphicsResetStatusEXT(), GL_GUILTY_CONTEXT_RESET);
    // Errors should be continually generated
    for (size_t i = 0; i < 10; i++)
    {
        glBindTexture(GL_TEXTURE_2D, 0);
        EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    }
}
// Use GL_CHROMIUM_lose_context to lose a context and verify using GL_KHR_robustness
TEST_P(ContextLostTest, BasicUsageKHR)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_KHR_robustness") ||
                       !IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"));
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    EXPECT_GL_NO_ERROR();
    EXPECT_GLENUM_EQ(glGetGraphicsResetStatusKHR(), GL_GUILTY_CONTEXT_RESET);
    // Errors should be continually generated
    for (size_t i = 0; i < 10; i++)
    {
        glBindTexture(GL_TEXTURE_2D, 0);
        EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    }
}
// When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always
// return GL_SIGNALED
TEST_P(ContextLostTest, PollingQuery)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
    GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
    EXPECT_GL_NO_ERROR();
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    EXPECT_GL_NO_ERROR();
    GLint syncStatus = 0;
    glGetSynciv(sync, GL_SYNC_STATUS, 1, nullptr, &syncStatus);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(syncStatus, GL_SIGNALED);
    // Check that the query fails and the result is unmodified for other queries
    GLint syncCondition = 0xBADF00D;
    glGetSynciv(sync, GL_SYNC_CONDITION, 1, nullptr, &syncCondition);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(syncCondition, 0xBADF00D);
}
// When context is lost, polling queries such as glGetSynciv with GL_SYNC_STATUS should always
// return GL_SIGNALED
TEST_P(ContextLostTest, ParallelCompileReadyQuery)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_KHR_parallel_shader_compile"));
    GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple());
    GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl1_shaders::fs::UniformColor());
    GLuint program = glCreateProgram();
    glAttachShader(program, vs);
    glAttachShader(program, fs);
    glLinkProgram(program);
    EXPECT_GL_NO_ERROR();
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    EXPECT_GL_NO_ERROR();
    GLint shaderCompletionStatus = 0;
    glGetShaderiv(vs, GL_COMPLETION_STATUS_KHR, &shaderCompletionStatus);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(shaderCompletionStatus, GL_TRUE);
    GLint programCompletionStatus = 0;
    glGetProgramiv(program, GL_COMPLETION_STATUS_KHR, &programCompletionStatus);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(programCompletionStatus, GL_TRUE);
    // Check that the query fails and the result is unmodified for other queries
    GLint shaderType = 0xBADF00D;
    glGetShaderiv(vs, GL_SHADER_TYPE, &shaderType);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(shaderType, 0xBADF00D);
    GLint linkStatus = 0xBADF00D;
    glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
    EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    EXPECT_GLENUM_EQ(linkStatus, 0xBADF00D);
}
class ContextLostTestES32 : public ContextLostTest
{};
// Use GL_CHROMIUM_lose_context to lose a context and verify using GLES 3.2 function
TEST_P(ContextLostTestES32, BasicUsage)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"));
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    EXPECT_GL_NO_ERROR();
    EXPECT_GLENUM_EQ(glGetGraphicsResetStatus(), GL_GUILTY_CONTEXT_RESET);
    // Errors should be continually generated
    for (size_t i = 0; i < 10; i++)
    {
        glBindTexture(GL_TEXTURE_2D, 0);
        EXPECT_GL_ERROR(GL_CONTEXT_LOST);
    }
}
class ContextLostSkipValidationTest : public ANGLETest<>
{
  protected:
    ContextLostSkipValidationTest() {}
    void testSetUp() override
    {
        if (IsEGLClientExtensionEnabled("EGL_EXT_create_context_robustness"))
        {
            setContextResetStrategy(EGL_LOSE_CONTEXT_ON_RESET_EXT);
            setNoErrorEnabled(true);
        }
        else
        {
            setContextResetStrategy(EGL_NO_RESET_NOTIFICATION_EXT);
        }
    }
};
// Use GL_CHROMIUM_lose_context to lose a context and verify
TEST_P(ContextLostSkipValidationTest, LostNoErrorGetProgram)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_CHROMIUM_lose_context"));
    GLuint program = glCreateProgram();
    glLoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET, GL_INNOCENT_CONTEXT_RESET);
    GLint val = 0;
    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &val);  // Should not crash.
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST(ContextLostTest,
                       WithRobustness(ES2_NULL()),
                       WithRobustness(ES2_D3D9()),
                       WithRobustness(ES2_D3D11()),
                       WithRobustness(ES3_D3D11()),
                       WithRobustness(ES2_VULKAN()),
                       WithRobustness(ES3_VULKAN()));
ANGLE_INSTANTIATE_TEST(ContextLostSkipValidationTest,
                       WithRobustness(ES2_NULL()),
                       WithRobustness(ES2_D3D9()),
                       WithRobustness(ES2_D3D11()),
                       WithRobustness(ES3_D3D11()),
                       WithRobustness(ES2_VULKAN()),
                       WithRobustness(ES3_VULKAN()));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ContextLostTestES32);
ANGLE_INSTANTIATE_TEST(ContextLostTestES32, WithRobustness(ES32_VULKAN()));
}  // namespace angle