Hash :
341a36cc
Author :
Date :
2017-05-24T09:53:25
Fix zero size buffer robust init crash. We were not correctly checking for a zero-size buffer, which should not trigger allocating a scratch buffer. BUG=angleproject:1635 Change-Id: Iac0a3d8f1eeeb7b39c59eec411bec78a4f21bcd3 Reviewed-on: https://chromium-review.googlesource.com/513478 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@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
//
// Copyright 2017 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.
//
// RobustResourceInitTest: Tests for GL_ANGLE_robust_resource_initialization.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
namespace angle
{
class RobustResourceInitTest : public ANGLETest
{
protected:
RobustResourceInitTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
// Defer context init until the test body.
setDeferContextInit(true);
setRobustResourceInit(true);
}
bool hasEGLExtension()
{
EGLDisplay display = getEGLWindow()->getDisplay();
ASSERT(display != EGL_NO_DISPLAY);
return (eglDisplayExtensionEnabled(
display, "EGL_ANGLE_create_context_robust_resource_initialization"));
}
bool setup()
{
if (!hasEGLExtension())
{
return false;
}
if (!getEGLWindow()->initializeContext())
{
EXPECT_TRUE(false);
return false;
}
return true;
}
};
// Context creation should fail if EGL_ANGLE_create_context_robust_resource_initialization
// is not available, and succeed otherwise.
TEST_P(RobustResourceInitTest, ExtensionInit)
{
if (hasEGLExtension())
{
// Context creation shold succeed with robust resource init enabled.
EXPECT_TRUE(getEGLWindow()->initializeContext());
// Robust resource init extension should be available.
EXPECT_TRUE(extensionEnabled("GL_ANGLE_robust_resource_initialization"));
// Querying the state value should return true.
GLboolean enabled = 0;
glGetBooleanv(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE, &enabled);
EXPECT_GL_NO_ERROR();
EXPECT_GL_TRUE(enabled);
EXPECT_GL_TRUE(glIsEnabled(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE));
}
else
{
// Context creation should fail with robust resource init enabled.
EXPECT_FALSE(getEGLWindow()->initializeContext());
// Context creation should succeed with robust resource init disabled.
setRobustResourceInit(false);
ASSERT_TRUE(getEGLWindow()->initializeGL(GetOSWindow()));
// If context extension string exposed, check queries.
if (extensionEnabled("GL_ANGLE_robust_resource_initialization"))
{
GLboolean enabled = 0;
glGetBooleanv(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE, &enabled);
EXPECT_GL_FALSE(enabled);
EXPECT_GL_FALSE(glIsEnabled(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE));
EXPECT_GL_NO_ERROR();
}
else
{
// Querying robust resource init should return INVALID_ENUM.
GLboolean enabled = 0;
glGetBooleanv(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE, &enabled);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
}
}
// Test queries on a normal, non-robust enabled context.
TEST_P(RobustResourceInitTest, QueriesOnNonRobustContext)
{
EGLDisplay display = getEGLWindow()->getDisplay();
ASSERT_TRUE(display != EGL_NO_DISPLAY);
if (!hasEGLExtension())
{
return;
}
setRobustResourceInit(false);
EXPECT_TRUE(getEGLWindow()->initializeContext());
// If context extension string exposed, check queries.
ASSERT_TRUE(extensionEnabled("GL_ANGLE_robust_resource_initialization"));
// Querying robust resource init should return INVALID_ENUM.
GLboolean enabled = 0;
glGetBooleanv(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE, &enabled);
EXPECT_GL_FALSE(enabled);
EXPECT_GL_FALSE(glIsEnabled(GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE));
EXPECT_GL_NO_ERROR();
}
// Tests that buffers start zero-filled if the data pointer is null.
TEST_P(RobustResourceInitTest, BufferData)
{
if (!setup())
{
return;
}
GLBuffer buffer;
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, getWindowWidth() * getWindowHeight() * sizeof(GLfloat), nullptr,
GL_STATIC_DRAW);
const std::string &vertexShader =
"attribute vec2 position;\n"
"attribute float testValue;\n"
"varying vec4 colorOut;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" colorOut = testValue == 0.0 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
"}";
const std::string &fragmentShader =
"varying mediump vec4 colorOut;\n"
"void main() {\n"
" gl_FragColor = colorOut;\n"
"}";
ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
GLint testValueLoc = glGetAttribLocation(program.get(), "testValue");
ASSERT_NE(-1, testValueLoc);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glVertexAttribPointer(testValueLoc, 1, GL_FLOAT, GL_FALSE, 4, nullptr);
glEnableVertexAttribArray(testValueLoc);
glBindBuffer(GL_ARRAY_BUFFER, 0);
drawQuad(program.get(), "position", 0.5f);
ASSERT_GL_NO_ERROR();
std::vector<GLColor> expected(getWindowWidth() * getWindowHeight(), GLColor::green);
std::vector<GLColor> actual(getWindowWidth() * getWindowHeight());
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
actual.data());
EXPECT_EQ(expected, actual);
}
// Regression test for passing a zero size init buffer with the extension.
TEST_P(RobustResourceInitTest, BufferDataZeroSize)
{
if (!setup())
{
return;
}
GLBuffer buffer;
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_STATIC_DRAW);
}
ANGLE_INSTANTIATE_TEST(RobustResourceInitTest,
ES2_D3D9(),
ES2_D3D11(),
ES3_D3D11(),
ES2_D3D11_FL9_3(),
ES2_OPENGL(),
ES3_OPENGL(),
ES2_OPENGLES(),
ES3_OPENGLES());
} // namespace