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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
gpu / command_buffer / tests / gl_ext_blend_func_extended_unittest.cc [blame]
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
#include <GLES3/gl3.h>
#include <stdint.h>
#include <algorithm>
#include "base/command_line.h"
#include "build/build_config.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/tests/gl_manager.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "gpu/config/gpu_test_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#define SHADER(Src) #Src
#define BFE_SHADER(Src) "#extension GL_EXT_blend_func_extended : require\n" #Src
namespace {
// Partial implementation of weight function for GLES 2 blend equation that
// is dual-source aware.
template <int factor, int index>
float Weight(float /*dst*/[4], float src[4], float src1[4]) {
if (factor == GL_SRC_COLOR)
return src[index];
if (factor == GL_SRC_ALPHA)
return src[3];
if (factor == GL_SRC1_COLOR_EXT)
return src1[index];
if (factor == GL_SRC1_ALPHA_EXT)
return src1[3];
if (factor == GL_ONE_MINUS_SRC1_COLOR_EXT)
return 1.0f - src1[index];
if (factor == GL_ONE_MINUS_SRC1_ALPHA_EXT)
return 1.0f - src1[3];
return 0.0f;
}
// Implementation of GLES 2 blend equation that is dual-source aware.
template <int RGBs, int RGBd, int As, int Ad>
void BlendEquationFuncAdd(float dst[4],
float src[4],
float src1[4],
uint8_t result[4]) {
float r[4];
r[0] = src[0] * Weight<RGBs, 0>(dst, src, src1) +
dst[0] * Weight<RGBd, 0>(dst, src, src1);
r[1] = src[1] * Weight<RGBs, 1>(dst, src, src1) +
dst[1] * Weight<RGBd, 1>(dst, src, src1);
r[2] = src[2] * Weight<RGBs, 2>(dst, src, src1) +
dst[2] * Weight<RGBd, 2>(dst, src, src1);
r[3] = src[3] * Weight<As, 3>(dst, src, src1) +
dst[3] * Weight<Ad, 3>(dst, src, src1);
for (int i = 0; i < 4; ++i) {
result[i] =
static_cast<uint8_t>(std::floor(std::clamp(r[i], 0.0f, 1.0f) * 255.0f));
}
}
} // namespace
namespace gpu {
class EXTBlendFuncExtendedTest : public testing::Test {
public:
protected:
void SetUp() override { gl_.Initialize(GLManager::Options()); }
void TearDown() override { gl_.Destroy(); }
bool IsApplicable() const {
return GLTestHelper::HasExtension("GL_EXT_blend_func_extended");
}
GLManager gl_;
};
TEST_F(EXTBlendFuncExtendedTest, TestMaxDualSourceDrawBuffers) {
if (!IsApplicable())
return;
GLint maxDualSourceDrawBuffers = 0;
glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT, &maxDualSourceDrawBuffers);
EXPECT_GT(maxDualSourceDrawBuffers, 0);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
class EXTBlendFuncExtendedDrawTest : public testing::TestWithParam<bool> {
public:
static const GLsizei kWidth = 100;
static const GLsizei kHeight = 100;
EXTBlendFuncExtendedDrawTest() : program_(0) {}
protected:
void SetUp() override {
GLManager::Options options;
options.size = gfx::Size(kWidth, kHeight);
options.force_shader_name_hashing = GetParam();
gl_.Initialize(options);
}
bool IsApplicable() const {
#if BUILDFLAG(IS_ANDROID)
// Skip on Android due to Qualcomm driver bugs with implicitly assigned
// output locations and multiple render buffers. This extension is still
// used by Skia but Skia works around these bugs.
// http://anglebug.com/42267082
return false;
#else
return GLTestHelper::HasExtension("GL_EXT_blend_func_extended");
#endif
}
virtual const char* GetVertexShader() {
// clang-format off
static const char* kVertexShader =
SHADER(
attribute vec4 position;
void main() {
gl_Position = position;
});
// clang-format on
return kVertexShader;
}
void CreateProgramWithFragmentShader(const char* fragment_shader_str) {
GLuint vertex_shader =
GLTestHelper::LoadShader(GL_VERTEX_SHADER, GetVertexShader());
GLuint fragment_shader =
GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, fragment_shader_str);
ASSERT_NE(0u, vertex_shader);
ASSERT_NE(0u, fragment_shader);
program_ = glCreateProgram();
ASSERT_NE(0u, program_);
glAttachShader(program_, vertex_shader);
glAttachShader(program_, fragment_shader);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
}
testing::AssertionResult LinkProgram() {
glLinkProgram(program_);
GLint linked = 0;
glGetProgramiv(program_, GL_LINK_STATUS, &linked);
if (linked == 0) {
char buffer[1024];
GLsizei length = 0;
glGetProgramInfoLog(program_, sizeof(buffer), &length, buffer);
std::string log(buffer, length);
return testing::AssertionFailure() << "Error linking program: " << log;
}
glUseProgram(program_);
position_loc_ = glGetAttribLocation(program_, "position");
src_loc_ = glGetUniformLocation(program_, "src");
src1_loc_ = glGetUniformLocation(program_, "src1");
return testing::AssertionSuccess();
}
void TearDown() override {
if (program_ != 0)
glDeleteProgram(program_);
gl_.Destroy();
}
void DrawAndVerify() {
float kDst[4] = {0.5f, 0.5f, 0.5f, 0.5f};
float kSrc[4] = {1.0f, 1.0f, 1.0f, 1.0f};
float kSrc1[4] = {0.3f, 0.6f, 0.9f, 0.7f};
glUniform4f(src_loc_, kSrc[0], kSrc[1], kSrc[2], kSrc[3]);
glUniform4f(src1_loc_, kSrc1[0], kSrc1[1], kSrc1[2], kSrc1[3]);
GLTestHelper::SetupUnitQuad(position_loc_);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC1_COLOR_EXT, GL_SRC_ALPHA,
GL_ONE_MINUS_SRC1_COLOR_EXT,
GL_ONE_MINUS_SRC1_ALPHA_EXT);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
// Draw one triangle (bottom left half).
glViewport(0, 0, kWidth, kHeight);
glClearColor(kDst[0], kDst[1], kDst[2], kDst[3]);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
// Verify.
uint8_t color[4];
BlendEquationFuncAdd<GL_SRC1_COLOR_EXT, GL_SRC_ALPHA,
GL_ONE_MINUS_SRC1_COLOR_EXT,
GL_ONE_MINUS_SRC1_ALPHA_EXT>(kDst, kSrc, kSrc1, color);
EXPECT_TRUE(GLTestHelper::CheckPixels(kWidth / 4, (3 * kHeight) / 4, 1, 1,
1, color, nullptr));
EXPECT_TRUE(
GLTestHelper::CheckPixels(kWidth - 1, 0, 1, 1, 1, color, nullptr));
}
protected:
GLuint program_;
GLuint position_loc_;
GLuint src_loc_;
GLuint src1_loc_;
GLManager gl_;
};
TEST_P(EXTBlendFuncExtendedDrawTest, ESSL1FragColor) {
if (!IsApplicable())
return;
// Fails on AMDGPU-PRO driver crbug.com/786219
gpu::GPUTestBotConfig bot_config;
if (bot_config.LoadCurrentConfig(nullptr) &&
bot_config.Matches("linux amd")) {
return;
}
// clang-format off
static const char* kFragColorShader =
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
void main() {
gl_FragColor = src;
gl_SecondaryFragColorEXT = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
LinkProgram();
DrawAndVerify();
}
TEST_P(EXTBlendFuncExtendedDrawTest, ESSL1FragData) {
if (!IsApplicable())
return;
// Fails on the Intel Mesa driver, see
// https://bugs.freedesktop.org/show_bug.cgi?id=96617
gpu::GPUTestBotConfig bot_config;
if (bot_config.LoadCurrentConfig(nullptr) &&
bot_config.Matches("linux intel")) {
return;
}
// clang-format off
static const char* kFragDataShader =
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
void main() {
gl_FragData[0] = src;
gl_SecondaryFragDataEXT[0] = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragDataShader);
LinkProgram();
DrawAndVerify();
}
class EXTBlendFuncExtendedES3DrawTest : public EXTBlendFuncExtendedDrawTest {
protected:
void SetUp() override {
#if BUILDFLAG(IS_ANDROID)
auto* command_line = base::CommandLine::ForCurrentProcess();
if (!gles2::UsePassthroughCommandDecoder(command_line)) {
// TODO(crbug.com/40160681): remove suppression when passthrough ships.
GTEST_SKIP();
}
#endif
GLManager::Options options;
options.size = gfx::Size(kWidth, kHeight);
options.context_type = CONTEXT_TYPE_OPENGLES3;
options.force_shader_name_hashing = GetParam();
gl_.Initialize(options);
}
bool IsApplicable() const {
return gl_.IsInitialized() && EXTBlendFuncExtendedDrawTest::IsApplicable();
}
const char* GetVertexShader() override {
// clang-format off
static const char* kVertexShader =
"#version 300 es\n"
SHADER(
in vec4 position;
void main() {
gl_Position = position;
});
// clang-format on
return kVertexShader;
}
};
TEST_P(EXTBlendFuncExtendedES3DrawTest, ESSL3Var) {
if (!IsApplicable())
return;
// clang-format off
static const char* kFragColorShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragColor;
out vec4 SecondaryFragColor;
void main() {
FragColor = src;
SecondaryFragColor = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragColor");
LinkProgram();
DrawAndVerify();
}
TEST_P(EXTBlendFuncExtendedES3DrawTest, ESSL3BindArrayWithSimpleName) {
if (!IsApplicable())
return;
// Fails on the Intel Mesa driver, see
// https://bugs.freedesktop.org/show_bug.cgi?id=96765
gpu::GPUTestBotConfig bot_config;
if (bot_config.LoadCurrentConfig(nullptr) &&
bot_config.Matches("linux intel")) {
return;
}
// clang-format off
static const char* kFragDataShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData[1];
out vec4 SecondaryFragData[1];
void main() {
FragData[0] = src;
SecondaryFragData[0] = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragDataShader);
glBindFragDataLocationEXT(program_, 0, "FragData");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragData");
LinkProgram();
DrawAndVerify();
}
TEST_P(EXTBlendFuncExtendedES3DrawTest, ESSL3BindSimpleVarAsArrayNoBind) {
if (!IsApplicable())
return;
// clang-format off
static const char* kFragDataShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData;
out vec4 SecondaryFragData;
void main() {
FragData = src;
SecondaryFragData = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragDataShader);
glBindFragDataLocationEXT(program_, 0, "FragData[0]");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragData[0]");
// Does not fail, since FragData[0] and SecondaryFragData[0] do not exist.
EXPECT_TRUE(LinkProgram());
EXPECT_EQ(-1, glGetFragDataLocation(program_, "FragData[0]"));
EXPECT_EQ(0, glGetFragDataLocation(program_, "FragData"));
EXPECT_EQ(1, glGetFragDataLocation(program_, "SecondaryFragData"));
// Did not bind index.
EXPECT_EQ(0, glGetFragDataIndexEXT(program_, "SecondaryFragData"));
glBindFragDataLocationEXT(program_, 0, "FragData");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragData");
EXPECT_TRUE(LinkProgram());
DrawAndVerify();
}
TEST_P(EXTBlendFuncExtendedES3DrawTest, ESSL3BindArrayAsArray) {
if (!IsApplicable())
return;
// Fails on the Intel Mesa driver, see
// https://bugs.freedesktop.org/show_bug.cgi?id=96765
gpu::GPUTestBotConfig bot_config;
if (bot_config.LoadCurrentConfig(nullptr) &&
bot_config.Matches("linux intel")) {
return;
}
// clang-format off
static const char* kFragDataShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData[1];
out vec4 SecondaryFragData[1];
void main() {
FragData[0] = src;
SecondaryFragData[0] = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragDataShader);
glBindFragDataLocationEXT(program_, 0, "FragData[0]");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragData[0]");
LinkProgram();
DrawAndVerify();
}
TEST_P(EXTBlendFuncExtendedES3DrawTest, ES3Getters) {
if (!IsApplicable())
return;
// clang-format off
static const char* kFragColorShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragColor;
out vec4 SecondaryFragColor;
void main() {
FragColor = src;
SecondaryFragColor = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
glBindFragDataLocationEXT(program_, 0, "FragColor");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragColor");
// Getters return GL error before linking.
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
GLint location = glGetFragDataLocation(program_, "FragColor");
EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
GLint index = glGetFragDataIndexEXT(program_, "FragColor");
EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
location = glGetFragDataLocation(program_, "SecondaryFragColor");
EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
index = glGetFragDataIndexEXT(program_, "SecondaryFragColor");
EXPECT_EQ(static_cast<GLenum>(GL_INVALID_OPERATION), glGetError());
LinkProgram();
// Getters return location and index after linking. Run twice to confirm that
// setters do not affect the getters until next link.
for (int i = 0; i < 2; ++i) {
SCOPED_TRACE(testing::Message() << "Testing getters after link, iteration "
<< i);
location = glGetFragDataLocation(program_, "FragColor");
EXPECT_EQ(0, location);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
index = glGetFragDataIndexEXT(program_, "FragColor");
EXPECT_EQ(0, index);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
location = glGetFragDataLocation(program_, "SecondaryFragColor");
EXPECT_EQ(0, location);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
index = glGetFragDataIndexEXT(program_, "SecondaryFragColor");
EXPECT_EQ(1, index);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
// The calls should not affect the getters until re-linking.
glBindFragDataLocationEXT(program_, 0, "SecondaryFragColor");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "FragColor");
}
LinkProgram();
location = glGetFragDataLocation(program_, "FragColor");
EXPECT_EQ(0, location);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
index = glGetFragDataIndexEXT(program_, "FragColor");
EXPECT_EQ(1, index);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
location = glGetFragDataLocation(program_, "SecondaryFragColor");
EXPECT_EQ(0, location);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
index = glGetFragDataIndexEXT(program_, "SecondaryFragColor");
EXPECT_EQ(0, index);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
// Unknown colors return location -1, index -1.
location = glGetFragDataLocation(program_, "UnknownColor");
EXPECT_EQ(-1, location);
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
index = glGetFragDataIndexEXT(program_, "UnknownColor");
EXPECT_EQ(-1, index);
// Reset the settings and verify that the driver gets them correct.
glBindFragDataLocationEXT(program_, 0, "FragColor");
glBindFragDataLocationIndexedEXT(program_, 0, 1, "SecondaryFragColor");
LinkProgram();
DrawAndVerify();
}
// Test that tests glBindFragDataLocationEXT, glBindFragDataLocationIndexedEXT,
// glGetFragDataLocation, glGetFragDataIndexEXT work correctly with
// GLSL array output variables. The output variable can be bound by
// referring to the variable name with or without the first element array
// accessor. The getters can query location of the individual elements in
// the array. The test does not actually use the base test drawing,
// since the drivers at the time of writing do not support multiple
// buffers and dual source blending.
TEST_P(EXTBlendFuncExtendedES3DrawTest, ES3GettersArray) {
if (!IsApplicable())
return;
// TODO(zmo): Figure out why this fails on AMD. crbug.com/585132.
// Also fails on the Intel Mesa driver, see
// https://bugs.freedesktop.org/show_bug.cgi?id=96765
gpu::GPUTestBotConfig bot_config;
if (bot_config.LoadCurrentConfig(nullptr) &&
(bot_config.Matches("linux amd") ||
bot_config.Matches("linux intel"))) {
return;
}
const GLint kTestArraySize = 2;
const GLint kFragData0Location = 2;
const GLint kFragData1Location = 1;
const GLint kUnusedLocation = 5;
// The test binds kTestArraySize -sized array to location 1 for test purposes.
// The GL_MAX_DRAW_BUFFERS must be > kTestArraySize, since an
// array will be bound to continuous locations, starting from the first
// location.
GLint maxDrawBuffers = 0;
glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers);
EXPECT_LT(kTestArraySize, maxDrawBuffers);
// clang-format off
static const char* kFragColorShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData[2];
void main() {
FragData[0] = src;
FragData[1] = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
for (int testcase = 0; testcase < 4; ++testcase) {
if (testcase == 0) {
glBindFragDataLocationEXT(program_, kUnusedLocation, "FragData[0]");
glBindFragDataLocationEXT(program_, kFragData0Location, "FragData");
glBindFragDataLocationEXT(program_, kFragData1Location, "FragData[1]");
} else if (testcase == 1) {
glBindFragDataLocationEXT(program_, kUnusedLocation, "FragData");
glBindFragDataLocationEXT(program_, kFragData0Location, "FragData[0]");
glBindFragDataLocationEXT(program_, kFragData1Location, "FragData[1]");
} else if (testcase == 2) {
glBindFragDataLocationIndexedEXT(program_, kUnusedLocation, 0,
"FragData[0]");
glBindFragDataLocationIndexedEXT(program_, kFragData0Location, 0,
"FragData");
glBindFragDataLocationIndexedEXT(program_, kFragData1Location, 0,
"FragData[1]");
} else if (testcase == 3) {
glBindFragDataLocationIndexedEXT(program_, kUnusedLocation, 0,
"FragData");
glBindFragDataLocationIndexedEXT(program_, kFragData0Location, 0,
"FragData[0]");
glBindFragDataLocationIndexedEXT(program_, kFragData1Location, 0,
"FragData[1]");
}
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
LinkProgram();
EXPECT_EQ(kFragData0Location, glGetFragDataLocation(program_, "FragData"));
EXPECT_EQ(0, glGetFragDataIndexEXT(program_, "FragData"));
EXPECT_EQ(kFragData0Location,
glGetFragDataLocation(program_, "FragData[0]"));
EXPECT_EQ(0, glGetFragDataIndexEXT(program_, "FragData[0]"));
EXPECT_EQ(kFragData1Location,
glGetFragDataLocation(program_, "FragData[1]"));
EXPECT_EQ(0, glGetFragDataIndexEXT(program_, "FragData[1]"));
// Index bigger than the GLSL variable array length does not find anything.
EXPECT_EQ(-1, glGetFragDataLocation(program_, "FragData[3]"));
}
}
// Test that tests glBindFragDataLocationEXT, glBindFragDataLocationIndexedEXT
// conflicts
// with GLSL output variables.
TEST_P(EXTBlendFuncExtendedES3DrawTest, ES3Conflicts) {
if (!IsApplicable())
return;
const GLint kTestArraySize = 2;
const GLint kColorName0Location = 0;
const GLint kColorName1Location = 1;
GLint maxDrawBuffers = 0;
glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers);
EXPECT_LT(kTestArraySize, maxDrawBuffers);
// clang-format off
static const char* kFragColorShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData0;
out vec4 FragData1;
void main() {
FragData0 = src;
FragData1 = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
glBindFragDataLocationEXT(program_, kColorName0Location, "FragData0");
glBindFragDataLocationEXT(program_, kColorName0Location, "FragData1");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_FALSE(LinkProgram());
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 0,
"FragData0");
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 0,
"FragData1");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_FALSE(LinkProgram());
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 1,
"FragData0");
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 1,
"FragData1");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_FALSE(LinkProgram());
// Test that correct binding actually works.
glBindFragDataLocationEXT(program_, kColorName0Location, "FragData0");
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData1");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_TRUE(LinkProgram());
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 0,
"FragData0");
glBindFragDataLocationIndexedEXT(program_, kColorName0Location, 1,
"FragData1");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_TRUE(LinkProgram());
}
// Test that tests glBindFragDataLocationEXT conflicts
// with GLSL array output variables.
TEST_P(EXTBlendFuncExtendedES3DrawTest, ES3ConflictsArray) {
if (!IsApplicable())
return;
const GLint kTestArraySize = 2;
const GLint kColorName0Location = 0;
const GLint kColorName1Location = 1;
const GLint kUnusedLocation = 5;
GLint maxDrawBuffers = 0;
glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &maxDrawBuffers);
EXPECT_LT(kTestArraySize, maxDrawBuffers);
// clang-format off
static const char* kFragColorShader =
"#version 300 es\n"
BFE_SHADER(
precision mediump float;
uniform vec4 src;
uniform vec4 src1;
out vec4 FragData[2];
void main() {
FragData[0] = src;
FragData[1] = src1;
});
// clang-format on
CreateProgramWithFragmentShader(kFragColorShader);
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData");
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData[1]");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_FALSE(LinkProgram());
glBindFragDataLocationEXT(program_, kUnusedLocation, "FragData");
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData[0]");
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData[1]");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_FALSE(LinkProgram());
// Test that binding actually works.
glBindFragDataLocationEXT(program_, kColorName0Location, "FragData[0]");
glBindFragDataLocationEXT(program_, kColorName1Location, "FragData[1]");
EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
EXPECT_TRUE(LinkProgram());
}
INSTANTIATE_TEST_SUITE_P(TranslatorVariants,
EXTBlendFuncExtendedDrawTest,
::testing::Bool());
INSTANTIATE_TEST_SUITE_P(TranslatorVariants,
EXTBlendFuncExtendedES3DrawTest,
::testing::Bool());
} // namespace gpu