lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
/*-------------------------------------------------------------------------
 * drawElements Quality Program Tester Core
 * ----------------------------------------
 *
 * 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 Texture compare (shadow) result verifier.
 *//*--------------------------------------------------------------------*/
 
#include "tcuTexCompareVerifier.hpp"
#include "tcuTexVerifierUtil.hpp"
#include "tcuTextureUtil.hpp"
#include "tcuVectorUtil.hpp"
#include "deMath.h"
 
namespace tcu
{
 
using namespace TexVerifierUtil;
 
// Generic utilities
 
#if defined(DE_DEBUG)
static bool isSamplerSupported (const Sampler& sampler)
{
   return sampler.compare != Sampler::COMPAREMODE_NONE &&
          isWrapModeSupported(sampler.wrapS)            &&
          isWrapModeSupported(sampler.wrapT)            &&
          isWrapModeSupported(sampler.wrapR);
}
#endif // DE_DEBUG
 
struct CmpResultSet
{
   bool    isTrue;
   bool    isFalse;
 
   CmpResultSet (void)
       : isTrue    (false)
       , isFalse    (false)
   {
   }
};
 
static CmpResultSet execCompare (const Sampler::CompareMode    compareMode,
                                const float                cmpValue_,
                                const float                cmpReference_,
                                const int                    referenceBits,
                                const bool                    isFixedPoint)
{
   const bool        clampValues        = isFixedPoint;    // if comparing against a floating point texture, ref (and value) is not clamped
   const float        cmpValue        = (clampValues) ? (de::clamp(cmpValue_, 0.0f, 1.0f)) : (cmpValue_);
   const float        cmpReference    = (clampValues) ? (de::clamp(cmpReference_, 0.0f, 1.0f)) : (cmpReference_);
   const float        err                = computeFixedPointError(referenceBits);
   CmpResultSet    res;
 
   switch (compareMode)
   {
       case Sampler::COMPAREMODE_LESS:
           res.isTrue    = cmpReference-err < cmpValue;
           res.isFalse    = cmpReference+err >= cmpValue;
           break;
 
       case Sampler::COMPAREMODE_LESS_OR_EQUAL:
           res.isTrue    = cmpReference-err <= cmpValue;
           res.isFalse    = cmpReference+err > cmpValue;
           break;
 
       case Sampler::COMPAREMODE_GREATER:
           res.isTrue    = cmpReference+err > cmpValue;
           res.isFalse    = cmpReference-err <= cmpValue;
           break;
 
       case Sampler::COMPAREMODE_GREATER_OR_EQUAL:
           res.isTrue    = cmpReference+err >= cmpValue;
           res.isFalse    = cmpReference-err < cmpValue;
           break;
 
       case Sampler::COMPAREMODE_EQUAL:
           res.isTrue    = de::inRange(cmpValue, cmpReference-err, cmpReference+err);
           res.isFalse    = err != 0.0f || cmpValue != cmpReference;
           break;
 
       case Sampler::COMPAREMODE_NOT_EQUAL:
           res.isTrue    = err != 0.0f || cmpValue != cmpReference;
           res.isFalse    = de::inRange(cmpValue, cmpReference-err, cmpReference+err);
           break;
 
       case Sampler::COMPAREMODE_ALWAYS:
           res.isTrue    = true;
           break;
 
       case Sampler::COMPAREMODE_NEVER:
           res.isFalse    = true;
           break;
 
       default:
           DE_ASSERT(false);
   }
 
   DE_ASSERT(res.isTrue || res.isFalse);
   return res;
}
 
static inline bool isResultInSet (const CmpResultSet resultSet, const float result, const int resultBits)
{
   const float err        = computeFixedPointError(resultBits);
   const float    minR    = result-err;
   const float    maxR    = result+err;
 
   return (resultSet.isTrue    && de::inRange(1.0f, minR, maxR)) ||
          (resultSet.isFalse    && de::inRange(0.0f, minR, maxR));
}
 
static inline bool coordsInBounds (const ConstPixelBufferAccess& access, int x, int y, int z)
{
   return de::inBounds(x, 0, access.getWidth()) && de::inBounds(y, 0, access.getHeight()) && de::inBounds(z, 0, access.getDepth());
}
 
static float lookupDepth (const tcu::ConstPixelBufferAccess& access, const Sampler& sampler, int i, int j, int k)
{
   if (coordsInBounds(access, i, j, k))
       return access.getPixDepth(i, j, k);
   else
       return sampleTextureBorder<float>(access.getFormat(), sampler).x();
}
 
// lookup depth value at a point that is guaranteed to not sample border such as cube map faces.
static float lookupDepthNoBorder (const tcu::ConstPixelBufferAccess& access, const Sampler& sampler, int i, int j, int k = 0)
{
   DE_UNREF(sampler);
   DE_ASSERT(coordsInBounds(access, i, j, k));
   return access.getPixDepth(i, j, k);
}
 
// Values are in order (0,0), (1,0), (0,1), (1,1)
static float bilinearInterpolate (const Vec4& values, const float x, const float y)
{
   const float        v00        = values[0];
   const float        v10        = values[1];
   const float        v01        = values[2];
   const float        v11        = values[3];
   const float        res        = v00*(1.0f-x)*(1.0f-y) + v10*x*(1.0f-y) + v01*(1.0f-x)*y + v11*x*y;
   return res;
}
 
static bool isFixedPointDepthTextureFormat (const tcu::TextureFormat& format)
{
   const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
 
   if (format.order == TextureFormat::D)
   {
       // depth internal formats cannot be non-normalized integers
       return channelClass != tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
   }
   else if (format.order == TextureFormat::DS)
   {
       // combined formats have no single channel class, detect format manually
       switch (format.type)
       {
           case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:    return false;
           case tcu::TextureFormat::UNSIGNED_INT_16_8_8:            return true;
           case tcu::TextureFormat::UNSIGNED_INT_24_8:                return true;
           case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:            return true;
 
           default:
           {
               // unknown format
               DE_ASSERT(false);
               return true;
           }
       }
   }
 
   return false;
}
 
static bool isLinearCompareValid (const Sampler::CompareMode    compareMode,
                                 const TexComparePrecision&    prec,
                                 const Vec2&                    depths,
                                 const Vec2&                    fBounds,
                                 const float                    cmpReference,
                                 const float                    result,
                                 const bool                    isFixedPointDepth)
{
   DE_ASSERT(0.0f <= fBounds.x() && fBounds.x() <= fBounds.y() && fBounds.y() <= 1.0f);
 
   const float            d0            = depths[0];
   const float            d1            = depths[1];
 
   const CmpResultSet    cmp0        = execCompare(compareMode, d0, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp1        = execCompare(compareMode, d1, cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const deUint32        isTrue        = (deUint32(cmp0.isTrue)<<0)
                                   | (deUint32(cmp1.isTrue)<<1);
   const deUint32        isFalse        = (deUint32(cmp0.isFalse)<<0)
                                   | (deUint32(cmp1.isFalse)<<1);
 
   // Interpolation parameters
   const float            f0            = fBounds.x();
   const float            f1            = fBounds.y();
 
   // Error parameters
   const float            pcfErr        = computeFixedPointError(prec.pcfBits);
   const float            resErr        = computeFixedPointError(prec.resultBits);
   const float            totalErr    = pcfErr+resErr;
 
   // Iterate over all valid combinations.
   for (deUint32 comb = 0; comb < (1<<2); comb++)
   {
       // Filter out invalid combinations.
       if (((comb & isTrue) | (~comb & isFalse)) != (1<<2)-1)
           continue;
 
       const bool        cmp0True    = ((comb>>0)&1) != 0;
       const bool        cmp1True    = ((comb>>1)&1) != 0;
 
       const float        ref0        = cmp0True ? 1.0f : 0.0f;
       const float        ref1        = cmp1True ? 1.0f : 0.0f;
 
       const float        v0            = ref0*(1.0f-f0) + ref1*f0;
       const float        v1            = ref0*(1.0f-f1) + ref1*f1;
       const float        minV        = de::min(v0, v1);
       const float        maxV        = de::max(v0, v1);
       const float        minR        = minV-totalErr;
       const float        maxR        = maxV+totalErr;
 
       if (de::inRange(result, minR, maxR))
           return true;
   }
 
   return false;
}
 
static inline BVec4 extractBVec4 (const deUint32 val, int offset)
{
   return BVec4(((val>>(offset+0))&1) != 0,
                ((val>>(offset+1))&1) != 0,
                ((val>>(offset+2))&1) != 0,
                ((val>>(offset+3))&1) != 0);
}
 
static bool isBilinearAnyCompareValid (const Sampler::CompareMode    compareMode,
                                      const TexComparePrecision&    prec,
                                      const Vec4&                    depths,
                                      const float                    cmpReference,
                                      const float                    result,
                                      const bool                    isFixedPointDepth)
{
   DE_ASSERT(prec.pcfBits == 0);
 
   const float            d0            = depths[0];
   const float            d1            = depths[1];
   const float            d2            = depths[2];
   const float            d3            = depths[3];
 
   const CmpResultSet    cmp0        = execCompare(compareMode, d0, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp1        = execCompare(compareMode, d1, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp2        = execCompare(compareMode, d2, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp3        = execCompare(compareMode, d3, cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const bool            canBeTrue    = cmp0.isTrue || cmp1.isTrue || cmp2.isTrue || cmp3.isTrue;
   const bool            canBeFalse    = cmp0.isFalse || cmp1.isFalse || cmp2.isFalse || cmp3.isFalse;
 
   const float            resErr        = computeFixedPointError(prec.resultBits);
 
   const float            minBound    = canBeFalse ? 0.0f : 1.0f;
   const float            maxBound    = canBeTrue ? 1.0f : 0.0f;
 
   return de::inRange(result, minBound-resErr, maxBound+resErr);
}
 
static bool isBilinearPCFCompareValid (const Sampler::CompareMode    compareMode,
                                      const TexComparePrecision&    prec,
                                      const Vec4&                    depths,
                                      const Vec2&                    xBounds,
                                      const Vec2&                    yBounds,
                                      const float                    cmpReference,
                                      const float                    result,
                                      const bool                    isFixedPointDepth)
{
   DE_ASSERT(0.0f <= xBounds.x() && xBounds.x() <= xBounds.y() && xBounds.y() <= 1.0f);
   DE_ASSERT(0.0f <= yBounds.x() && yBounds.x() <= yBounds.y() && yBounds.y() <= 1.0f);
   DE_ASSERT(prec.pcfBits > 0);
 
   const float            d0            = depths[0];
   const float            d1            = depths[1];
   const float            d2            = depths[2];
   const float            d3            = depths[3];
 
   const CmpResultSet    cmp0        = execCompare(compareMode, d0, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp1        = execCompare(compareMode, d1, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp2        = execCompare(compareMode, d2, cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp3        = execCompare(compareMode, d3, cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const deUint32        isTrue        = (deUint32(cmp0.isTrue)<<0)
                                   | (deUint32(cmp1.isTrue)<<1)
                                   | (deUint32(cmp2.isTrue)<<2)
                                   | (deUint32(cmp3.isTrue)<<3);
   const deUint32        isFalse        = (deUint32(cmp0.isFalse)<<0)
                                   | (deUint32(cmp1.isFalse)<<1)
                                   | (deUint32(cmp2.isFalse)<<2)
                                   | (deUint32(cmp3.isFalse)<<3);
 
   // Interpolation parameters
   const float            x0            = xBounds.x();
   const float            x1            = xBounds.y();
   const float            y0            = yBounds.x();
   const float            y1            = yBounds.y();
 
   // Error parameters
   const float            pcfErr        = computeFixedPointError(prec.pcfBits);
   const float            resErr        = computeFixedPointError(prec.resultBits);
   const float            totalErr    = pcfErr+resErr;
 
   // Iterate over all valid combinations.
   // \note It is not enough to compute minmax over all possible result sets, as ranges may
   //         not necessarily overlap, i.e. there are gaps between valid ranges.
   for (deUint32 comb = 0; comb < (1<<4); comb++)
   {
       // Filter out invalid combinations:
       //  1) True bit is set in comb but not in isTrue => sample can not be true
       //  2) True bit is NOT set in comb and not in isFalse => sample can not be false
       if (((comb & isTrue) | (~comb & isFalse)) != (1<<4)-1)
           continue;
 
       const BVec4        cmpTrue        = extractBVec4(comb, 0);
       const Vec4        refVal        = select(Vec4(1.0f), Vec4(0.0f), cmpTrue);
 
       const float        v0            = bilinearInterpolate(refVal, x0, y0);
       const float        v1            = bilinearInterpolate(refVal, x1, y0);
       const float        v2            = bilinearInterpolate(refVal, x0, y1);
       const float        v3            = bilinearInterpolate(refVal, x1, y1);
       const float        minV        = de::min(v0, de::min(v1, de::min(v2, v3)));
       const float        maxV        = de::max(v0, de::max(v1, de::max(v2, v3)));
       const float        minR        = minV-totalErr;
       const float        maxR        = maxV+totalErr;
 
       if (de::inRange(result, minR, maxR))
           return true;
   }
 
   return false;
}
 
static bool isBilinearCompareValid (const Sampler::CompareMode    compareMode,
                                   const TexComparePrecision&    prec,
                                   const Vec4&                    depths,
                                   const Vec2&                    xBounds,
                                   const Vec2&                    yBounds,
                                   const float                    cmpReference,
                                   const float                    result,
                                   const bool                    isFixedPointDepth)
{
   if (prec.pcfBits > 0)
       return isBilinearPCFCompareValid(compareMode, prec, depths, xBounds, yBounds, cmpReference, result, isFixedPointDepth);
   else
       return isBilinearAnyCompareValid(compareMode, prec, depths, cmpReference, result, isFixedPointDepth);
}
 
static bool isTrilinearAnyCompareValid (const Sampler::CompareMode    compareMode,
                                       const TexComparePrecision&    prec,
                                       const Vec4&                    depths0,
                                       const Vec4&                    depths1,
                                       const float                    cmpReference,
                                       const float                    result,
                                       const bool                    isFixedPointDepth)
{
   DE_ASSERT(prec.pcfBits == 0);
 
   const CmpResultSet    cmp00        = execCompare(compareMode, depths0[0], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp01        = execCompare(compareMode, depths0[1], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp02        = execCompare(compareMode, depths0[2], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp03        = execCompare(compareMode, depths0[3], cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const CmpResultSet    cmp10        = execCompare(compareMode, depths1[0], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp11        = execCompare(compareMode, depths1[1], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp12        = execCompare(compareMode, depths1[2], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp13        = execCompare(compareMode, depths1[3], cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const bool            canBeTrue    = cmp00.isTrue ||
                                     cmp01.isTrue ||
                                     cmp02.isTrue ||
                                     cmp03.isTrue ||
                                     cmp10.isTrue ||
                                     cmp11.isTrue ||
                                     cmp12.isTrue ||
                                     cmp13.isTrue;
   const bool            canBeFalse    = cmp00.isFalse ||
                                     cmp01.isFalse ||
                                     cmp02.isFalse ||
                                     cmp03.isFalse ||
                                     cmp10.isFalse ||
                                     cmp11.isFalse ||
                                     cmp12.isFalse ||
                                     cmp13.isFalse;
 
   const float            resErr        = computeFixedPointError(prec.resultBits);
 
   const float            minBound    = canBeFalse ? 0.0f : 1.0f;
   const float            maxBound    = canBeTrue ? 1.0f : 0.0f;
 
   return de::inRange(result, minBound-resErr, maxBound+resErr);
}
 
static bool isTrilinearPCFCompareValid (const Sampler::CompareMode    compareMode,
                                       const TexComparePrecision&    prec,
                                       const Vec4&                    depths0,
                                       const Vec4&                    depths1,
                                       const Vec2&                    xBounds0,
                                       const Vec2&                    yBounds0,
                                       const Vec2&                    xBounds1,
                                       const Vec2&                    yBounds1,
                                       const Vec2&                    fBounds,
                                       const float                    cmpReference,
                                       const float                    result,
                                       const bool                    isFixedPointDepth)
{
   DE_ASSERT(0.0f <= xBounds0.x() && xBounds0.x() <= xBounds0.y() && xBounds0.y() <= 1.0f);
   DE_ASSERT(0.0f <= yBounds0.x() && yBounds0.x() <= yBounds0.y() && yBounds0.y() <= 1.0f);
   DE_ASSERT(0.0f <= xBounds1.x() && xBounds1.x() <= xBounds1.y() && xBounds1.y() <= 1.0f);
   DE_ASSERT(0.0f <= yBounds1.x() && yBounds1.x() <= yBounds1.y() && yBounds1.y() <= 1.0f);
   DE_ASSERT(0.0f <= fBounds.x() && fBounds.x() <= fBounds.y() && fBounds.y() <= 1.0f);
   DE_ASSERT(prec.pcfBits > 0);
 
   const CmpResultSet    cmp00        = execCompare(compareMode, depths0[0], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp01        = execCompare(compareMode, depths0[1], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp02        = execCompare(compareMode, depths0[2], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp03        = execCompare(compareMode, depths0[3], cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const CmpResultSet    cmp10        = execCompare(compareMode, depths1[0], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp11        = execCompare(compareMode, depths1[1], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp12        = execCompare(compareMode, depths1[2], cmpReference, prec.referenceBits, isFixedPointDepth);
   const CmpResultSet    cmp13        = execCompare(compareMode, depths1[3], cmpReference, prec.referenceBits, isFixedPointDepth);
 
   const deUint32        isTrue        = (deUint32(cmp00.isTrue)<<0)
                                   | (deUint32(cmp01.isTrue)<<1)
                                   | (deUint32(cmp02.isTrue)<<2)
                                   | (deUint32(cmp03.isTrue)<<3)
                                   | (deUint32(cmp10.isTrue)<<4)
                                   | (deUint32(cmp11.isTrue)<<5)
                                   | (deUint32(cmp12.isTrue)<<6)
                                   | (deUint32(cmp13.isTrue)<<7);
   const deUint32        isFalse        = (deUint32(cmp00.isFalse)<<0)
                                   | (deUint32(cmp01.isFalse)<<1)
                                   | (deUint32(cmp02.isFalse)<<2)
                                   | (deUint32(cmp03.isFalse)<<3)
                                   | (deUint32(cmp10.isFalse)<<4)
                                   | (deUint32(cmp11.isFalse)<<5)
                                   | (deUint32(cmp12.isFalse)<<6)
                                   | (deUint32(cmp13.isFalse)<<7);
 
   // Error parameters
   const float            pcfErr        = computeFixedPointError(prec.pcfBits);
   const float            resErr        = computeFixedPointError(prec.resultBits);
   const float            totalErr    = pcfErr+resErr;
 
   // Iterate over all valid combinations.
   for (deUint32 comb = 0; comb < (1<<8); comb++)
   {
       // Filter out invalid combinations.
       if (((comb & isTrue) | (~comb & isFalse)) != (1<<8)-1)
           continue;
 
       const BVec4        cmpTrue0    = extractBVec4(comb, 0);
       const BVec4        cmpTrue1    = extractBVec4(comb, 4);
       const Vec4        refVal0        = select(Vec4(1.0f), Vec4(0.0f), cmpTrue0);
       const Vec4        refVal1        = select(Vec4(1.0f), Vec4(0.0f), cmpTrue1);
 
       // Bilinear interpolation within levels.
       const float        v00            = bilinearInterpolate(refVal0, xBounds0.x(), yBounds0.x());
       const float        v01            = bilinearInterpolate(refVal0, xBounds0.y(), yBounds0.x());
       const float        v02            = bilinearInterpolate(refVal0, xBounds0.x(), yBounds0.y());
       const float        v03            = bilinearInterpolate(refVal0, xBounds0.y(), yBounds0.y());
       const float        minV0        = de::min(v00, de::min(v01, de::min(v02, v03)));
       const float        maxV0        = de::max(v00, de::max(v01, de::max(v02, v03)));
 
       const float        v10            = bilinearInterpolate(refVal1, xBounds1.x(), yBounds1.x());
       const float        v11            = bilinearInterpolate(refVal1, xBounds1.y(), yBounds1.x());
       const float        v12            = bilinearInterpolate(refVal1, xBounds1.x(), yBounds1.y());
       const float        v13            = bilinearInterpolate(refVal1, xBounds1.y(), yBounds1.y());
       const float        minV1        = de::min(v10, de::min(v11, de::min(v12, v13)));
       const float        maxV1        = de::max(v10, de::max(v11, de::max(v12, v13)));
 
       // Compute min-max bounds by filtering between minimum bounds and maximum bounds between levels.
       // HW can end up choosing pretty much any of samples between levels, and thus interpolating
       // between minimums should yield lower bound for range, and same for upper bound.
       // \todo [2013-07-17 pyry] This seems separable? Can this be optimized? At least ranges could be pre-computed and later combined.
       const float        minF0        = minV0*(1.0f-fBounds.x()) + minV1*fBounds.x();
       const float        minF1        = minV0*(1.0f-fBounds.y()) + minV1*fBounds.y();
       const float        maxF0        = maxV0*(1.0f-fBounds.x()) + maxV1*fBounds.x();
       const float        maxF1        = maxV0*(1.0f-fBounds.y()) + maxV1*fBounds.y();
 
       const float        minF        = de::min(minF0, minF1);
       const float        maxF        = de::max(maxF0, maxF1);
 
       const float        minR        = minF-totalErr;
       const float        maxR        = maxF+totalErr;
 
       if (de::inRange(result, minR, maxR))
           return true;
   }
 
   return false;
}
 
static bool isTrilinearCompareValid (const Sampler::CompareMode    compareMode,
                                    const TexComparePrecision&    prec,
                                    const Vec4&                depths0,
                                    const Vec4&                depths1,
                                    const Vec2&                xBounds0,
                                    const Vec2&                yBounds0,
                                    const Vec2&                xBounds1,
                                    const Vec2&                yBounds1,
                                    const Vec2&                fBounds,
                                    const float                cmpReference,
                                    const float                result,
                                    const bool                    isFixedPointDepth)
{
   if (prec.pcfBits > 0)
       return isTrilinearPCFCompareValid(compareMode, prec, depths0, depths1, xBounds0, yBounds0, xBounds1, yBounds1, fBounds, cmpReference, result, isFixedPointDepth);
   else
       return isTrilinearAnyCompareValid(compareMode, prec, depths0, depths1, cmpReference, result, isFixedPointDepth);
}
 
static bool isNearestCompareResultValid (const ConstPixelBufferAccess&        level,
                                        const Sampler&                        sampler,
                                        const TexComparePrecision&            prec,
                                        const Vec2&                        coord,
                                        const int                            coordZ,
                                        const float                        cmpReference,
                                        const float                        result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(level.getFormat());
   const Vec2    uBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, level.getWidth(),    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, level.getHeight(),    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinates - without wrap mode
   const int    minI        = deFloorFloatToInt32(uBounds.x());
   const int    maxI        = deFloorFloatToInt32(uBounds.y());
   const int    minJ        = deFloorFloatToInt32(vBounds.x());
   const int    maxJ        = deFloorFloatToInt32(vBounds.y());
 
   for (int j = minJ; j <= maxJ; j++)
   {
       for (int i = minI; i <= maxI; i++)
       {
           const int            x        = wrap(sampler.wrapS, i, level.getWidth());
           const int            y        = wrap(sampler.wrapT, j, level.getHeight());
           const float            depth    = lookupDepth(level, sampler, x, y, coordZ);
           const CmpResultSet    resSet    = execCompare(sampler.compare, depth, cmpReference, prec.referenceBits, isFixedPointDepth);
 
           if (isResultInSet(resSet, result, prec.resultBits))
               return true;
       }
   }
 
   return false;
}
 
static bool isLinearCompareResultValid (const ConstPixelBufferAccess&        level,
                                       const Sampler&                        sampler,
                                       const TexComparePrecision&            prec,
                                       const Vec2&                            coord,
                                       const int                            coordZ,
                                       const float                            cmpReference,
                                       const float                            result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(level.getFormat());
   const Vec2    uBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, level.getWidth(),    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, level.getHeight(),    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinate bounds for (x0,y0) - without wrap mode
   const int    minI        = deFloorFloatToInt32(uBounds.x()-0.5f);
   const int    maxI        = deFloorFloatToInt32(uBounds.y()-0.5f);
   const int    minJ        = deFloorFloatToInt32(vBounds.x()-0.5f);
   const int    maxJ        = deFloorFloatToInt32(vBounds.y()-0.5f);
 
   const int    w            = level.getWidth();
   const int    h            = level.getHeight();
 
   // \todo [2013-07-03 pyry] This could be optimized by first computing ranges based on wrap mode.
 
   for (int j = minJ; j <= maxJ; j++)
   {
       for (int i = minI; i <= maxI; i++)
       {
           // Wrapped coordinates
           const int    x0        = wrap(sampler.wrapS, i  , w);
           const int    x1        = wrap(sampler.wrapS, i+1, w);
           const int    y0        = wrap(sampler.wrapT, j  , h);
           const int    y1        = wrap(sampler.wrapT, j+1, h);
 
           // Bounds for filtering factors
           const float    minA    = de::clamp((uBounds.x()-0.5f)-float(i), 0.0f, 1.0f);
           const float    maxA    = de::clamp((uBounds.y()-0.5f)-float(i), 0.0f, 1.0f);
           const float    minB    = de::clamp((vBounds.x()-0.5f)-float(j), 0.0f, 1.0f);
           const float    maxB    = de::clamp((vBounds.y()-0.5f)-float(j), 0.0f, 1.0f);
 
           const Vec4    depths    (lookupDepth(level, sampler, x0, y0, coordZ),
                                lookupDepth(level, sampler, x1, y0, coordZ),
                                lookupDepth(level, sampler, x0, y1, coordZ),
                                lookupDepth(level, sampler, x1, y1, coordZ));
 
           if (isBilinearCompareValid(sampler.compare, prec, depths, Vec2(minA, maxA), Vec2(minB, maxB), cmpReference, result, isFixedPointDepth))
               return true;
       }
   }
 
   return false;
}
 
static bool isLevelCompareResultValid (const ConstPixelBufferAccess&    level,
                                      const Sampler&                    sampler,
                                      const Sampler::FilterMode        filterMode,
                                      const TexComparePrecision&        prec,
                                      const Vec2&                        coord,
                                      const int                        coordZ,
                                      const float                        cmpReference,
                                      const float                        result)
{
   if (filterMode == Sampler::LINEAR)
       return isLinearCompareResultValid(level, sampler, prec, coord, coordZ, cmpReference, result);
   else
       return isNearestCompareResultValid(level, sampler, prec, coord, coordZ, cmpReference, result);
}
 
static bool isNearestMipmapLinearCompareResultValid (const ConstPixelBufferAccess&    level0,
                                                    const ConstPixelBufferAccess&    level1,
                                                    const Sampler&                    sampler,
                                                    const TexComparePrecision&        prec,
                                                    const Vec2&                    coord,
                                                    const int                        coordZ,
                                                    const Vec2&                    fBounds,
                                                    const float                    cmpReference,
                                                    const float                    result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(level0.getFormat());
 
   const int    w0                    = level0.getWidth();
   const int    w1                    = level1.getWidth();
   const int    h0                    = level0.getHeight();
   const int    h1                    = level1.getHeight();
 
   const Vec2    uBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, w0,    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    uBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, w1,    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, h0,    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
   const Vec2    vBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, h1,    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinates - without wrap mode
   const int    minI0                = deFloorFloatToInt32(uBounds0.x());
   const int    maxI0                = deFloorFloatToInt32(uBounds0.y());
   const int    minI1                = deFloorFloatToInt32(uBounds1.x());
   const int    maxI1                = deFloorFloatToInt32(uBounds1.y());
   const int    minJ0                = deFloorFloatToInt32(vBounds0.x());
   const int    maxJ0                = deFloorFloatToInt32(vBounds0.y());
   const int    minJ1                = deFloorFloatToInt32(vBounds1.x());
   const int    maxJ1                = deFloorFloatToInt32(vBounds1.y());
 
   for (int j0 = minJ0; j0 <= maxJ0; j0++)
   {
       for (int i0 = minI0; i0 <= maxI0; i0++)
       {
           const float    depth0    = lookupDepth(level0, sampler, wrap(sampler.wrapS, i0, w0), wrap(sampler.wrapT, j0, h0), coordZ);
 
           for (int j1 = minJ1; j1 <= maxJ1; j1++)
           {
               for (int i1 = minI1; i1 <= maxI1; i1++)
               {
                   const float    depth1    = lookupDepth(level1, sampler, wrap(sampler.wrapS, i1, w1), wrap(sampler.wrapT, j1, h1), coordZ);
 
                   if (isLinearCompareValid(sampler.compare, prec, Vec2(depth0, depth1), fBounds, cmpReference, result, isFixedPointDepth))
                       return true;
               }
           }
       }
   }
 
   return false;
}
 
static bool isLinearMipmapLinearCompareResultValid (const ConstPixelBufferAccess&    level0,
                                                   const ConstPixelBufferAccess&    level1,
                                                   const Sampler&                    sampler,
                                                   const TexComparePrecision&        prec,
                                                   const Vec2&                        coord,
                                                   const int                        coordZ,
                                                   const Vec2&                        fBounds,
                                                   const float                        cmpReference,
                                                   const float                        result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(level0.getFormat());
 
   // \todo [2013-07-04 pyry] This is strictly not correct as coordinates between levels should be dependent.
   //                           Right now this allows pairing any two valid bilinear quads.
 
   const int    w0                    = level0.getWidth();
   const int    w1                    = level1.getWidth();
   const int    h0                    = level0.getHeight();
   const int    h1                    = level1.getHeight();
 
   const Vec2    uBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, w0,    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    uBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, w1,    coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, h0,    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
   const Vec2    vBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, h1,    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinates - without wrap mode
   const int    minI0                = deFloorFloatToInt32(uBounds0.x()-0.5f);
   const int    maxI0                = deFloorFloatToInt32(uBounds0.y()-0.5f);
   const int    minI1                = deFloorFloatToInt32(uBounds1.x()-0.5f);
   const int    maxI1                = deFloorFloatToInt32(uBounds1.y()-0.5f);
   const int    minJ0                = deFloorFloatToInt32(vBounds0.x()-0.5f);
   const int    maxJ0                = deFloorFloatToInt32(vBounds0.y()-0.5f);
   const int    minJ1                = deFloorFloatToInt32(vBounds1.x()-0.5f);
   const int    maxJ1                = deFloorFloatToInt32(vBounds1.y()-0.5f);
 
   for (int j0 = minJ0; j0 <= maxJ0; j0++)
   {
       for (int i0 = minI0; i0 <= maxI0; i0++)
       {
           const float    minA0    = de::clamp((uBounds0.x()-0.5f)-float(i0), 0.0f, 1.0f);
           const float    maxA0    = de::clamp((uBounds0.y()-0.5f)-float(i0), 0.0f, 1.0f);
           const float    minB0    = de::clamp((vBounds0.x()-0.5f)-float(j0), 0.0f, 1.0f);
           const float    maxB0    = de::clamp((vBounds0.y()-0.5f)-float(j0), 0.0f, 1.0f);
           Vec4        depths0;
 
           {
               const int    x0        = wrap(sampler.wrapS, i0  , w0);
               const int    x1        = wrap(sampler.wrapS, i0+1, w0);
               const int    y0        = wrap(sampler.wrapT, j0  , h0);
               const int    y1        = wrap(sampler.wrapT, j0+1, h0);
 
               depths0[0] = lookupDepth(level0, sampler, x0, y0, coordZ);
               depths0[1] = lookupDepth(level0, sampler, x1, y0, coordZ);
               depths0[2] = lookupDepth(level0, sampler, x0, y1, coordZ);
               depths0[3] = lookupDepth(level0, sampler, x1, y1, coordZ);
           }
 
           for (int j1 = minJ1; j1 <= maxJ1; j1++)
           {
               for (int i1 = minI1; i1 <= maxI1; i1++)
               {
                   const float    minA1    = de::clamp((uBounds1.x()-0.5f)-float(i1), 0.0f, 1.0f);
                   const float    maxA1    = de::clamp((uBounds1.y()-0.5f)-float(i1), 0.0f, 1.0f);
                   const float    minB1    = de::clamp((vBounds1.x()-0.5f)-float(j1), 0.0f, 1.0f);
                   const float    maxB1    = de::clamp((vBounds1.y()-0.5f)-float(j1), 0.0f, 1.0f);
                   Vec4        depths1;
 
                   {
                       const int    x0        = wrap(sampler.wrapS, i1  , w1);
                       const int    x1        = wrap(sampler.wrapS, i1+1, w1);
                       const int    y0        = wrap(sampler.wrapT, j1  , h1);
                       const int    y1        = wrap(sampler.wrapT, j1+1, h1);
 
                       depths1[0] = lookupDepth(level1, sampler, x0, y0, coordZ);
                       depths1[1] = lookupDepth(level1, sampler, x1, y0, coordZ);
                       depths1[2] = lookupDepth(level1, sampler, x0, y1, coordZ);
                       depths1[3] = lookupDepth(level1, sampler, x1, y1, coordZ);
                   }
 
                   if (isTrilinearCompareValid(sampler.compare, prec, depths0, depths1,
                                               Vec2(minA0, maxA0), Vec2(minB0, maxB0),
                                               Vec2(minA1, maxA1), Vec2(minB1, maxB1),
                                               fBounds, cmpReference, result, isFixedPointDepth))
                       return true;
               }
           }
       }
   }
 
   return false;
}
 
static bool isMipmapLinearCompareResultValid (const ConstPixelBufferAccess&        level0,
                                             const ConstPixelBufferAccess&        level1,
                                             const Sampler&                    sampler,
                                             const Sampler::FilterMode            levelFilter,
                                             const TexComparePrecision&        prec,
                                             const Vec2&                        coord,
                                             const int                            coordZ,
                                             const Vec2&                        fBounds,
                                             const float                        cmpReference,
                                             const float                        result)
{
   if (levelFilter == Sampler::LINEAR)
       return isLinearMipmapLinearCompareResultValid(level0, level1, sampler, prec, coord, coordZ, fBounds, cmpReference, result);
   else
       return isNearestMipmapLinearCompareResultValid(level0, level1, sampler, prec, coord, coordZ, fBounds, cmpReference, result);
}
 
bool isTexCompareResultValid (const Texture2DView&            texture,
                             const Sampler&                sampler,
                             const TexComparePrecision&    prec,
                             const Vec2&                    coord,
                             const Vec2&                    lodBounds,
                             const float                    cmpReference,
                             const float                    result)
{
   const float        minLod            = lodBounds.x();
   const float        maxLod            = lodBounds.y();
   const bool        canBeMagnified    = minLod <= sampler.lodThreshold;
   const bool        canBeMinified    = maxLod > sampler.lodThreshold;
 
   DE_ASSERT(isSamplerSupported(sampler));
 
   if (canBeMagnified)
   {
       if (isLevelCompareResultValid(texture.getLevel(0), sampler, sampler.magFilter, prec, coord, 0, cmpReference, result))
           return true;
   }
 
   if (canBeMinified)
   {
       const bool    isNearestMipmap    = isNearestMipmapFilter(sampler.minFilter);
       const bool    isLinearMipmap    = isLinearMipmapFilter(sampler.minFilter);
       const int    minTexLevel        = 0;
       const int    maxTexLevel        = texture.getNumLevels()-1;
 
       DE_ASSERT(minTexLevel < maxTexLevel);
 
       if (isLinearMipmap)
       {
           const int        minLevel        = de::clamp((int)deFloatFloor(minLod), minTexLevel, maxTexLevel-1);
           const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod), minTexLevel, maxTexLevel-1);
 
           DE_ASSERT(minLevel <= maxLevel);
 
           for (int level = minLevel; level <= maxLevel; level++)
           {
               const float        minF    = de::clamp(minLod - float(level), 0.0f, 1.0f);
               const float        maxF    = de::clamp(maxLod - float(level), 0.0f, 1.0f);
 
               if (isMipmapLinearCompareResultValid(texture.getLevel(level), texture.getLevel(level+1), sampler, getLevelFilter(sampler.minFilter), prec, coord, 0, Vec2(minF, maxF), cmpReference, result))
                   return true;
           }
       }
       else if (isNearestMipmap)
       {
           // \note The accurate formula for nearest mipmapping is level = ceil(lod + 0.5) - 1 but Khronos has made
           //         decision to allow floor(lod + 0.5) as well.
           const int        minLevel        = de::clamp((int)deFloatCeil(minLod + 0.5f) - 1,    minTexLevel, maxTexLevel);
           const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod + 0.5f),        minTexLevel, maxTexLevel);
 
           DE_ASSERT(minLevel <= maxLevel);
 
           for (int level = minLevel; level <= maxLevel; level++)
           {
               if (isLevelCompareResultValid(texture.getLevel(level), sampler, getLevelFilter(sampler.minFilter), prec, coord, 0, cmpReference, result))
                   return true;
           }
       }
       else
       {
           if (isLevelCompareResultValid(texture.getLevel(0), sampler, sampler.minFilter, prec, coord, 0, cmpReference, result))
               return true;
       }
   }
 
   return false;
}
 
static bool isSeamplessLinearMipmapLinearCompareResultValid (const TextureCubeView&            texture,
                                                            const int                        baseLevelNdx,
                                                            const Sampler&                    sampler,
                                                            const TexComparePrecision&        prec,
                                                            const CubeFaceFloatCoords&        coords,
                                                            const Vec2&                    fBounds,
                                                            const float                    cmpReference,
                                                            const float                    result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(texture.getLevelFace(baseLevelNdx, CUBEFACE_NEGATIVE_X).getFormat());
   const int    size0                = texture.getLevelFace(baseLevelNdx,    coords.face).getWidth();
   const int    size1                = texture.getLevelFace(baseLevelNdx+1,    coords.face).getWidth();
 
   const Vec2    uBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size0,    coords.s, prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    uBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size1,    coords.s, prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds0            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size0,    coords.t, prec.coordBits.y(), prec.uvwBits.y());
   const Vec2    vBounds1            = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size1,    coords.t, prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinates - without wrap mode
   const int    minI0                = deFloorFloatToInt32(uBounds0.x()-0.5f);
   const int    maxI0                = deFloorFloatToInt32(uBounds0.y()-0.5f);
   const int    minI1                = deFloorFloatToInt32(uBounds1.x()-0.5f);
   const int    maxI1                = deFloorFloatToInt32(uBounds1.y()-0.5f);
   const int    minJ0                = deFloorFloatToInt32(vBounds0.x()-0.5f);
   const int    maxJ0                = deFloorFloatToInt32(vBounds0.y()-0.5f);
   const int    minJ1                = deFloorFloatToInt32(vBounds1.x()-0.5f);
   const int    maxJ1                = deFloorFloatToInt32(vBounds1.y()-0.5f);
 
   tcu::ConstPixelBufferAccess faces0[CUBEFACE_LAST];
   tcu::ConstPixelBufferAccess faces1[CUBEFACE_LAST];
 
   for (int face = 0; face < CUBEFACE_LAST; face++)
   {
       faces0[face] = texture.getLevelFace(baseLevelNdx,    CubeFace(face));
       faces1[face] = texture.getLevelFace(baseLevelNdx+1,    CubeFace(face));
   }
 
   for (int j0 = minJ0; j0 <= maxJ0; j0++)
   {
       for (int i0 = minI0; i0 <= maxI0; i0++)
       {
           const float    minA0    = de::clamp((uBounds0.x()-0.5f)-float(i0), 0.0f, 1.0f);
           const float    maxA0    = de::clamp((uBounds0.y()-0.5f)-float(i0), 0.0f, 1.0f);
           const float    minB0    = de::clamp((vBounds0.x()-0.5f)-float(j0), 0.0f, 1.0f);
           const float    maxB0    = de::clamp((vBounds0.y()-0.5f)-float(j0), 0.0f, 1.0f);
           Vec4        depths0;
 
           {
               const CubeFaceIntCoords    c00    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i0+0, j0+0)), size0);
               const CubeFaceIntCoords    c10    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i0+1, j0+0)), size0);
               const CubeFaceIntCoords    c01    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i0+0, j0+1)), size0);
               const CubeFaceIntCoords    c11    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i0+1, j0+1)), size0);
 
               // If any of samples is out of both edges, implementations can do pretty much anything according to spec.
               // \todo [2013-07-08 pyry] Test the special case where all corner pixels have exactly the same color.
               if (c00.face == CUBEFACE_LAST || c01.face == CUBEFACE_LAST || c10.face == CUBEFACE_LAST || c11.face == CUBEFACE_LAST)
                   return true;
 
               depths0[0] = lookupDepthNoBorder(faces0[c00.face], sampler, c00.s, c00.t);
               depths0[1] = lookupDepthNoBorder(faces0[c10.face], sampler, c10.s, c10.t);
               depths0[2] = lookupDepthNoBorder(faces0[c01.face], sampler, c01.s, c01.t);
               depths0[3] = lookupDepthNoBorder(faces0[c11.face], sampler, c11.s, c11.t);
           }
 
           for (int j1 = minJ1; j1 <= maxJ1; j1++)
           {
               for (int i1 = minI1; i1 <= maxI1; i1++)
               {
                   const float    minA1    = de::clamp((uBounds1.x()-0.5f)-float(i1), 0.0f, 1.0f);
                   const float    maxA1    = de::clamp((uBounds1.y()-0.5f)-float(i1), 0.0f, 1.0f);
                   const float    minB1    = de::clamp((vBounds1.x()-0.5f)-float(j1), 0.0f, 1.0f);
                   const float    maxB1    = de::clamp((vBounds1.y()-0.5f)-float(j1), 0.0f, 1.0f);
                   Vec4        depths1;
 
                   {
                       const CubeFaceIntCoords    c00    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i1+0, j1+0)), size1);
                       const CubeFaceIntCoords    c10    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i1+1, j1+0)), size1);
                       const CubeFaceIntCoords    c01    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i1+0, j1+1)), size1);
                       const CubeFaceIntCoords    c11    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i1+1, j1+1)), size1);
 
                       if (c00.face == CUBEFACE_LAST || c01.face == CUBEFACE_LAST || c10.face == CUBEFACE_LAST || c11.face == CUBEFACE_LAST)
                           return true;
 
                       depths1[0] = lookupDepthNoBorder(faces1[c00.face], sampler, c00.s, c00.t);
                       depths1[1] = lookupDepthNoBorder(faces1[c10.face], sampler, c10.s, c10.t);
                       depths1[2] = lookupDepthNoBorder(faces1[c01.face], sampler, c01.s, c01.t);
                       depths1[3] = lookupDepthNoBorder(faces1[c11.face], sampler, c11.s, c11.t);
                   }
 
 
                   if (isTrilinearCompareValid(sampler.compare, prec, depths0, depths1,
                                               Vec2(minA0, maxA0), Vec2(minB0, maxB0),
                                               Vec2(minA1, maxA1), Vec2(minB1, maxB1),
                                               fBounds, cmpReference, result, isFixedPointDepth))
                       return true;
               }
           }
       }
   }
 
   return false;
}
 
static bool isCubeMipmapLinearCompareResultValid (const TextureCubeView&        texture,
                                                 const int                        baseLevelNdx,
                                                 const Sampler&                sampler,
                                                 const Sampler::FilterMode        levelFilter,
                                                 const TexComparePrecision&    prec,
                                                 const CubeFaceFloatCoords&    coords,
                                                 const Vec2&                    fBounds,
                                                 const float                    cmpReference,
                                                 const float                    result)
{
   if (levelFilter == Sampler::LINEAR)
   {
       if (sampler.seamlessCubeMap)
           return isSeamplessLinearMipmapLinearCompareResultValid(texture, baseLevelNdx, sampler, prec, coords, fBounds, cmpReference, result);
       else
           return isLinearMipmapLinearCompareResultValid(texture.getLevelFace(baseLevelNdx,    coords.face),
                                                         texture.getLevelFace(baseLevelNdx+1,    coords.face),
                                                         sampler, prec, Vec2(coords.s, coords.t), 0, fBounds, cmpReference, result);
   }
   else
       return isNearestMipmapLinearCompareResultValid(texture.getLevelFace(baseLevelNdx,    coords.face),
                                                      texture.getLevelFace(baseLevelNdx+1,    coords.face),
                                                      sampler, prec, Vec2(coords.s, coords.t), 0, fBounds, cmpReference, result);
}
 
static bool isSeamlessLinearCompareResultValid (const TextureCubeView&        texture,
                                               const int                    levelNdx,
                                               const Sampler&                sampler,
                                               const TexComparePrecision&    prec,
                                               const CubeFaceFloatCoords&    coords,
                                               const float                    cmpReference,
                                               const float                    result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(texture.getLevelFace(levelNdx, CUBEFACE_NEGATIVE_X).getFormat());
   const int    size                = texture.getLevelFace(levelNdx, coords.face).getWidth();
 
   const Vec2    uBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size, coords.s, prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size, coords.t, prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinate bounds for (x0,y0) - without wrap mode
   const int    minI                = deFloorFloatToInt32(uBounds.x()-0.5f);
   const int    maxI                = deFloorFloatToInt32(uBounds.y()-0.5f);
   const int    minJ                = deFloorFloatToInt32(vBounds.x()-0.5f);
   const int    maxJ                = deFloorFloatToInt32(vBounds.y()-0.5f);
 
   // Face accesses
   ConstPixelBufferAccess faces[CUBEFACE_LAST];
   for (int face = 0; face < CUBEFACE_LAST; face++)
       faces[face] = texture.getLevelFace(levelNdx, CubeFace(face));
 
   for (int j = minJ; j <= maxJ; j++)
   {
       for (int i = minI; i <= maxI; i++)
       {
           const CubeFaceIntCoords    c00    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i+0, j+0)), size);
           const CubeFaceIntCoords    c10    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i+1, j+0)), size);
           const CubeFaceIntCoords    c01    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i+0, j+1)), size);
           const CubeFaceIntCoords    c11    = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, IVec2(i+1, j+1)), size);
 
           // If any of samples is out of both edges, implementations can do pretty much anything according to spec.
           // \todo [2013-07-08 pyry] Test the special case where all corner pixels have exactly the same color.
           if (c00.face == CUBEFACE_LAST || c01.face == CUBEFACE_LAST || c10.face == CUBEFACE_LAST || c11.face == CUBEFACE_LAST)
               return true;
 
           // Bounds for filtering factors
           const float    minA    = de::clamp((uBounds.x()-0.5f)-float(i), 0.0f, 1.0f);
           const float    maxA    = de::clamp((uBounds.y()-0.5f)-float(i), 0.0f, 1.0f);
           const float    minB    = de::clamp((vBounds.x()-0.5f)-float(j), 0.0f, 1.0f);
           const float    maxB    = de::clamp((vBounds.y()-0.5f)-float(j), 0.0f, 1.0f);
 
           Vec4 depths;
           depths[0] = lookupDepthNoBorder(faces[c00.face], sampler, c00.s, c00.t);
           depths[1] = lookupDepthNoBorder(faces[c10.face], sampler, c10.s, c10.t);
           depths[2] = lookupDepthNoBorder(faces[c01.face], sampler, c01.s, c01.t);
           depths[3] = lookupDepthNoBorder(faces[c11.face], sampler, c11.s, c11.t);
 
           if (isBilinearCompareValid(sampler.compare, prec, depths, Vec2(minA, maxA), Vec2(minB, maxB), cmpReference, result, isFixedPointDepth))
               return true;
       }
   }
 
   return false;
}
 
static bool isCubeLevelCompareResultValid (const TextureCubeView&            texture,
                                          const int                        levelNdx,
                                          const Sampler&                    sampler,
                                          const Sampler::FilterMode        filterMode,
                                          const TexComparePrecision&        prec,
                                          const CubeFaceFloatCoords&        coords,
                                          const float                        cmpReference,
                                          const float                        result)
{
   if (filterMode == Sampler::LINEAR)
   {
       if (sampler.seamlessCubeMap)
           return isSeamlessLinearCompareResultValid(texture, levelNdx, sampler, prec, coords, cmpReference, result);
       else
           return isLinearCompareResultValid(texture.getLevelFace(levelNdx, coords.face), sampler, prec, Vec2(coords.s, coords.t), 0, cmpReference, result);
   }
   else
       return isNearestCompareResultValid(texture.getLevelFace(levelNdx, coords.face), sampler, prec, Vec2(coords.s, coords.t), 0, cmpReference, result);
}
 
bool isTexCompareResultValid (const TextureCubeView& texture, const Sampler& sampler, const TexComparePrecision& prec, const Vec3& coord, const Vec2& lodBounds, const float cmpReference, const float result)
{
   int            numPossibleFaces                = 0;
   CubeFace    possibleFaces[CUBEFACE_LAST];
 
   DE_ASSERT(isSamplerSupported(sampler));
 
   getPossibleCubeFaces(coord, prec.coordBits, &possibleFaces[0], numPossibleFaces);
 
   if (numPossibleFaces == 0)
       return true; // Result is undefined.
 
   for (int tryFaceNdx = 0; tryFaceNdx < numPossibleFaces; tryFaceNdx++)
   {
       const CubeFaceFloatCoords    faceCoords        (possibleFaces[tryFaceNdx], projectToFace(possibleFaces[tryFaceNdx], coord));
       const float                    minLod            = lodBounds.x();
       const float                    maxLod            = lodBounds.y();
       const bool                    canBeMagnified    = minLod <= sampler.lodThreshold;
       const bool                    canBeMinified    = maxLod > sampler.lodThreshold;
 
       if (canBeMagnified)
       {
           if (isCubeLevelCompareResultValid(texture, 0, sampler, sampler.magFilter, prec, faceCoords, cmpReference, result))
               return true;
       }
 
       if (canBeMinified)
       {
           const bool    isNearestMipmap    = isNearestMipmapFilter(sampler.minFilter);
           const bool    isLinearMipmap    = isLinearMipmapFilter(sampler.minFilter);
           const int    minTexLevel        = 0;
           const int    maxTexLevel        = texture.getNumLevels()-1;
 
           DE_ASSERT(minTexLevel < maxTexLevel);
 
           if (isLinearMipmap)
           {
               const int        minLevel        = de::clamp((int)deFloatFloor(minLod), minTexLevel, maxTexLevel-1);
               const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod), minTexLevel, maxTexLevel-1);
 
               DE_ASSERT(minLevel <= maxLevel);
 
               for (int level = minLevel; level <= maxLevel; level++)
               {
                   const float        minF    = de::clamp(minLod - float(level), 0.0f, 1.0f);
                   const float        maxF    = de::clamp(maxLod - float(level), 0.0f, 1.0f);
 
                   if (isCubeMipmapLinearCompareResultValid(texture, level, sampler, getLevelFilter(sampler.minFilter), prec, faceCoords, Vec2(minF, maxF), cmpReference, result))
                       return true;
               }
           }
           else if (isNearestMipmap)
           {
               // \note The accurate formula for nearest mipmapping is level = ceil(lod + 0.5) - 1 but Khronos has made
               //         decision to allow floor(lod + 0.5) as well.
               const int        minLevel        = de::clamp((int)deFloatCeil(minLod + 0.5f) - 1,    minTexLevel, maxTexLevel);
               const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod + 0.5f),        minTexLevel, maxTexLevel);
 
               DE_ASSERT(minLevel <= maxLevel);
 
               for (int level = minLevel; level <= maxLevel; level++)
               {
                   if (isCubeLevelCompareResultValid(texture, level, sampler, getLevelFilter(sampler.minFilter), prec, faceCoords, cmpReference, result))
                       return true;
               }
           }
           else
           {
               if (isCubeLevelCompareResultValid(texture, 0, sampler, sampler.minFilter, prec, faceCoords, cmpReference, result))
                   return true;
           }
       }
   }
 
   return false;
}
 
bool isTexCompareResultValid (const Texture2DArrayView& texture, const Sampler& sampler, const TexComparePrecision& prec, const Vec3& coord, const Vec2& lodBounds, const float cmpReference, const float result)
{
   const float        depthErr    = computeFloatingPointError(coord.z(), prec.coordBits.z()) + computeFixedPointError(prec.uvwBits.z());
   const float        minZ        = coord.z()-depthErr;
   const float        maxZ        = coord.z()+depthErr;
   const int        minLayer    = de::clamp(deFloorFloatToInt32(minZ + 0.5f), 0, texture.getNumLayers()-1);
   const int        maxLayer    = de::clamp(deFloorFloatToInt32(maxZ + 0.5f), 0, texture.getNumLayers()-1);
 
   DE_ASSERT(isSamplerSupported(sampler));
 
   for (int layer = minLayer; layer <= maxLayer; layer++)
   {
       const float        minLod            = lodBounds.x();
       const float        maxLod            = lodBounds.y();
       const bool        canBeMagnified    = minLod <= sampler.lodThreshold;
       const bool        canBeMinified    = maxLod > sampler.lodThreshold;
 
       if (canBeMagnified)
       {
           if (isLevelCompareResultValid(texture.getLevel(0), sampler, sampler.magFilter, prec, coord.swizzle(0,1), layer, cmpReference, result))
               return true;
       }
 
       if (canBeMinified)
       {
           const bool    isNearestMipmap    = isNearestMipmapFilter(sampler.minFilter);
           const bool    isLinearMipmap    = isLinearMipmapFilter(sampler.minFilter);
           const int    minTexLevel        = 0;
           const int    maxTexLevel        = texture.getNumLevels()-1;
 
           DE_ASSERT(minTexLevel < maxTexLevel);
 
           if (isLinearMipmap)
           {
               const int        minLevel        = de::clamp((int)deFloatFloor(minLod), minTexLevel, maxTexLevel-1);
               const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod), minTexLevel, maxTexLevel-1);
 
               DE_ASSERT(minLevel <= maxLevel);
 
               for (int level = minLevel; level <= maxLevel; level++)
               {
                   const float        minF    = de::clamp(minLod - float(level), 0.0f, 1.0f);
                   const float        maxF    = de::clamp(maxLod - float(level), 0.0f, 1.0f);
 
                   if (isMipmapLinearCompareResultValid(texture.getLevel(level), texture.getLevel(level+1), sampler, getLevelFilter(sampler.minFilter), prec, coord.swizzle(0,1), layer, Vec2(minF, maxF), cmpReference, result))
                       return true;
               }
           }
           else if (isNearestMipmap)
           {
               // \note The accurate formula for nearest mipmapping is level = ceil(lod + 0.5) - 1 but Khronos has made
               //         decision to allow floor(lod + 0.5) as well.
               const int        minLevel        = de::clamp((int)deFloatCeil(minLod + 0.5f) - 1,    minTexLevel, maxTexLevel);
               const int        maxLevel        = de::clamp((int)deFloatFloor(maxLod + 0.5f),        minTexLevel, maxTexLevel);
 
               DE_ASSERT(minLevel <= maxLevel);
 
               for (int level = minLevel; level <= maxLevel; level++)
               {
                   if (isLevelCompareResultValid(texture.getLevel(level), sampler, getLevelFilter(sampler.minFilter), prec, coord.swizzle(0,1), layer, cmpReference, result))
                       return true;
               }
           }
           else
           {
               if (isLevelCompareResultValid(texture.getLevel(0), sampler, sampler.minFilter, prec, coord.swizzle(0,1), layer, cmpReference, result))
                   return true;
           }
       }
   }
 
   return false;
}
 
static bool isGatherOffsetsCompareResultValid (const ConstPixelBufferAccess&    texture,
                                              const Sampler&                    sampler,
                                              const TexComparePrecision&        prec,
                                              const Vec2&                        coord,
                                              int                                coordZ,
                                              const IVec2                        (&offsets)[4],
                                              float                            cmpReference,
                                              const Vec4&                        result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(texture.getFormat());
   const Vec2    uBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, texture.getWidth(),        coord.x(), prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, texture.getHeight(),    coord.y(), prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinate bounds for (x0, y0) - without wrap mode
   const int    minI                = deFloorFloatToInt32(uBounds.x()-0.5f);
   const int    maxI                = deFloorFloatToInt32(uBounds.y()-0.5f);
   const int    minJ                = deFloorFloatToInt32(vBounds.x()-0.5f);
   const int    maxJ                = deFloorFloatToInt32(vBounds.y()-0.5f);
 
   const int    w                    = texture.getWidth();
   const int    h                    = texture.getHeight();
 
   for (int j = minJ; j <= maxJ; j++)
   {
       for (int i = minI; i <= maxI; i++)
       {
           bool isCurrentPixelValid = true;
 
           for (int offNdx = 0; offNdx < 4 && isCurrentPixelValid; offNdx++)
           {
               // offNdx-th coordinate offset and then wrapped.
               const int            x        = wrap(sampler.wrapS, i+offsets[offNdx].x(), w);
               const int            y        = wrap(sampler.wrapT, j+offsets[offNdx].y(), h);
               const float            depth    = lookupDepth(texture, sampler, x, y, coordZ);
               const CmpResultSet    resSet    = execCompare(sampler.compare, depth, cmpReference, prec.referenceBits, isFixedPointDepth);
 
               if (!isResultInSet(resSet, result[offNdx], prec.resultBits))
                   isCurrentPixelValid = false;
           }
 
           if (isCurrentPixelValid)
               return true;
       }
   }
 
   return false;
}
 
bool isGatherOffsetsCompareResultValid (const Texture2DView&        texture,
                                       const Sampler&                sampler,
                                       const TexComparePrecision&    prec,
                                       const Vec2&                    coord,
                                       const IVec2                    (&offsets)[4],
                                       float                        cmpReference,
                                       const Vec4&                    result)
{
   DE_ASSERT(isSamplerSupported(sampler));
 
   return isGatherOffsetsCompareResultValid(texture.getLevel(0), sampler, prec, coord, 0, offsets, cmpReference, result);
}
 
bool isGatherOffsetsCompareResultValid (const Texture2DArrayView&    texture,
                                       const Sampler&                sampler,
                                       const TexComparePrecision&    prec,
                                       const Vec3&                    coord,
                                       const IVec2                    (&offsets)[4],
                                       float                        cmpReference,
                                       const Vec4&                    result)
{
   const float        depthErr    = computeFloatingPointError(coord.z(), prec.coordBits.z()) + computeFixedPointError(prec.uvwBits.z());
   const float        minZ        = coord.z()-depthErr;
   const float        maxZ        = coord.z()+depthErr;
   const int        minLayer    = de::clamp(deFloorFloatToInt32(minZ + 0.5f), 0, texture.getNumLayers()-1);
   const int        maxLayer    = de::clamp(deFloorFloatToInt32(maxZ + 0.5f), 0, texture.getNumLayers()-1);
 
   DE_ASSERT(isSamplerSupported(sampler));
 
   for (int layer = minLayer; layer <= maxLayer; layer++)
   {
       if (isGatherOffsetsCompareResultValid(texture.getLevel(0), sampler, prec, coord.swizzle(0,1), layer, offsets, cmpReference, result))
           return true;
   }
   return false;
}
 
static bool isGatherCompareResultValid (const TextureCubeView&        texture,
                                       const Sampler&                sampler,
                                       const TexComparePrecision&    prec,
                                       const CubeFaceFloatCoords&    coords,
                                       float                        cmpReference,
                                       const Vec4&                    result)
{
   const bool    isFixedPointDepth    = isFixedPointDepthTextureFormat(texture.getLevelFace(0, coords.face).getFormat());
   const int    size                = texture.getLevelFace(0, coords.face).getWidth();
   const Vec2    uBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size, coords.s, prec.coordBits.x(), prec.uvwBits.x());
   const Vec2    vBounds                = computeNonNormalizedCoordBounds(sampler.normalizedCoords, size, coords.t, prec.coordBits.y(), prec.uvwBits.y());
 
   // Integer coordinate bounds for (x0,y0) - without wrap mode
   const int    minI                = deFloorFloatToInt32(uBounds.x()-0.5f);
   const int    maxI                = deFloorFloatToInt32(uBounds.y()-0.5f);
   const int    minJ                = deFloorFloatToInt32(vBounds.x()-0.5f);
   const int    maxJ                = deFloorFloatToInt32(vBounds.y()-0.5f);
 
   // Face accesses
   ConstPixelBufferAccess faces[CUBEFACE_LAST];
   for (int face = 0; face < CUBEFACE_LAST; face++)
       faces[face] = texture.getLevelFace(0, CubeFace(face));
 
   for (int j = minJ; j <= maxJ; j++)
   {
       for (int i = minI; i <= maxI; i++)
       {
           static const IVec2 offsets[4] =
           {
               IVec2(0, 1),
               IVec2(1, 1),
               IVec2(1, 0),
               IVec2(0, 0)
           };
 
           bool isCurrentPixelValid = true;
 
           for (int offNdx = 0; offNdx < 4 && isCurrentPixelValid; offNdx++)
           {
               const CubeFaceIntCoords c = remapCubeEdgeCoords(CubeFaceIntCoords(coords.face, i+offsets[offNdx].x(), j+offsets[offNdx].y()), size);
               // If any of samples is out of both edges, implementations can do pretty much anything according to spec.
               // \todo [2014-06-05 nuutti] Test the special case where all corner pixels have exactly the same color.
               //                             See also isSeamlessLinearCompareResultValid and similar.
               if (c.face == CUBEFACE_LAST)
                   return true;
 
               const float            depth    = lookupDepthNoBorder(faces[c.face], sampler, c.s, c.t);
               const CmpResultSet    resSet    = execCompare(sampler.compare, depth, cmpReference, prec.referenceBits, isFixedPointDepth);
 
               if (!isResultInSet(resSet, result[offNdx], prec.resultBits))
                   isCurrentPixelValid = false;
           }
 
           if (isCurrentPixelValid)
               return true;
       }
   }
 
   return false;
}
 
bool isGatherCompareResultValid (const TextureCubeView&            texture,
                                const Sampler&                    sampler,
                                const TexComparePrecision&        prec,
                                const Vec3&                    coord,
                                float                            cmpReference,
                                const Vec4&                    result)
{
   int            numPossibleFaces                = 0;
   CubeFace    possibleFaces[CUBEFACE_LAST];
 
   DE_ASSERT(isSamplerSupported(sampler));
 
   getPossibleCubeFaces(coord, prec.coordBits, &possibleFaces[0], numPossibleFaces);
 
   if (numPossibleFaces == 0)
       return true; // Result is undefined.
 
   for (int tryFaceNdx = 0; tryFaceNdx < numPossibleFaces; tryFaceNdx++)
   {
       const CubeFaceFloatCoords faceCoords(possibleFaces[tryFaceNdx], projectToFace(possibleFaces[tryFaceNdx], coord));
 
       if (isGatherCompareResultValid(texture, sampler, prec, faceCoords, cmpReference, result))
           return true;
   }
 
   return false;
}
 
} // tcu