Hash :
9fc3682c
Author :
Date :
2015-11-18T13:08:07
D3D: Rework varying packing code. In D3D we pack varyings by making a register map, and using the recommended GLSL ES algorithm to reserve register space. We use this map to assign row and column slots to each varying and then produce a semantic index value. The existing scheme had a number of bugs, and was failing several angle_end2end_tests. The new design cleans up the code somewhat and uses a different counting scheme for the semantic indexes: just sort the varyings in packing order and use a simple incrementing semantic index per varying. In SM4+, the HLSL compiler sorts and packs the varyings correctly itself, and in SM3, handle the cases we don't support by returning an error instead of a D3D compiler link error. Also refactor how we store varying information for TF Feedback/ StreamOut. Only store the necessary D3D information, instead of extra information like the name and type. This fixes several tests in GLSLTest/*. This also will allow us to fix interpolation qualifier packing and the structure packing in HLSL, which seems to work differently than the rest of the varying types. BUG=angleproject:1202 TEST=bots,dEQP-GLES3.functional.transform_feedback.* Change-Id: Ie5bfbb4f71d8bf97f39115fc46d2e61b131df639 Reviewed-on: https://chromium-review.googlesource.com/311241 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
//
// 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 "Vector.h"
using namespace angle;
namespace
{
class TransformFeedbackTest : public ANGLETest
{
protected:
TransformFeedbackTest()
: mProgram(0),
mTransformFeedbackBufferSize(0),
mTransformFeedbackBuffer(0),
mTransformFeedback(0)
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
void SetUp() override
{
ANGLETest::SetUp();
glGenBuffers(1, &mTransformFeedbackBuffer);
mTransformFeedbackBufferSize = 1 << 24; // ~16MB
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBufferSize, NULL,
GL_STATIC_DRAW);
glGenTransformFeedbacks(1, &mTransformFeedback);
ASSERT_GL_NO_ERROR();
}
void TearDown() override
{
if (mProgram != 0)
{
glDeleteProgram(mProgram);
mProgram = 0;
}
if (mTransformFeedbackBuffer != 0)
{
glDeleteBuffers(1, &mTransformFeedbackBuffer);
mTransformFeedbackBuffer = 0;
}
if (mTransformFeedback != 0)
{
glDeleteTransformFeedbacks(1, &mTransformFeedback);
mTransformFeedback = 0;
}
ANGLETest::TearDown();
}
void compileDefaultProgram(const std::vector<std::string> &tfVaryings, GLenum bufferMode)
{
ASSERT_EQ(0u, mProgram);
const std::string vertexShaderSource = SHADER_SOURCE
(
precision highp float;
attribute vec4 position;
void main()
{
gl_Position = position;
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
(
precision highp float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
);
mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource,
tfVaryings, bufferMode);
ASSERT_NE(0u, mProgram);
}
GLuint mProgram;
size_t mTransformFeedbackBufferSize;
GLuint mTransformFeedbackBuffer;
GLuint mTransformFeedback;
};
TEST_P(TransformFeedbackTest, ZeroSizedViewport)
{
// Set the program's transform feedback varyings (just gl_Position)
std::vector<std::string> tfVaryings;
tfVaryings.push_back("gl_Position");
compileDefaultProgram(tfVaryings, GL_INTERLEAVED_ATTRIBS);
glUseProgram(mProgram);
// Bind the buffer for transform feedback output and start transform feedback
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTransformFeedbackBuffer);
glBeginTransformFeedback(GL_TRIANGLES);
// Create a query to check how many primitives were written
GLuint primitivesWrittenQuery = 0;
glGenQueries(1, &primitivesWrittenQuery);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, primitivesWrittenQuery);
// Set a viewport that would result in no pixels being written to the framebuffer and draw
// a quad
glViewport(0, 0, 0, 0);
drawQuad(mProgram, "position", 0.5f);
// End the query and transform feedkback
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glEndTransformFeedback();
// Check how many primitives were written and verify that some were written even if
// no pixels were rendered
GLuint primitivesWritten = 0;
glGetQueryObjectuiv(primitivesWrittenQuery, GL_QUERY_RESULT_EXT, &primitivesWritten);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(2u, primitivesWritten);
}
// Test that XFB can write back vertices to a buffer and that we can draw from this buffer afterward.
TEST_P(TransformFeedbackTest, RecordAndDraw)
{
// TODO(jmadill): Figure out why this fails on Intel.
if (isIntel() && GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
std::cout << "Test skipped on Intel." << std::endl;
return;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Set the program's transform feedback varyings (just gl_Position)
std::vector<std::string> tfVaryings;
tfVaryings.push_back("gl_Position");
compileDefaultProgram(tfVaryings, GL_INTERLEAVED_ATTRIBS);
glUseProgram(mProgram);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
// First pass: draw 6 points to the XFB buffer
glEnable(GL_RASTERIZER_DISCARD);
const GLfloat vertices[] =
{
-1.0f, 1.0f, 0.5f,
-1.0f, -1.0f, 0.5f,
1.0f, -1.0f, 0.5f,
-1.0f, 1.0f, 0.5f,
1.0f, -1.0f, 0.5f,
1.0f, 1.0f, 0.5f,
};
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(positionLocation);
// Bind the buffer for transform feedback output and start transform feedback
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTransformFeedbackBuffer);
glBeginTransformFeedback(GL_POINTS);
// Create a query to check how many primitives were written
GLuint primitivesWrittenQuery = 0;
glGenQueries(1, &primitivesWrittenQuery);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, primitivesWrittenQuery);
glDrawArrays(GL_POINTS, 0, 6);
glDisableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, NULL);
// End the query and transform feedkback
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glEndTransformFeedback();
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
glDisable(GL_RASTERIZER_DISCARD);
// Check how many primitives were written and verify that some were written even if
// no pixels were rendered
GLuint primitivesWritten = 0;
glGetQueryObjectuiv(primitivesWrittenQuery, GL_QUERY_RESULT_EXT, &primitivesWritten);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(6u, primitivesWritten);
// Nothing should have been drawn to the framebuffer
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 0, 0, 0);
// Second pass: draw from the feedback buffer
glBindBuffer(GL_ARRAY_BUFFER, mTransformFeedbackBuffer);
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 0, 0, 255);
EXPECT_GL_NO_ERROR();
}
// Test that buffer binding happens only on the current transform feedback object
TEST_P(TransformFeedbackTest, BufferBinding)
{
// Reset any state
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
// Generate a new buffer
GLuint scratchBuffer = 0;
glGenBuffers(1, &scratchBuffer);
EXPECT_GL_NO_ERROR();
// Bind TF 0 and a buffer
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer);
EXPECT_GL_NO_ERROR();
// Check that the buffer ID matches the one that was just bound
GLint currentBufferBinding = 0;
glGetIntegerv(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, ¤tBufferBinding);
EXPECT_EQ(static_cast<GLuint>(currentBufferBinding), mTransformFeedbackBuffer);
EXPECT_GL_NO_ERROR();
// Check that the buffer ID for the newly bound transform feedback is zero
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, mTransformFeedback);
glGetIntegerv(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, ¤tBufferBinding);
EXPECT_EQ(0, currentBufferBinding);
EXPECT_GL_NO_ERROR();
// Bind a buffer to this TF
glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, scratchBuffer, 0, 32);
glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, 0, ¤tBufferBinding);
EXPECT_EQ(static_cast<GLuint>(currentBufferBinding), scratchBuffer);
EXPECT_GL_NO_ERROR();
// Rebind the original TF and check it's bindings
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, 0, ¤tBufferBinding);
EXPECT_EQ(0, currentBufferBinding);
EXPECT_GL_NO_ERROR();
// Clean up
glDeleteBuffers(1, &scratchBuffer);
}
// Test that we can capture varyings only used in the vertex shader.
TEST_P(TransformFeedbackTest, VertexOnly)
{
const std::string &vertexShaderSource =
"#version 300 es\n"
"in vec2 position;\n"
"in float attrib;\n"
"out float varyingAttrib;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" varyingAttrib = attrib;\n"
"}";
const std::string &fragmentShaderSource =
"#version 300 es\n"
"out mediump vec4 color;\n"
"void main() {\n"
" color = vec4(0.0, 1.0, 0.0, 1.0);\n"
"}";
std::vector<std::string> tfVaryings;
tfVaryings.push_back("varyingAttrib");
mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource,
tfVaryings, GL_INTERLEAVED_ATTRIBS);
ASSERT_NE(0u, mProgram);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, mTransformFeedback);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTransformFeedbackBuffer);
std::vector<float> attribData;
for (unsigned int cnt = 0; cnt < 100; ++cnt)
{
attribData.push_back(static_cast<float>(cnt));
}
GLint attribLocation = glGetAttribLocation(mProgram, "attrib");
ASSERT_NE(-1, attribLocation);
glVertexAttribPointer(attribLocation, 1, GL_FLOAT, GL_FALSE, 4, &attribData[0]);
glEnableVertexAttribArray(attribLocation);
glBeginTransformFeedback(GL_TRIANGLES);
drawQuad(mProgram, "position", 0.5f);
glEndTransformFeedback();
ASSERT_GL_NO_ERROR();
GLvoid *mappedBuffer =
glMapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(float) * 6, GL_MAP_READ_BIT);
ASSERT_NE(nullptr, mappedBuffer);
float *mappedFloats = static_cast<float *>(mappedBuffer);
for (unsigned int cnt = 0; cnt < 6; ++cnt)
{
EXPECT_EQ(attribData[cnt], mappedFloats[cnt]);
}
EXPECT_GL_NO_ERROR();
}
// Test that multiple paused transform feedbacks do not generate errors or crash
TEST_P(TransformFeedbackTest, MultiplePaused)
{
const size_t drawSize = 1024;
std::vector<float> transformFeedbackData(drawSize);
for (size_t i = 0; i < drawSize; i++)
{
transformFeedbackData[i] = static_cast<float>(i + 1);
}
// Initialize the buffers to zero
size_t bufferSize = drawSize;
std::vector<float> bufferInitialData(bufferSize, 0);
const size_t transformFeedbackCount = 8;
// clang-format off
const std::string vertexShaderSource = SHADER_SOURCE
( #version 300 es\n
in highp vec4 position;
in float transformFeedbackInput;
out float transformFeedbackOutput;
void main(void)
{
gl_Position = position;
transformFeedbackOutput = transformFeedbackInput;
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
( #version 300 es\n
out mediump vec4 color;
void main(void)
{
color = vec4(1.0, 1.0, 1.0, 1.0);
}
);
// clang-format on
std::vector<std::string> tfVaryings;
tfVaryings.push_back("transformFeedbackOutput");
mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource,
tfVaryings, GL_INTERLEAVED_ATTRIBS);
ASSERT_NE(0u, mProgram);
glUseProgram(mProgram);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glDisableVertexAttribArray(positionLocation);
glVertexAttrib4f(positionLocation, 0.0f, 0.0f, 0.0f, 1.0f);
GLint tfInputLocation = glGetAttribLocation(mProgram, "transformFeedbackInput");
glEnableVertexAttribArray(tfInputLocation);
glVertexAttribPointer(tfInputLocation, 1, GL_FLOAT, false, 0, &transformFeedbackData[0]);
glDepthMask(GL_FALSE);
glEnable(GL_DEPTH_TEST);
ASSERT_GL_NO_ERROR();
GLuint transformFeedbacks[transformFeedbackCount];
glGenTransformFeedbacks(transformFeedbackCount, transformFeedbacks);
GLuint buffers[transformFeedbackCount];
glGenBuffers(transformFeedbackCount, buffers);
for (size_t i = 0; i < transformFeedbackCount; i++)
{
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbacks[i]);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buffers[i]);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, bufferSize * sizeof(GLfloat),
&bufferInitialData[0], GL_DYNAMIC_DRAW);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffers[i]);
ASSERT_GL_NO_ERROR();
glBeginTransformFeedback(GL_POINTS);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(drawSize));
glPauseTransformFeedback();
EXPECT_GL_NO_ERROR();
}
for (size_t i = 0; i < transformFeedbackCount; i++)
{
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbacks[i]);
glEndTransformFeedback();
glDeleteTransformFeedbacks(1, &transformFeedbacks[i]);
EXPECT_GL_NO_ERROR();
}
}
// Test that running multiple simultaneous queries and transform feedbacks from multiple EGL
// contexts returns the correct results. Helps expose bugs in ANGLE's virtual contexts.
TEST_P(TransformFeedbackTest, MultiContext)
{
if (GetParam() == ES3_D3D11())
{
std::cout << "Test skipped because the D3D backends cannot support simultaneous transform "
"feedback or queries on multiple contexts yet."
<< std::endl;
return;
}
#if defined(ANGLE_PLATFORM_APPLE)
if ((isNVidia() || isAMD()) && GetParam() == ES3_OPENGL())
{
std::cout << "Test skipped on NVidia and AMD OpenGL on OSX." << std::endl;
return;
}
#endif
#if defined(ANGLE_PLATFORM_LINUX)
if (isAMD() && GetParam() == ES3_OPENGL())
{
std::cout << "Test skipped on AMD OpenGL on Linux." << std::endl;
return;
}
#endif
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR,
GetParam().majorVersion,
EGL_CONTEXT_MINOR_VERSION_KHR,
GetParam().minorVersion,
EGL_NONE,
};
EGLWindow *window = getEGLWindow();
EGLDisplay display = window->getDisplay();
EGLConfig config = window->getConfig();
EGLSurface surface = window->getSurface();
const size_t passCount = 5;
struct ContextInfo
{
EGLContext context;
GLuint program;
GLuint query;
GLuint buffer;
size_t primitiveCounts[passCount];
};
ContextInfo contexts[32];
const size_t maxDrawSize = 1024;
std::vector<float> transformFeedbackData(maxDrawSize);
for (size_t i = 0; i < maxDrawSize; i++)
{
transformFeedbackData[i] = static_cast<float>(i + 1);
}
// Initialize the buffers to zero
size_t bufferSize = maxDrawSize * passCount;
std::vector<float> bufferInitialData(bufferSize, 0);
for (auto &context : contexts)
{
context.context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes);
ASSERT_NE(context.context, EGL_NO_CONTEXT);
eglMakeCurrent(display, surface, surface, context.context);
// clang-format off
const std::string vertexShaderSource = SHADER_SOURCE
( #version 300 es\n
in highp vec4 position;
in float transformFeedbackInput;
out float transformFeedbackOutput;
void main(void)
{
gl_Position = position;
transformFeedbackOutput = transformFeedbackInput;
}
);
const std::string fragmentShaderSource = SHADER_SOURCE
( #version 300 es\n
out mediump vec4 color;
void main(void)
{
color = vec4(1.0, 1.0, 1.0, 1.0);
}
);
// clang-format on
std::vector<std::string> tfVaryings;
tfVaryings.push_back("transformFeedbackOutput");
context.program = CompileProgramWithTransformFeedback(
vertexShaderSource, fragmentShaderSource, tfVaryings, GL_INTERLEAVED_ATTRIBS);
ASSERT_NE(context.program, 0u);
glUseProgram(context.program);
GLint positionLocation = glGetAttribLocation(context.program, "position");
glDisableVertexAttribArray(positionLocation);
glVertexAttrib4f(positionLocation, 0.0f, 0.0f, 0.0f, 1.0f);
GLint tfInputLocation = glGetAttribLocation(context.program, "transformFeedbackInput");
glEnableVertexAttribArray(tfInputLocation);
glVertexAttribPointer(tfInputLocation, 1, GL_FLOAT, false, 0, &transformFeedbackData[0]);
glDepthMask(GL_FALSE);
glEnable(GL_DEPTH_TEST);
glGenQueriesEXT(1, &context.query);
glBeginQueryEXT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, context.query);
ASSERT_GL_NO_ERROR();
glGenBuffers(1, &context.buffer);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, context.buffer);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, bufferSize * sizeof(GLfloat),
&bufferInitialData[0], GL_DYNAMIC_DRAW);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, context.buffer);
ASSERT_GL_NO_ERROR();
// For each pass, draw between 0 and maxDrawSize primitives
for (auto &primCount : context.primitiveCounts)
{
primCount = rand() % maxDrawSize;
}
glBeginTransformFeedback(GL_POINTS);
}
for (size_t pass = 0; pass < passCount; pass++)
{
for (const auto &context : contexts)
{
eglMakeCurrent(display, surface, surface, context.context);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(context.primitiveCounts[pass]));
}
}
for (const auto &context : contexts)
{
eglMakeCurrent(display, surface, surface, context.context);
glEndTransformFeedback();
glEndQueryEXT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
GLuint result = 0;
glGetQueryObjectuivEXT(context.query, GL_QUERY_RESULT_EXT, &result);
EXPECT_GL_NO_ERROR();
size_t totalPrimCount = 0;
for (const auto &primCount : context.primitiveCounts)
{
totalPrimCount += primCount;
}
EXPECT_EQ(static_cast<GLuint>(totalPrimCount), result);
const float *bufferData = reinterpret_cast<float *>(glMapBufferRange(
GL_TRANSFORM_FEEDBACK_BUFFER, 0, bufferSize * sizeof(GLfloat), GL_MAP_READ_BIT));
size_t curBufferIndex = 0;
for (const auto &primCount : context.primitiveCounts)
{
for (size_t prim = 0; prim < primCount; prim++)
{
EXPECT_EQ(bufferData[curBufferIndex], prim + 1);
curBufferIndex++;
}
}
while (curBufferIndex < bufferSize)
{
EXPECT_EQ(bufferData[curBufferIndex], 0.0f);
curBufferIndex++;
}
glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
}
eglMakeCurrent(display, surface, surface, window->getContext());
for (auto &context : contexts)
{
eglDestroyContext(display, context.context);
context.context = EGL_NO_CONTEXT;
}
}
// Test that when two vec2s are packed into the same register, we can still capture both of them.
TEST_P(TransformFeedbackTest, PackingBug)
{
// TODO(jmadill): With points and rasterizer discard?
const std::string &vertexShaderSource =
"#version 300 es\n"
"in vec2 inAttrib1;\n"
"in vec2 inAttrib2;\n"
"out vec2 outAttrib1;\n"
"out vec2 outAttrib2;\n"
"in vec2 position;\n"
"void main() {"
" outAttrib1 = inAttrib1;\n"
" outAttrib2 = inAttrib2;\n"
" gl_Position = vec4(position, 0, 1);\n"
"}";
const std::string &fragmentShaderSource =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 color;\n"
"void main() {\n"
" color = vec4(0);\n"
"}";
std::vector<std::string> tfVaryings;
tfVaryings.push_back("outAttrib1");
tfVaryings.push_back("outAttrib2");
mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource,
tfVaryings, GL_INTERLEAVED_ATTRIBS);
ASSERT_NE(0u, mProgram);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(Vector2) * 2 * 6, nullptr, GL_STREAM_DRAW);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, mTransformFeedback);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTransformFeedbackBuffer);
GLint attrib1Loc = glGetAttribLocation(mProgram, "inAttrib1");
GLint attrib2Loc = glGetAttribLocation(mProgram, "inAttrib2");
Vector2 attrib1Data[] = {Vector2(1.0, 2.0), Vector2(3.0, 4.0), Vector2(5.0, 6.0)};
Vector2 attrib2Data[] = {Vector2(11.0, 12.0), Vector2(13.0, 14.0), Vector2(15.0, 16.0)};
glEnableVertexAttribArray(attrib1Loc);
glEnableVertexAttribArray(attrib2Loc);
glVertexAttribPointer(attrib1Loc, 2, GL_FLOAT, GL_FALSE, 0, attrib1Data);
glVertexAttribPointer(attrib2Loc, 2, GL_FLOAT, GL_FALSE, 0, attrib2Data);
glBeginTransformFeedback(GL_TRIANGLES);
drawQuad(mProgram, "position", 0.5f);
glEndTransformFeedback();
ASSERT_GL_NO_ERROR();
const GLvoid *mapPointer =
glMapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(Vector2) * 2 * 6, GL_MAP_READ_BIT);
ASSERT_NE(nullptr, mapPointer);
const Vector2 *vecPointer = static_cast<const Vector2 *>(mapPointer);
for (unsigned int vectorIndex = 0; vectorIndex < 3; ++vectorIndex)
{
unsigned int stream1Index = vectorIndex * 2;
unsigned int stream2Index = vectorIndex * 2 + 1;
EXPECT_EQ(attrib1Data[vectorIndex], vecPointer[stream1Index]);
EXPECT_EQ(attrib2Data[vectorIndex], vecPointer[stream2Index]);
}
ASSERT_GL_NO_ERROR();
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(TransformFeedbackTest, ES3_D3D11(), ES3_OPENGL());
} // anonymous namespace