-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathes3fClippingTests.cpp
2328 lines (1983 loc) · 107 KB
/
es3fClippingTests.cpp
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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------------------------------------------------------------
* drawElements Quality Program OpenGL ES 3.0 Module
* -------------------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Clipping tests.
*//*--------------------------------------------------------------------*/
#include "es3fClippingTests.hpp"
#include "tcuRenderTarget.hpp"
#include "tcuTextureUtil.hpp"
#include "tcuImageCompare.hpp"
#include "tcuVectorUtil.hpp"
#include "deStringUtil.hpp"
#include "deRandom.hpp"
#include "sglrReferenceContext.hpp"
#include "sglrGLContext.hpp"
#include "glwEnums.hpp"
#include "glwDefs.hpp"
#include "glwFunctions.hpp"
using namespace glw; // GLint and other GL types
namespace deqp
{
namespace gles3
{
namespace Functional
{
namespace
{
using tcu::ConstPixelBufferAccess;
using tcu::PixelBufferAccess;
using tcu::TestLog;
static const tcu::Vec4 MASK_COLOR_OK = tcu::Vec4(0.0f, 0.1f, 0.0f, 1.0f);
static const tcu::Vec4 MASK_COLOR_DEV = tcu::Vec4(0.8f, 0.5f, 0.0f, 1.0f);
static const tcu::Vec4 MASK_COLOR_FAIL = tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f);
const int TEST_CANVAS_SIZE = 200;
const rr::WindowRectangle VIEWPORT_WHOLE(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
const rr::WindowRectangle VIEWPORT_CENTER(TEST_CANVAS_SIZE / 4, TEST_CANVAS_SIZE / 4, TEST_CANVAS_SIZE / 2,
TEST_CANVAS_SIZE / 2);
const rr::WindowRectangle VIEWPORT_CORNER(TEST_CANVAS_SIZE / 2, TEST_CANVAS_SIZE / 2, TEST_CANVAS_SIZE / 2,
TEST_CANVAS_SIZE / 2);
const char *shaderSourceVertex = "#version 300 es\n"
"in highp vec4 a_position;\n"
"in highp vec4 a_color;\n"
"in highp float a_pointSize;\n"
"out highp vec4 varFragColor;\n"
"void main (void)\n"
"{\n"
" gl_Position = a_position;\n"
" gl_PointSize = a_pointSize;\n"
" varFragColor = a_color;\n"
"}\n";
const char *shaderSourceFragment = "#version 300 es\n"
"layout(location = 0) out mediump vec4 fragColor;"
"in highp vec4 varFragColor;\n"
"void main (void)\n"
"{\n"
" fragColor = varFragColor;\n"
"}\n";
inline bool isBlack(const tcu::IVec4 &a)
{
return a.x() == 0 && a.y() == 0 && a.z() == 0;
}
inline bool isHalfFilled(const tcu::IVec4 &a)
{
const tcu::IVec4 halfFilled(127, 0, 0, 0);
const tcu::IVec4 threshold(20, 256, 256, 256);
return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - halfFilled), threshold));
}
inline bool isLessThanHalfFilled(const tcu::IVec4 &a)
{
const int halfFilled = 127;
const int threshold = 20;
return a.x() + threshold < halfFilled;
}
inline bool compareBlackNonBlackPixels(const tcu::IVec4 &a, const tcu::IVec4 &b)
{
return isBlack(a) == isBlack(b);
}
inline bool compareColoredPixels(const tcu::IVec4 &a, const tcu::IVec4 &b)
{
const bool aIsBlack = isBlack(a);
const bool bIsBlack = isBlack(b);
const tcu::IVec4 threshold(20, 20, 20, 0);
if (aIsBlack && bIsBlack)
return true;
if (aIsBlack != bIsBlack)
return false;
return tcu::boolAll(tcu::lessThanEqual(tcu::abs(a - b), threshold));
}
void blitImageOnBlackSurface(const ConstPixelBufferAccess &src, const PixelBufferAccess &dst)
{
const int height = src.getHeight();
const int width = src.getWidth();
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
const tcu::IVec4 cSrc = src.getPixelInt(x, y);
const tcu::IVec4 cDst = tcu::IVec4(cSrc.x(), cSrc.y(), cSrc.z(), 255);
dst.setPixel(cDst, x, y);
}
}
/*--------------------------------------------------------------------*//*!
* \brief Pixelwise comparison of two images.
* \note copied & modified from glsRasterizationTests
*
* Kernel radius defines maximum allowed distance. If radius is 0, only
* perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
* equal if pixelCmp returns true..
*
* Return values: -1 = Perfect match
* 0 = Deviation within kernel
* >0 = Number of faulty pixels
*//*--------------------------------------------------------------------*/
inline int compareImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
const PixelBufferAccess &diffMask, int kernelRadius,
bool (*pixelCmp)(const tcu::IVec4 &a, const tcu::IVec4 &b))
{
const int height = test.getHeight();
const int width = test.getWidth();
int deviatingPixels = 0;
int faultyPixels = 0;
int compareFailed = -1;
tcu::clear(diffMask, MASK_COLOR_OK);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
const tcu::IVec4 cRef = ref.getPixelInt(x, y);
const tcu::IVec4 cTest = test.getPixelInt(x, y);
// Pixelwise match, no deviation or fault
if ((*pixelCmp)(cRef, cTest))
continue;
// Deviation
{
const int radius = kernelRadius;
bool foundRef = false;
bool foundTest = false;
// edges are considered a "deviation" too. The suitable pixel could be "behind" the edge
if (y < radius || x < radius || y + radius >= height || x + radius >= width)
{
foundRef = true;
foundTest = true;
}
else
{
// find ref
for (int kY = y - radius; kY <= y + radius; kY++)
for (int kX = x - radius; kX <= x + radius; kX++)
{
if ((*pixelCmp)(cRef, test.getPixelInt(kX, kY)))
{
foundRef = true;
break;
}
}
// find result
for (int kY = y - radius; kY <= y + radius; kY++)
for (int kX = x - radius; kX <= x + radius; kX++)
{
if ((*pixelCmp)(cTest, ref.getPixelInt(kX, kY)))
{
foundTest = true;
break;
}
}
}
// A pixel is deviating if the reference color is found inside the kernel and (~= every pixel reference draws must be drawn by the gl too)
// the result color is found in the reference image inside the kernel (~= every pixel gl draws must be drawn by the reference too)
if (foundRef && foundTest)
{
diffMask.setPixel(MASK_COLOR_DEV, x, y);
if (compareFailed == -1)
compareFailed = 0;
deviatingPixels++;
continue;
}
}
diffMask.setPixel(MASK_COLOR_FAIL, x, y);
faultyPixels++; // The pixel is faulty if the color is not found
compareFailed = 1;
}
}
log << TestLog::Message << deviatingPixels << " deviating pixel(s) found." << TestLog::EndMessage;
log << TestLog::Message << faultyPixels << " faulty pixel(s) found." << TestLog::EndMessage;
return (compareFailed == 1 ? faultyPixels : compareFailed);
}
/*--------------------------------------------------------------------*//*!
* \brief Pixelwise comparison of two images.
*
* Kernel radius defines maximum allowed distance. If radius is 0, only
* perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
* equal if they both are black, or both are non-black.
*
* Return values: -1 = Perfect match
* 0 = Deviation within kernel
* >0 = Number of faulty pixels
*//*--------------------------------------------------------------------*/
int compareBlackNonBlackImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
const PixelBufferAccess &diffMask, int kernelRadius)
{
return compareImages(log, test, ref, diffMask, kernelRadius, compareBlackNonBlackPixels);
}
/*--------------------------------------------------------------------*//*!
* \brief Pixelwise comparison of two images.
*
* Kernel radius defines maximum allowed distance. If radius is 0, only
* perfect match is allowed. Radius of 1 gives a 3x3 kernel. Pixels are
* equal if they both are black, or both are non-black with color values
* close to each other.
*
* Return values: -1 = Perfect match
* 0 = Deviation within kernel
* >0 = Number of faulty pixels
*//*--------------------------------------------------------------------*/
int compareColoredImages(tcu::TestLog &log, const ConstPixelBufferAccess &test, const ConstPixelBufferAccess &ref,
const PixelBufferAccess &diffMask, int kernelRadius)
{
return compareImages(log, test, ref, diffMask, kernelRadius, compareColoredPixels);
}
/*--------------------------------------------------------------------*//*!
* \brief Overdraw check verification
*
* Check that image does not have at any point a
* pixel with red component value > 0.5
*
* Return values: false = area not filled, or leaking
*//*--------------------------------------------------------------------*/
bool checkHalfFilledImageOverdraw(tcu::TestLog &log, const tcu::RenderTarget &m_renderTarget,
const ConstPixelBufferAccess &image, const PixelBufferAccess &output)
{
const int height = image.getHeight();
const int width = image.getWidth();
bool faulty = false;
tcu::clear(output, MASK_COLOR_OK);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
const tcu::IVec4 cTest = image.getPixelInt(x, y);
const bool pixelValid = isBlack(cTest) || isHalfFilled(cTest) ||
(m_renderTarget.getNumSamples() > 1 && isLessThanHalfFilled(cTest));
if (!pixelValid)
{
output.setPixel(MASK_COLOR_FAIL, x, y);
faulty = true;
}
}
}
if (faulty)
log << TestLog::Message << "Faulty pixel(s) found." << TestLog::EndMessage;
return !faulty;
}
void checkPointSize(const glw::Functions &gl, float pointSize)
{
GLfloat pointSizeRange[2] = {0, 0};
gl.getFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
if (pointSizeRange[1] < pointSize)
throw tcu::NotSupportedError("Maximum point size is too low for this test");
}
void checkLineWidth(const glw::Functions &gl, float lineWidth)
{
GLfloat lineWidthRange[2] = {0, 0};
gl.getFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange);
if (lineWidthRange[1] < lineWidth)
throw tcu::NotSupportedError("Maximum line width is too low for this test");
}
tcu::Vec3 IVec3ToVec3(const tcu::IVec3 &v)
{
return tcu::Vec3((float)v.x(), (float)v.y(), (float)v.z());
}
bool pointOnTriangle(const tcu::IVec3 &p, const tcu::IVec3 &t0, const tcu::IVec3 &t1, const tcu::IVec3 &t2)
{
// Must be on the plane
const tcu::IVec3 n = tcu::cross(t1 - t0, t2 - t0);
const tcu::IVec3 d = (p - t0);
if (tcu::dot(n, d))
return false;
// Must be within the triangle area
if (deSign32(tcu::dot(n, tcu::cross(t1 - t0, p - t0))) == deSign32(tcu::dot(n, tcu::cross(t2 - t0, p - t0))))
return false;
if (deSign32(tcu::dot(n, tcu::cross(t2 - t1, p - t1))) == deSign32(tcu::dot(n, tcu::cross(t0 - t1, p - t1))))
return false;
if (deSign32(tcu::dot(n, tcu::cross(t0 - t2, p - t2))) == deSign32(tcu::dot(n, tcu::cross(t1 - t2, p - t2))))
return false;
return true;
}
bool pointsOnLine(const tcu::IVec2 &t0, const tcu::IVec2 &t1, const tcu::IVec2 &t2)
{
return (t1 - t0).x() * (t2 - t0).y() - (t2 - t0).x() * (t1 - t0).y() == 0;
}
// returns true for cases where polygon is (almost) along xz or yz planes (normal.z < 0.1)
// \note[jarkko] Doesn't have to be accurate, just to detect some obviously bad cases
bool twoPointClippedTriangleInvisible(const tcu::Vec3 &p, const tcu::IVec3 &dir1, const tcu::IVec3 &dir2)
{
// fixed-point-like coords
const int64_t fixedScale = 64;
const int64_t farValue = 1024;
const tcu::Vector<int64_t, 3> d1 = tcu::Vector<int64_t, 3>(dir1.x(), dir1.y(), dir1.z());
const tcu::Vector<int64_t, 3> d2 = tcu::Vector<int64_t, 3>(dir2.x(), dir2.y(), dir2.z());
const tcu::Vector<int64_t, 3> pfixed =
tcu::Vector<int64_t, 3>(deFloorFloatToInt32(p.x() * fixedScale), deFloorFloatToInt32(p.y() * fixedScale),
deFloorFloatToInt32(p.z() * fixedScale));
const tcu::Vector<int64_t, 3> normalDir = tcu::cross(d1 * farValue - pfixed, d2 * farValue - pfixed);
const int64_t normalLen2 = tcu::lengthSquared(normalDir);
return (normalDir.z() * normalDir.z() - normalLen2 / 100) < 0;
}
std::string genClippingPointInfoString(const tcu::Vec4 &p)
{
std::ostringstream msg;
if (p.x() < -p.w())
msg << "\t(-X clip)";
if (p.x() > p.w())
msg << "\t(+X clip)";
if (p.y() < -p.w())
msg << "\t(-Y clip)";
if (p.y() > p.w())
msg << "\t(+Y clip)";
if (p.z() < -p.w())
msg << "\t(-Z clip)";
if (p.z() > p.w())
msg << "\t(+Z clip)";
return msg.str();
}
std::string genColorString(const tcu::Vec4 &p)
{
const tcu::Vec4 white(1.0f, 1.0f, 1.0f, 1.0f);
const tcu::Vec4 red(1.0f, 0.0f, 0.0f, 1.0f);
const tcu::Vec4 yellow(1.0f, 1.0f, 0.0f, 1.0f);
const tcu::Vec4 blue(0.0f, 0.0f, 1.0f, 1.0f);
if (p == white)
return "(white)";
if (p == red)
return "(red)";
if (p == yellow)
return "(yellow)";
if (p == blue)
return "(blue)";
return "";
}
class PositionColorShader : public sglr::ShaderProgram
{
public:
enum
{
VARYINGLOC_COLOR = 0
};
PositionColorShader(void);
void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
const rr::FragmentShadingContext &context) const;
};
PositionColorShader::PositionColorShader(void)
: sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
<< sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
<< sglr::pdec::VertexAttribute("a_color", rr::GENERICVECTYPE_FLOAT)
<< sglr::pdec::VertexAttribute("a_pointSize", rr::GENERICVECTYPE_FLOAT)
<< sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
<< sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
<< sglr::pdec::VertexSource(shaderSourceVertex)
<< sglr::pdec::FragmentSource(shaderSourceFragment))
{
}
void PositionColorShader::shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets,
const int numPackets) const
{
for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
{
const int positionAttrLoc = 0;
const int colorAttrLoc = 1;
const int pointSizeAttrLoc = 2;
rr::VertexPacket &packet = *packets[packetNdx];
// Transform to position
packet.position = rr::readVertexAttribFloat(inputs[positionAttrLoc], packet.instanceNdx, packet.vertexNdx);
// output point size
packet.pointSize =
rr::readVertexAttribFloat(inputs[pointSizeAttrLoc], packet.instanceNdx, packet.vertexNdx).x();
// Pass color to FS
packet.outputs[VARYINGLOC_COLOR] =
rr::readVertexAttribFloat(inputs[colorAttrLoc], packet.instanceNdx, packet.vertexNdx);
}
}
void PositionColorShader::shadeFragments(rr::FragmentPacket *packets, const int numPackets,
const rr::FragmentShadingContext &context) const
{
for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
{
rr::FragmentPacket &packet = packets[packetNdx];
for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
rr::writeFragmentOutput(context, packetNdx, fragNdx, 0,
rr::readVarying<float>(packet, context, VARYINGLOC_COLOR, fragNdx));
}
}
class RenderTestCase : public TestCase
{
public:
RenderTestCase(Context &context, const char *name, const char *description);
virtual void testRender(void) = 0;
virtual void init(void)
{
}
IterateResult iterate(void);
};
RenderTestCase::RenderTestCase(Context &context, const char *name, const char *description)
: TestCase(context, name, description)
{
}
RenderTestCase::IterateResult RenderTestCase::iterate(void)
{
const int width = m_context.getRenderTarget().getWidth();
const int height = m_context.getRenderTarget().getHeight();
m_testCtx.getLog() << TestLog::Message << "Render target size: " << width << "x" << height << TestLog::EndMessage;
if (width < TEST_CANVAS_SIZE || height < TEST_CANVAS_SIZE)
throw tcu::NotSupportedError(std::string("Render target size must be at least ") +
de::toString(TEST_CANVAS_SIZE) + "x" + de::toString(TEST_CANVAS_SIZE));
m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); // success by default
testRender();
return STOP;
}
class PointCase : public RenderTestCase
{
public:
PointCase(Context &context, const char *name, const char *description, const tcu::Vec4 *pointsBegin,
const tcu::Vec4 *pointsEnd, float pointSize, const rr::WindowRectangle &viewport);
void init(void);
void testRender(void);
private:
const std::vector<tcu::Vec4> m_points;
const float m_pointSize;
const rr::WindowRectangle m_viewport;
};
PointCase::PointCase(Context &context, const char *name, const char *description, const tcu::Vec4 *pointsBegin,
const tcu::Vec4 *pointsEnd, float pointSize, const rr::WindowRectangle &viewport)
: RenderTestCase(context, name, description)
, m_points(pointsBegin, pointsEnd)
, m_pointSize(pointSize)
, m_viewport(viewport)
{
}
void PointCase::init(void)
{
const glw::Functions &gl = m_context.getRenderContext().getFunctions();
checkPointSize(gl, m_pointSize);
}
void PointCase::testRender(void)
{
using tcu::TestLog;
const int numSamples = de::max(m_context.getRenderTarget().getNumSamples(), 1);
tcu::TestLog &log = m_testCtx.getLog();
sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
sglr::ReferenceContextLimits limits;
sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
TEST_CANVAS_SIZE, numSamples);
sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
buffers.getStencilbuffer());
PositionColorShader program;
tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
sglr::Context *contexts[2] = {&glesContext, &refContext};
tcu::Surface *surfaces[2] = {&testSurface, &refSurface};
// log the purpose of the test
log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
<< "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
log << TestLog::Message << "Rendering points with point size " << m_pointSize
<< ". Coordinates:" << TestLog::EndMessage;
for (size_t ndx = 0; ndx < m_points.size(); ++ndx)
log << TestLog::Message << "\tx=" << m_points[ndx].x() << "\ty=" << m_points[ndx].y()
<< "\tz=" << m_points[ndx].z() << "\tw=" << m_points[ndx].w() << "\t"
<< genClippingPointInfoString(m_points[ndx]) << TestLog::EndMessage;
for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
{
sglr::Context &ctx = *contexts[contextNdx];
tcu::Surface &dstSurface = *surfaces[contextNdx];
const uint32_t programId = ctx.createProgram(&program);
const GLint positionLoc = ctx.getAttribLocation(programId, "a_position");
const GLint pointSizeLoc = ctx.getAttribLocation(programId, "a_pointSize");
const GLint colorLoc = ctx.getAttribLocation(programId, "a_color");
ctx.clearColor(0, 0, 0, 1);
ctx.clearDepthf(1.0f);
ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
ctx.useProgram(programId);
ctx.enableVertexAttribArray(positionLoc);
ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, &m_points[0]);
ctx.vertexAttrib1f(pointSizeLoc, m_pointSize);
ctx.vertexAttrib4f(colorLoc, 1.0f, 1.0f, 1.0f, 1.0f);
ctx.drawArrays(GL_POINTS, 0, (glw::GLsizei)m_points.size());
ctx.disableVertexAttribArray(positionLoc);
ctx.useProgram(0);
ctx.deleteProgram(programId);
ctx.finish();
ctx.readPixels(dstSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
}
// do the comparison
{
tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
const int kernelRadius = 1;
int faultyPixels;
log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
<< TestLog::EndMessage;
faultyPixels = compareBlackNonBlackImages(log, testSurface.getAccess(), refSurface.getAccess(),
diffMask.getAccess(), kernelRadius);
if (faultyPixels > 0)
{
log << TestLog::ImageSet("Images", "Image comparison")
<< TestLog::Image("TestImage", "Test image", testSurface.getAccess())
<< TestLog::Image("ReferenceImage", "Reference image", refSurface.getAccess())
<< TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
<< tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
}
}
}
class LineRenderTestCase : public RenderTestCase
{
public:
struct ColoredLineData
{
tcu::Vec4 p0;
tcu::Vec4 c0;
tcu::Vec4 p1;
tcu::Vec4 c1;
};
struct ColorlessLineData
{
tcu::Vec4 p0;
tcu::Vec4 p1;
};
LineRenderTestCase(Context &context, const char *name, const char *description, const ColoredLineData *linesBegin,
const ColoredLineData *linesEnd, float lineWidth, const rr::WindowRectangle &viewport);
LineRenderTestCase(Context &context, const char *name, const char *description, const ColorlessLineData *linesBegin,
const ColorlessLineData *linesEnd, float lineWidth, const rr::WindowRectangle &viewport);
virtual void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess) = 0;
void init(void);
void testRender(void);
protected:
const float m_lineWidth;
private:
std::vector<ColoredLineData> convertToColoredLines(const ColorlessLineData *linesBegin,
const ColorlessLineData *linesEnd);
const std::vector<ColoredLineData> m_lines;
const rr::WindowRectangle m_viewport;
};
LineRenderTestCase::LineRenderTestCase(Context &context, const char *name, const char *description,
const ColoredLineData *linesBegin, const ColoredLineData *linesEnd,
float lineWidth, const rr::WindowRectangle &viewport)
: RenderTestCase(context, name, description)
, m_lineWidth(lineWidth)
, m_lines(linesBegin, linesEnd)
, m_viewport(viewport)
{
}
LineRenderTestCase::LineRenderTestCase(Context &context, const char *name, const char *description,
const ColorlessLineData *linesBegin, const ColorlessLineData *linesEnd,
float lineWidth, const rr::WindowRectangle &viewport)
: RenderTestCase(context, name, description)
, m_lineWidth(lineWidth)
, m_lines(convertToColoredLines(linesBegin, linesEnd))
, m_viewport(viewport)
{
}
void LineRenderTestCase::init(void)
{
const glw::Functions &gl = m_context.getRenderContext().getFunctions();
checkLineWidth(gl, m_lineWidth);
}
void LineRenderTestCase::testRender(void)
{
using tcu::TestLog;
const int numSamples = de::max(m_context.getRenderTarget().getNumSamples(), 1);
const int verticesPerLine = 2;
tcu::TestLog &log = m_testCtx.getLog();
sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
sglr::ReferenceContextLimits limits;
sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
TEST_CANVAS_SIZE, numSamples);
sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
buffers.getStencilbuffer());
PositionColorShader program;
tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
sglr::Context *contexts[2] = {&glesContext, &refContext};
tcu::Surface *surfaces[2] = {&testSurface, &refSurface};
// log the purpose of the test
log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
<< "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
log << TestLog::Message << "Rendering lines with line width " << m_lineWidth
<< ". Coordinates:" << TestLog::EndMessage;
for (size_t ndx = 0; ndx < m_lines.size(); ++ndx)
{
const std::string fromProperties = genClippingPointInfoString(m_lines[ndx].p0);
const std::string toProperties = genClippingPointInfoString(m_lines[ndx].p1);
log << TestLog::Message << "\tfrom (x=" << m_lines[ndx].p0.x() << "\ty=" << m_lines[ndx].p0.y()
<< "\tz=" << m_lines[ndx].p0.z() << "\tw=" << m_lines[ndx].p0.w() << ")\t" << fromProperties
<< TestLog::EndMessage;
log << TestLog::Message << "\tto (x=" << m_lines[ndx].p1.x() << "\ty=" << m_lines[ndx].p1.y()
<< "\tz=" << m_lines[ndx].p1.z() << "\tw=" << m_lines[ndx].p1.w() << ")\t" << toProperties
<< TestLog::EndMessage;
log << TestLog::Message << TestLog::EndMessage;
}
// render test image
for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
{
sglr::Context &ctx = *contexts[contextNdx];
tcu::Surface &dstSurface = *surfaces[contextNdx];
const uint32_t programId = ctx.createProgram(&program);
const GLint positionLoc = ctx.getAttribLocation(programId, "a_position");
const GLint colorLoc = ctx.getAttribLocation(programId, "a_color");
ctx.clearColor(0, 0, 0, 1);
ctx.clearDepthf(1.0f);
ctx.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ctx.viewport(m_viewport.left, m_viewport.bottom, m_viewport.width, m_viewport.height);
ctx.useProgram(programId);
ctx.enableVertexAttribArray(positionLoc);
ctx.enableVertexAttribArray(colorLoc);
ctx.vertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_lines[0].p0);
ctx.vertexAttribPointer(colorLoc, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat[8]), &m_lines[0].c0);
ctx.lineWidth(m_lineWidth);
ctx.drawArrays(GL_LINES, 0, verticesPerLine * (glw::GLsizei)m_lines.size());
ctx.disableVertexAttribArray(positionLoc);
ctx.disableVertexAttribArray(colorLoc);
ctx.useProgram(0);
ctx.deleteProgram(programId);
ctx.finish();
ctx.readPixels(dstSurface, 0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
}
// compare
verifyImage(testSurface.getAccess(), refSurface.getAccess());
}
std::vector<LineRenderTestCase::ColoredLineData> LineRenderTestCase::convertToColoredLines(
const ColorlessLineData *linesBegin, const ColorlessLineData *linesEnd)
{
std::vector<ColoredLineData> ret;
for (const ColorlessLineData *it = linesBegin; it != linesEnd; ++it)
{
ColoredLineData r;
r.p0 = (*it).p0;
r.c0 = tcu::Vec4(1, 1, 1, 1);
r.p1 = (*it).p1;
r.c1 = tcu::Vec4(1, 1, 1, 1);
ret.push_back(r);
}
return ret;
}
class LineCase : public LineRenderTestCase
{
public:
LineCase(Context &context, const char *name, const char *description,
const LineRenderTestCase::ColorlessLineData *linesBegin,
const LineRenderTestCase::ColorlessLineData *linesEnd, float lineWidth,
const rr::WindowRectangle &viewport, int searchKernelSize = 1);
void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess);
private:
const int m_searchKernelSize;
};
LineCase::LineCase(Context &context, const char *name, const char *description,
const LineRenderTestCase::ColorlessLineData *linesBegin,
const LineRenderTestCase::ColorlessLineData *linesEnd, float lineWidth,
const rr::WindowRectangle &viewport, int searchKernelSize)
: LineRenderTestCase(context, name, description, linesBegin, linesEnd, lineWidth, viewport)
, m_searchKernelSize(searchKernelSize)
{
}
void LineCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess)
{
const int faultyLimit = 6;
int faultyPixels;
const bool isMsaa = m_context.getRenderTarget().getNumSamples() > 1;
tcu::TestLog &log = m_testCtx.getLog();
tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
log << TestLog::Message << "Deviation within radius of " << m_searchKernelSize << " is allowed."
<< TestLog::EndMessage;
log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
faultyPixels = compareBlackNonBlackImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(),
m_searchKernelSize);
if (faultyPixels > faultyLimit)
{
log << TestLog::ImageSet("Images", "Image comparison")
<< TestLog::Image("TestImage", "Test image", testImageAccess)
<< TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
<< TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
<< tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
if (m_lineWidth != 1.0f && isMsaa)
{
log << TestLog::Message << "Wide line support is optional, reporting compatibility warning."
<< TestLog::EndMessage;
m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Wide line clipping failed");
}
else
m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
}
}
class ColoredLineCase : public LineRenderTestCase
{
public:
ColoredLineCase(Context &context, const char *name, const char *description,
const LineRenderTestCase::ColoredLineData *linesBegin,
const LineRenderTestCase::ColoredLineData *linesEnd, float lineWidth,
const rr::WindowRectangle &viewport);
void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess);
};
ColoredLineCase::ColoredLineCase(Context &context, const char *name, const char *description,
const LineRenderTestCase::ColoredLineData *linesBegin,
const LineRenderTestCase::ColoredLineData *linesEnd, float lineWidth,
const rr::WindowRectangle &viewport)
: LineRenderTestCase(context, name, description, linesBegin, linesEnd, lineWidth, viewport)
{
}
void ColoredLineCase::verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess)
{
const bool msaa = m_context.getRenderTarget().getNumSamples() > 1;
tcu::TestLog &log = m_testCtx.getLog();
if (!msaa)
{
const int kernelRadius = 1;
const int faultyLimit = 6;
int faultyPixels;
tcu::Surface diffMask(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
log << TestLog::Message << "Comparing images... " << TestLog::EndMessage;
log << TestLog::Message << "Deviation within radius of " << kernelRadius << " is allowed."
<< TestLog::EndMessage;
log << TestLog::Message << faultyLimit << " faulty pixels are allowed." << TestLog::EndMessage;
faultyPixels =
compareColoredImages(log, testImageAccess, referenceImageAccess, diffMask.getAccess(), kernelRadius);
if (faultyPixels > faultyLimit)
{
log << TestLog::ImageSet("Images", "Image comparison")
<< TestLog::Image("TestImage", "Test image", testImageAccess)
<< TestLog::Image("ReferenceImage", "Reference image", referenceImageAccess)
<< TestLog::Image("DifferenceMask", "Difference mask", diffMask.getAccess()) << TestLog::EndImageSet
<< tcu::TestLog::Message << "Got " << faultyPixels << " faulty pixel(s)." << tcu::TestLog::EndMessage;
m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
}
}
else
{
const float threshold = 0.3f;
if (!tcu::fuzzyCompare(log, "Images", "", referenceImageAccess, testImageAccess, threshold,
tcu::COMPARE_LOG_ON_ERROR))
{
if (m_lineWidth != 1.0f)
{
log << TestLog::Message << "Wide line support is optional, reporting compatibility warning."
<< TestLog::EndMessage;
m_testCtx.setTestResult(QP_TEST_RESULT_COMPATIBILITY_WARNING, "Wide line clipping failed");
}
else
m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got faulty pixels");
}
}
}
class TriangleCaseBase : public RenderTestCase
{
public:
struct TriangleData
{
tcu::Vec4 p0;
tcu::Vec4 c0;
tcu::Vec4 p1;
tcu::Vec4 c1;
tcu::Vec4 p2;
tcu::Vec4 c2;
};
TriangleCaseBase(Context &context, const char *name, const char *description, const TriangleData *polysBegin,
const TriangleData *polysEnd, const rr::WindowRectangle &viewport);
virtual void verifyImage(const tcu::ConstPixelBufferAccess &testImageAccess,
const tcu::ConstPixelBufferAccess &referenceImageAccess) = 0;
void testRender(void);
private:
const std::vector<TriangleData> m_polys;
const rr::WindowRectangle m_viewport;
};
TriangleCaseBase::TriangleCaseBase(Context &context, const char *name, const char *description,
const TriangleData *polysBegin, const TriangleData *polysEnd,
const rr::WindowRectangle &viewport)
: RenderTestCase(context, name, description)
, m_polys(polysBegin, polysEnd)
, m_viewport(viewport)
{
}
void TriangleCaseBase::testRender(void)
{
using tcu::TestLog;
const int numSamples = de::max(m_context.getRenderTarget().getNumSamples(), 1);
const int verticesPerTriangle = 3;
tcu::TestLog &log = m_testCtx.getLog();
sglr::GLContext glesContext(m_context.getRenderContext(), log, 0,
tcu::IVec4(0, 0, TEST_CANVAS_SIZE, TEST_CANVAS_SIZE));
sglr::ReferenceContextLimits limits;
sglr::ReferenceContextBuffers buffers(m_context.getRenderTarget().getPixelFormat(),
m_context.getRenderTarget().getDepthBits(), 0, TEST_CANVAS_SIZE,
TEST_CANVAS_SIZE, numSamples);
sglr::ReferenceContext refContext(limits, buffers.getColorbuffer(), buffers.getDepthbuffer(),
buffers.getStencilbuffer());
PositionColorShader program;
tcu::Surface testSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
tcu::Surface refSurface(TEST_CANVAS_SIZE, TEST_CANVAS_SIZE);
sglr::Context *contexts[2] = {&glesContext, &refContext};
tcu::Surface *surfaces[2] = {&testSurface, &refSurface};
// log the purpose of the test
log << TestLog::Message << "Viewport: left=" << m_viewport.left << "\tbottom=" << m_viewport.bottom
<< "\twidth=" << m_viewport.width << "\theight=" << m_viewport.height << TestLog::EndMessage;
log << TestLog::Message << "Rendering triangles. Coordinates:" << TestLog::EndMessage;
for (size_t ndx = 0; ndx < m_polys.size(); ++ndx)
{
const std::string v0Properties = genClippingPointInfoString(m_polys[ndx].p0);
const std::string v1Properties = genClippingPointInfoString(m_polys[ndx].p1);
const std::string v2Properties = genClippingPointInfoString(m_polys[ndx].p2);
const std::string c0Properties = genColorString(m_polys[ndx].c0);
const std::string c1Properties = genColorString(m_polys[ndx].c1);
const std::string c2Properties = genColorString(m_polys[ndx].c2);
log << TestLog::Message << "\tv0 (x=" << m_polys[ndx].p0.x() << "\ty=" << m_polys[ndx].p0.y()
<< "\tz=" << m_polys[ndx].p0.z() << "\tw=" << m_polys[ndx].p0.w() << ")\t" << v0Properties << "\t"
<< c0Properties << TestLog::EndMessage;
log << TestLog::Message << "\tv1 (x=" << m_polys[ndx].p1.x() << "\ty=" << m_polys[ndx].p1.y()
<< "\tz=" << m_polys[ndx].p1.z() << "\tw=" << m_polys[ndx].p1.w() << ")\t" << v1Properties << "\t"
<< c1Properties << TestLog::EndMessage;
log << TestLog::Message << "\tv2 (x=" << m_polys[ndx].p2.x() << "\ty=" << m_polys[ndx].p2.y()
<< "\tz=" << m_polys[ndx].p2.z() << "\tw=" << m_polys[ndx].p2.w() << ")\t" << v2Properties << "\t"
<< c2Properties << TestLog::EndMessage;
log << TestLog::Message << TestLog::EndMessage;
}
// render test image
for (int contextNdx = 0; contextNdx < 2; ++contextNdx)
{
sglr::Context &ctx = *contexts[contextNdx];
tcu::Surface &dstSurface = *surfaces[contextNdx];
const uint32_t programId = ctx.createProgram(&program);