Hash :
c13ca2af
Author :
Date :
2019-07-17T15:46:29
Vulkan: Allow more than one atomic counter buffer binding dEQP assumes there are more than one atomic counter buffers available. This is technically not a requirement by the standard, but nevertheless could be what applications expect as well. This change adds support for multiple atomic counter buffer bindings. This is done by declaring an array of storage buffers for the atomic counter buffers (instead of declaring only one) and passing the (binding, offset) pair around to functions instead of just the offset. The atomic counter is found by indexing `binding` into the storage buffer array first before indexing `offset` into its `uint[]`. ProgramVk's default uniform collection is also fixed not to include atomic counter uniforms. A remaining issue is that atomic counter buffer offsets don't have alignment requirements in GLES, but Vulkan does for storage buffers. Similar to emulated transform feedback buffer offsets, these should be sent to the shader through uniform values. This will be done in a follow up change. Bug: angleproject:3566 Change-Id: I5600225c24c38f1a8ecf5c64388073055733197d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1707931 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-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
//
// 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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
// 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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
// 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);
}
// Test atomic counter increment and decrement.
TEST_P(AtomicCounterBufferTest31, AtomicCounterIncrementAndDecrement)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
// 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)
{
// Crashes in older drivers. http://anglebug.com/3738
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && IsAMD());
// 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);
}
}
ANGLE_INSTANTIATE_TEST(AtomicCounterBufferTest,
ES3_OPENGL(),
ES3_OPENGLES(),
ES31_OPENGL(),
ES31_OPENGLES(),
ES31_D3D11(),
ES31_VULKAN());
ANGLE_INSTANTIATE_TEST(AtomicCounterBufferTest31,
ES31_OPENGL(),
ES31_OPENGLES(),
ES31_D3D11(),
ES31_VULKAN());
} // namespace