Hash :
df90bbc5
Author :
Date :
2024-07-12T18:04:53
Refactoring: move angle::HashMap and HashSet to own header Underlying abseil includes pull in a large set of headers Bug: angleproject:42266508 Change-Id: Icee47143a8a59bb0795a054b67c0aa4ddcfca4d4 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5704137 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: 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
//
// Copyright 2023 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.
//
// Test built-in variables added by OES_sample_variables
#include <unordered_set>
#include "common/mathutil.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
class SampleVariablesTest : public ANGLETest<>
{
protected:
SampleVariablesTest()
{
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Test gl_MaxSamples == GL_MAX_SAMPLES
TEST_P(SampleVariablesTest, MaxSamples)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
GLint maxSamples = -1;
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
ASSERT_GT(maxSamples, 0);
ASSERT_LE(maxSamples, 32);
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
void main()
{
color = vec4(float(gl_MaxSamples * 4) / 255.0, 0.0, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_NEAR(0, 0, maxSamples * 4, 0, 0, 255, 1.0);
}
// Test gl_NumSamples == GL_SAMPLES
TEST_P(SampleVariablesTest, NumSamples)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
void main()
{
color = vec4(float(gl_NumSamples * 4) / 255.0, 0.0, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
for (GLint sampleCount : sampleCounts)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA8, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
GLint samples = -1;
glGetIntegerv(GL_SAMPLES, &samples);
EXPECT_EQ(samples, sampleCount);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLubyte pixel[4];
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_NEAR(std::max(samples, 1) * 4, pixel[0], 1.0) << "Samples: " << sampleCount;
}
}
// Test gl_SampleID values
TEST_P(SampleVariablesTest, SampleID)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_half_float"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
uniform int id;
void main()
{
// 1.0 when the selected sample is processed, 0.0 otherwise
float r = float(gl_SampleID == id);
// Must always be 0.0
float g = float(gl_SampleID < 0 || gl_SampleID >= gl_NumSamples);
color = vec4(r, g, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
GLFramebuffer fboResolve;
glBindFramebuffer(GL_FRAMEBUFFER, fboResolve);
GLRenderbuffer rboResolve;
glBindRenderbuffer(GL_RENDERBUFFER, rboResolve);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rboResolve);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
ASSERT_GL_NO_ERROR();
for (GLint sampleCount : sampleCounts)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
for (int sample = 0; sample < std::max(sampleCount, 1); sample++)
{
glUniform1i(glGetUniformLocation(program, "id"), sample);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboResolve);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLfloat pixel[4];
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboResolve);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, pixel);
EXPECT_GL_NO_ERROR();
// Only one sample has 1.0 value
EXPECT_NEAR(1.0 / std::max(sampleCount, 1), pixel[0], 0.001)
<< "Samples: " << sampleCount << ", SampleID: " << sample;
EXPECT_EQ(0.0, pixel[1]);
}
}
}
// Test gl_SamplePosition values
TEST_P(SampleVariablesTest, SamplePosition)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_half_float"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
uniform int id;
void main()
{
vec2 rg = (gl_SampleID == id) ? gl_SamplePosition : vec2(0.0, 0.0);
// Must always be 0.0
float b = float(gl_SamplePosition.x < 0.0 || gl_SamplePosition.x > 1.0);
float a = float(gl_SamplePosition.y < 0.0 || gl_SamplePosition.y > 1.0);
color = vec4(rg, b, a);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
GLFramebuffer fboResolve;
glBindFramebuffer(GL_FRAMEBUFFER, fboResolve);
GLRenderbuffer rboResolve;
glBindRenderbuffer(GL_RENDERBUFFER, rboResolve);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rboResolve);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
for (GLint sampleCount : sampleCounts)
{
if (sampleCount > 16)
{
// Sample positions for MSAAx32 are not defined.
continue;
}
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
std::unordered_set<GLfloat> positionX;
std::unordered_set<GLfloat> positionY;
for (int sample = 0; sample < std::max(sampleCount, 1); sample++)
{
glUniform1i(glGetUniformLocation(program, "id"), sample);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboResolve);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLfloat pixel[4];
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboResolve);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, pixel);
EXPECT_GL_NO_ERROR();
// Check that positions are unique for each sample
const int realSampleCount = std::max(sampleCount, 1);
EXPECT_TRUE(positionX.insert(pixel[0]).second)
<< "Samples: " << realSampleCount << " SampleID: " << sample
<< " X: " << (pixel[0] * realSampleCount);
EXPECT_TRUE(positionY.insert(pixel[1]).second)
<< "Samples: " << realSampleCount << " SampleID: " << sample
<< " Y: " << (pixel[1] * realSampleCount);
// Check that sample positions are in the normalized range
EXPECT_EQ(0, pixel[2]);
EXPECT_EQ(0, pixel[3]);
}
}
}
// Test gl_SampleMaskIn values
TEST_P(SampleVariablesTest, SampleMaskIn)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
uint popcount(uint v)
{
uint c = 0u;
for (; v != 0u; v >>= 1) c += v & 1u;
return c;
}
void main()
{
float r = 0.0;
r = float(popcount(uint(gl_SampleMaskIn[0])));
color = vec4(r * 4.0 / 255.0, 0, 0, 1);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
auto test = [&](GLint sampleCount, bool sampleCoverageEnabled, GLfloat coverage) {
if (sampleCoverageEnabled)
{
glEnable(GL_SAMPLE_COVERAGE);
}
else
{
glDisable(GL_SAMPLE_COVERAGE);
}
glSampleCoverage(coverage, false);
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA8, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLubyte pixel[4];
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
EXPECT_GL_NO_ERROR();
// Shader scales up the number of input samples to increase precision in unorm8 space.
int expected = std::max(sampleCount, 1) * 4;
// Sample coverage must not affect single sampled buffers
if (sampleCoverageEnabled && sampleCount > 0)
{
// The number of samples in gl_SampleMaskIn must be affected by the sample
// coverage GL state and then the resolved value must be scaled down again.
expected *= coverage * coverage;
}
EXPECT_NEAR(expected, pixel[0], 1.0)
<< "Samples: " << sampleCount
<< ", Sample Coverage: " << (sampleCoverageEnabled ? "Enabled" : "Disabled")
<< ", Coverage: " << coverage;
};
for (GLint sampleCount : sampleCounts)
{
if (sampleCount > 32)
{
// The test shader will not work with MSAAx64.
continue;
}
for (bool sampleCoverageEnabled : {false, true})
{
for (GLfloat coverage : {0.0, 0.5, 1.0})
{
if (sampleCount == 1 && coverage != 0.0 && coverage != 1.0)
{
continue;
}
test(sampleCount, sampleCoverageEnabled, coverage);
}
}
}
}
// Test gl_SampleMaskIn values with per-sample shading
TEST_P(SampleVariablesTest, SampleMaskInPerSample)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
out vec4 color;
void main()
{
float r = float(gl_SampleMaskIn[0] == (1 << gl_SampleID));
color = vec4(r, 0, 0, 1);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
for (GLint sampleCount : sampleCounts)
{
if (sampleCount > 32)
{
// The test shader will not work with MSAAx64.
continue;
}
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA8, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red) << "Samples: " << sampleCount;
}
}
// Test writing gl_SampleMask
TEST_P(SampleVariablesTest, SampleMask)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_sample_variables"));
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_color_buffer_half_float"));
const char kFS[] = R"(#version 300 es
#extension GL_OES_sample_variables : require
precision highp float;
uniform highp int sampleMask;
out vec4 color;
void main()
{
gl_SampleMask[0] = sampleMask;
color = vec4(1, 0, 0, 1);
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
glUseProgram(program);
GLint numSampleCounts = 0;
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
ASSERT_GT(numSampleCounts, 0);
std::vector<GLint> sampleCounts;
sampleCounts.resize(numSampleCounts);
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA16F, GL_SAMPLES, numSampleCounts,
sampleCounts.data());
sampleCounts.push_back(0);
GLFramebuffer fboResolve;
glBindFramebuffer(GL_FRAMEBUFFER, fboResolve);
GLRenderbuffer rboResolve;
glBindRenderbuffer(GL_RENDERBUFFER, rboResolve);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rboResolve);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
auto test = [&](GLint sampleCount, GLint sampleMask, bool sampleCoverageEnabled,
GLfloat coverage) {
if (sampleCoverageEnabled)
{
glEnable(GL_SAMPLE_COVERAGE);
}
else
{
glDisable(GL_SAMPLE_COVERAGE);
}
ASSERT(coverage == 0.0 || coverage == 1.0);
glSampleCoverage(coverage, false);
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer rbo;
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_RGBA16F, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT);
glUniform1i(glGetUniformLocation(program, "sampleMask"), sampleMask);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboResolve);
glBlitFramebuffer(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLfloat pixel[4];
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboResolve);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, pixel);
EXPECT_GL_NO_ERROR();
float expected = 1.0;
if (sampleCount > 0)
{
if (sampleCoverageEnabled && coverage == 0.0)
{
expected = 0.0;
}
else
{
uint32_t fullSampleCount = std::max(sampleCount, 1);
uint32_t realSampleMask = sampleMask & (0xFFFFFFFFu >> (32 - fullSampleCount));
expected = static_cast<float>(gl::BitCount(realSampleMask)) / fullSampleCount;
}
}
EXPECT_EQ(expected, pixel[0])
<< "Samples: " << sampleCount << ", gl_SampleMask[0]: " << sampleMask
<< ", Sample Coverage: " << (sampleCoverageEnabled ? "Enabled" : "Disabled")
<< ", Coverage: " << coverage;
};
for (GLint sampleCount : sampleCounts)
{
if (sampleCount > 32)
{
// The test shader will not work with MSAAx64.
continue;
}
for (bool sampleCoverageEnabled : {false, true})
{
for (GLfloat coverage : {0.0, 1.0})
{
for (GLint sampleMask : {0xFFFFFFFFu, 0x55555555u, 0xAAAAAAAAu, 0x00000000u})
{
test(sampleCount, sampleMask, sampleCoverageEnabled, coverage);
}
}
}
}
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SampleVariablesTest);
ANGLE_INSTANTIATE_TEST_ES3(SampleVariablesTest);
} // anonymous namespace