Hash :
ba319ba3
Author :
Date :
2018-12-29T10:29:33
Re-land "Load entry points dynamically in tests and samples." Fixes the Android/ChromeOS/Fuchsia builds by using consistent EGL headers. This CL adds a dynamic loader generator based on XML files. It also refactors the entry point generation script to move the XML parsing into a helper class. Additionally this includes a new GLES 1.0 base header. The new header allows for function pointer types and hiding prototypes. All tests and samples now load ANGLE dynamically. In the future this will be extended to load entry points from the driver directly when possible. This will allow us to perform more accurate A/B testing. The new build configuration leads to some tests having more warnings applied. The CL includes fixes for the new warnings. Bug: angleproject:2995 Change-Id: I5a8772f41a0f89570b3736b785f44b7de1539b57 Reviewed-on: https://chromium-review.googlesource.com/c/1392382 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 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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
//
// 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.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
class InstancingTest : public ANGLETest
{
protected:
InstancingTest()
{
setWindowWidth(256);
setWindowHeight(256);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
void TearDown() override
{
glDeleteBuffers(1, &mInstanceBuffer);
glDeleteProgram(mProgram0);
glDeleteProgram(mProgram1);
}
void SetUp() override
{
ANGLETest::SetUp();
for (int i = 0; i < kMaxDrawn; ++i)
{
mInstanceData[i] = i * kDrawSize;
}
glGenBuffers(1, &mInstanceBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mInstanceBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(mInstanceData), mInstanceData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
const std::string inst = "attribute float a_instance;";
const std::string pos = "attribute vec2 a_position;";
const std::string main = R"(
void main()
{
gl_PointSize = 6.0;
gl_Position = vec4(a_position.x, a_position.y + a_instance, 0, 1);
}
)";
// attrib 0 is instanced
const std::string inst0 = inst + pos + main;
mProgram0 = CompileProgram(inst0.c_str(), essl1_shaders::fs::Red());
ASSERT_NE(0u, mProgram0);
ASSERT_EQ(0, glGetAttribLocation(mProgram0, "a_instance"));
ASSERT_EQ(1, glGetAttribLocation(mProgram0, "a_position"));
// attrib 1 is instanced
const std::string inst1 = pos + inst + main;
mProgram1 = CompileProgram(inst1.c_str(), essl1_shaders::fs::Red());
ASSERT_NE(0u, mProgram1);
ASSERT_EQ(1, glGetAttribLocation(mProgram1, "a_instance"));
ASSERT_EQ(0, glGetAttribLocation(mProgram1, "a_position"));
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
void runTest(
unsigned numInstance,
unsigned divisor,
bool attribZeroInstanced, // true: attrib 0 is instance, false: attrib 1 is instanced
bool points, // true: draw points, false: draw quad
bool indexed, // true: DrawElements, false: DrawArrays
bool offset, // true: pass nonzero offset to DrawArrays, false: zero offset
bool buffer) // true: use instance data in buffer, false: in client memory
{
// The window is divided into kMaxDrawn slices of size kDrawSize.
// The slice drawn into is determined by the instance datum.
// The instance data array selects all the slices in order.
// 'lastDrawn' is the index (zero-based) of the last slice into which we draw.
const unsigned lastDrawn = (numInstance - 1) / divisor;
const int instanceAttrib = attribZeroInstanced ? 0 : 1;
const int positionAttrib = attribZeroInstanced ? 1 : 0;
glUseProgram(attribZeroInstanced ? mProgram0 : mProgram1);
glBindBuffer(GL_ARRAY_BUFFER, buffer ? mInstanceBuffer : 0);
glVertexAttribPointer(instanceAttrib, 1, GL_FLOAT, GL_FALSE, 0,
buffer ? nullptr : mInstanceData);
glEnableVertexAttribArray(instanceAttrib);
glVertexAttribDivisorANGLE(instanceAttrib, divisor);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(positionAttrib, 2, GL_FLOAT, GL_FALSE, 0,
points ? kPointVertices : kQuadVertices);
glEnableVertexAttribArray(positionAttrib);
glVertexAttribDivisorANGLE(positionAttrib, 0);
glClear(GL_COLOR_BUFFER_BIT);
if (points)
{
if (indexed)
glDrawElementsInstancedANGLE(GL_POINTS, ArraySize(kPointIndices), GL_UNSIGNED_SHORT,
kPointIndices, numInstance);
else
glDrawArraysInstancedANGLE(GL_POINTS, offset ? 2 : 0, 4, numInstance);
}
else
{
if (indexed)
glDrawElementsInstancedANGLE(GL_TRIANGLES, ArraySize(kQuadIndices),
GL_UNSIGNED_SHORT, kQuadIndices, numInstance);
else
glDrawArraysInstancedANGLE(GL_TRIANGLES, offset ? 4 : 0, 6, numInstance);
}
ASSERT_GL_NO_ERROR();
checkDrawing(lastDrawn);
}
void checkDrawing(unsigned lastDrawn)
{
for (unsigned i = 0; i < kMaxDrawn; ++i)
{
float y =
-1.0f + static_cast<float>(kDrawSize) / 2.0f + static_cast<float>(i * kDrawSize);
int iy = static_cast<int>((y + 1.0f) / 2.0f * getWindowHeight());
for (unsigned j = 0; j < 8; j += 2)
{
int ix = static_cast<int>((kPointVertices[j] + 1.0f) / 2.0f * getWindowWidth());
EXPECT_PIXEL_COLOR_EQ(ix, iy, i <= lastDrawn ? GLColor::red : GLColor::blue);
}
}
}
GLuint mProgram0;
GLuint mProgram1;
GLuint mInstanceBuffer;
static constexpr int kMaxDrawn = 4;
static constexpr float kDrawSize = 2.0 / kMaxDrawn;
GLfloat mInstanceData[kMaxDrawn];
// clang-format off
// Vertices 0-5 are two triangles that form a quad filling the first "slice" of the window.
// See above about slices. Vertices 4-9 are the same two triangles.
static constexpr GLfloat kQuadVertices[] = {
-1, -1,
1, -1,
-1, -1 + kDrawSize,
1, -1,
1, -1 + kDrawSize,
-1, -1 + kDrawSize,
1, -1,
1, -1,
-1, -1 + kDrawSize,
-1, -1,
};
// Points 0-3 are spread across the first "slice."
// Points 2-4 are the same.
static constexpr GLfloat kPointVertices[] = {
-0.6f, -1 + kDrawSize / 2.0,
-0.2f, -1 + kDrawSize / 2.0,
0.2f, -1 + kDrawSize / 2.0,
0.6f, -1 + kDrawSize / 2.0,
-0.2f, -1 + kDrawSize / 2.0,
-0.6f, -1 + kDrawSize / 2.0,
};
// clang-format on
// Same two triangles as described above.
static constexpr GLushort kQuadIndices[] = {2, 9, 7, 5, 6, 4};
// Same four points as described above.
static constexpr GLushort kPointIndices[] = {1, 5, 3, 2};
};
constexpr GLfloat InstancingTest::kQuadVertices[];
constexpr GLfloat InstancingTest::kPointVertices[];
constexpr GLushort InstancingTest::kQuadIndices[];
constexpr GLushort InstancingTest::kPointIndices[];
class InstancingTestAllConfigs : public InstancingTest
{
protected:
InstancingTestAllConfigs() {}
};
class InstancingTestNo9_3 : public InstancingTest
{
protected:
InstancingTestNo9_3() {}
};
class InstancingTestPoints : public InstancingTest
{
protected:
InstancingTestPoints() {}
};
// This test uses a vertex shader with the first attribute (attribute zero) instanced.
// On D3D9 and D3D11 FL9_3, this triggers a special codepath that rearranges the input layout sent
// to D3D, to ensure that slot/stream zero of the input layout doesn't contain per-instance data.
TEST_P(InstancingTestAllConfigs, AttributeZeroInstanced)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
runTest(4, 1, true /* attrib 0 instanced */, false /* quads */, true /* DrawElements */,
false /* N/A */, false /* no buffer */);
}
// Same as AttributeZeroInstanced, but attribute zero is not instanced.
// This ensures the general instancing codepath (i.e. without rearranging the input layout) works as
// expected.
TEST_P(InstancingTestAllConfigs, AttributeZeroNotInstanced)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
runTest(4, 1, false /* attrib 1 instanced */, false /* quads */, true /* DrawElements */,
false /* N/A */, false /* no buffer */);
}
// Tests that the "first" parameter to glDrawArraysInstancedANGLE is only an offset into
// the non-instanced vertex attributes.
TEST_P(InstancingTestNo9_3, DrawArraysWithOffset)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
runTest(4, 1, false /* attribute 1 instanced */, false /* quads */, false /* DrawArrays */,
true /* offset>0 */, true /* buffer */);
}
// This test verifies instancing with GL_POINTS with glDrawArraysInstanced works.
// On D3D11 FL9_3, this triggers a special codepath that emulates instanced points rendering.
TEST_P(InstancingTestPoints, DrawArrays)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
// Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
// On Win7, the D3D SDK Layers emits a false warning for these tests.
// This doesn't occur on Windows 10 (Version 1511) though.
ignoreD3D11SDKLayersWarnings();
runTest(4, 1, false /* attrib 1 instanced */, true /* points */, false /* DrawArrays */,
false /* offset=0 */, true /* buffer */);
}
// This test verifies instancing with GL_POINTS with glDrawElementsInstanced works.
// On D3D11 FL9_3, this triggers a special codepath that emulates instanced points rendering.
TEST_P(InstancingTestPoints, DrawElements)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
// Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
// On Win7, the D3D SDK Layers emits a false warning for these tests.
// This doesn't occur on Windows 10 (Version 1511) though.
ignoreD3D11SDKLayersWarnings();
runTest(4, 1, false /* attrib 1 instanced */, true /* points */, true /* DrawElements */,
false /* N/A */, true /* buffer */);
}
class InstancingTestES3 : public InstancingTest
{
public:
InstancingTestES3() {}
};
class InstancingTestES31 : public InstancingTest
{
public:
InstancingTestES31() {}
};
// Verify that VertexAttribDivisor can update both binding divisor and attribBinding.
TEST_P(InstancingTestES31, UpdateAttribBindingByVertexAttribDivisor)
{
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_instanced_arrays"));
glUseProgram(mProgram0);
// Get the attribute locations
GLint positionLoc = glGetAttribLocation(mProgram0, "a_position");
GLint instancePosLoc = glGetAttribLocation(mProgram0, "a_instance");
ASSERT_NE(-1, positionLoc);
ASSERT_NE(-1, instancePosLoc);
ASSERT_GL_NO_ERROR();
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLBuffer quadBuffer;
glBindBuffer(GL_ARRAY_BUFFER, quadBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
const unsigned numInstance = 4;
const unsigned divisor = 1;
const unsigned lastDrawn = (numInstance - 1) / divisor;
// Set the formats by VertexAttribFormat
glVertexAttribFormat(positionLoc, 2, GL_FLOAT, GL_FALSE, 0);
glVertexAttribFormat(instancePosLoc, 1, GL_FLOAT, GL_FALSE, 0);
glEnableVertexAttribArray(positionLoc);
glEnableVertexAttribArray(instancePosLoc);
const GLint positionBinding = instancePosLoc;
const GLint instanceBinding = positionLoc;
// Load the vertex position into the binding indexed positionBinding (== instancePosLoc)
// Load the instance position into the binding indexed instanceBinding (== positionLoc)
glBindVertexBuffer(positionBinding, quadBuffer, 0, 2 * sizeof(kQuadVertices[0]));
glBindVertexBuffer(instanceBinding, mInstanceBuffer, 0, sizeof(mInstanceData[0]));
// The attribute indexed positionLoc is using the binding indexed positionBinding
// The attribute indexed instancePosLoc is using the binding indexed instanceBinding
glVertexAttribBinding(positionLoc, positionBinding);
glVertexAttribBinding(instancePosLoc, instanceBinding);
// Enable instancing on the binding indexed instanceBinding
glVertexBindingDivisor(instanceBinding, divisor);
// Do the first instanced draw
glClear(GL_COLOR_BUFFER_BIT);
glDrawElementsInstanced(GL_TRIANGLES, ArraySize(kQuadIndices), GL_UNSIGNED_SHORT, kQuadIndices,
numInstance);
checkDrawing(lastDrawn);
// Disable instancing.
glVertexBindingDivisor(instanceBinding, 0);
// Load the vertex position into the binding indexed positionLoc.
// Load the instance position into the binding indexed instancePosLoc.
glBindVertexBuffer(positionLoc, quadBuffer, 0, 2 * sizeof(kQuadVertices[0]));
glBindVertexBuffer(instancePosLoc, mInstanceBuffer, 0, sizeof(mInstanceData[0]));
// The attribute indexed positionLoc is using the binding indexed positionLoc.
glVertexAttribBinding(positionLoc, positionLoc);
// Call VertexAttribDivisor to both enable instancing on instancePosLoc and set the attribute
// indexed instancePosLoc using the binding indexed instancePosLoc.
glVertexAttribDivisor(instancePosLoc, divisor);
// Do the second instanced draw
glClear(GL_COLOR_BUFFER_BIT);
glDrawElementsInstanced(GL_TRIANGLES, ArraySize(kQuadIndices), GL_UNSIGNED_SHORT, kQuadIndices,
numInstance);
checkDrawing(lastDrawn);
glDeleteVertexArrays(1, &vao);
}
// Verify that a large divisor that also changes doesn't cause issues and renders correctly.
TEST_P(InstancingTestES3, LargeDivisor)
{
constexpr char kVS[] = R"(#version 300 es
layout(location = 0) in vec4 a_position;
layout(location = 1) in vec4 a_color;
out vec4 v_color;
void main()
{
gl_Position = a_position;
gl_PointSize = 4.0f;
v_color = a_color;
})";
constexpr char kFS[] = R"(#version 300 es
precision highp float;
in vec4 v_color;
out vec4 my_FragColor;
void main()
{
my_FragColor = v_color;
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
GLBuffer buf;
glBindBuffer(GL_ARRAY_BUFFER, buf);
std::vector<GLfloat> vertices;
for (size_t i = 0u; i < 4u; ++i)
{
vertices.push_back(0.0f + i * 0.25f);
vertices.push_back(0.0f);
vertices.push_back(0.0f);
vertices.push_back(1.0f);
}
glBufferData(GL_ARRAY_BUFFER, vertices.size() * 4u, vertices.data(), GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr);
ASSERT_GL_NO_ERROR();
GLBuffer colorBuf;
glBindBuffer(GL_ARRAY_BUFFER, colorBuf);
std::array<GLColor, 4> ubyteColors = {GLColor::red, GLColor::green};
std::vector<float> floatColors;
for (const GLColor &color : ubyteColors)
{
floatColors.push_back(color.R / 255.0f);
floatColors.push_back(color.G / 255.0f);
floatColors.push_back(color.B / 255.0f);
floatColors.push_back(color.A / 255.0f);
}
glBufferData(GL_ARRAY_BUFFER, floatColors.size() * 4u, floatColors.data(), GL_DYNAMIC_DRAW);
const GLuint kColorDivisor = 65536u * 2u;
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, nullptr);
glVertexAttribDivisor(1, kColorDivisor);
std::array<GLuint, 1u> indices = {0u};
std::array<GLuint, 3u> divisorsToTry = {256u, 65536u, 65536u * 2u};
for (GLuint divisorToTry : divisorsToTry)
{
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribDivisor(0, divisorToTry);
GLuint instanceCount = divisorToTry + 1u;
unsigned int pointsRendered = (instanceCount - 1u) / divisorToTry + 1u;
glDrawElementsInstanced(GL_POINTS, indices.size(), GL_UNSIGNED_INT, indices.data(),
instanceCount);
ASSERT_GL_NO_ERROR();
// Check that the intended number of points has been rendered.
for (unsigned int pointIndex = 0u; pointIndex < pointsRendered + 1u; ++pointIndex)
{
GLint pointx = static_cast<GLint>((pointIndex * 0.125f + 0.5f) * getWindowWidth());
GLint pointy = static_cast<GLint>(0.5f * getWindowHeight());
if (pointIndex < pointsRendered)
{
GLuint pointColorIndex = (pointIndex * divisorToTry) / kColorDivisor;
EXPECT_PIXEL_COLOR_EQ(pointx, pointy, ubyteColors[pointColorIndex]);
}
else
{
// Clear color.
EXPECT_PIXEL_COLOR_EQ(pointx, pointy, GLColor::blue);
}
}
}
}
// This is a regression test. If VertexAttribDivisor was returned as a signed integer, it would be
// incorrectly clamped down to the maximum signed integer.
TEST_P(InstancingTestES3, LargestDivisor)
{
constexpr GLuint kLargeDivisor = std::numeric_limits<GLuint>::max();
glVertexAttribDivisor(0, kLargeDivisor);
GLuint divisor = 0;
glGetVertexAttribIuiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
EXPECT_EQ(kLargeDivisor, divisor)
<< "Vertex attrib divisor read was not the same that was passed in.";
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against. We test on D3D9 and D3D11 9_3 because they use special codepaths
// when attribute zero is instanced, unlike D3D11.
ANGLE_INSTANTIATE_TEST(InstancingTestAllConfigs,
ES2_D3D9(),
ES2_D3D11(),
ES2_D3D11_FL9_3(),
ES2_OPENGL(),
ES2_OPENGLES(),
ES2_VULKAN());
// TODO(jmadill): Figure out the situation with DrawInstanced on FL 9_3
ANGLE_INSTANTIATE_TEST(InstancingTestNo9_3, ES2_D3D9(), ES2_D3D11());
ANGLE_INSTANTIATE_TEST(InstancingTestPoints, ES2_D3D11(), ES2_D3D11_FL9_3());
ANGLE_INSTANTIATE_TEST(InstancingTestES3, ES3_OPENGL(), ES3_OPENGLES(), ES3_D3D11());
ANGLE_INSTANTIATE_TEST(InstancingTestES31, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11());