Hash :
41c93c55
Author :
Date :
2020-09-01T11:34:32
Vulkan: Bug fix in atomic counter buffer count calculation When binding a new atomic counter buffer to a slot it is necessary to take into account the previous binding of that slot. This rectifies a bug introduced in f7b607c63c Bug: angleproject:3566 Test: angle_unittests.exe --gtest_filter=AtomicCounterBufferTest31.AtomicCounterBuffer* Change-Id: If78954d27c3345e8620294a84e839058d7dd7b9a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2388431 Commit-Queue: Mohan Maiya <m.maiya@samsung.com> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@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
//
// 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.
//
// AtomicCounterBufferTest:
// Various tests related for atomic counter buffers.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
class AtomicCounterBufferTest : public ANGLETest
{
protected:
AtomicCounterBufferTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Test GL_ATOMIC_COUNTER_BUFFER is not supported with version lower than ES31.
TEST_P(AtomicCounterBufferTest, AtomicCounterBufferBindings)
{
ASSERT_EQ(3, getClientMajorVersion());
GLBuffer atomicCounterBuffer;
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer.get());
if (getClientMinorVersion() < 1)
{
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
else
{
EXPECT_GL_NO_ERROR();
}
}
class AtomicCounterBufferTest31 : public AtomicCounterBufferTest
{};
// Linking should fail if counters in vertex shader exceed gl_MaxVertexAtomicCounters.
TEST_P(AtomicCounterBufferTest31, ExceedMaxVertexAtomicCounters)
{
constexpr char kVS[] =
"#version 310 es\n"
"layout(binding = 0) uniform atomic_uint foo[gl_MaxVertexAtomicCounters + 1];\n"
"void main()\n"
"{\n"
" atomicCounterIncrement(foo[0]);\n"
"}\n";
constexpr char kFS[] =
"#version 310 es\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_EQ(0u, program);
}
// Counters matching across shader stages should fail if offsets aren't all specified.
// GLSL ES Spec 3.10.4, section 9.2.1.
TEST_P(AtomicCounterBufferTest31, OffsetNotAllSpecified)
{
constexpr char kVS[] =
"#version 310 es\n"
"layout(binding = 0, offset = 4) uniform atomic_uint foo;\n"
"void main()\n"
"{\n"
" atomicCounterIncrement(foo);\n"
"}\n";
constexpr char kFS[] =
"#version 310 es\n"
"layout(binding = 0) uniform atomic_uint foo;\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_EQ(0u, program);
}
// Counters matching across shader stages should fail if offsets aren't all specified with same
// value.
TEST_P(AtomicCounterBufferTest31, OffsetNotAllSpecifiedWithSameValue)
{
constexpr char kVS[] =
"#version 310 es\n"
"layout(binding = 0, offset = 4) uniform atomic_uint foo;\n"
"void main()\n"
"{\n"
" atomicCounterIncrement(foo);\n"
"}\n";
constexpr char kFS[] =
"#version 310 es\n"
"layout(binding = 0, offset = 8) uniform atomic_uint foo;\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_EQ(0u, program);
}
// Tests atomic counter reads using compute shaders. Used as a sanity check for the translator.
TEST_P(AtomicCounterBufferTest31, AtomicCounterReadCompute)
{
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
// Skipping due to a bug on the Adreno OpenGLES Android driver.
// http://anglebug.com/2925
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
void atomicCounterInFunction(in atomic_uint counter[3]);
layout(binding = 0, offset = 8) uniform atomic_uint ac[3];
void atomicCounterInFunction(in atomic_uint counter[3])
{
atomicCounter(counter[0]);
}
void main()
{
atomicCounterInFunction(ac);
atomicCounter(ac[gl_LocalInvocationIndex + 1u]);
})";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
}
// Test atomic counter read.
TEST_P(AtomicCounterBufferTest31, AtomicCounterRead)
{
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
// Skipping test while we work on enabling atomic counter buffer support in th D3D renderer.
// http://anglebug.com/1729
ANGLE_SKIP_TEST_IF(IsD3D11());
constexpr char kFS[] =
"#version 310 es\n"
"precision highp float;\n"
"layout(binding = 0, offset = 4) uniform atomic_uint ac;\n"
"out highp vec4 my_color;\n"
"void main()\n"
"{\n"
" my_color = vec4(0.0);\n"
" uint a1 = atomicCounter(ac);\n"
" if (a1 == 3u) my_color = vec4(1.0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
glUseProgram(program.get());
// The initial value of counter 'ac' is 3u.
unsigned int bufferData[3] = {11u, 3u, 1u};
GLBuffer atomicCounterBuffer;
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData), bufferData, GL_STATIC_DRAW);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer);
drawQuad(program.get(), essl31_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
}
// Updating atomic counter buffer's offsets was optimized based on a count of valid bindings.
// This test will fail if there are bugs in how we count valid bindings.
TEST_P(AtomicCounterBufferTest31, AtomicCounterBufferRangeRead)
{
// Skipping due to a bug on the Qualcomm driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsNexus5X());
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
// Skipping test while we work on enabling atomic counter buffer support in th D3D renderer.
// http://anglebug.com/1729
ANGLE_SKIP_TEST_IF(IsD3D11());
constexpr char kFS[] =
"#version 310 es\n"
"precision highp float;\n"
"layout(binding = 0, offset = 4) uniform atomic_uint ac;\n"
"out highp vec4 my_color;\n"
"void main()\n"
"{\n"
" my_color = vec4(0.0);\n"
" uint a1 = atomicCounter(ac);\n"
" if (a1 == 3u) my_color = vec4(1.0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
glUseProgram(program.get());
// The initial value of counter 'ac' is 3u.
unsigned int bufferData[] = {0u, 0u, 0u, 0u, 0u, 11u, 3u, 1u};
constexpr GLintptr kOffset = 20;
GLint maxAtomicCounterBuffers = 0;
GLBuffer atomicCounterBuffer;
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS, &maxAtomicCounterBuffers);
// Repeatedly bind the same buffer (GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS + 1) times
// A bug in counting valid atomic counter buffers will cause a crash when we
// exceed GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS
for (int32_t i = 0; i < maxAtomicCounterBuffers + 1; i++)
{
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData), bufferData, GL_STATIC_DRAW);
glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer, kOffset,
sizeof(bufferData) - kOffset);
}
drawQuad(program.get(), essl31_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
}
// Updating atomic counter buffer's offsets was optimized based on a count of valid bindings.
// Repeatedly bind/unbind buffers across available binding points. The test will fail if
// there are bugs in how we count valid bindings.
TEST_P(AtomicCounterBufferTest31, AtomicCounterBufferRepeatedBindUnbind)
{
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
// Skipping test while we work on enabling atomic counter buffer support in th D3D renderer.
// http://anglebug.com/1729
ANGLE_SKIP_TEST_IF(IsD3D11());
constexpr char kFS[] =
"#version 310 es\n"
"precision highp float;\n"
"layout(binding = 0, offset = 4) uniform atomic_uint ac;\n"
"out highp vec4 my_color;\n"
"void main()\n"
"{\n"
" my_color = vec4(0.0);\n"
" uint a1 = atomicCounter(ac);\n"
" if (a1 == 3u) my_color = vec4(1.0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
glUseProgram(program.get());
constexpr int32_t kBufferCount = 16;
// The initial value of counter 'ac' is 3u.
unsigned int bufferData[3] = {11u, 3u, 1u};
GLBuffer atomicCounterBuffer[kBufferCount];
// Populate atomicCounterBuffer[0] with valid data and the rest with nullptr
for (int32_t bufferIndex = 0; bufferIndex < kBufferCount; bufferIndex++)
{
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer[bufferIndex]);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData),
(bufferIndex == 0) ? bufferData : nullptr, GL_STATIC_DRAW);
}
GLint maxAtomicCounterBuffers = 0;
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS, &maxAtomicCounterBuffers);
// Cycle through multiple buffers
for (int32_t i = 0; i < kBufferCount; i++)
{
constexpr int32_t kBufferIndices[kBufferCount] = {7, 12, 15, 5, 13, 14, 1, 2,
0, 6, 4, 9, 8, 11, 3, 10};
int32_t bufferIndex = kBufferIndices[i];
// Randomly bind/unbind buffers to/from different binding points,
// capped by GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS
for (int32_t bufferCount = 0; bufferCount < maxAtomicCounterBuffers; bufferCount++)
{
constexpr uint32_t kBindingSlotsSize = kBufferCount;
constexpr uint32_t kBindingSlots[kBindingSlotsSize] = {1, 3, 4, 14, 15, 9, 0, 6,
12, 11, 8, 5, 10, 2, 7, 13};
uint32_t bindingSlotIndex = bufferCount % kBindingSlotsSize;
uint32_t bindingSlot = kBindingSlots[bindingSlotIndex];
uint32_t bindingPoint = bindingSlot % maxAtomicCounterBuffers;
bool even = (bufferCount % 2 == 0);
int32_t bufferId = (even) ? 0 : atomicCounterBuffer[bufferIndex];
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, bindingPoint, bufferId);
}
}
// Bind atomicCounterBuffer[0] to slot 0 and verify result
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer[0]);
drawQuad(program.get(), essl31_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
}
// Test atomic counter increment and decrement.
TEST_P(AtomicCounterBufferTest31, AtomicCounterIncrementAndDecrement)
{
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
constexpr char kCS[] =
"#version 310 es\n"
"layout(local_size_x=1, local_size_y=1, local_size_z=1) in;\n"
"layout(binding = 0, offset = 4) uniform atomic_uint ac[2];\n"
"void main()\n"
"{\n"
" atomicCounterIncrement(ac[0]);\n"
" atomicCounterDecrement(ac[1]);\n"
"}\n";
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program.get());
// The initial value of 'ac[0]' is 3u, 'ac[1]' is 1u.
unsigned int bufferData[3] = {11u, 3u, 1u};
GLBuffer atomicCounterBuffer;
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData), bufferData, GL_STATIC_DRAW);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer);
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
void *mappedBuffer =
glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint) * 3, GL_MAP_READ_BIT);
memcpy(bufferData, mappedBuffer, sizeof(bufferData));
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
EXPECT_EQ(11u, bufferData[0]);
EXPECT_EQ(4u, bufferData[1]);
EXPECT_EQ(0u, bufferData[2]);
}
// Tests multiple atomic counter buffers.
TEST_P(AtomicCounterBufferTest31, AtomicCounterMultipleBuffers)
{
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
GLint maxAtomicCounterBuffers = 0;
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS, &maxAtomicCounterBuffers);
constexpr unsigned int kBufferCount = 3;
// ES 3.1 table 20.45 only guarantees 1 atomic counter buffer
ANGLE_SKIP_TEST_IF(maxAtomicCounterBuffers < static_cast<int>(kBufferCount));
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(binding = 0) uniform atomic_uint ac1;
layout(binding = 1) uniform atomic_uint ac2;
layout(binding = 2) uniform atomic_uint ac3;
void main()
{
atomicCounterIncrement(ac1);
atomicCounterIncrement(ac2);
atomicCounterIncrement(ac3);
})";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
GLBuffer atomicCounterBuffers[kBufferCount];
for (unsigned int ii = 0; ii < kBufferCount; ++ii)
{
GLuint initialData[1] = {ii};
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffers[ii]);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(initialData), initialData, GL_STATIC_DRAW);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, ii, atomicCounterBuffers[ii]);
}
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
for (unsigned int ii = 0; ii < kBufferCount; ++ii)
{
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffers[ii]);
GLuint *mappedBuffer = static_cast<GLuint *>(
glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(GLuint), GL_MAP_READ_BIT));
EXPECT_EQ(ii + 1, mappedBuffer[0]);
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
}
}
// Test atomic counter array of array.
TEST_P(AtomicCounterBufferTest31, AtomicCounterArrayOfArray)
{
// Fails on D3D. Some counters are double-incremented while some are untouched, hinting at a
// bug in index translation. http://anglebug.com/3783
ANGLE_SKIP_TEST_IF(IsD3D11());
// Nvidia's OpenGL driver fails to compile the shader. http://anglebug.com/3791
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsNVIDIA());
// Intel's Windows OpenGL driver crashes in this test. http://anglebug.com/3791
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsIntel() && IsWindows());
// Skipping due to a bug on the Qualcomm Vulkan Android driver.
// http://anglebug.com/3726
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(binding = 0) uniform atomic_uint ac[7][5][3];
void f0(in atomic_uint ac)
{
atomicCounterIncrement(ac);
}
void f1(in atomic_uint ac[3])
{
atomicCounterIncrement(ac[0]);
f0(ac[1]);
int index = 2;
f0(ac[index]);
}
void f2(in atomic_uint ac[5][3])
{
// Increment all in ac[0], ac[1] and ac[2]
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 2; ++j)
{
f0(ac[i][j]);
}
f0(ac[i][2]);
}
// Increment all in ac[3]
f1(ac[3]);
// Increment all in ac[4]
for (int i = 0; i < 2; ++i)
{
atomicCounterIncrement(ac[4][i]);
}
f0(ac[4][2]);
}
void f3(in atomic_uint ac[7][5][3])
{
// Increment all in ac[0], ac[1], ac[2] and ac[3]
f2(ac[0]);
for (int i = 1; i < 4; ++i)
{
f2(ac[i]);
}
// Increment all in ac[5][0], ac[5][1], ac[5][2] and ac[5][3]
for (int i = 0; i < 4; ++i)
{
f1(ac[5][i]);
}
// Increment all in ac[5][4][0], ac[5][4][1] and ac[5][4][2]
f0(ac[5][4][0]);
for (int i = 1; i < 3; ++i)
{
f0(ac[5][4][i]);
}
// Increment all in ac[6]
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 2; ++j)
{
atomicCounterIncrement(ac[6][i][j]);
}
atomicCounterIncrement(ac[6][i][2]);
}
}
void main()
{
// Increment all in ac except ac[4]
f3(ac);
// Increment all in ac[4]
f2(ac[4]);
})";
constexpr uint32_t kAtomicCounterRows = 7;
constexpr uint32_t kAtomicCounterCols = 5;
constexpr uint32_t kAtomicCounterDepth = 3;
constexpr uint32_t kAtomicCounterCount =
kAtomicCounterRows * kAtomicCounterCols * kAtomicCounterDepth;
GLint maxAtomicCounters = 0;
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTERS, &maxAtomicCounters);
EXPECT_GL_NO_ERROR();
// Required minimum is 8 by the spec
EXPECT_GE(maxAtomicCounters, 8);
ANGLE_SKIP_TEST_IF(static_cast<uint32_t>(maxAtomicCounters) < kAtomicCounterCount);
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program.get());
// The initial value of atomic counters is 0, 1, 2, ...
unsigned int bufferData[kAtomicCounterCount] = {};
for (uint32_t index = 0; index < kAtomicCounterCount; ++index)
{
bufferData[index] = index;
}
GLBuffer atomicCounterBuffer;
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(bufferData), bufferData, GL_STATIC_DRAW);
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomicCounterBuffer);
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
unsigned int result[kAtomicCounterCount] = {};
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, atomicCounterBuffer);
void *mappedBuffer =
glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(bufferData), GL_MAP_READ_BIT);
memcpy(result, mappedBuffer, sizeof(bufferData));
glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
for (uint32_t index = 0; index < kAtomicCounterCount; ++index)
{
EXPECT_EQ(result[index], bufferData[index] + 1) << "index " << index;
}
}
// Test inactive atomic counter
TEST_P(AtomicCounterBufferTest31, AtomicCounterInactive)
{
constexpr char kFS[] =
"#version 310 es\n"
"precision highp float;\n"
// This inactive atomic counter should be removed by RemoveInactiveInterfaceVariables
"layout(binding = 0) uniform atomic_uint inactive;\n"
"out highp vec4 my_color;\n"
"void main()\n"
"{\n"
" my_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
glUseProgram(program);
drawQuad(program, essl31_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Test inactive memoryBarrierAtomicCounter
TEST_P(AtomicCounterBufferTest31, AtomicCounterMemoryBarrier)
{
constexpr char kFS[] =
"#version 310 es\n"
"precision highp float;\n"
// This inactive atomic counter should be removed by RemoveInactiveInterfaceVariables
"layout(binding = 0) uniform atomic_uint inactive;\n"
"out highp vec4 my_color;\n"
"void main()\n"
"{\n"
" my_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
// This barrier should be removed by RemoveAtomicCounterBuiltins because
// there are no active atomic counters
" memoryBarrierAtomicCounter();\n"
"}\n";
ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS);
glUseProgram(program);
drawQuad(program, essl31_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// TODO(syoussefi): re-enable tests on Vulkan once http://anglebug.com/3738 is resolved. The issue
// is with WGL where if a Vulkan test is run first in the shard, it causes crashes when an OpenGL
// test is run afterwards. AtomicCounter* tests are alphabetically first, and having them not run
// on Vulkan makes every shard our bots currently make do have at least some OpenGL test run before
// any Vulkan test. When these tests can be enabled on Vulkan, can replace the current macros with
// the updated macros below that include Vulkan:
#if !defined(ANGLE_PLATFORM_WINDOWS)
ANGLE_INSTANTIATE_TEST_ES3_AND_ES31(AtomicCounterBufferTest);
ANGLE_INSTANTIATE_TEST_ES31(AtomicCounterBufferTest31);
#else
ANGLE_INSTANTIATE_TEST(AtomicCounterBufferTest,
ES3_OPENGL(),
ES3_OPENGLES(),
ES31_OPENGL(),
ES31_OPENGLES(),
ES31_D3D11());
ANGLE_INSTANTIATE_TEST(AtomicCounterBufferTest31, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11());
#endif
} // namespace