Merge vulkan-cts-1.0.2 into aosp/master
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cEnhancedLayoutsTests.cpp
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23
24 /**
25  * \file  gl4cEnhancedLayoutsTests.cpp
26  * \brief Implements conformance tests for "Enhanced Layouts" functionality.
27  */ /*-------------------------------------------------------------------*/
28
29 #include "gl4cEnhancedLayoutsTests.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuTestLog.hpp"
37
38 #include <algorithm>
39 #include <iomanip>
40 #include <string>
41 #include <vector>
42
43 /* DEBUG */
44 #define USE_NSIGHT 0
45 #define DEBUG_ENBALE_MESSAGE_CALLBACK 0
46 #define DEBUG_NEG_LOG_ERROR 0
47 #define DEBUG_REPLACE_TOKEN 0
48 #define DEBUG_REPEAT_TEST_CASE 0
49 #define DEBUG_REPEATED_TEST_CASE 0
50
51 /* Texture test base */
52 #define DEBUG_TTB_VERIFICATION_SNIPPET_STAGE 0
53 #define DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE 0
54
55 /* Tests */
56 #define DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE 0
57
58 /* WORKAROUNDS */
59 #define WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST 0
60 #define WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST 0
61 #define WRKARD_UNIFORMBLOCKALIGNMENT 0
62 #define WRKARD_VARYINGLOCATIONSTEST 0
63
64 using namespace glw;
65
66 namespace gl4cts
67 {
68 namespace EnhancedLayouts
69 {
70 namespace Utils
71 {
72 /** Constants used by "random" generators **/
73 static const GLuint s_rand_start        = 3;
74 static const GLuint s_rand_max          = 16;
75 static const GLuint s_rand_max_half = s_rand_max / 2;
76
77 /** Seed used by "random" generators **/
78 static GLuint s_rand = s_rand_start;
79
80 /** Get "random" unsigned int value
81  *
82  * @return Value
83  **/
84 static GLuint GetRandUint()
85 {
86         const GLuint rand = s_rand++;
87
88         if (s_rand_max <= s_rand)
89         {
90                 s_rand = s_rand_start;
91         }
92
93         return rand;
94 }
95
96 /** Get "random" int value
97  *
98  * @return Value
99  **/
100 GLint GetRandInt()
101 {
102         const GLint rand = GetRandUint() - s_rand_max_half;
103
104         return rand;
105 }
106
107 /** Get "random" double value
108  *
109  * @return Value
110  **/
111 GLdouble GetRandDouble()
112 {
113         const GLint rand = GetRandInt();
114
115         GLdouble result = (GLfloat)rand / (GLdouble)s_rand_max_half;
116
117         return result;
118 }
119
120 /** Get "random" float value
121  *
122  * @return Value
123  **/
124 GLfloat GetRandFloat()
125 {
126         const GLint rand = GetRandInt();
127
128         GLfloat result = (GLfloat)rand / (GLfloat)s_rand_max_half;
129
130         return result;
131 }
132
133 /** String used by list routines **/
134 static const GLchar* const g_list = "LIST";
135
136 /** Type constants **/
137 const Type Type::_double = Type::GetType(Type::Double, 1, 1);
138 const Type Type::dmat2   = Type::GetType(Type::Double, 2, 2);
139 const Type Type::dmat2x3 = Type::GetType(Type::Double, 2, 3);
140 const Type Type::dmat2x4 = Type::GetType(Type::Double, 2, 4);
141 const Type Type::dmat3x2 = Type::GetType(Type::Double, 3, 2);
142 const Type Type::dmat3   = Type::GetType(Type::Double, 3, 3);
143 const Type Type::dmat3x4 = Type::GetType(Type::Double, 3, 4);
144 const Type Type::dmat4x2 = Type::GetType(Type::Double, 4, 2);
145 const Type Type::dmat4x3 = Type::GetType(Type::Double, 4, 3);
146 const Type Type::dmat4   = Type::GetType(Type::Double, 4, 4);
147 const Type Type::dvec2   = Type::GetType(Type::Double, 1, 2);
148 const Type Type::dvec3   = Type::GetType(Type::Double, 1, 3);
149 const Type Type::dvec4   = Type::GetType(Type::Double, 1, 4);
150 const Type Type::_int   = Type::GetType(Type::Int, 1, 1);
151 const Type Type::ivec2   = Type::GetType(Type::Int, 1, 2);
152 const Type Type::ivec3   = Type::GetType(Type::Int, 1, 3);
153 const Type Type::ivec4   = Type::GetType(Type::Int, 1, 4);
154 const Type Type::_float  = Type::GetType(Type::Float, 1, 1);
155 const Type Type::mat2   = Type::GetType(Type::Float, 2, 2);
156 const Type Type::mat2x3  = Type::GetType(Type::Float, 2, 3);
157 const Type Type::mat2x4  = Type::GetType(Type::Float, 2, 4);
158 const Type Type::mat3x2  = Type::GetType(Type::Float, 3, 2);
159 const Type Type::mat3   = Type::GetType(Type::Float, 3, 3);
160 const Type Type::mat3x4  = Type::GetType(Type::Float, 3, 4);
161 const Type Type::mat4x2  = Type::GetType(Type::Float, 4, 2);
162 const Type Type::mat4x3  = Type::GetType(Type::Float, 4, 3);
163 const Type Type::mat4   = Type::GetType(Type::Float, 4, 4);
164 const Type Type::vec2   = Type::GetType(Type::Float, 1, 2);
165 const Type Type::vec3   = Type::GetType(Type::Float, 1, 3);
166 const Type Type::vec4   = Type::GetType(Type::Float, 1, 4);
167 const Type Type::uint   = Type::GetType(Type::Uint, 1, 1);
168 const Type Type::uvec2   = Type::GetType(Type::Uint, 1, 2);
169 const Type Type::uvec3   = Type::GetType(Type::Uint, 1, 3);
170 const Type Type::uvec4   = Type::GetType(Type::Uint, 1, 4);
171
172 /** Generate data for type. This routine follows STD140 rules
173  *
174  * @return Vector of bytes filled with data
175  **/
176 std::vector<GLubyte> Type::GenerateData() const
177 {
178         const GLuint alignment = GetActualAlignment(0, false);
179
180         std::vector<GLubyte> data;
181         data.resize(alignment * m_n_columns);
182
183         for (GLuint column = 0; column < m_n_columns; ++column)
184         {
185                 GLvoid* ptr = (GLvoid*)&data[column * alignment];
186
187                 switch (m_basic_type)
188                 {
189                 case Double:
190                 {
191                         GLdouble* d_ptr = (GLdouble*)ptr;
192
193                         for (GLuint i = 0; i < m_n_rows; ++i)
194                         {
195                                 d_ptr[i] = GetRandDouble();
196                         }
197                 }
198                 break;
199                 case Float:
200                 {
201                         GLfloat* f_ptr = (GLfloat*)ptr;
202
203                         for (GLuint i = 0; i < m_n_rows; ++i)
204                         {
205                                 f_ptr[i] = GetRandFloat();
206                         }
207                 }
208                 break;
209                 case Int:
210                 {
211                         GLint* i_ptr = (GLint*)ptr;
212
213                         for (GLuint i = 0; i < m_n_rows; ++i)
214                         {
215                                 i_ptr[i] = GetRandInt();
216                         }
217                 }
218                 break;
219                 case Uint:
220                 {
221                         GLuint* ui_ptr = (GLuint*)ptr;
222
223                         for (GLuint i = 0; i < m_n_rows; ++i)
224                         {
225                                 ui_ptr[i] = GetRandUint();
226                         }
227                 }
228                 break;
229                 }
230         }
231
232         return data;
233 }
234
235 /** Generate data for type. This routine packs data tightly.
236  *
237  * @return Vector of bytes filled with data
238  **/
239 std::vector<GLubyte> Type::GenerateDataPacked() const
240 {
241         const GLuint basic_size = GetTypeSize(m_basic_type);
242         const GLuint n_elements = m_n_columns * m_n_rows;
243         const GLuint size               = basic_size * n_elements;
244
245         std::vector<GLubyte> data;
246         data.resize(size);
247
248         GLvoid* ptr = (GLvoid*)&data[0];
249
250         switch (m_basic_type)
251         {
252         case Double:
253         {
254                 GLdouble* d_ptr = (GLdouble*)ptr;
255
256                 for (GLuint i = 0; i < n_elements; ++i)
257                 {
258                         d_ptr[i] = GetRandDouble();
259                 }
260         }
261         break;
262         case Float:
263         {
264                 GLfloat* f_ptr = (GLfloat*)ptr;
265
266                 for (GLuint i = 0; i < n_elements; ++i)
267                 {
268                         f_ptr[i] = GetRandFloat();
269                 }
270         }
271         break;
272         case Int:
273         {
274                 GLint* i_ptr = (GLint*)ptr;
275
276                 for (GLuint i = 0; i < n_elements; ++i)
277                 {
278                         i_ptr[i] = GetRandInt();
279                 }
280         }
281         break;
282         case Uint:
283         {
284                 GLuint* ui_ptr = (GLuint*)ptr;
285
286                 for (GLuint i = 0; i < n_elements; ++i)
287                 {
288                         ui_ptr[i] = GetRandUint();
289                 }
290         }
291         break;
292         }
293
294         return data;
295 }
296
297 /** Calculate "actual alignment". It work under assumption that align value is valid
298  *
299  * @param align    Requested alignment, eg with "align" qualifier
300  * @param is_array Selects if an array of type or single instance should be considered
301  *
302  * @return Calculated value
303  **/
304 GLuint Type::GetActualAlignment(GLuint align, bool is_array) const
305 {
306         const GLuint base_alignment = GetBaseAlignment(is_array);
307
308         return std::max(align, base_alignment);
309 }
310
311 /** Align given ofset with specified alignment
312  *
313  * @param offset    Offset
314  * @param alignment Alignment
315  *
316  * @return Calculated value
317  **/
318 GLuint align(GLuint offset, GLuint alignment)
319 {
320         const GLuint rest = offset % alignment;
321
322         if (0 != rest)
323         {
324                 GLuint missing = alignment - rest;
325                 offset += missing;
326         }
327
328         return offset;
329 }
330
331 /** Calculate "actual offset"
332  *
333  * @param start_offset     Requested offset
334  * @param actual_alignment Actual alignemnt
335  *
336  * @return Calculated value
337  **/
338 GLuint Type::GetActualOffset(GLuint start_offset, GLuint actual_alignment)
339 {
340         GLuint offset = align(start_offset, actual_alignment);
341
342         return offset;
343 }
344
345 /** Calculate "base alignment" for given type
346  *
347  * @param is_array Select if array or single instance should be considered
348  *
349  * @return Calculated value
350  **/
351 GLuint Type::GetBaseAlignment(bool is_array) const
352 {
353         GLuint elements = 1;
354
355         switch (m_n_rows)
356         {
357         case 2:
358                 elements = 2;
359                 break;
360         case 3:
361         case 4:
362                 elements = 4;
363                 break;
364         default:
365                 break;
366         }
367
368         GLuint N                 = GetTypeSize(m_basic_type);
369         GLuint alignment = N * elements;
370
371         if ((true == is_array) || (1 != m_n_columns))
372         {
373                 alignment = align(alignment, 16 /* vec4 alignment */);
374         }
375
376         return alignment;
377 }
378
379 /** Returns string representing GLSL constructor of type with arguments provided in data
380  *
381  * @param data Array of values that will be used as construcotr arguments.
382  *             It is interpreted as tightly packed array of type matching this type.
383  *
384  * @return String in form "Type(args)"
385  **/
386 std::string Type::GetGLSLConstructor(const GLvoid* data) const
387 {
388         const GLchar* type = GetGLSLTypeName();
389
390         std::stringstream stream;
391
392         stream << type << "(";
393
394         /* Scalar or vector */
395         if (1 == m_n_columns)
396         {
397                 for (GLuint row = 0; row < m_n_rows; ++row)
398                 {
399                         switch (m_basic_type)
400                         {
401                         case Double:
402                                 stream << ((GLdouble*)data)[row];
403                                 break;
404                         case Float:
405                                 stream << ((GLfloat*)data)[row];
406                                 break;
407                         case Int:
408                                 stream << ((GLint*)data)[row];
409                                 break;
410                         case Uint:
411                                 stream << ((GLuint*)data)[row];
412                                 break;
413                         }
414
415                         if (row + 1 != m_n_rows)
416                         {
417                                 stream << ", ";
418                         }
419                 }
420         }
421         else /* Matrix: mat(vec(), vec() .. ) */
422         {
423                 const GLuint basic_size = GetTypeSize(m_basic_type);
424                 // Very indescoverable defect, the column stride should be calculated by rows, such as mat2x3, which is 2, columns 3 rows, its column stride should be 3 * sizeof(float)
425                 const GLuint column_stride = m_n_rows * basic_size;
426                 const Type   column_type   = GetType(m_basic_type, 1, m_n_rows);
427
428                 for (GLuint column = 0; column < m_n_columns; ++column)
429                 {
430                         const GLuint  column_offset = column * column_stride;
431                         const GLvoid* column_data   = (GLubyte*)data + column_offset;
432
433                         stream << column_type.GetGLSLConstructor(column_data);
434
435                         if (column + 1 != m_n_columns)
436                         {
437                                 stream << ", ";
438                         }
439                 }
440         }
441
442         stream << ")";
443
444         return stream.str();
445 }
446
447 /** Get glsl name of the type
448  *
449  * @return Name of glsl type
450  **/
451 const glw::GLchar* Type::GetGLSLTypeName() const
452 {
453         static const GLchar* float_lut[4][4] = {
454                 { "float", "vec2", "vec3", "vec4" },
455                 { 0, "mat2", "mat2x3", "mat2x4" },
456                 { 0, "mat3x2", "mat3", "mat3x4" },
457                 { 0, "mat4x2", "mat4x3", "mat4" },
458         };
459
460         static const GLchar* double_lut[4][4] = {
461                 { "double", "dvec2", "dvec3", "dvec4" },
462                 { 0, "dmat2", "dmat2x3", "dmat2x4" },
463                 { 0, "dmat3x2", "dmat3", "dmat3x4" },
464                 { 0, "dmat4x2", "dmat4x3", "dmat4" },
465         };
466
467         static const GLchar* int_lut[4] = { "int", "ivec2", "ivec3", "ivec4" };
468
469         static const GLchar* uint_lut[4] = { "uint", "uvec2", "uvec3", "uvec4" };
470
471         const GLchar* result = 0;
472
473         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
474         {
475                 return 0;
476         }
477
478         switch (m_basic_type)
479         {
480         case Float:
481                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
482                 break;
483         case Double:
484                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
485                 break;
486         case Int:
487                 result = int_lut[m_n_rows - 1];
488                 break;
489         case Uint:
490                 result = uint_lut[m_n_rows - 1];
491                 break;
492         default:
493                 TCU_FAIL("Invliad enum");
494         }
495
496         return result;
497 }
498
499 /** Get number of locations required for the type
500  *
501  * @return Number of columns times:
502  *          - 2 when type is double with 3 or 4 rows,
503  *          - 1 otherwise.
504  **/
505 GLuint Type::GetLocations() const
506 {
507         GLuint n_loc_per_column;
508
509         /* 1 or 2 doubles any for rest */
510         if ((2 >= m_n_rows) || (Double != m_basic_type))
511         {
512                 n_loc_per_column = 1;
513         }
514         else
515         {
516                 /* 3 and 4 doubles */
517                 n_loc_per_column = 2;
518         }
519
520         return n_loc_per_column * m_n_columns;
521 }
522
523 /** Get size of the type in bytes. Note that this routine assumes tightly packing
524  *
525  * @return Formula Number of columns * number of rows * sizeof(base_type)
526  **/
527 GLuint Type::GetSize() const
528 {
529         const GLuint basic_type_size = GetTypeSize(m_basic_type);
530         const GLuint n_elements          = m_n_columns * m_n_rows;
531
532         return basic_type_size * n_elements;
533 }
534
535 /** Get GLenum representing the type
536  *
537  * @return GLenum
538  **/
539 GLenum Type::GetTypeGLenum() const
540 {
541         static const GLenum float_lut[4][4] = {
542                 { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 },
543                 { 0, GL_FLOAT_MAT2, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4 },
544                 { 0, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3, GL_FLOAT_MAT3x4 },
545                 { 0, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3, GL_FLOAT_MAT4 },
546         };
547
548         static const GLenum double_lut[4][4] = {
549                 { GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4 },
550                 { 0, GL_DOUBLE_MAT2, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4 },
551                 { 0, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT3x4 },
552                 { 0, GL_DOUBLE_MAT4x2, GL_DOUBLE_MAT4x3, GL_DOUBLE_MAT4 },
553         };
554
555         static const GLenum int_lut[4] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
556
557         static const GLenum uint_lut[4] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3,
558                                                                                 GL_UNSIGNED_INT_VEC4 };
559
560         GLenum result = 0;
561
562         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
563         {
564                 return 0;
565         }
566
567         switch (m_basic_type)
568         {
569         case Float:
570                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
571                 break;
572         case Double:
573                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
574                 break;
575         case Int:
576                 result = int_lut[m_n_rows - 1];
577                 break;
578         case Uint:
579                 result = uint_lut[m_n_rows - 1];
580                 break;
581         default:
582                 TCU_FAIL("Invliad enum");
583         }
584
585         return result;
586 }
587
588 /** Calculate the numbe of components consumed by a type
589  *   according to 11.1.2.1 Output Variables
590  *
591  * @return Calculated number of components for the type
592  **/
593 GLuint Type::GetNumComponents() const
594 {
595         // Rule 3 of Section 7.6.2.2
596         // If the member is a three-component vector with components consuming N
597         // basic machine units, the base alignment is 4N.
598         GLuint num_components = (m_n_rows == 3 ? 4 : m_n_rows) * m_n_columns;
599
600         if (m_basic_type == Double)
601         {
602                 num_components *= 2;
603         }
604
605         return num_components;
606 }
607
608 /** Calculate stride for the type according to std140 rules
609  *
610  * @param alignment        Alignment of type
611  * @param n_columns        Number of columns
612  * @param n_array_elements Number of elements in array
613  *
614  * @return Calculated value
615  **/
616 GLuint Type::CalculateStd140Stride(GLuint alignment, GLuint n_columns, GLuint n_array_elements)
617 {
618         GLuint stride = alignment * n_columns;
619         if (0 != n_array_elements)
620         {
621                 stride *= n_array_elements;
622         }
623
624         return stride;
625 }
626
627 /** Check if glsl support matrices for specific basic type
628  *
629  * @param type Basic type
630  *
631  * @return true if matrices of <type> are supported, false otherwise
632  **/
633 bool Type::DoesTypeSupportMatrix(TYPES type)
634 {
635         bool result = false;
636
637         switch (type)
638         {
639         case Float:
640         case Double:
641                 result = true;
642                 break;
643         case Int:
644         case Uint:
645                 result = false;
646                 break;
647         default:
648                 TCU_FAIL("Invliad enum");
649         }
650
651         return result;
652 }
653
654 /** Creates instance of Type
655  *
656  * @param basic_type Select basic type of instance
657  * @param n_columns  Number of columns
658  * @param n_rows     Number of rows
659  *
660  * @return Type instance
661  **/
662 Type Type::GetType(TYPES basic_type, glw::GLuint n_columns, glw::GLuint n_rows)
663 {
664         Type type = { basic_type, n_columns, n_rows };
665
666         return type;
667 }
668
669 /** Get Size of given type in bytes
670  *
671  * @param type
672  *
673  * @return Size of type
674  **/
675 GLuint Type::GetTypeSize(TYPES type)
676 {
677         GLuint result = 0;
678
679         switch (type)
680         {
681         case Float:
682                 result = sizeof(GLfloat);
683                 break;
684         case Double:
685                 result = sizeof(GLdouble);
686                 break;
687         case Int:
688                 result = sizeof(GLint);
689                 break;
690         case Uint:
691                 result = sizeof(GLuint);
692                 break;
693         default:
694                 TCU_FAIL("Invalid enum");
695         }
696
697         return result;
698 }
699
700 /** Get GLenum representing given type
701  *
702  * @param type
703  *
704  * @return GLenum value
705  **/
706 GLenum Type::GetTypeGLenum(TYPES type)
707 {
708         GLenum result = 0;
709
710         switch (type)
711         {
712         case Float:
713                 result = GL_FLOAT;
714                 break;
715         case Double:
716                 result = GL_DOUBLE;
717                 break;
718         case Int:
719                 result = GL_INT;
720                 break;
721         case Uint:
722                 result = GL_UNSIGNED_INT;
723                 break;
724         default:
725                 TCU_FAIL("Invalid enum");
726         }
727
728         return result;
729 }
730
731 /** Get proper glUniformNdv routine for vectors with specified number of rows
732  *
733  * @param gl     GL functions
734  * @param n_rows Number of rows
735  *
736  * @return Function address
737  **/
738 uniformNdv getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
739 {
740         uniformNdv result = 0;
741
742         switch (n_rows)
743         {
744         case 1:
745                 result = gl.uniform1dv;
746                 break;
747         case 2:
748                 result = gl.uniform2dv;
749                 break;
750         case 3:
751                 result = gl.uniform3dv;
752                 break;
753         case 4:
754                 result = gl.uniform4dv;
755                 break;
756         default:
757                 TCU_FAIL("Invalid number of rows");
758         }
759
760         return result;
761 }
762
763 /** Get proper glUniformNfv routine for vectors with specified number of rows
764  *
765  * @param gl     GL functions
766  * @param n_rows Number of rows
767  *
768  * @return Function address
769  **/
770 uniformNfv getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
771 {
772         uniformNfv result = 0;
773
774         switch (n_rows)
775         {
776         case 1:
777                 result = gl.uniform1fv;
778                 break;
779         case 2:
780                 result = gl.uniform2fv;
781                 break;
782         case 3:
783                 result = gl.uniform3fv;
784                 break;
785         case 4:
786                 result = gl.uniform4fv;
787                 break;
788         default:
789                 TCU_FAIL("Invalid number of rows");
790         }
791
792         return result;
793 }
794
795 /** Get proper glUniformNiv routine for vectors with specified number of rows
796  *
797  * @param gl     GL functions
798  * @param n_rows Number of rows
799  *
800  * @return Function address
801  **/
802 uniformNiv getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
803 {
804         uniformNiv result = 0;
805
806         switch (n_rows)
807         {
808         case 1:
809                 result = gl.uniform1iv;
810                 break;
811         case 2:
812                 result = gl.uniform2iv;
813                 break;
814         case 3:
815                 result = gl.uniform3iv;
816                 break;
817         case 4:
818                 result = gl.uniform4iv;
819                 break;
820         default:
821                 TCU_FAIL("Invalid number of rows");
822         }
823
824         return result;
825 }
826
827 /** Get proper glUniformNuiv routine for vectors with specified number of rows
828  *
829  * @param gl     GL functions
830  * @param n_rows Number of rows
831  *
832  * @return Function address
833  **/
834 uniformNuiv getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
835 {
836         uniformNuiv result = 0;
837
838         switch (n_rows)
839         {
840         case 1:
841                 result = gl.uniform1uiv;
842                 break;
843         case 2:
844                 result = gl.uniform2uiv;
845                 break;
846         case 3:
847                 result = gl.uniform3uiv;
848                 break;
849         case 4:
850                 result = gl.uniform4uiv;
851                 break;
852         default:
853                 TCU_FAIL("Invalid number of rows");
854         }
855
856         return result;
857 }
858
859 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
860  *
861  * @param gl     GL functions
862  * @param n_rows Number of rows
863  *
864  * @return Function address
865  **/
866 uniformMatrixNdv getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
867 {
868         uniformMatrixNdv result = 0;
869
870         switch (n_columns)
871         {
872         case 2:
873                 switch (n_rows)
874                 {
875                 case 2:
876                         result = gl.uniformMatrix2dv;
877                         break;
878                 case 3:
879                         result = gl.uniformMatrix2x3dv;
880                         break;
881                 case 4:
882                         result = gl.uniformMatrix2x4dv;
883                         break;
884                 default:
885                         TCU_FAIL("Invalid number of rows");
886                 }
887                 break;
888         case 3:
889                 switch (n_rows)
890                 {
891                 case 2:
892                         result = gl.uniformMatrix3x2dv;
893                         break;
894                 case 3:
895                         result = gl.uniformMatrix3dv;
896                         break;
897                 case 4:
898                         result = gl.uniformMatrix3x4dv;
899                         break;
900                 default:
901                         TCU_FAIL("Invalid number of rows");
902                 }
903                 break;
904         case 4:
905                 switch (n_rows)
906                 {
907                 case 2:
908                         result = gl.uniformMatrix4x2dv;
909                         break;
910                 case 3:
911                         result = gl.uniformMatrix4x3dv;
912                         break;
913                 case 4:
914                         result = gl.uniformMatrix4dv;
915                         break;
916                 default:
917                         TCU_FAIL("Invalid number of rows");
918                 }
919                 break;
920         default:
921                 TCU_FAIL("Invalid number of columns");
922         }
923
924         return result;
925 }
926
927 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
928  *
929  * @param gl     GL functions
930  * @param n_rows Number of rows
931  *
932  * @return Function address
933  **/
934 uniformMatrixNfv getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
935 {
936         uniformMatrixNfv result = 0;
937
938         switch (n_columns)
939         {
940         case 2:
941                 switch (n_rows)
942                 {
943                 case 2:
944                         result = gl.uniformMatrix2fv;
945                         break;
946                 case 3:
947                         result = gl.uniformMatrix2x3fv;
948                         break;
949                 case 4:
950                         result = gl.uniformMatrix2x4fv;
951                         break;
952                 default:
953                         TCU_FAIL("Invalid number of rows");
954                 }
955                 break;
956         case 3:
957                 switch (n_rows)
958                 {
959                 case 2:
960                         result = gl.uniformMatrix3x2fv;
961                         break;
962                 case 3:
963                         result = gl.uniformMatrix3fv;
964                         break;
965                 case 4:
966                         result = gl.uniformMatrix3x4fv;
967                         break;
968                 default:
969                         TCU_FAIL("Invalid number of rows");
970                 }
971                 break;
972         case 4:
973                 switch (n_rows)
974                 {
975                 case 2:
976                         result = gl.uniformMatrix4x2fv;
977                         break;
978                 case 3:
979                         result = gl.uniformMatrix4x3fv;
980                         break;
981                 case 4:
982                         result = gl.uniformMatrix4fv;
983                         break;
984                 default:
985                         TCU_FAIL("Invalid number of rows");
986                 }
987                 break;
988         default:
989                 TCU_FAIL("Invalid number of columns");
990         }
991
992         return result;
993 }
994
995 bool verifyVarying(Program& program, const std::string& parent_name, const Variable::Descriptor& desc,
996                                    std::stringstream& stream, bool is_input)
997 {
998         GLint  component = 0;
999         GLuint index     = 0;
1000         GLenum interface = GL_PROGRAM_INPUT;
1001         GLint  location  = 0;
1002
1003         if (false == is_input)
1004         {
1005                 interface = GL_PROGRAM_OUTPUT;
1006         }
1007
1008         const std::string& name = Utils::Variable::GetReference(parent_name, desc, Utils::Variable::BASIC, 0);
1009
1010         try
1011         {
1012                 index = program.GetResourceIndex(name, interface);
1013
1014                 program.GetResource(interface, index, GL_LOCATION, 1 /* size */, &location);
1015                 program.GetResource(interface, index, GL_LOCATION_COMPONENT, 1 /* size */, &component);
1016         }
1017         catch (std::exception& exc)
1018         {
1019                 stream << "Failed to query program for varying: " << desc.m_name << ". Reason: " << exc.what() << "\n";
1020
1021                 return false;
1022         }
1023
1024         bool result = true;
1025
1026         if (location != desc.m_expected_location)
1027         {
1028                 stream << "Attribute: " << desc.m_name << " - invalid location: " << location
1029                            << " expected: " << desc.m_expected_location << std::endl;
1030                 result = false;
1031         }
1032         if (component != desc.m_expected_component)
1033         {
1034                 stream << "Attribute: " << desc.m_name << " - invalid component: " << component
1035                            << " expected: " << desc.m_expected_component << std::endl;
1036                 result = false;
1037         }
1038
1039         return result;
1040 }
1041
1042 /** Query program resource for given variable and verify that everything is as expected
1043  *
1044  * @param program  Program object
1045  * @param variable Variable object
1046  * @param stream   Stream that will be used to log any error
1047  * @param is_input Selects if varying is input or output
1048  *
1049  * @return true if verification is positive, false otherwise
1050  **/
1051 bool checkVarying(Program& program, const Variable& variable, std::stringstream& stream, bool is_input)
1052 {
1053         bool result = true;
1054
1055         if (variable.IsBlock())
1056         {
1057                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1058                 const size_t      n_members = interface->m_members.size();
1059
1060                 for (size_t i = 0; i < n_members; ++i)
1061                 {
1062                         const Variable::Descriptor& member = interface->m_members[i];
1063                         bool member_result                                 = verifyVarying(program, interface->m_name, member, stream, is_input);
1064
1065                         if (false == member_result)
1066                         {
1067                                 result = false;
1068                         }
1069                 }
1070         }
1071         /*
1072          To query the the location of struct member by glGetProgramResource, we need pass the variable name "gs_fs_output[0].single",
1073          but in original implementation, the test pass the name "Data.single", which can't get any valid result.
1074          struct Data {
1075          dmat2 single;
1076          dmat2 array[1];
1077          };
1078          layout (location = 0) in Data gs_fs_output[1];
1079          */
1080         else if (variable.IsStruct())
1081         {
1082                 Utils::Interface* interface              = variable.m_descriptor.m_interface;
1083                 const size_t      n_members              = interface->m_members.size();
1084                 std::string               structVariable = variable.m_descriptor.m_name;
1085                 // If struct variable is an array
1086                 if (0 != variable.m_descriptor.m_n_array_elements)
1087                 {
1088                         for (GLuint i = 0; i < variable.m_descriptor.m_n_array_elements; i++)
1089                         {
1090                                 GLchar buffer[16];
1091                                 sprintf(buffer, "%d", i);
1092                                 structVariable.append("[");
1093                                 structVariable.append(buffer);
1094                                 structVariable.append("]");
1095                                 for (size_t j = 0; j < n_members; ++j)
1096                                 {
1097                                         const Variable::Descriptor& member = interface->m_members[j];
1098                                         bool member_result = verifyVarying(program, structVariable, member, stream, is_input);
1099
1100                                         if (false == member_result)
1101                                         {
1102                                                 result = false;
1103                                         }
1104                                 }
1105                         }
1106                 }
1107                 else
1108                 {
1109                         for (GLuint i = 0; i < n_members; ++i)
1110                         {
1111                                 const Variable::Descriptor& member = interface->m_members[i];
1112                                 bool member_result                                 = verifyVarying(program, structVariable, member, stream, is_input);
1113
1114                                 if (false == member_result)
1115                                 {
1116                                         result = false;
1117                                 }
1118                         }
1119                 }
1120         }
1121         else
1122         {
1123                 result = verifyVarying(program, "", variable.m_descriptor, stream, is_input);
1124         }
1125         return result;
1126 }
1127
1128 /** Query program resource for given variable and verify that everything is as expected
1129  *
1130  * @param program  Program object
1131  * @param variable Variable object
1132  * @param stream   Stream that will be used to log any error
1133  *
1134  * @return true if verification is positive, false otherwise
1135  **/
1136 bool checkUniform(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1137 {
1138         bool result = true;
1139
1140         if (false == variable.IsBlock())
1141         {
1142                 TCU_FAIL("Not implemented");
1143         }
1144         else
1145         {
1146                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1147
1148                 size_t size = interface->m_members.size();
1149
1150                 std::vector<GLuint>              indices;
1151                 std::vector<const char*> names;
1152                 std::vector<std::string> names_str;
1153                 std::vector<GLint>               offsets;
1154
1155                 indices.resize(size);
1156                 names.resize(size);
1157                 names_str.resize(size);
1158                 offsets.resize(size);
1159
1160                 for (size_t i = 0; i < size; ++i)
1161                 {
1162                         indices[i] = 0;
1163                         offsets[i] = 0;
1164
1165                         const std::string& name =
1166                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1167
1168                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1169                         {
1170                                 const std::string& member_name = Utils::Variable::GetReference(
1171                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1172
1173                                 names_str[i] = member_name;
1174                         }
1175                         else
1176                         {
1177                                 names_str[i] = name;
1178                         }
1179
1180                         names[i] = names_str[i].c_str();
1181                 }
1182
1183                 try
1184                 {
1185                         program.GetUniformIndices(static_cast<glw::GLsizei>(size), &names[0], &indices[0]);
1186                         program.GetActiveUniformsiv(static_cast<glw::GLsizei>(size), &indices[0], GL_UNIFORM_OFFSET, &offsets[0]);
1187                 }
1188                 catch (std::exception& exc)
1189                 {
1190                         stream << "Failed to query program for uniforms in block: " << variable.m_descriptor.m_name
1191                                    << ". Reason: " << exc.what() << "\n";
1192
1193                         return false;
1194                 }
1195
1196                 for (size_t i = 0; i < size; ++i)
1197                 {
1198                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1199
1200                         if (offsets[i] != (GLint)desc.m_offset)
1201                         {
1202                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offsets[i]
1203                                            << " expected: " << desc.m_offset << std::endl;
1204                                 result = false;
1205                         }
1206                 }
1207         }
1208
1209         return result;
1210 }
1211
1212 /** Query program resource for given variable and verify that everything is as expected
1213  *
1214  * @param program  Program object
1215  * @param variable Variable object
1216  * @param stream   Stream that will be used to log any error
1217  *
1218  * @return true if verification is positive, false otherwise
1219  **/
1220 bool checkSSB(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1221 {
1222         bool result = true;
1223
1224         if (false == variable.IsBlock())
1225         {
1226                 TCU_FAIL("Not implemented");
1227         }
1228         else
1229         {
1230                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1231
1232                 size_t size = interface->m_members.size();
1233
1234                 for (size_t i = 0; i < size; ++i)
1235                 {
1236                         GLuint          index   = 0;
1237                         std::string name_str = "";
1238                         GLint           offset   = 0;
1239
1240                         const std::string& name =
1241                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1242
1243                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1244                         {
1245                                 const std::string& member_name = Utils::Variable::GetReference(
1246                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1247
1248                                 name_str = member_name;
1249                         }
1250                         else
1251                         {
1252                                 name_str = name;
1253                         }
1254
1255                         try
1256                         {
1257                                 index = program.GetResourceIndex(name_str, GL_BUFFER_VARIABLE);
1258
1259                                 program.GetResource(GL_BUFFER_VARIABLE, index, GL_OFFSET, 1, &offset);
1260                         }
1261                         catch (std::exception& exc)
1262                         {
1263                                 stream << "Failed to query program for buffer variable: " << variable.m_descriptor.m_name
1264                                            << ". Reason: " << exc.what() << "\n";
1265
1266                                 return false;
1267                         }
1268
1269                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1270
1271                         if (offset != (GLint)desc.m_offset)
1272                         {
1273                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offset
1274                                            << " expected: " << desc.m_offset << std::endl;
1275                                 result = false;
1276                         }
1277                 }
1278         }
1279
1280         return result;
1281 }
1282
1283 /** Query program resources at given stage and verifies results
1284  *
1285  * @param program           Program object
1286  * @param program_interface Definition of program interface
1287  * @param stage             Stage to be verified
1288  * @param check_inputs      Select if inputs should be verified
1289  * @param check_outputs     Select if output should be verified
1290  * @param check_uniforms    Select if uniforms should be verified
1291  * @param check_ssbs        Select if buffers should be verified
1292  * @param stream            Stream that will be used to log any error
1293  *
1294  * @return true if verification is positive, false otherwise
1295  **/
1296 bool checkProgramStage(Program& program, const ProgramInterface& program_interface, Utils::Shader::STAGES stage,
1297                                            bool check_inputs, bool check_outputs, bool check_uniforms, bool check_ssbs,
1298                                            std::stringstream& stream)
1299 {
1300         typedef Variable::PtrVector::const_iterator const_iterator;
1301
1302         const ShaderInterface& interface = program_interface.GetShaderInterface(stage);
1303
1304         bool result = true;
1305
1306         /* Inputs */
1307         if (true == check_inputs)
1308         {
1309                 const Variable::PtrVector& inputs = interface.m_inputs;
1310
1311                 for (const_iterator it = inputs.begin(); it != inputs.end(); ++it)
1312                 {
1313                         if (false == checkVarying(program, **it, stream, true))
1314                         {
1315                                 result = false;
1316                         }
1317                 }
1318         }
1319
1320         /* Outputs */
1321         if (true == check_outputs)
1322         {
1323                 const Variable::PtrVector& outputs = interface.m_outputs;
1324
1325                 for (const_iterator it = outputs.begin(); it != outputs.end(); ++it)
1326                 {
1327                         if (false == checkVarying(program, **it, stream, false))
1328                         {
1329                                 result = false;
1330                         }
1331                 }
1332         }
1333
1334         /* Uniforms */
1335         if (true == check_uniforms)
1336         {
1337                 const Variable::PtrVector& uniforms = interface.m_uniforms;
1338
1339                 for (const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
1340                 {
1341                         if (false == checkUniform(program, **it, stream))
1342                         {
1343                                 result = false;
1344                         }
1345                 }
1346         }
1347
1348         /* SSBs */
1349         if (true == check_ssbs)
1350         {
1351                 const Variable::PtrVector& ssbs = interface.m_ssb_blocks;
1352
1353                 for (const_iterator it = ssbs.begin(); it != ssbs.end(); ++it)
1354                 {
1355                         if (false == checkSSB(program, **it, stream))
1356                         {
1357                                 result = false;
1358                         }
1359                 }
1360         }
1361
1362         return result;
1363 }
1364
1365 /** Query resources of monolithic compute program and verifies results
1366  *
1367  * @param program           Program object
1368  * @param program_interface Definition of program interface
1369  * @param stream            Stream that will be used to log any error
1370  *
1371  * @return true if verification is positive, false otherwise
1372  **/
1373 bool checkMonolithicComputeProgramInterface(Program& program, const ProgramInterface& program_interface,
1374                                                                                         std::stringstream& stream)
1375 {
1376         bool result = true;
1377
1378         if (false == checkProgramStage(program, program_interface, Shader::COMPUTE, false, false, true, true, stream))
1379         {
1380                 result = false;
1381         }
1382
1383         /* Done */
1384         return result;
1385 }
1386
1387 /** Query resources of monolithic draw program and verifies results
1388  *
1389  * @param program           Program object
1390  * @param program_interface Definition of program interface
1391  * @param stream            Stream that will be used to log any error
1392  *
1393  * @return true if verification is positive, false otherwise
1394  **/
1395 bool checkMonolithicDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1396                                                                                  std::stringstream& stream)
1397 {
1398         bool result = true;
1399
1400         if (false == checkProgramStage(program, program_interface, Shader::VERTEX, true, false, true, true, stream))
1401         {
1402                 result = false;
1403         }
1404
1405         /* Done */
1406         return result;
1407 }
1408
1409 /** Query resources of separable draw program and verifies results
1410  *
1411  * @param program           Program object
1412  * @param program_interface Definition of program interface
1413  * @param stream            Stream that will be used to log any error
1414  *
1415  * @return true if verification is positive, false otherwise
1416  **/
1417 bool checkSeparableDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1418                                                                                 Utils::Shader::STAGES stage, std::stringstream& stream)
1419 {
1420         bool result = true;
1421
1422         if (false == checkProgramStage(program, program_interface, stage, true, true, true, true, stream))
1423         {
1424                 result = false;
1425         }
1426
1427         /* Done */
1428         return result;
1429 }
1430
1431 /** Check if extension is supported
1432  *
1433  * @param context        Test context
1434  * @param extension_name Name of extension
1435  *
1436  * @return true if extension is supported, false otherwise
1437  **/
1438 bool isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1439 {
1440         const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1441
1442         if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1443         {
1444                 return false;
1445         }
1446
1447         return true;
1448 }
1449
1450 /** Check if GL context meets version requirements
1451  *
1452  * @param gl             Functions
1453  * @param required_major Minimum required MAJOR_VERSION
1454  * @param required_minor Minimum required MINOR_VERSION
1455  *
1456  * @return true if GL context version is at least as requested, false otherwise
1457  **/
1458 bool isGLVersionAtLeast(const Functions& gl, GLint required_major, GLint required_minor)
1459 {
1460         glw::GLint major = 0;
1461         glw::GLint minor = 0;
1462
1463         gl.getIntegerv(GL_MAJOR_VERSION, &major);
1464         gl.getIntegerv(GL_MINOR_VERSION, &minor);
1465
1466         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1467
1468         if (major > required_major)
1469         {
1470                 /* Major is higher than required one */
1471                 return true;
1472         }
1473         else if (major == required_major)
1474         {
1475                 if (minor >= required_minor)
1476                 {
1477                         /* Major is equal to required one */
1478                         /* Minor is higher than or equal to required one */
1479                         return true;
1480                 }
1481                 else
1482                 {
1483                         /* Major is equal to required one */
1484                         /* Minor is lower than required one */
1485                         return false;
1486                 }
1487         }
1488         else
1489         {
1490                 /* Major is lower than required one */
1491                 return false;
1492         }
1493 }
1494
1495 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1496  *
1497  * @param token           Token string
1498  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1499  * @param text            String that will be used as replacement for <token>
1500  * @param string          String to work on
1501  **/
1502 void replaceToken(const GLchar* token, size_t& search_position, const GLchar* text, std::string& string)
1503 {
1504         const size_t text_length        = strlen(text);
1505         const size_t token_length   = strlen(token);
1506         const size_t token_position = string.find(token, search_position);
1507
1508 #if DEBUG_REPLACE_TOKEN
1509         if (std::string::npos == token_position)
1510         {
1511                 string.append("\n\nInvalid token: ");
1512                 string.append(token);
1513
1514                 TCU_FAIL(string.c_str());
1515         }
1516 #endif /* DEBUG_REPLACE_TOKEN */
1517
1518         string.replace(token_position, token_length, text, text_length);
1519
1520         search_position = token_position + text_length;
1521 }
1522
1523 /** Replace all occurances of <token> with <text> in <string>
1524  *
1525  * @param token           Token string
1526  * @param text            String that will be used as replacement for <token>
1527  * @param string          String to work on
1528  **/
1529 void replaceAllTokens(const GLchar* token, const GLchar* text, std::string& string)
1530 {
1531         const size_t text_length  = strlen(text);
1532         const size_t token_length = strlen(token);
1533
1534         size_t search_position = 0;
1535
1536         while (1)
1537         {
1538                 const size_t token_position = string.find(token, search_position);
1539
1540                 if (std::string::npos == token_position)
1541                 {
1542                         break;
1543                 }
1544
1545                 search_position = token_position + text_length;
1546
1547                 string.replace(token_position, token_length, text, text_length);
1548         }
1549 }
1550
1551 /** Rounds up the value to the next power of 2.
1552  * This routine does not work for 0, see the url for explanations.
1553  *
1554  * @param value Starting point
1555  *
1556  * @return Calculated value
1557  **/
1558 glw::GLuint roundUpToPowerOf2(glw::GLuint value)
1559 {
1560         /* Taken from: graphics.stanford.edu/~seander/bithacks.html */
1561         --value;
1562
1563         value |= value >> 1;
1564         value |= value >> 2;
1565         value |= value >> 4;
1566         value |= value >> 8;
1567         value |= value >> 16;
1568
1569         ++value;
1570
1571         return value;
1572 }
1573
1574 /** Insert elements of list into string.
1575  * List in string is represented either by token "LIST" or "SEPARATORLIST".
1576  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>.
1577  * LIST is replaced with <element>SEPARATORLIST
1578  *
1579  * @param element         Element to be inserted
1580  * @param separator       Separator inserted between elements
1581  * @param search_position Position in string, where search for list should start
1582  * @param string          String
1583  **/
1584 void insertElementOfList(const GLchar* element, const GLchar* separator, size_t& search_position, std::string& string)
1585 {
1586         static const char* list         = g_list;
1587         static const char* sep_list = "SEPARATORLIST";
1588
1589         /* Try to get "list" positions */
1590         const size_t list_position       = string.find(list, search_position);
1591         const size_t sep_list_position = string.find(sep_list, search_position);
1592
1593         /* There is no list in string */
1594         if (std::string::npos == list_position)
1595         {
1596                 return;
1597         }
1598
1599         if (9 /* strlen(SEPARATOR) */ == list_position - sep_list_position)
1600         {
1601                 replaceToken("SEPARATOR", search_position, separator, string);
1602         }
1603
1604         /* Save search_position */
1605         const size_t start_position = search_position;
1606
1607         /* Prepare new element */
1608         replaceToken("LIST", search_position, "ELEMENTSEPARATORLIST", string);
1609
1610         /* Restore search_position */
1611         search_position = start_position;
1612
1613         /* Replace element and separator */
1614         replaceToken("ELEMENT", search_position, element, string);
1615 }
1616
1617 /** Close list in string.
1618  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>
1619  * LIST is replaced with ""
1620  *
1621  * @param separator       Separator inserted between elements
1622  * @param search_position Position in string, where search for list should start
1623  * @param string          String
1624  **/
1625 void endList(const glw::GLchar* separator, size_t& search_position, std::string& string)
1626 {
1627         const size_t sep_position = string.find("SEPARATOR", search_position);
1628         if (std::string::npos != sep_position)
1629         {
1630                 replaceToken("SEPARATOR", search_position, separator, string);
1631         }
1632
1633         replaceToken("LIST", search_position, "", string);
1634 }
1635
1636 /* Buffer constants */
1637 const GLuint Buffer::m_invalid_id = -1;
1638
1639 /** Constructor.
1640  *
1641  * @param context CTS context.
1642  **/
1643 Buffer::Buffer(deqp::Context& context) : m_id(m_invalid_id), m_buffer(Array), m_context(context)
1644 {
1645 }
1646
1647 /** Destructor
1648  *
1649  **/
1650 Buffer::~Buffer()
1651 {
1652         Release();
1653 }
1654
1655 /** Initialize buffer instance
1656  *
1657  * @param buffer Buffer type
1658  * @param usage  Buffer usage enum
1659  * @param size   <size> parameter
1660  * @param data   <data> parameter
1661  **/
1662 void Buffer::Init(BUFFERS buffer, USAGE usage, GLsizeiptr size, GLvoid* data)
1663 {
1664         /* Delete previous buffer instance */
1665         Release();
1666
1667         m_buffer = buffer;
1668
1669         const Functions& gl = m_context.getRenderContext().getFunctions();
1670
1671         Generate(gl, m_id);
1672         Bind(gl, m_id, m_buffer);
1673         Data(gl, m_buffer, usage, size, data);
1674 }
1675
1676 /** Release buffer instance
1677  *
1678  **/
1679 void Buffer::Release()
1680 {
1681         if (m_invalid_id != m_id)
1682         {
1683                 const Functions& gl = m_context.getRenderContext().getFunctions();
1684
1685                 gl.deleteBuffers(1, &m_id);
1686                 m_id = m_invalid_id;
1687         }
1688 }
1689
1690 /** Binds buffer to its target
1691  *
1692  **/
1693 void Buffer::Bind() const
1694 {
1695         const Functions& gl = m_context.getRenderContext().getFunctions();
1696
1697         Bind(gl, m_id, m_buffer);
1698 }
1699
1700 /** Binds indexed buffer
1701  *
1702  * @param index <index> parameter
1703  **/
1704 void Buffer::BindBase(GLuint index) const
1705 {
1706         const Functions& gl = m_context.getRenderContext().getFunctions();
1707
1708         BindBase(gl, m_id, m_buffer, index);
1709 }
1710
1711 /** Binds range of buffer
1712  *
1713  * @param index  <index> parameter
1714  * @param offset <offset> parameter
1715  * @param size   <size> parameter
1716  **/
1717 void Buffer::BindRange(GLuint index, GLintptr offset, GLsizeiptr size) const
1718 {
1719         const Functions& gl = m_context.getRenderContext().getFunctions();
1720
1721         BindRange(gl, m_id, m_buffer, index, offset, size);
1722 }
1723
1724 /** Allocate memory for buffer and sends initial content
1725  *
1726  * @param usage  Buffer usage enum
1727  * @param size   <size> parameter
1728  * @param data   <data> parameter
1729  **/
1730 void Buffer::Data(USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1731 {
1732         const Functions& gl = m_context.getRenderContext().getFunctions();
1733
1734         Data(gl, m_buffer, usage, size, data);
1735 }
1736
1737 /** Maps contents of buffer into CPU space
1738  *
1739  * @param access Requested access
1740  *
1741  * @return Pointer to memory region available for CPU
1742  **/
1743 GLvoid* Buffer::Map(ACCESS access)
1744 {
1745         const Functions& gl = m_context.getRenderContext().getFunctions();
1746
1747         return Map(gl, m_buffer, access);
1748 }
1749
1750 /** Allocate memory for buffer and sends initial content
1751  *
1752  * @param offset Offset in buffer
1753  * @param size   <size> parameter
1754  * @param data   <data> parameter
1755  **/
1756 void Buffer::SubData(glw::GLintptr offset, glw::GLsizeiptr size, glw::GLvoid* data)
1757 {
1758         const Functions& gl = m_context.getRenderContext().getFunctions();
1759
1760         SubData(gl, m_buffer, offset, size, data);
1761 }
1762
1763 /** Maps contents of buffer into CPU space
1764  **/
1765 void Buffer::UnMap()
1766 {
1767         const Functions& gl = m_context.getRenderContext().getFunctions();
1768
1769         return UnMap(gl, m_buffer);
1770 }
1771
1772 /** Bind buffer to given target
1773  *
1774  * @param gl     GL functions
1775  * @param id     Id of buffer
1776  * @param buffer Buffer enum
1777  **/
1778 void Buffer::Bind(const Functions& gl, GLuint id, BUFFERS buffer)
1779 {
1780         GLenum target = GetBufferGLenum(buffer);
1781
1782         gl.bindBuffer(target, id);
1783         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
1784 }
1785
1786 /** Binds indexed buffer
1787  *
1788  * @param gl     GL functions
1789  * @param id     Id of buffer
1790  * @param buffer Buffer enum
1791  * @param index  <index> parameter
1792  **/
1793 void Buffer::BindBase(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index)
1794 {
1795         GLenum target = GetBufferGLenum(buffer);
1796
1797         gl.bindBufferBase(target, index, id);
1798         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferBase");
1799 }
1800
1801 /** Binds buffer range
1802  *
1803  * @param gl     GL functions
1804  * @param id     Id of buffer
1805  * @param buffer Buffer enum
1806  * @param index  <index> parameter
1807  * @param offset <offset> parameter
1808  * @param size   <size> parameter
1809  **/
1810 void Buffer::BindRange(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1811 {
1812         GLenum target = GetBufferGLenum(buffer);
1813
1814         gl.bindBufferRange(target, index, id, offset, size);
1815         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
1816 }
1817
1818 /** Allocate memory for buffer and sends initial content
1819  *
1820  * @param gl     GL functions
1821  * @param buffer Buffer enum
1822  * @param usage  Buffer usage enum
1823  * @param size   <size> parameter
1824  * @param data   <data> parameter
1825  **/
1826 void Buffer::Data(const glw::Functions& gl, BUFFERS buffer, USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1827 {
1828         GLenum target   = GetBufferGLenum(buffer);
1829         GLenum gl_usage = GetUsageGLenum(usage);
1830
1831         gl.bufferData(target, size, data, gl_usage);
1832         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferData");
1833 }
1834
1835 /** Allocate memory for buffer and sends initial content
1836  *
1837  * @param gl     GL functions
1838  * @param buffer Buffer enum
1839  * @param offset Offset in buffer
1840  * @param size   <size> parameter
1841  * @param data   <data> parameter
1842  **/
1843 void Buffer::SubData(const glw::Functions& gl, BUFFERS buffer, glw::GLintptr offset, glw::GLsizeiptr size,
1844                                          glw::GLvoid* data)
1845 {
1846         GLenum target = GetBufferGLenum(buffer);
1847
1848         gl.bufferSubData(target, offset, size, data);
1849         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferSubData");
1850 }
1851
1852 /** Generate buffer
1853  *
1854  * @param gl     GL functions
1855  * @param out_id Id of buffer
1856  **/
1857 void Buffer::Generate(const Functions& gl, GLuint& out_id)
1858 {
1859         GLuint id = m_invalid_id;
1860
1861         gl.genBuffers(1, &id);
1862         GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
1863
1864         if (m_invalid_id == id)
1865         {
1866                 TCU_FAIL("Got invalid id");
1867         }
1868
1869         out_id = id;
1870 }
1871
1872 /** Maps buffer content
1873  *
1874  * @param gl     GL functions
1875  * @param buffer Buffer enum
1876  * @param access Access rights for mapped region
1877  *
1878  * @return Mapped memory
1879  **/
1880 void* Buffer::Map(const Functions& gl, BUFFERS buffer, ACCESS access)
1881 {
1882         GLenum target   = GetBufferGLenum(buffer);
1883         GLenum gl_access = GetAccessGLenum(access);
1884
1885         void* result = gl.mapBuffer(target, gl_access);
1886         GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
1887
1888         return result;
1889 }
1890
1891 /** Unmaps buffer
1892  *
1893  **/
1894 void Buffer::UnMap(const Functions& gl, BUFFERS buffer)
1895 {
1896         GLenum target = GetBufferGLenum(buffer);
1897
1898         gl.unmapBuffer(target);
1899         GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
1900 }
1901
1902 /** Return GLenum representation of requested access
1903  *
1904  * @param access Requested access
1905  *
1906  * @return GLenum value
1907  **/
1908 GLenum Buffer::GetAccessGLenum(ACCESS access)
1909 {
1910         GLenum result = 0;
1911
1912         switch (access)
1913         {
1914         case ReadOnly:
1915                 result = GL_READ_ONLY;
1916                 break;
1917         case WriteOnly:
1918                 result = GL_WRITE_ONLY;
1919                 break;
1920         case ReadWrite:
1921                 result = GL_READ_WRITE;
1922                 break;
1923         default:
1924                 TCU_FAIL("Invalid enum");
1925         }
1926
1927         return result;
1928 }
1929
1930 /** Return GLenum representation of requested buffer type
1931  *
1932  * @param buffer Requested buffer type
1933  *
1934  * @return GLenum value
1935  **/
1936 GLenum Buffer::GetBufferGLenum(BUFFERS buffer)
1937 {
1938         GLenum result = 0;
1939
1940         switch (buffer)
1941         {
1942         case Array:
1943                 result = GL_ARRAY_BUFFER;
1944                 break;
1945         case Element:
1946                 result = GL_ELEMENT_ARRAY_BUFFER;
1947                 break;
1948         case Shader_Storage:
1949                 result = GL_SHADER_STORAGE_BUFFER;
1950                 break;
1951         case Texture:
1952                 result = GL_TEXTURE_BUFFER;
1953                 break;
1954         case Transform_feedback:
1955                 result = GL_TRANSFORM_FEEDBACK_BUFFER;
1956                 break;
1957         case Uniform:
1958                 result = GL_UNIFORM_BUFFER;
1959                 break;
1960         default:
1961                 TCU_FAIL("Invalid enum");
1962         }
1963
1964         return result;
1965 }
1966
1967 /** Return GLenum representation of requested usage
1968  *
1969  * @param usage Requested usage
1970  *
1971  * @return GLenum value
1972  **/
1973 GLenum Buffer::GetUsageGLenum(USAGE usage)
1974 {
1975         GLenum result = 0;
1976
1977         switch (usage)
1978         {
1979         case DynamicCopy:
1980                 result = GL_DYNAMIC_COPY;
1981                 break;
1982         case DynamicDraw:
1983                 result = GL_DYNAMIC_DRAW;
1984                 break;
1985         case DynamicRead:
1986                 result = GL_DYNAMIC_READ;
1987                 break;
1988         case StaticCopy:
1989                 result = GL_STATIC_COPY;
1990                 break;
1991         case StaticDraw:
1992                 result = GL_STATIC_DRAW;
1993                 break;
1994         case StaticRead:
1995                 result = GL_STATIC_READ;
1996                 break;
1997         case StreamCopy:
1998                 result = GL_STREAM_COPY;
1999                 break;
2000         case StreamDraw:
2001                 result = GL_STREAM_DRAW;
2002                 break;
2003         case StreamRead:
2004                 result = GL_STREAM_READ;
2005                 break;
2006         default:
2007                 TCU_FAIL("Invalid enum");
2008         }
2009
2010         return result;
2011 }
2012
2013 /** Returns name of buffer target
2014  *
2015  * @param buffer Target enum
2016  *
2017  * @return Name of target
2018  **/
2019 const GLchar* Buffer::GetBufferName(BUFFERS buffer)
2020 {
2021         const GLchar* name = 0;
2022
2023         switch (buffer)
2024         {
2025         case Array:
2026                 name = "Array";
2027                 break;
2028         case Element:
2029                 name = "Element";
2030                 break;
2031         case Shader_Storage:
2032                 name = "Shader_Storage";
2033                 break;
2034         case Texture:
2035                 name = "Texture";
2036                 break;
2037         case Transform_feedback:
2038                 name = "Transform_feedback";
2039                 break;
2040         case Uniform:
2041                 name = "Uniform";
2042                 break;
2043         default:
2044                 TCU_FAIL("Invalid enum");
2045         }
2046
2047         return name;
2048 }
2049
2050 /* Framebuffer constants */
2051 const GLuint Framebuffer::m_invalid_id = -1;
2052
2053 /** Constructor
2054  *
2055  * @param context CTS context
2056  **/
2057 Framebuffer::Framebuffer(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2058 {
2059         /* Nothing to be done here */
2060 }
2061
2062 /** Destructor
2063  *
2064  **/
2065 Framebuffer::~Framebuffer()
2066 {
2067         Release();
2068 }
2069
2070 /** Initialize framebuffer instance
2071  *
2072  **/
2073 void Framebuffer::Init()
2074 {
2075         /* Delete previous instance */
2076         Release();
2077
2078         const Functions& gl = m_context.getRenderContext().getFunctions();
2079
2080         Generate(gl, m_id);
2081 }
2082
2083 /** Release framebuffer instance
2084  *
2085  **/
2086 void Framebuffer::Release()
2087 {
2088         if (m_invalid_id != m_id)
2089         {
2090                 const Functions& gl = m_context.getRenderContext().getFunctions();
2091
2092                 gl.deleteFramebuffers(1, &m_id);
2093                 m_id = m_invalid_id;
2094         }
2095 }
2096
2097 /** Attach texture to specified attachment
2098  *
2099  * @param attachment Attachment
2100  * @param texture_id Texture id
2101  * @param width      Texture width
2102  * @param height     Texture height
2103  **/
2104 void Framebuffer::AttachTexture(GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2105 {
2106         const Functions& gl = m_context.getRenderContext().getFunctions();
2107
2108         AttachTexture(gl, attachment, texture_id, width, height);
2109 }
2110
2111 /** Binds framebuffer to DRAW_FRAMEBUFFER
2112  *
2113  **/
2114 void Framebuffer::Bind()
2115 {
2116         const Functions& gl = m_context.getRenderContext().getFunctions();
2117
2118         Bind(gl, m_id);
2119 }
2120
2121 /** Clear framebuffer
2122  *
2123  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2124  **/
2125 void Framebuffer::Clear(GLenum mask)
2126 {
2127         const Functions& gl = m_context.getRenderContext().getFunctions();
2128
2129         Clear(gl, mask);
2130 }
2131
2132 /** Specifies clear color
2133  *
2134  * @param red   Red channel
2135  * @param green Green channel
2136  * @param blue  Blue channel
2137  * @param alpha Alpha channel
2138  **/
2139 void Framebuffer::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2140 {
2141         const Functions& gl = m_context.getRenderContext().getFunctions();
2142
2143         ClearColor(gl, red, green, blue, alpha);
2144 }
2145
2146 /** Attach texture to specified attachment
2147  *
2148  * @param gl         GL functions
2149  * @param attachment Attachment
2150  * @param texture_id Texture id
2151  * @param width      Texture width
2152  * @param height     Texture height
2153  **/
2154 void Framebuffer::AttachTexture(const Functions& gl, GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2155 {
2156         gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, attachment, texture_id, 0 /* level */);
2157         GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture");
2158
2159         gl.viewport(0 /* x */, 0 /* y */, width, height);
2160         GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
2161 }
2162
2163 /** Binds framebuffer to DRAW_FRAMEBUFFER
2164  *
2165  * @param gl GL functions
2166  * @param id ID of framebuffer
2167  **/
2168 void Framebuffer::Bind(const Functions& gl, GLuint id)
2169 {
2170         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, id);
2171         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
2172 }
2173
2174 /** Clear framebuffer
2175  *
2176  * @param gl   GL functions
2177  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2178  **/
2179 void Framebuffer::Clear(const Functions& gl, GLenum mask)
2180 {
2181         gl.clear(mask);
2182         GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
2183 }
2184
2185 /** Specifies clear color
2186  *
2187  * @param gl    GL functions
2188  * @param red   Red channel
2189  * @param green Green channel
2190  * @param blue  Blue channel
2191  * @param alpha Alpha channel
2192  **/
2193 void Framebuffer::ClearColor(const Functions& gl, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2194 {
2195         gl.clearColor(red, green, blue, alpha);
2196         GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
2197 }
2198
2199 /** Generate framebuffer
2200  *
2201  **/
2202 void Framebuffer::Generate(const Functions& gl, GLuint& out_id)
2203 {
2204         GLuint id = m_invalid_id;
2205
2206         gl.genFramebuffers(1, &id);
2207         GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
2208
2209         if (m_invalid_id == id)
2210         {
2211                 TCU_FAIL("Invalid id");
2212         }
2213
2214         out_id = id;
2215 }
2216
2217 /* Shader's constants */
2218 const GLuint Shader::m_invalid_id = 0;
2219
2220 /** Constructor.
2221  *
2222  * @param context CTS context.
2223  **/
2224 Shader::Shader(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2225 {
2226         /* Nothing to be done here */
2227 }
2228
2229 /** Destructor
2230  *
2231  **/
2232 Shader::~Shader()
2233 {
2234         Release();
2235 }
2236
2237 /** Initialize shader instance
2238  *
2239  * @param stage  Shader stage
2240  * @param source Source code
2241  **/
2242 void Shader::Init(STAGES stage, const std::string& source)
2243 {
2244         if (true == source.empty())
2245         {
2246                 /* No source == no shader */
2247                 return;
2248         }
2249
2250         /* Delete any previous shader */
2251         Release();
2252
2253         /* Create, set source and compile */
2254         const Functions& gl = m_context.getRenderContext().getFunctions();
2255
2256         Create(gl, stage, m_id);
2257         Source(gl, m_id, source);
2258
2259         try
2260         {
2261                 Compile(gl, m_id);
2262         }
2263         catch (const CompilationException& exc)
2264         {
2265                 throw InvalidSourceException(exc.what(), source, stage);
2266         }
2267 }
2268
2269 /** Release shader instance
2270  *
2271  **/
2272 void Shader::Release()
2273 {
2274         if (m_invalid_id != m_id)
2275         {
2276                 const Functions& gl = m_context.getRenderContext().getFunctions();
2277
2278                 gl.deleteShader(m_id);
2279                 m_id = m_invalid_id;
2280         }
2281 }
2282
2283 /** Compile shader
2284  *
2285  * @param gl GL functions
2286  * @param id Shader id
2287  **/
2288 void Shader::Compile(const Functions& gl, GLuint id)
2289 {
2290         GLint status = GL_FALSE;
2291
2292         /* Compile */
2293         gl.compileShader(id);
2294         GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
2295
2296         /* Get compilation status */
2297         gl.getShaderiv(id, GL_COMPILE_STATUS, &status);
2298         GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2299
2300         /* Log compilation error */
2301         if (GL_TRUE != status)
2302         {
2303                 glw::GLint  length = 0;
2304                 std::string message;
2305
2306                 /* Error log length */
2307                 gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &length);
2308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2309
2310                 /* Prepare storage */
2311                 message.resize(length, 0);
2312
2313                 /* Get error log */
2314                 gl.getShaderInfoLog(id, length, 0, &message[0]);
2315                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
2316
2317                 throw CompilationException(message.c_str());
2318         }
2319 }
2320
2321 /** Create shader
2322  *
2323  * @param gl     GL functions
2324  * @param stage  Shader stage
2325  * @param out_id Shader id
2326  **/
2327 void Shader::Create(const Functions& gl, STAGES stage, GLuint& out_id)
2328 {
2329         const GLenum shaderType = GetShaderStageGLenum(stage);
2330         const GLuint id                 = gl.createShader(shaderType);
2331         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
2332
2333         if (m_invalid_id == id)
2334         {
2335                 TCU_FAIL("Failed to create shader");
2336         }
2337
2338         out_id = id;
2339 }
2340
2341 /** Set shader's source code
2342  *
2343  * @param gl     GL functions
2344  * @param id     Shader id
2345  * @param source Shader source code
2346  **/
2347 void Shader::Source(const Functions& gl, GLuint id, const std::string& source)
2348 {
2349         const GLchar* code = source.c_str();
2350
2351         gl.shaderSource(id, 1 /* count */, &code, 0 /* lengths */);
2352         GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
2353 }
2354
2355 /** Get GLenum repesenting shader stage
2356  *
2357  * @param stage Shader stage
2358  *
2359  * @return GLenum
2360  **/
2361 GLenum Shader::GetShaderStageGLenum(STAGES stage)
2362 {
2363         GLenum result = 0;
2364
2365         switch (stage)
2366         {
2367         case COMPUTE:
2368                 result = GL_COMPUTE_SHADER;
2369                 break;
2370         case FRAGMENT:
2371                 result = GL_FRAGMENT_SHADER;
2372                 break;
2373         case GEOMETRY:
2374                 result = GL_GEOMETRY_SHADER;
2375                 break;
2376         case TESS_CTRL:
2377                 result = GL_TESS_CONTROL_SHADER;
2378                 break;
2379         case TESS_EVAL:
2380                 result = GL_TESS_EVALUATION_SHADER;
2381                 break;
2382         case VERTEX:
2383                 result = GL_VERTEX_SHADER;
2384                 break;
2385         default:
2386                 TCU_FAIL("Invalid enum");
2387         }
2388
2389         return result;
2390 }
2391
2392 /** Get string representing name of shader stage
2393  *
2394  * @param stage Shader stage
2395  *
2396  * @return String with name of shader stage
2397  **/
2398 const glw::GLchar* Shader::GetStageName(STAGES stage)
2399 {
2400         const GLchar* result = 0;
2401
2402         switch (stage)
2403         {
2404         case COMPUTE:
2405                 result = "compute";
2406                 break;
2407         case VERTEX:
2408                 result = "vertex";
2409                 break;
2410         case TESS_CTRL:
2411                 result = "tesselation control";
2412                 break;
2413         case TESS_EVAL:
2414                 result = "tesselation evaluation";
2415                 break;
2416         case GEOMETRY:
2417                 result = "geomtery";
2418                 break;
2419         case FRAGMENT:
2420                 result = "fragment";
2421                 break;
2422         default:
2423                 TCU_FAIL("Invalid enum");
2424         }
2425
2426         return result;
2427 }
2428
2429 /** Logs shader source
2430  *
2431  * @param context CTS context
2432  * @param source  Source of shader
2433  * @param stage   Shader stage
2434  **/
2435 void Shader::LogSource(deqp::Context& context, const std::string& source, STAGES stage)
2436 {
2437         /* Skip empty shaders */
2438         if (true == source.empty())
2439         {
2440                 return;
2441         }
2442
2443         context.getTestContext().getLog() << tcu::TestLog::Message
2444                                                                           << "Shader source. Stage: " << Shader::GetStageName(stage)
2445                                                                           << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(source);
2446 }
2447
2448 /** Constructor
2449  *
2450  * @param message Compilation error message
2451  **/
2452 Shader::CompilationException::CompilationException(const GLchar* message)
2453 {
2454         m_message = message;
2455 }
2456
2457 /** Returns error messages
2458  *
2459  * @return Compilation error message
2460  **/
2461 const char* Shader::CompilationException::what() const throw()
2462 {
2463         return m_message.c_str();
2464 }
2465
2466 /** Constructor
2467  *
2468  * @param message Compilation error message
2469  **/
2470 Shader::InvalidSourceException::InvalidSourceException(const GLchar* error_message, const std::string& source,
2471                                                                                                            STAGES stage)
2472         : m_message(error_message), m_source(source), m_stage(stage)
2473 {
2474 }
2475
2476 /** Returns error messages
2477  *
2478  * @return Compilation error message
2479  **/
2480 const char* Shader::InvalidSourceException::what() const throw()
2481 {
2482         return "Compilation error";
2483 }
2484
2485 /** Logs error message and shader sources **/
2486 void Shader::InvalidSourceException::log(deqp::Context& context) const
2487 {
2488         context.getTestContext().getLog() << tcu::TestLog::Message << "Failed to compile shader: " << m_message.c_str()
2489                                                                           << tcu::TestLog::EndMessage;
2490
2491         LogSource(context, m_source, m_stage);
2492 }
2493
2494 /* Program constants */
2495 const GLuint Pipeline::m_invalid_id = 0;
2496
2497 /** Constructor.
2498  *
2499  * @param context CTS context.
2500  **/
2501 Pipeline::Pipeline(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2502 {
2503         /* Nothing to be done here */
2504 }
2505
2506 /** Destructor
2507  *
2508  **/
2509 Pipeline::~Pipeline()
2510 {
2511         Release();
2512 }
2513
2514 /** Initialize pipline object
2515  *
2516  **/
2517 void Pipeline::Init()
2518 {
2519         Release();
2520
2521         const Functions& gl = m_context.getRenderContext().getFunctions();
2522
2523         /* Generate */
2524         gl.genProgramPipelines(1, &m_id);
2525         GLU_EXPECT_NO_ERROR(gl.getError(), "GenProgramPipelines");
2526 }
2527
2528 /** Release pipeline object
2529  *
2530  **/
2531 void Pipeline::Release()
2532 {
2533         if (m_invalid_id != m_id)
2534         {
2535                 const Functions& gl = m_context.getRenderContext().getFunctions();
2536
2537                 /* Generate */
2538                 gl.deleteProgramPipelines(1, &m_id);
2539                 GLU_EXPECT_NO_ERROR(gl.getError(), "DeleteProgramPipelines");
2540
2541                 m_id = m_invalid_id;
2542         }
2543 }
2544
2545 /** Bind pipeline
2546  *
2547  **/
2548 void Pipeline::Bind()
2549 {
2550         const Functions& gl = m_context.getRenderContext().getFunctions();
2551
2552         Bind(gl, m_id);
2553 }
2554
2555 /** Set which stages should be active
2556  *
2557  * @param program_id Id of program
2558  * @param stages     Logical combination of enums representing stages
2559  **/
2560 void Pipeline::UseProgramStages(GLuint program_id, GLenum stages)
2561 {
2562         const Functions& gl = m_context.getRenderContext().getFunctions();
2563
2564         UseProgramStages(gl, m_id, program_id, stages);
2565 }
2566
2567 /** Bind pipeline
2568  *
2569  * @param gl Functiions
2570  * @param id Pipeline id
2571  **/
2572 void Pipeline::Bind(const Functions& gl, GLuint id)
2573 {
2574         gl.bindProgramPipeline(id);
2575         GLU_EXPECT_NO_ERROR(gl.getError(), "BindProgramPipeline");
2576 }
2577
2578 /** Set which stages should be active
2579  *
2580  * @param gl         Functiions
2581  * @param id         Pipeline id
2582  * @param program_id Id of program
2583  * @param stages     Logical combination of enums representing stages
2584  **/
2585 void Pipeline::UseProgramStages(const Functions& gl, GLuint id, GLuint program_id, GLenum stages)
2586 {
2587         gl.useProgramStages(id, stages, program_id);
2588         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgramStages");
2589 }
2590
2591 /* Program constants */
2592 const GLuint Program::m_invalid_id = 0;
2593
2594 /** Constructor.
2595  *
2596  * @param context CTS context.
2597  **/
2598 Program::Program(deqp::Context& context)
2599         : m_id(m_invalid_id)
2600         , m_compute(context)
2601         , m_fragment(context)
2602         , m_geometry(context)
2603         , m_tess_ctrl(context)
2604         , m_tess_eval(context)
2605         , m_vertex(context)
2606         , m_context(context)
2607 {
2608         /* Nothing to be done here */
2609 }
2610
2611 /** Destructor
2612  *
2613  **/
2614 Program::~Program()
2615 {
2616         Release();
2617 }
2618
2619 /** Initialize program instance
2620  *
2621  * @param compute_shader                Compute shader source code
2622  * @param fragment_shader               Fragment shader source code
2623  * @param geometry_shader               Geometry shader source code
2624  * @param tesselation_control_shader    Tesselation control shader source code
2625  * @param tesselation_evaluation_shader Tesselation evaluation shader source code
2626  * @param vertex_shader                 Vertex shader source code
2627  * @param captured_varyings             Vector of variables to be captured with transfrom feedback
2628  * @param capture_interleaved           Select mode of transform feedback (separate or interleaved)
2629  * @param is_separable                  Selects if monolithic or separable program should be built. Defaults to false
2630  **/
2631 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2632                                    const std::string& geometry_shader, const std::string& tesselation_control_shader,
2633                                    const std::string& tesselation_evaluation_shader, const std::string& vertex_shader,
2634                                    const NameVector& captured_varyings, bool capture_interleaved, bool is_separable)
2635 {
2636         /* Delete previous program */
2637         Release();
2638
2639         /* GL entry points */
2640         const Functions& gl = m_context.getRenderContext().getFunctions();
2641
2642         /* Initialize shaders */
2643         m_compute.Init(Shader::COMPUTE, compute_shader);
2644         m_fragment.Init(Shader::FRAGMENT, fragment_shader);
2645         m_geometry.Init(Shader::GEOMETRY, geometry_shader);
2646         m_tess_ctrl.Init(Shader::TESS_CTRL, tesselation_control_shader);
2647         m_tess_eval.Init(Shader::TESS_EVAL, tesselation_evaluation_shader);
2648         m_vertex.Init(Shader::VERTEX, vertex_shader);
2649
2650         /* Create program, set up transform feedback and attach shaders */
2651         Create(gl, m_id);
2652         Capture(gl, m_id, captured_varyings, capture_interleaved);
2653         Attach(gl, m_id, m_compute.m_id);
2654         Attach(gl, m_id, m_fragment.m_id);
2655         Attach(gl, m_id, m_geometry.m_id);
2656         Attach(gl, m_id, m_tess_ctrl.m_id);
2657         Attach(gl, m_id, m_tess_eval.m_id);
2658         Attach(gl, m_id, m_vertex.m_id);
2659
2660         /* Set separable parameter */
2661         if (true == is_separable)
2662         {
2663                 gl.programParameteri(m_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
2664                 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
2665         }
2666
2667         try
2668         {
2669                 /* Link program */
2670                 Link(gl, m_id);
2671         }
2672         catch (const LinkageException& exc)
2673         {
2674                 throw BuildException(exc.what(), compute_shader, fragment_shader, geometry_shader, tesselation_control_shader,
2675                                                          tesselation_evaluation_shader, vertex_shader);
2676         }
2677 }
2678
2679 /** Initialize program instance
2680  *
2681  * @param compute_shader                Compute shader source code
2682  * @param fragment_shader               Fragment shader source code
2683  * @param geometry_shader               Geometry shader source code
2684  * @param tesselation_control_shader    Tesselation control shader source code
2685  * @param tesselation_evaluation_shader Tesselation evaluation shader source code
2686  * @param vertex_shader                 Vertex shader source code
2687  * @param is_separable                  Selects if monolithic or separable program should be built. Defaults to false
2688  **/
2689 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2690                                    const std::string& geometry_shader, const std::string& tesselation_control_shader,
2691                                    const std::string& tesselation_evaluation_shader, const std::string& vertex_shader,
2692                                    bool is_separable)
2693 {
2694         NameVector captured_varying;
2695
2696         Init(compute_shader, fragment_shader, geometry_shader, tesselation_control_shader, tesselation_evaluation_shader,
2697                  vertex_shader, captured_varying, true, is_separable);
2698 }
2699
2700 /** Release program instance
2701  *
2702  **/
2703 void Program::Release()
2704 {
2705         const Functions& gl = m_context.getRenderContext().getFunctions();
2706
2707         if (m_invalid_id != m_id)
2708         {
2709                 Use(gl, m_invalid_id);
2710
2711                 gl.deleteProgram(m_id);
2712                 m_id = m_invalid_id;
2713         }
2714
2715         m_compute.Release();
2716         m_fragment.Release();
2717         m_geometry.Release();
2718         m_tess_ctrl.Release();
2719         m_tess_eval.Release();
2720         m_vertex.Release();
2721 }
2722
2723 /** Get <pname> for a set of active uniforms
2724  *
2725  * @param count   Number of indices
2726  * @param indices Indices of uniforms
2727  * @param pname   Queired pname
2728  * @param params  Array that will be filled with values of parameters
2729  **/
2730 void Program::GetActiveUniformsiv(GLsizei count, const GLuint* indices, GLenum pname, GLint* params) const
2731 {
2732         const Functions& gl = m_context.getRenderContext().getFunctions();
2733
2734         GetActiveUniformsiv(gl, m_id, count, indices, pname, params);
2735 }
2736
2737 /** Get location of attribute
2738  *
2739  * @param name Name of attribute
2740  *
2741  * @return Result of query
2742  **/
2743 glw::GLint Program::GetAttribLocation(const std::string& name) const
2744 {
2745         const Functions& gl = m_context.getRenderContext().getFunctions();
2746
2747         return GetAttribLocation(gl, m_id, name);
2748 }
2749
2750 /** Query resource
2751  *
2752  * @param interface Interface to be queried
2753  * @param index     Index of resource
2754  * @param property  Property to be queried
2755  * @param buf_size  Size of <params> buffer
2756  * @param params    Results of query
2757  **/
2758 void Program::GetResource(GLenum interface, GLuint index, GLenum property, GLsizei buf_size, GLint* params) const
2759 {
2760         const Functions& gl = m_context.getRenderContext().getFunctions();
2761
2762         GetResource(gl, m_id, interface, index, property, buf_size, params);
2763 }
2764
2765 /** Query for index of resource
2766  *
2767  * @param name      Name of resource
2768  * @param interface Interface to be queried
2769  *
2770  * @return Result of query
2771  **/
2772 glw::GLuint Program::GetResourceIndex(const std::string& name, GLenum interface) const
2773 {
2774         const Functions& gl = m_context.getRenderContext().getFunctions();
2775
2776         return GetResourceIndex(gl, m_id, name, interface);
2777 }
2778
2779 /** Get indices for a set of uniforms
2780  *
2781  * @param count   Count number of uniforms
2782  * @param names   Names of uniforms
2783  * @param indices Buffer that will be filled with indices
2784  **/
2785 void Program::GetUniformIndices(GLsizei count, const GLchar** names, GLuint* indices) const
2786 {
2787         const Functions& gl = m_context.getRenderContext().getFunctions();
2788
2789         GetUniformIndices(gl, m_id, count, names, indices);
2790 }
2791
2792 /** Get uniform location
2793  *
2794  * @param name Name of uniform
2795  *
2796  * @return Results of query
2797  **/
2798 glw::GLint Program::GetUniformLocation(const std::string& name) const
2799 {
2800         const Functions& gl = m_context.getRenderContext().getFunctions();
2801
2802         return GetUniformLocation(gl, m_id, name);
2803 }
2804
2805 /** Set program as active
2806  *
2807  **/
2808 void Program::Use() const
2809 {
2810         const Functions& gl = m_context.getRenderContext().getFunctions();
2811
2812         Use(gl, m_id);
2813 }
2814
2815 /** Attach shader to program
2816  *
2817  * @param gl         GL functions
2818  * @param program_id Id of program
2819  * @param shader_id  Id of shader
2820  **/
2821 void Program::Attach(const Functions& gl, GLuint program_id, GLuint shader_id)
2822 {
2823         /* Sanity checks */
2824         if ((m_invalid_id == program_id) || (Shader::m_invalid_id == shader_id))
2825         {
2826                 return;
2827         }
2828
2829         gl.attachShader(program_id, shader_id);
2830         GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
2831 }
2832
2833 /** Set up captured varyings
2834  *
2835  * @param gl                  GL functions
2836  * @param id                  Id of program
2837  * @param captured_varyings   Vector of varyings
2838  * @param capture_interleaved Selects if interleaved or separate mode should be used
2839  **/
2840 void Program::Capture(const Functions& gl, GLuint id, const NameVector& captured_varyings, bool capture_interleaved)
2841 {
2842         const size_t n_varyings = captured_varyings.size();
2843
2844         if (0 == n_varyings)
2845         {
2846                 /* empty list, skip */
2847                 return;
2848         }
2849
2850         std::vector<const GLchar*> varying_names;
2851         varying_names.resize(n_varyings);
2852
2853         for (size_t i = 0; i < n_varyings; ++i)
2854         {
2855                 varying_names[i] = captured_varyings[i].c_str();
2856         }
2857
2858         GLenum mode = 0;
2859         if (true == capture_interleaved)
2860         {
2861                 mode = GL_INTERLEAVED_ATTRIBS;
2862         }
2863         else
2864         {
2865                 mode = GL_SEPARATE_ATTRIBS;
2866         }
2867
2868         gl.transformFeedbackVaryings(id, static_cast<GLsizei>(n_varyings), &varying_names[0], mode);
2869         GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
2870 }
2871
2872 /** Create program instance
2873  *
2874  * @param gl     GL functions
2875  * @param out_id Id of program
2876  **/
2877 void Program::Create(const Functions& gl, GLuint& out_id)
2878 {
2879         const GLuint id = gl.createProgram();
2880         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
2881
2882         if (m_invalid_id == id)
2883         {
2884                 TCU_FAIL("Failed to create program");
2885         }
2886
2887         out_id = id;
2888 }
2889
2890 /** Get <pname> for a set of active uniforms
2891  *
2892  * @param gl         Functions
2893  * @param program_id Id of program
2894  * @param count      Number of indices
2895  * @param indices    Indices of uniforms
2896  * @param pname      Queired pname
2897  * @param params     Array that will be filled with values of parameters
2898  **/
2899 void Program::GetActiveUniformsiv(const Functions& gl, GLuint program_id, GLsizei count, const GLuint* indices,
2900                                                                   GLenum pname, GLint* params)
2901 {
2902         gl.getActiveUniformsiv(program_id, count, indices, pname, params);
2903         GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformsiv");
2904 }
2905
2906 /** Get indices for a set of uniforms
2907  *
2908  * @param gl         Functions
2909  * @param program_id Id of program
2910  * @param count      Count number of uniforms
2911  * @param names      Names of uniforms
2912  * @param indices    Buffer that will be filled with indices
2913  **/
2914 void Program::GetUniformIndices(const Functions& gl, GLuint program_id, GLsizei count, const GLchar** names,
2915                                                                 GLuint* indices)
2916 {
2917         gl.getUniformIndices(program_id, count, names, indices);
2918         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformIndices");
2919 }
2920
2921 /** Link program
2922  *
2923  * @param gl GL functions
2924  * @param id Id of program
2925  **/
2926 void Program::Link(const Functions& gl, GLuint id)
2927 {
2928         GLint status = GL_FALSE;
2929
2930         gl.linkProgram(id);
2931         GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
2932
2933         /* Get link status */
2934         gl.getProgramiv(id, GL_LINK_STATUS, &status);
2935         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2936
2937         /* Log link error */
2938         if (GL_TRUE != status)
2939         {
2940                 glw::GLint  length = 0;
2941                 std::string message;
2942
2943                 /* Get error log length */
2944                 gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &length);
2945                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2946
2947                 message.resize(length, 0);
2948
2949                 /* Get error log */
2950                 gl.getProgramInfoLog(id, length, 0, &message[0]);
2951                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
2952
2953                 throw LinkageException(message.c_str());
2954         }
2955 }
2956
2957 /** Set generic uniform
2958  *
2959  * @param gl       Functions
2960  * @param type     Type of uniform
2961  * @param count    Length of array
2962  * @param location Location of uniform
2963  * @param data     Data that will be used
2964  **/
2965 void Program::Uniform(const Functions& gl, const Type& type, GLsizei count, GLint location, const GLvoid* data)
2966 {
2967         if (-1 == location)
2968         {
2969                 TCU_FAIL("Uniform is inactive");
2970         }
2971
2972         switch (type.m_basic_type)
2973         {
2974         case Type::Double:
2975                 if (1 == type.m_n_columns)
2976                 {
2977                         getUniformNdv(gl, type.m_n_rows)(location, count, (const GLdouble*)data);
2978                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
2979                 }
2980                 else
2981                 {
2982                         getUniformMatrixNdv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLdouble*)data);
2983                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
2984                 }
2985                 break;
2986         case Type::Float:
2987                 if (1 == type.m_n_columns)
2988                 {
2989                         getUniformNfv(gl, type.m_n_rows)(location, count, (const GLfloat*)data);
2990                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
2991                 }
2992                 else
2993                 {
2994                         getUniformMatrixNfv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLfloat*)data);
2995                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
2996                 }
2997                 break;
2998         case Type::Int:
2999                 getUniformNiv(gl, type.m_n_rows)(location, count, (const GLint*)data);
3000                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
3001                 break;
3002         case Type::Uint:
3003                 getUniformNuiv(gl, type.m_n_rows)(location, count, (const GLuint*)data);
3004                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
3005                 break;
3006         default:
3007                 TCU_FAIL("Invalid enum");
3008         }
3009 }
3010
3011 /** Use program
3012  *
3013  * @param gl GL functions
3014  * @param id Id of program
3015  **/
3016 void Program::Use(const Functions& gl, GLuint id)
3017 {
3018         gl.useProgram(id);
3019         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
3020 }
3021
3022 /** Get location of attribute
3023  *
3024  * @param gl   GL functions
3025  * @param id   Id of program
3026  * @param name Name of attribute
3027  *
3028  * @return Location of attribute
3029  **/
3030 GLint Program::GetAttribLocation(const Functions& gl, GLuint id, const std::string& name)
3031 {
3032         GLint location = gl.getAttribLocation(id, name.c_str());
3033         GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
3034
3035         return location;
3036 }
3037
3038 /** Query resource
3039  *
3040  * @param gl        GL functions
3041  * @param id        Id of program
3042  * @param interface Interface to be queried
3043  * @param index     Index of resource
3044  * @param property  Property to be queried
3045  * @param buf_size  Size of <params> buffer
3046  * @param params    Results of query
3047  **/
3048 void Program::GetResource(const Functions& gl, GLuint id, GLenum interface, GLuint index, GLenum property,
3049                                                   GLsizei buf_size, GLint* params)
3050 {
3051         gl.getProgramResourceiv(id, interface, index, 1 /* propCount */, &property, buf_size /* bufSize */, 0 /* length */,
3052                                                         params);
3053         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceiv");
3054 }
3055
3056 /** Get index of resource
3057  *
3058  * @param gl        GL functions
3059  * @param id        Id of program
3060  * @param name      Name of resource
3061  * @param interface Program interface to queried
3062  *
3063  * @return Location of attribute
3064  **/
3065 GLuint Program::GetResourceIndex(const Functions& gl, GLuint id, const std::string& name, GLenum interface)
3066 {
3067         GLuint index = gl.getProgramResourceIndex(id, interface, name.c_str());
3068         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceIndex");
3069
3070         return index;
3071 }
3072
3073 /** Get location of attribute
3074  *
3075  * @param gl   GL functions
3076  * @param id   Id of program
3077  * @param name Name of attribute
3078  *
3079  * @return Location of uniform
3080  **/
3081 GLint Program::GetUniformLocation(const Functions& gl, GLuint id, const std::string& name)
3082 {
3083         GLint location = gl.getUniformLocation(id, name.c_str());
3084         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
3085
3086         return location;
3087 }
3088
3089 /** Constructor
3090  *
3091  * @param error_message    Error message
3092  * @param compute_shader   Source code for compute stage
3093  * @param fragment_shader  Source code for fragment stage
3094  * @param geometry_shader  Source code for geometry stage
3095  * @param tess_ctrl_shader Source code for tesselation control stage
3096  * @param tess_eval_shader Source code for tesselation evaluation stage
3097  * @param vertex_shader    Source code for vertex stage
3098  **/
3099 Program::BuildException::BuildException(const glw::GLchar* error_message, const std::string compute_shader,
3100                                                                                 const std::string fragment_shader, const std::string geometry_shader,
3101                                                                                 const std::string tess_ctrl_shader, const std::string tess_eval_shader,
3102                                                                                 const std::string vertex_shader)
3103         : m_error_message(error_message)
3104         , m_compute_shader(compute_shader)
3105         , m_fragment_shader(fragment_shader)
3106         , m_geometry_shader(geometry_shader)
3107         , m_tess_ctrl_shader(tess_ctrl_shader)
3108         , m_tess_eval_shader(tess_eval_shader)
3109         , m_vertex_shader(vertex_shader)
3110 {
3111 }
3112
3113 /** Overwrites std::exception::what method
3114  *
3115  * @return Message compossed from error message and shader sources
3116  **/
3117 const char* Program::BuildException::what() const throw()
3118 {
3119         return "Failed to link program";
3120 }
3121
3122 /** Logs error message and shader sources **/
3123 void Program::BuildException::log(deqp::Context& context) const
3124 {
3125         context.getTestContext().getLog() << tcu::TestLog::Message << "Link failure: " << m_error_message
3126                                                                           << tcu::TestLog::EndMessage;
3127
3128         Shader::LogSource(context, m_vertex_shader, Shader::VERTEX);
3129         Shader::LogSource(context, m_tess_ctrl_shader, Shader::TESS_CTRL);
3130         Shader::LogSource(context, m_tess_eval_shader, Shader::TESS_EVAL);
3131         Shader::LogSource(context, m_geometry_shader, Shader::GEOMETRY);
3132         Shader::LogSource(context, m_fragment_shader, Shader::FRAGMENT);
3133         Shader::LogSource(context, m_compute_shader, Shader::COMPUTE);
3134 }
3135
3136 /** Constructor
3137  *
3138  * @param message Linking error message
3139  **/
3140 Program::LinkageException::LinkageException(const glw::GLchar* message) : m_error_message(message)
3141 {
3142         /* Nothing to be done */
3143 }
3144
3145 /** Returns error messages
3146  *
3147  * @return Linking error message
3148  **/
3149 const char* Program::LinkageException::what() const throw()
3150 {
3151         return m_error_message.c_str();
3152 }
3153
3154 /* Texture constants */
3155 const GLuint Texture::m_invalid_id = -1;
3156
3157 /** Constructor.
3158  *
3159  * @param context CTS context.
3160  **/
3161 Texture::Texture(deqp::Context& context) : m_id(m_invalid_id), m_context(context), m_type(TEX_2D)
3162 {
3163         /* Nothing to done here */
3164 }
3165
3166 /** Destructor
3167  *
3168  **/
3169 Texture::~Texture()
3170 {
3171         Release();
3172 }
3173
3174 /** Initialize texture instance
3175  *
3176  * @param tex_type        Type of texture
3177  * @param width           Width of texture
3178  * @param height          Height of texture
3179  * @param depth           Depth of texture
3180  * @param internal_format Internal format of texture
3181  * @param format          Format of texture data
3182  * @param type            Type of texture data
3183  * @param data            Texture data
3184  **/
3185 void Texture::Init(TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum internal_format, GLenum format,
3186                                    GLenum type, GLvoid* data)
3187 {
3188         const Functions& gl = m_context.getRenderContext().getFunctions();
3189
3190         /* Delete previous texture */
3191         Release();
3192
3193         m_type = tex_type;
3194
3195         /* Generate, bind, allocate storage and upload data */
3196         Generate(gl, m_id);
3197         Bind(gl, m_id, tex_type);
3198         Storage(gl, tex_type, width, height, depth, internal_format);
3199         Update(gl, tex_type, width, height, depth, format, type, data);
3200 }
3201
3202 /** Initialize buffer texture
3203  *
3204  * @param internal_format Internal format of texture
3205  * @param buffer_id       Id of buffer that will be used as data source
3206  **/
3207 void Texture::Init(GLenum internal_format, GLuint buffer_id)
3208 {
3209         const Functions& gl = m_context.getRenderContext().getFunctions();
3210
3211         /* Delete previous texture */
3212         Release();
3213
3214         m_type = TEX_BUFFER;
3215
3216         /* Generate, bind and attach buffer */
3217         Generate(gl, m_id);
3218         Bind(gl, m_id, TEX_BUFFER);
3219         TexBuffer(gl, buffer_id, internal_format);
3220 }
3221
3222 /** Release texture instance
3223  *
3224  **/
3225 void Texture::Release()
3226 {
3227         if (m_invalid_id != m_id)
3228         {
3229                 const Functions& gl = m_context.getRenderContext().getFunctions();
3230
3231                 gl.deleteTextures(1, &m_id);
3232                 m_id = m_invalid_id;
3233         }
3234 }
3235
3236 /** Bind texture to its target
3237  *
3238  **/
3239 void Texture::Bind() const
3240 {
3241         const Functions& gl = m_context.getRenderContext().getFunctions();
3242
3243         Bind(gl, m_id, m_type);
3244 }
3245
3246 /** Get texture data
3247  *
3248  * @param format   Format of data
3249  * @param type     Type of data
3250  * @param out_data Buffer for data
3251  **/
3252 void Texture::Get(GLenum format, GLenum type, GLvoid* out_data) const
3253 {
3254         const Functions& gl = m_context.getRenderContext().getFunctions();
3255
3256         Bind(gl, m_id, m_type);
3257         Get(gl, m_type, format, type, out_data);
3258 }
3259
3260 /** Bind texture to target
3261  *
3262  * @param gl       GL functions
3263  * @param id       Id of texture
3264  * @param tex_type Type of texture
3265  **/
3266 void Texture::Bind(const Functions& gl, GLuint id, TYPES tex_type)
3267 {
3268         GLenum target = GetTargetGLenum(tex_type);
3269
3270         gl.bindTexture(target, id);
3271         GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
3272 }
3273
3274 /** Generate texture instance
3275  *
3276  * @param gl     GL functions
3277  * @param out_id Id of texture
3278  **/
3279 void Texture::Generate(const Functions& gl, GLuint& out_id)
3280 {
3281         GLuint id = m_invalid_id;
3282
3283         gl.genTextures(1, &id);
3284         GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
3285
3286         if (m_invalid_id == id)
3287         {
3288                 TCU_FAIL("Invalid id");
3289         }
3290
3291         out_id = id;
3292 }
3293
3294 /** Get texture data
3295  *
3296  * @param gl       GL functions
3297  * @param format   Format of data
3298  * @param type     Type of data
3299  * @param out_data Buffer for data
3300  **/
3301 void Texture::Get(const Functions& gl, TYPES tex_type, GLenum format, GLenum type, GLvoid* out_data)
3302 {
3303         GLenum target = GetTargetGLenum(tex_type);
3304
3305         if (TEX_CUBE != tex_type)
3306         {
3307                 gl.getTexImage(target, 0 /* level */, format, type, out_data);
3308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3309         }
3310         else
3311         {
3312                 GLint width;
3313                 GLint height;
3314
3315                 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
3316                 {
3317                         TCU_FAIL("Not implemented");
3318                 }
3319
3320                 GLuint texel_size = 4;
3321
3322                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
3323                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3324
3325                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
3326                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3327
3328                 const GLuint image_size = width * height * texel_size;
3329
3330                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
3331                                            (GLvoid*)((GLchar*)out_data + (image_size * 0)));
3332                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
3333                                            (GLvoid*)((GLchar*)out_data + (image_size * 1)));
3334                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
3335                                            (GLvoid*)((GLchar*)out_data + (image_size * 2)));
3336                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
3337                                            (GLvoid*)((GLchar*)out_data + (image_size * 3)));
3338                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
3339                                            (GLvoid*)((GLchar*)out_data + (image_size * 4)));
3340                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
3341                                            (GLvoid*)((GLchar*)out_data + (image_size * 5)));
3342                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3343         }
3344 }
3345
3346 /** Allocate storage for texture
3347  *
3348  * @param gl              GL functions
3349  * @param tex_type        Type of texture
3350  * @param width           Width of texture
3351  * @param height          Height of texture
3352  * @param depth           Depth of texture
3353  * @param internal_format Internal format of texture
3354  **/
3355 void Texture::Storage(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth,
3356                                           GLenum internal_format)
3357 {
3358         static const GLuint levels = 1;
3359
3360         GLenum target = GetTargetGLenum(tex_type);
3361
3362         switch (tex_type)
3363         {
3364         case TEX_1D:
3365                 gl.texStorage1D(target, levels, internal_format, width);
3366                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3367                 break;
3368         case TEX_2D:
3369         case TEX_1D_ARRAY:
3370         case TEX_2D_RECT:
3371         case TEX_CUBE:
3372                 gl.texStorage2D(target, levels, internal_format, width, height);
3373                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3374                 break;
3375         case TEX_3D:
3376         case TEX_2D_ARRAY:
3377                 gl.texStorage3D(target, levels, internal_format, width, height, depth);
3378                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3379                 break;
3380         default:
3381                 TCU_FAIL("Invliad enum");
3382                 break;
3383         }
3384 }
3385
3386 /** Attach buffer as source of texture buffer data
3387  *
3388  * @param gl              GL functions
3389  * @param internal_format Internal format of texture
3390  * @param buffer_id       Id of buffer that will be used as data source
3391  **/
3392 void Texture::TexBuffer(const Functions& gl, GLenum internal_format, GLuint& buffer_id)
3393 {
3394         gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
3395         GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
3396 }
3397
3398 /** Update contents of texture
3399  *
3400  * @param gl       GL functions
3401  * @param tex_type Type of texture
3402  * @param width    Width of texture
3403  * @param height   Height of texture
3404  * @param format   Format of data
3405  * @param type     Type of data
3406  * @param data     Buffer with image data
3407  **/
3408 void Texture::Update(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum format,
3409                                          GLenum type, GLvoid* data)
3410 {
3411         static const GLuint level = 0;
3412
3413         GLenum target = GetTargetGLenum(tex_type);
3414
3415         switch (tex_type)
3416         {
3417         case TEX_1D:
3418                 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
3419                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3420                 break;
3421         case TEX_2D:
3422         case TEX_1D_ARRAY:
3423         case TEX_2D_RECT:
3424                 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
3425                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3426                 break;
3427         case TEX_CUBE:
3428                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3429                                                  data);
3430                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3431                                                  data);
3432                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3433                                                  data);
3434                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3435                                                  data);
3436                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3437                                                  data);
3438                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3439                                                  data);
3440                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3441                 break;
3442         case TEX_3D:
3443         case TEX_2D_ARRAY:
3444                 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
3445                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3446                 break;
3447         default:
3448                 TCU_FAIL("Invliad enum");
3449                 break;
3450         }
3451 }
3452
3453 /** Get target for given texture type
3454  *
3455  * @param type Type of texture
3456  *
3457  * @return Target
3458  **/
3459 GLenum Texture::GetTargetGLenum(TYPES type)
3460 {
3461         GLenum result = 0;
3462
3463         switch (type)
3464         {
3465         case TEX_BUFFER:
3466                 result = GL_TEXTURE_BUFFER;
3467                 break;
3468         case TEX_2D:
3469                 result = GL_TEXTURE_2D;
3470                 break;
3471         case TEX_2D_RECT:
3472                 result = GL_TEXTURE_RECTANGLE;
3473                 break;
3474         case TEX_2D_ARRAY:
3475                 result = GL_TEXTURE_2D_ARRAY;
3476                 break;
3477         case TEX_3D:
3478                 result = GL_TEXTURE_3D;
3479                 break;
3480         case TEX_CUBE:
3481                 result = GL_TEXTURE_CUBE_MAP;
3482                 break;
3483         case TEX_1D:
3484                 result = GL_TEXTURE_1D;
3485                 break;
3486         case TEX_1D_ARRAY:
3487                 result = GL_TEXTURE_1D_ARRAY;
3488                 break;
3489         }
3490
3491         return result;
3492 }
3493
3494 /* VertexArray constants */
3495 const GLuint VertexArray::m_invalid_id = -1;
3496
3497 /** Constructor.
3498  *
3499  * @param context CTS context.
3500  **/
3501 VertexArray::VertexArray(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
3502 {
3503 }
3504
3505 /** Destructor
3506  *
3507  **/
3508 VertexArray::~VertexArray()
3509 {
3510         Release();
3511 }
3512
3513 /** Initialize vertex array instance
3514  *
3515  **/
3516 void VertexArray::Init()
3517 {
3518         /* Delete previous instance */
3519         Release();
3520
3521         const Functions& gl = m_context.getRenderContext().getFunctions();
3522
3523         Generate(gl, m_id);
3524 }
3525
3526 /** Release vertex array object instance
3527  *
3528  **/
3529 void VertexArray::Release()
3530 {
3531         if (m_invalid_id != m_id)
3532         {
3533                 const Functions& gl = m_context.getRenderContext().getFunctions();
3534
3535                 gl.deleteVertexArrays(1, &m_id);
3536
3537                 m_id = m_invalid_id;
3538         }
3539 }
3540
3541 /** Set attribute in VAO
3542  *
3543  * @param index            Index of attribute
3544  * @param type             Type of attribute
3545  * @param n_array_elements Arary length
3546  * @param normalized       Selectis if values should be normalized
3547  * @param stride           Stride
3548  * @param pointer          Pointer to data, or offset in buffer
3549  **/
3550 void VertexArray::Attribute(GLuint index, const Type& type, GLuint n_array_elements, GLboolean normalized,
3551                                                         GLsizei stride, const GLvoid* pointer)
3552 {
3553         const Functions& gl = m_context.getRenderContext().getFunctions();
3554
3555         AttribPointer(gl, index, type, n_array_elements, normalized, stride, pointer);
3556         Enable(gl, index, type, n_array_elements);
3557 }
3558
3559 /** Binds Vertex array object
3560  *
3561  **/
3562 void VertexArray::Bind()
3563 {
3564         const Functions& gl = m_context.getRenderContext().getFunctions();
3565
3566         Bind(gl, m_id);
3567 }
3568
3569 /** Set attribute in VAO
3570  *
3571  * @param gl               Functions
3572  * @param index            Index of attribute
3573  * @param type             Type of attribute
3574  * @param n_array_elements Arary length
3575  * @param normalized       Selectis if values should be normalized
3576  * @param stride           Stride
3577  * @param pointer          Pointer to data, or offset in buffer
3578  **/
3579 void VertexArray::AttribPointer(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements,
3580                                                                 GLboolean normalized, GLsizei stride, const GLvoid* pointer)
3581 {
3582         const GLuint basic_type_size = Type::GetTypeSize(type.m_basic_type);
3583         const GLint  size                        = (GLint)type.m_n_rows;
3584         const GLuint column_size         = (GLuint)size * basic_type_size;
3585         const GLenum gl_type             = Type::GetTypeGLenum(type.m_basic_type);
3586
3587         GLuint offset = 0;
3588
3589         /* If attribute is not an array */
3590         if (0 == n_array_elements)
3591         {
3592                 n_array_elements = 1;
3593         }
3594
3595         /* For each element in array */
3596         for (GLuint element = 0; element < n_array_elements; ++element)
3597         {
3598                 /* For each column in matrix */
3599                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3600                 {
3601                         /* Calculate offset */
3602                         const GLvoid* ptr = (GLubyte*)pointer + offset;
3603
3604                         /* Set up attribute */
3605                         switch (type.m_basic_type)
3606                         {
3607                         case Type::Float:
3608                                 gl.vertexAttribPointer(index, size, gl_type, normalized, stride, ptr);
3609                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3610                                 break;
3611                         case Type::Int:
3612                         case Type::Uint:
3613                                 gl.vertexAttribIPointer(index, size, gl_type, stride, ptr);
3614                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
3615                                 break;
3616                         case Type::Double:
3617                                 gl.vertexAttribLPointer(index, size, gl_type, stride, ptr);
3618                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribLPointer");
3619                                 break;
3620                         default:
3621                                 TCU_FAIL("Invalid enum");
3622                         }
3623
3624                         /* Next location */
3625                         offset += column_size;
3626                         index += 1;
3627                 }
3628         }
3629 }
3630
3631 /** Binds Vertex array object
3632  *
3633  * @param gl GL functions
3634  * @param id ID of vertex array object
3635  **/
3636 void VertexArray::Bind(const glw::Functions& gl, glw::GLuint id)
3637 {
3638         gl.bindVertexArray(id);
3639         GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
3640 }
3641
3642 /** Disable attribute in VAO
3643  *
3644  * @param gl               Functions
3645  * @param index            Index of attribute
3646  * @param type             Type of attribute
3647  * @param n_array_elements Arary length
3648  **/
3649 void VertexArray::Disable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3650 {
3651         /* If attribute is not an array */
3652         if (0 == n_array_elements)
3653         {
3654                 n_array_elements = 1;
3655         }
3656
3657         /* For each element in array */
3658         for (GLuint element = 0; element < n_array_elements; ++element)
3659         {
3660                 /* For each column in matrix */
3661                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3662                 {
3663                         /* Enable attribute array */
3664                         gl.disableVertexAttribArray(index);
3665                         GLU_EXPECT_NO_ERROR(gl.getError(), "DisableVertexAttribArray");
3666
3667                         /* Next location */
3668                         index += 1;
3669                 }
3670         }
3671 }
3672
3673 /** Set divisor for attribute
3674  *
3675  * @param gl               Functions
3676  * @param index            Index of attribute
3677  * @param divisor          New divisor value
3678  **/
3679 void VertexArray::Divisor(const Functions& gl, GLuint index, GLuint divisor)
3680 {
3681         gl.vertexAttribDivisor(index, divisor);
3682         GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribDivisor");
3683 }
3684
3685 /** Enables attribute in VAO
3686  *
3687  * @param gl               Functions
3688  * @param index            Index of attribute
3689  * @param type             Type of attribute
3690  * @param n_array_elements Arary length
3691  **/
3692 void VertexArray::Enable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3693 {
3694         /* If attribute is not an array */
3695         if (0 == n_array_elements)
3696         {
3697                 n_array_elements = 1;
3698         }
3699
3700         /* For each element in array */
3701         for (GLuint element = 0; element < n_array_elements; ++element)
3702         {
3703                 /* For each column in matrix */
3704                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3705                 {
3706                         /* Enable attribute array */
3707                         gl.enableVertexAttribArray(index);
3708                         GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3709
3710                         /* Next location */
3711                         index += 1;
3712                 }
3713         }
3714 }
3715
3716 /** Generates Vertex array object
3717  *
3718  * @param gl     GL functions
3719  * @param out_id ID of vertex array object
3720  **/
3721 void VertexArray::Generate(const glw::Functions& gl, glw::GLuint& out_id)
3722 {
3723         GLuint id = m_invalid_id;
3724
3725         gl.genVertexArrays(1, &id);
3726         GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
3727
3728         if (m_invalid_id == id)
3729         {
3730                 TCU_FAIL("Invalid id");
3731         }
3732
3733         out_id = id;
3734 }
3735
3736 /* Constatns used by Variable */
3737 const GLint Variable::m_automatic_location = -1;
3738
3739 /** Copy constructor
3740  *
3741  **/
3742 Variable::Variable(const Variable& var)
3743         : m_data(var.m_data)
3744         , m_data_size(var.m_data_size)
3745         , m_descriptor(var.m_descriptor.m_name.c_str(), var.m_descriptor.m_qualifiers.c_str(),
3746                                    var.m_descriptor.m_expected_component, var.m_descriptor.m_expected_location,
3747                                    var.m_descriptor.m_builtin, var.m_descriptor.m_normalized, var.m_descriptor.m_n_array_elements,
3748                                    var.m_descriptor.m_expected_stride_of_element, var.m_descriptor.m_offset)
3749         , m_storage(var.m_storage)
3750 {
3751         m_descriptor.m_type = var.m_descriptor.m_type;
3752
3753         if (BUILTIN != var.m_descriptor.m_type)
3754         {
3755                 m_descriptor.m_interface = var.m_descriptor.m_interface;
3756         }
3757 }
3758
3759 /** Get code that defines variable
3760  *
3761  * @param flavour Provides info if variable is array or not
3762  *
3763  * @return String with code
3764  **/
3765 std::string Variable::GetDefinition(FLAVOUR flavour) const
3766 {
3767         return m_descriptor.GetDefinition(flavour, m_storage);
3768 }
3769
3770 /** Calcualtes stride of variable
3771  *
3772  * @return Calculated value
3773  **/
3774 GLuint Variable::GetStride() const
3775 {
3776         GLint variable_stride = 0;
3777
3778         if (0 == m_descriptor.m_n_array_elements)
3779         {
3780                 variable_stride = m_descriptor.m_expected_stride_of_element;
3781         }
3782         else
3783         {
3784                 variable_stride = m_descriptor.m_expected_stride_of_element * m_descriptor.m_n_array_elements;
3785         }
3786
3787         return variable_stride;
3788 }
3789
3790 /** Check if variable is block
3791  *
3792  * @return true if variable type is block, false otherwise
3793  **/
3794 bool Variable::IsBlock() const
3795 {
3796         if (BUILTIN == m_descriptor.m_type)
3797         {
3798                 return false;
3799         }
3800
3801         const Interface* interface = m_descriptor.m_interface;
3802         if (0 == interface)
3803         {
3804                 TCU_FAIL("Nullptr");
3805         }
3806
3807         return (Interface::BLOCK == interface->m_type);
3808 }
3809
3810 /** Check if variable is struct
3811  *
3812  * @return true if variable type is struct, false otherwise
3813  **/
3814 bool Variable::IsStruct() const
3815 {
3816         if (BUILTIN == m_descriptor.m_type)
3817         {
3818                 return false;
3819         }
3820
3821         const Interface* interface = m_descriptor.m_interface;
3822         if (0 == interface)
3823         {
3824                 TCU_FAIL("Nullptr");
3825         }
3826
3827         return (Interface::STRUCT == interface->m_type);
3828 }
3829 /** Get code that reference variable
3830  *
3831  * @param parent_name Name of parent
3832  * @param variable    Descriptor of variable
3833  * @param flavour     Provides info about how variable should be referenced
3834  * @param array_index Index of array, ignored when variable is not array
3835  *
3836  * @return String with code
3837  **/
3838 std::string Variable::GetReference(const std::string& parent_name, const Descriptor& variable, FLAVOUR flavour,
3839                                                                    GLuint array_index)
3840 {
3841         std::string name;
3842
3843         /* Prepare name */
3844         if (false == parent_name.empty())
3845         {
3846                 name = parent_name;
3847                 name.append(".");
3848                 name.append(variable.m_name);
3849         }
3850         else
3851         {
3852                 name = variable.m_name;
3853         }
3854
3855         /* */
3856         switch (flavour)
3857         {
3858         case Utils::Variable::BASIC:
3859                 break;
3860
3861         case Utils::Variable::ARRAY:
3862                 name.append("[0]");
3863                 break;
3864
3865         case Utils::Variable::INDEXED_BY_INVOCATION_ID:
3866                 name.append("[gl_InvocationID]");
3867                 break;
3868         }
3869
3870         /* Assumption that both variables have same lengths */
3871         if (0 != variable.m_n_array_elements)
3872         {
3873                 GLchar buffer[16];
3874                 sprintf(buffer, "%d", array_index);
3875                 name.append("[");
3876                 name.append(buffer);
3877                 name.append("]");
3878         }
3879
3880         return name;
3881 }
3882
3883 /** Get "flavour" of varying
3884  *
3885  * @param stage     Stage of shader
3886  * @param direction Selects if varying is in or out
3887  *
3888  * @return Flavour
3889  **/
3890 Variable::FLAVOUR Variable::GetFlavour(Shader::STAGES stage, VARYING_DIRECTION direction)
3891 {
3892         FLAVOUR result = BASIC;
3893
3894         switch (stage)
3895         {
3896         case Shader::GEOMETRY:
3897         case Shader::TESS_EVAL:
3898                 if (INPUT == direction)
3899                 {
3900                         result = ARRAY;
3901                 }
3902                 break;
3903         case Shader::TESS_CTRL:
3904                 result = INDEXED_BY_INVOCATION_ID;
3905                 break;
3906         default:
3907                 break;
3908         }
3909
3910         return result;
3911 }
3912
3913 /** Constructor, for built-in types
3914  *
3915  * @param name                       Name
3916  * @param qualifiers                 Qualifiers
3917  * @param expected_component         Expected component of variable
3918  * @param expected_location          Expected location
3919  * @param type                       Type
3920  * @param normalized                 Selects if data should be normalized
3921  * @param n_array_elements           Length of array
3922  * @param expected_stride_of_element Expected stride of element
3923  * @param offset                     Offset
3924  **/
3925 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
3926                                                                  GLint expected_location, const Type& type, GLboolean normalized,
3927                                                                  GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
3928         : m_expected_component(expected_component)
3929         , m_expected_location(expected_location)
3930         , m_expected_stride_of_element(expected_stride_of_element)
3931         , m_n_array_elements(n_array_elements)
3932         , m_name(name)
3933         , m_normalized(normalized)
3934         , m_offset(offset)
3935         , m_qualifiers(qualifiers)
3936         , m_type(BUILTIN)
3937         , m_builtin(type)
3938 {
3939 }
3940
3941 /** Constructor, for interface types
3942  *
3943  * @param name                       Name
3944  * @param qualifiers                 Qualifiers
3945  * @param expected_component         Expected component of variable
3946  * @param expected_location          Expected location
3947  * @param interface                  Interface of variable
3948  * @param n_array_elements           Length of array
3949  * @param expected_stride_of_element Expected stride of element
3950  * @param offset                     Offset
3951  **/
3952 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_componenet,
3953                                                                  GLint expected_location, Interface* interface, GLuint n_array_elements,
3954                                                                  GLint expected_stride_of_element, GLuint offset)
3955         : m_expected_component(expected_componenet)
3956         , m_expected_location(expected_location)
3957         , m_expected_stride_of_element(expected_stride_of_element)
3958         , m_n_array_elements(n_array_elements)
3959         , m_name(name)
3960         , m_normalized(GL_FALSE)
3961         , m_offset(offset)
3962         , m_qualifiers(qualifiers)
3963         , m_type(INTERFACE)
3964         , m_interface(interface)
3965 {
3966 }
3967
3968 /** Get definition of variable
3969  *
3970  * @param flavour Flavour of variable
3971  * @param storage Storage used for variable
3972  *
3973  * @return code with defintion
3974  **/
3975 std::string Variable::Descriptor::GetDefinition(FLAVOUR flavour, STORAGE storage) const
3976 {
3977         static const GLchar* basic_template = "QUALIFIERS STORAGETYPE NAMEARRAY;";
3978         static const GLchar* array_template = "QUALIFIERS STORAGETYPE NAME[]ARRAY;";
3979         const GLchar*            storage_str    = 0;
3980
3981         std::string definition;
3982         size_t          position = 0;
3983
3984         /* Select definition template */
3985         switch (flavour)
3986         {
3987         case BASIC:
3988                 definition = basic_template;
3989                 break;
3990         case ARRAY:
3991         case INDEXED_BY_INVOCATION_ID:
3992                 definition = array_template;
3993                 break;
3994         default:
3995                 TCU_FAIL("Invliad enum");
3996                 break;
3997         }
3998
3999         if (BUILTIN != m_type)
4000         {
4001                 if (0 == m_interface)
4002                 {
4003                         TCU_FAIL("Nullptr");
4004                 }
4005         }
4006
4007         /* Qualifiers */
4008         if (true == m_qualifiers.empty())
4009         {
4010                 replaceToken("QUALIFIERS ", position, "", definition);
4011         }
4012         else
4013         {
4014                 replaceToken("QUALIFIERS", position, m_qualifiers.c_str(), definition);
4015         }
4016
4017         // According to spec: integer or unsigned integer type must always be declared with flat qualifier
4018         bool flat_qualifier = false;
4019         if (m_type != BUILTIN && m_interface != NULL)
4020         {
4021                 if (m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Int ||
4022                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Uint)
4023                 {
4024                         flat_qualifier = true;
4025                 }
4026         }
4027         /* Storage */
4028         switch (storage)
4029         {
4030         case VARYING_INPUT:
4031                 storage_str = flat_qualifier ? "flat in " : "in ";
4032                 break;
4033         case VARYING_OUTPUT:
4034                 storage_str = "out ";
4035                 break;
4036         case UNIFORM:
4037                 storage_str = "uniform ";
4038                 break;
4039         case SSB:
4040                 storage_str = "buffer ";
4041                 break;
4042         case MEMBER:
4043                 storage_str = "";
4044                 break;
4045         default:
4046                 TCU_FAIL("Invalid enum");
4047                 break;
4048         }
4049
4050         replaceToken("STORAGE", position, storage_str, definition);
4051
4052         /* Type */
4053         if (BUILTIN == m_type)
4054         {
4055                 replaceToken("TYPE", position, m_builtin.GetGLSLTypeName(), definition);
4056         }
4057         else
4058         {
4059                 if (Interface::STRUCT == m_interface->m_type)
4060                 {
4061                         replaceToken("TYPE", position, m_interface->m_name.c_str(), definition);
4062                 }
4063                 else
4064                 {
4065                         const std::string& block_definition = m_interface->GetDefinition();
4066
4067                         replaceToken("TYPE", position, block_definition.c_str(), definition);
4068                 }
4069         }
4070
4071         /* Name */
4072         replaceToken("NAME", position, m_name.c_str(), definition);
4073
4074         /* Array size */
4075         if (0 == m_n_array_elements)
4076         {
4077                 replaceToken("ARRAY", position, "", definition);
4078         }
4079         else
4080         {
4081                 char buffer[16];
4082                 sprintf(buffer, "[%d]", m_n_array_elements);
4083
4084                 replaceToken("ARRAY", position, buffer, definition);
4085         }
4086
4087         /* Done */
4088         return definition;
4089 }
4090
4091 /** Get definitions for variables collected in vector
4092  *
4093  * @param vector  Collection of variables
4094  * @param flavour Flavour of variables
4095  *
4096  * @return Code with definitions
4097  **/
4098 std::string GetDefinitions(const Variable::PtrVector& vector, Variable::FLAVOUR flavour)
4099 {
4100         std::string list         = Utils::g_list;
4101         size_t          position = 0;
4102
4103         for (GLuint i = 0; i < vector.size(); ++i)
4104         {
4105                 Utils::insertElementOfList(vector[i]->GetDefinition(flavour).c_str(), "\n", position, list);
4106         }
4107
4108         Utils::endList("", position, list);
4109
4110         return list;
4111 }
4112
4113 /** Get definitions for interfaces collected in vector
4114  *
4115  * @param vector Collection of interfaces
4116  *
4117  * @return Code with definitions
4118  **/
4119 std::string GetDefinitions(const Interface::PtrVector& vector)
4120 {
4121         std::string list         = Utils::g_list;
4122         size_t          position = 0;
4123
4124         for (GLuint i = 0; i < vector.size(); ++i)
4125         {
4126                 Utils::insertElementOfList(vector[i]->GetDefinition().c_str(), "\n", position, list);
4127         }
4128
4129         Utils::endList("", position, list);
4130
4131         return list;
4132 }
4133
4134 /** Constructor
4135  *
4136  * @param name Name
4137  * @param type Type of interface
4138  **/
4139 Interface::Interface(const GLchar* name, Interface::TYPE type) : m_name(name), m_type(type)
4140 {
4141 }
4142
4143 /** Adds member to interface
4144  *
4145  * @param member Descriptor of new member
4146  *
4147  * @return Pointer to just created member
4148  **/
4149 Variable::Descriptor* Interface::AddMember(const Variable::Descriptor& member)
4150 {
4151         m_members.push_back(member);
4152
4153         return &m_members.back();
4154 }
4155
4156 /** Get definition of interface
4157  *
4158  * @param Code with definition
4159  **/
4160 std::string Interface::GetDefinition() const
4161 {
4162         std::string definition;
4163         size_t          position = 0;
4164
4165         const GLchar* member_list = "    MEMBER_DEFINITION\nMEMBER_LIST";
4166
4167         if (STRUCT == m_type)
4168         {
4169                 definition = "struct NAME {\nMEMBER_LIST};";
4170         }
4171         else
4172         {
4173                 definition = "NAME {\nMEMBER_LIST}";
4174         }
4175
4176         /* Name */
4177         replaceToken("NAME", position, m_name.c_str(), definition);
4178
4179         /* Member list */
4180         for (GLuint i = 0; i < m_members.size(); ++i)
4181         {
4182                 const size_t       start_position       = position;
4183                 const std::string& member_definition = m_members[i].GetDefinition(Variable::BASIC, Variable::MEMBER);
4184
4185                 /* Member list */
4186                 replaceToken("MEMBER_LIST", position, member_list, definition);
4187
4188                 /* Move back position */
4189                 position = start_position;
4190
4191                 /* Member definition */
4192                 replaceToken("MEMBER_DEFINITION", position, member_definition.c_str(), definition);
4193         }
4194
4195         /* Remove last member list */
4196         replaceToken("MEMBER_LIST", position, "", definition);
4197
4198         /* Done */
4199         return definition;
4200 }
4201
4202 /** Adds member of built-in type to interface
4203  *
4204  * @param name                       Name
4205  * @param qualifiers                 Qualifiers
4206  * @param expected_component         Expected component of variable
4207  * @param expected_location          Expected location
4208  * @param type                       Type
4209  * @param normalized                 Selects if data should be normalized
4210  * @param n_array_elements           Length of array
4211  * @param expected_stride_of_element Expected stride of element
4212  * @param offset                     Offset
4213  *
4214  * @return Pointer to just created member
4215  **/
4216 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4217                                                                                 GLint expected_location, const Type& type, GLboolean normalized,
4218                                                                                 GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
4219 {
4220         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, type, normalized,
4221                                                                                   n_array_elements, expected_stride_of_element, offset));
4222 }
4223
4224 /** Adds member of interface type to interface
4225  *
4226  * @param name                       Name
4227  * @param qualifiers                 Qualifiers
4228  * @param expected_component         Expected component of variable
4229  * @param expected_location          Expected location
4230  * @param type                       Type
4231  * @param normalized                 Selects if data should be normalized
4232  * @param n_array_elements           Length of array
4233  * @param expected_stride_of_element Expected stride of element
4234  * @param offset                     Offset
4235  *
4236  * @return Pointer to just created member
4237  **/
4238 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4239                                                                                 GLint expected_location, Interface* nterface, GLuint n_array_elements,
4240                                                                                 GLint expected_stride_of_element, GLuint offset)
4241 {
4242         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, nterface,
4243                                                                                   n_array_elements, expected_stride_of_element, offset));
4244 }
4245
4246 /** Clears contents of vector of pointers
4247  *
4248  * @tparam T Type of elements
4249  *
4250  * @param vector Collection to be cleared
4251  **/
4252 template <typename T>
4253 void clearPtrVector(std::vector<T*>& vector)
4254 {
4255         for (size_t i = 0; i < vector.size(); ++i)
4256         {
4257                 T* t = vector[i];
4258
4259                 vector[i] = 0;
4260
4261                 if (0 != t)
4262                 {
4263                         delete t;
4264                 }
4265         }
4266
4267         vector.clear();
4268 }
4269
4270 /** Constructor
4271  *
4272  * @param stage Stage described by that interface
4273  **/
4274 ShaderInterface::ShaderInterface(Shader::STAGES stage) : m_stage(stage)
4275 {
4276         /* Nothing to be done */
4277 }
4278
4279 /** Get definitions of globals
4280  *
4281  * @return Code with definitions
4282  **/
4283 std::string ShaderInterface::GetDefinitionsGlobals() const
4284 {
4285         return m_globals;
4286 }
4287
4288 /** Get definitions of inputs
4289  *
4290  * @return Code with definitions
4291  **/
4292 std::string ShaderInterface::GetDefinitionsInputs() const
4293 {
4294         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::INPUT);
4295
4296         return GetDefinitions(m_inputs, flavour);
4297 }
4298
4299 /** Get definitions of outputs
4300  *
4301  * @return Code with definitions
4302  **/
4303 std::string ShaderInterface::GetDefinitionsOutputs() const
4304 {
4305         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::OUTPUT);
4306
4307         return GetDefinitions(m_outputs, flavour);
4308 }
4309
4310 /** Get definitions of buffers
4311  *
4312  * @return Code with definitions
4313  **/
4314 std::string ShaderInterface::GetDefinitionsSSBs() const
4315 {
4316         return GetDefinitions(m_ssb_blocks, Variable::BASIC);
4317 }
4318
4319 /** Get definitions of uniforms
4320  *
4321  * @return Code with definitions
4322  **/
4323 std::string ShaderInterface::GetDefinitionsUniforms() const
4324 {
4325         return GetDefinitions(m_uniforms, Variable::BASIC);
4326 }
4327
4328 /** Constructor
4329  *
4330  * @param in  Input variable
4331  * @param out Output variable
4332  **/
4333 VaryingConnection::VaryingConnection(Variable* in, Variable* out) : m_in(in), m_out(out)
4334 {
4335         /* NBothing to be done here */
4336 }
4337
4338 /** Adds new varying connection to given stage
4339  *
4340  * @param stage Shader stage
4341  * @param in    In varying
4342  * @param out   Out varying
4343  **/
4344 void VaryingPassthrough::Add(Shader::STAGES stage, Variable* in, Variable* out)
4345 {
4346         VaryingConnection::Vector& vector = Get(stage);
4347
4348         vector.push_back(VaryingConnection(in, out));
4349 }
4350
4351 /** Get all passthrough connections for given stage
4352  *
4353  * @param stage Shader stage
4354  *
4355  * @return Vector of connections
4356  **/
4357 VaryingConnection::Vector& VaryingPassthrough::Get(Shader::STAGES stage)
4358 {
4359         VaryingConnection::Vector* result = 0;
4360
4361         switch (stage)
4362         {
4363         case Shader::FRAGMENT:
4364                 result = &m_fragment;
4365                 break;
4366         case Shader::GEOMETRY:
4367                 result = &m_geometry;
4368                 break;
4369         case Shader::TESS_CTRL:
4370                 result = &m_tess_ctrl;
4371                 break;
4372         case Shader::TESS_EVAL:
4373                 result = &m_tess_eval;
4374                 break;
4375         case Shader::VERTEX:
4376                 result = &m_vertex;
4377                 break;
4378         default:
4379                 TCU_FAIL("Invalid enum");
4380         }
4381
4382         return *result;
4383 }
4384
4385 /** Constructor
4386  *
4387  **/
4388 ProgramInterface::ProgramInterface()
4389         : m_compute(Shader::COMPUTE)
4390         , m_vertex(Shader::VERTEX)
4391         , m_tess_ctrl(Shader::TESS_CTRL)
4392         , m_tess_eval(Shader::TESS_EVAL)
4393         , m_geometry(Shader::GEOMETRY)
4394         , m_fragment(Shader::FRAGMENT)
4395 {
4396 }
4397
4398 /** Destructor
4399  *
4400  **/
4401 ProgramInterface::~ProgramInterface()
4402 {
4403         clearPtrVector(m_blocks);
4404         clearPtrVector(m_structures);
4405 }
4406
4407 /** Adds new interface
4408  *
4409  * @param name
4410  * @param type
4411  *
4412  * @return Pointer to created interface
4413  **/
4414 Interface* ProgramInterface::AddInterface(const GLchar* name, Interface::TYPE type)
4415 {
4416         Interface* interface = 0;
4417
4418         if (Interface::STRUCT == type)
4419         {
4420                 interface = new Interface(name, type);
4421
4422                 m_structures.push_back(interface);
4423         }
4424         else
4425         {
4426                 interface = new Interface(name, type);
4427
4428                 m_blocks.push_back(interface);
4429         }
4430
4431         return interface;
4432 }
4433
4434 /** Adds new block interface
4435  *
4436  * @param name
4437  *
4438  * @return Pointer to created interface
4439  **/
4440 Interface* ProgramInterface::Block(const GLchar* name)
4441 {
4442         return AddInterface(name, Interface::BLOCK);
4443 }
4444
4445 /** Get interface of given shader stage
4446  *
4447  * @param stage Shader stage
4448  *
4449  * @return Reference to stage interface
4450  **/
4451 ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage)
4452 {
4453         ShaderInterface* interface = 0;
4454
4455         switch (stage)
4456         {
4457         case Shader::COMPUTE:
4458                 interface = &m_compute;
4459                 break;
4460         case Shader::FRAGMENT:
4461                 interface = &m_fragment;
4462                 break;
4463         case Shader::GEOMETRY:
4464                 interface = &m_geometry;
4465                 break;
4466         case Shader::TESS_CTRL:
4467                 interface = &m_tess_ctrl;
4468                 break;
4469         case Shader::TESS_EVAL:
4470                 interface = &m_tess_eval;
4471                 break;
4472         case Shader::VERTEX:
4473                 interface = &m_vertex;
4474                 break;
4475         default:
4476                 TCU_FAIL("Invalid enum");
4477         }
4478
4479         return *interface;
4480 }
4481
4482 /** Get interface of given shader stage
4483  *
4484  * @param stage Shader stage
4485  *
4486  * @return Reference to stage interface
4487  **/
4488 const ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage) const
4489 {
4490         const ShaderInterface* interface = 0;
4491
4492         switch (stage)
4493         {
4494         case Shader::COMPUTE:
4495                 interface = &m_compute;
4496                 break;
4497         case Shader::FRAGMENT:
4498                 interface = &m_fragment;
4499                 break;
4500         case Shader::GEOMETRY:
4501                 interface = &m_geometry;
4502                 break;
4503         case Shader::TESS_CTRL:
4504                 interface = &m_tess_ctrl;
4505                 break;
4506         case Shader::TESS_EVAL:
4507                 interface = &m_tess_eval;
4508                 break;
4509         case Shader::VERTEX:
4510                 interface = &m_vertex;
4511                 break;
4512         default:
4513                 TCU_FAIL("Invalid enum");
4514         }
4515
4516         return *interface;
4517 }
4518
4519 /** Clone interface of Vertex shader stage to other stages
4520  * It creates matching inputs, outputs, uniforms and buffers in other stages.
4521  * There are no additional outputs for FRAGMENT shader generated.
4522  *
4523  * @param varying_passthrough Collection of varyings connections
4524  **/
4525 void ProgramInterface::CloneVertexInterface(VaryingPassthrough& varying_passthrough)
4526 {
4527         /* VS outputs >> TCS inputs >> TCS outputs >> ..  >> FS inputs */
4528         for (size_t i = 0; i < m_vertex.m_outputs.size(); ++i)
4529         {
4530                 const Variable& vs_var = *m_vertex.m_outputs[i];
4531                 const GLchar*   prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4532
4533                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4534                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4535                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4536                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4537         }
4538
4539         /* Copy uniforms from VS to other stages */
4540         for (size_t i = 0; i < m_vertex.m_uniforms.size(); ++i)
4541         {
4542                 Variable&        vs_var = *m_vertex.m_uniforms[i];
4543                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4544
4545                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4546                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4547                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4548                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4549                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4550
4551                 /* Uniform blocks needs unique binding */
4552                 if (true == vs_var.IsBlock())
4553                 {
4554                         replaceBinding(vs_var, Shader::VERTEX);
4555                 }
4556         }
4557
4558         /* Copy SSBs from VS to other stages */
4559         for (size_t i = 0; i < m_vertex.m_ssb_blocks.size(); ++i)
4560         {
4561                 Variable&        vs_var = *m_vertex.m_ssb_blocks[i];
4562                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4563
4564                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4565                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4566                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4567                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4568                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4569
4570                 /* SSBs blocks needs unique binding */
4571                 if (true == vs_var.IsBlock())
4572                 {
4573                         replaceBinding(vs_var, Shader::VERTEX);
4574                 }
4575         }
4576
4577         m_compute.m_globals   = m_vertex.m_globals;
4578         m_fragment.m_globals  = m_vertex.m_globals;
4579         m_geometry.m_globals  = m_vertex.m_globals;
4580         m_tess_ctrl.m_globals = m_vertex.m_globals;
4581         m_tess_eval.m_globals = m_vertex.m_globals;
4582 }
4583
4584 /** Clone variable for specific stage
4585  *
4586  * @param variable            Variable
4587  * @param stage               Requested stage
4588  * @param prefix              Prefix used in variable name that is specific for original stage
4589  * @param varying_passthrough Collection of varyings connections
4590  **/
4591 void ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage, const GLchar* prefix,
4592                                                                                          VaryingPassthrough& varying_passthrough)
4593 {
4594         switch (variable.m_storage)
4595         {
4596         case Variable::VARYING_OUTPUT:
4597         {
4598                 Variable* in = cloneVariableForStage(variable, stage, Variable::VARYING_INPUT, prefix);
4599
4600                 if (Shader::FRAGMENT != stage)
4601                 {
4602                         Variable* out = cloneVariableForStage(variable, stage, Variable::VARYING_OUTPUT, prefix);
4603                         varying_passthrough.Add(stage, in, out);
4604                 }
4605         }
4606         break;
4607         case Variable::UNIFORM:
4608         case Variable::SSB:
4609                 cloneVariableForStage(variable, stage, variable.m_storage, prefix);
4610                 break;
4611         default:
4612                 TCU_FAIL("Invalid enum");
4613                 break;
4614         }
4615 }
4616
4617 /** Clone variable for specific stage
4618  *
4619  * @param variable Variable
4620  * @param stage    Requested stage
4621  * @param storage  Storage used by variable
4622  * @param prefix   Prefix used in variable name that is specific for original stage
4623  *
4624  * @return New variable
4625  **/
4626 Variable* ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage,
4627                                                                                                   Variable::STORAGE storage, const GLchar* prefix)
4628 {
4629         /* Initialize with original variable */
4630         Variable* var = new Variable(variable);
4631         if (0 == var)
4632         {
4633                 TCU_FAIL("Memory allocation");
4634         }
4635
4636         /* Set up storage */
4637         var->m_storage = storage;
4638
4639         /* Get name */
4640         std::string name = variable.m_descriptor.m_name;
4641
4642         /* Prefix name with stage ID, empty means default block */
4643         if (false == name.empty())
4644         {
4645                 size_t            position       = 0;
4646                 const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4647                 Utils::replaceToken(prefix, position, stage_prefix, name);
4648         }
4649         var->m_descriptor.m_name = name;
4650
4651         /* Clone block */
4652         const bool is_block = variable.IsBlock();
4653         if (true == is_block)
4654         {
4655                 const Interface* interface = variable.m_descriptor.m_interface;
4656
4657                 Interface* block = CloneBlockForStage(*interface, stage, storage, prefix);
4658
4659                 var->m_descriptor.m_interface = block;
4660         }
4661
4662         /* Store variable */
4663         ShaderInterface& si             = GetShaderInterface(stage);
4664         Variable*                result = 0;
4665
4666         switch (storage)
4667         {
4668         case Variable::VARYING_INPUT:
4669                 si.m_inputs.push_back(var);
4670                 result = si.m_inputs.back();
4671                 break;
4672         case Variable::VARYING_OUTPUT:
4673                 si.m_outputs.push_back(var);
4674                 result = si.m_outputs.back();
4675                 break;
4676         case Variable::UNIFORM:
4677                 /* Uniform blocks needs unique binding */
4678                 if (true == is_block)
4679                 {
4680                         replaceBinding(*var, stage);
4681                 }
4682
4683                 si.m_uniforms.push_back(var);
4684                 result = si.m_uniforms.back();
4685                 break;
4686         case Variable::SSB:
4687                 /* SSBs needs unique binding */
4688                 if (true == is_block)
4689                 {
4690                         replaceBinding(*var, stage);
4691                 }
4692
4693                 si.m_ssb_blocks.push_back(var);
4694                 result = si.m_ssb_blocks.back();
4695                 break;
4696         default:
4697                 TCU_FAIL("Invalid enum");
4698                 break;
4699         }
4700
4701         return result;
4702 }
4703
4704 /** clone block to specific stage
4705  *
4706  * @param block   Block to be copied
4707  * @param stage   Specific stage
4708  * @param storage Storage used by block
4709  * @param prefix  Prefix used in block name
4710  *
4711  * @return New interface
4712  **/
4713 Interface* ProgramInterface::CloneBlockForStage(const Interface& block, Shader::STAGES stage, Variable::STORAGE storage,
4714                                                                                                 const GLchar* prefix)
4715 {
4716         /* Get name */
4717         std::string name = block.m_name;
4718
4719         /* Prefix name with stage ID */
4720         size_t            position       = 0;
4721         const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4722         Utils::replaceToken(prefix, position, stage_prefix, name);
4723
4724         Interface* ptr = GetBlock(name.c_str());
4725
4726         if (0 == ptr)
4727         {
4728                 ptr = AddInterface(name.c_str(), Interface::BLOCK);
4729         }
4730
4731         ptr->m_members = block.m_members;
4732
4733         return ptr;
4734 }
4735
4736 /** Get stage specific prefix used in names
4737  *
4738  * @param stage   Stage
4739  * @param storage Storage class
4740  *
4741  * @return String
4742  **/
4743 const GLchar* ProgramInterface::GetStagePrefix(Shader::STAGES stage, Variable::STORAGE storage)
4744 {
4745         static const GLchar* lut[Shader::STAGE_MAX][Variable::STORAGE_MAX] = {
4746                 /*          IN          OUT         UNIFORM     SSB        MEMBER       */
4747                 /* CS  */ { 0, 0, "cs_uni_", "cs_buf_", "" },
4748                 /* VS  */ { "in_vs_", "vs_tcs_", "vs_uni_", "vs_buf_", "" },
4749                 /* TCS */ { "vs_tcs_", "tcs_tes_", "tcs_uni_", "tcs_buf_", "" },
4750                 /* TES */ { "tcs_tes_", "tes_gs_", "tes_uni_", "tes_buf_", "" },
4751                 /* GS  */ { "tes_gs_", "gs_fs_", "gs_uni_", "gs_buf_", "" },
4752                 /* FS  */ { "gs_fs_", "fs_out_", "fs_uni_", "fs_buf_", "" },
4753         };
4754
4755         const GLchar* result = 0;
4756
4757         result = lut[stage][storage];
4758
4759         return result;
4760 }
4761
4762 /** Get definitions of all structures used in program interface
4763  *
4764  * @return String with code
4765  **/
4766 std::string ProgramInterface::GetDefinitionsStructures() const
4767 {
4768         return GetDefinitions(m_structures);
4769 }
4770
4771 /** Get interface code for stage
4772  *
4773  * @param stage Specific stage
4774  *
4775  * @return String with code
4776  **/
4777 std::string ProgramInterface::GetInterfaceForStage(Shader::STAGES stage) const
4778 {
4779         size_t          position  = 0;
4780         std::string interface = "/* Globals */\n"
4781                                                         "GLOBALS\n"
4782                                                         "\n"
4783                                                         "/* Structures */\n"
4784                                                         "STRUCTURES\n"
4785                                                         "\n"
4786                                                         "/* Uniforms */\n"
4787                                                         "UNIFORMS\n"
4788                                                         "\n"
4789                                                         "/* Inputs */\n"
4790                                                         "INPUTS\n"
4791                                                         "\n"
4792                                                         "/* Outputs */\n"
4793                                                         "OUTPUTS\n"
4794                                                         "\n"
4795                                                         "/* Storage */\n"
4796                                                         "STORAGE\n";
4797
4798         const ShaderInterface& si = GetShaderInterface(stage);
4799
4800         const std::string& structures = GetDefinitionsStructures();
4801
4802         const std::string& globals  = si.GetDefinitionsGlobals();
4803         const std::string& inputs   = si.GetDefinitionsInputs();
4804         const std::string& outputs  = si.GetDefinitionsOutputs();
4805         const std::string& uniforms = si.GetDefinitionsUniforms();
4806         const std::string& ssbs         = si.GetDefinitionsSSBs();
4807
4808         replaceToken("GLOBALS", position, globals.c_str(), interface);
4809         replaceToken("STRUCTURES", position, structures.c_str(), interface);
4810         replaceToken("UNIFORMS", position, uniforms.c_str(), interface);
4811         replaceToken("INPUTS", position, inputs.c_str(), interface);
4812         replaceToken("OUTPUTS", position, outputs.c_str(), interface);
4813         replaceToken("STORAGE", position, ssbs.c_str(), interface);
4814
4815         return interface;
4816 }
4817
4818 /** Functional object used in find_if algorithm, in search for interface of given name
4819  *
4820  **/
4821 struct matchInterfaceName
4822 {
4823         matchInterfaceName(const GLchar* name) : m_name(name)
4824         {
4825         }
4826
4827         bool operator()(const Interface* interface)
4828         {
4829                 return 0 == interface->m_name.compare(m_name);
4830         }
4831
4832         const GLchar* m_name;
4833 };
4834
4835 /** Finds interface of given name in given vector of interfaces
4836  *
4837  * @param vector Collection of interfaces
4838  * @param name   Requested name
4839  *
4840  * @return Pointer to interface if available, 0 otherwise
4841  **/
4842 static Interface* findInterfaceByName(Interface::PtrVector& vector, const GLchar* name)
4843 {
4844         Interface::PtrVector::iterator it = std::find_if(vector.begin(), vector.end(), matchInterfaceName(name));
4845
4846         if (vector.end() != it)
4847         {
4848                 return *it;
4849         }
4850         else
4851         {
4852                 return 0;
4853         }
4854 }
4855
4856 /** Search for block of given name
4857  *
4858  * @param name Name of block
4859  *
4860  * @return Pointer to block or 0
4861  **/
4862 Interface* ProgramInterface::GetBlock(const GLchar* name)
4863 {
4864         return findInterfaceByName(m_blocks, name);
4865 }
4866
4867 /** Search for structure of given name
4868  *
4869  * @param name Name of structure
4870  *
4871  * @return Pointer to structure or 0
4872  **/
4873 Interface* ProgramInterface::GetStructure(const GLchar* name)
4874 {
4875         return findInterfaceByName(m_structures, name);
4876 }
4877
4878 /** Adds new sturcture to interface
4879  *
4880  * @param name Name of structure
4881  *
4882  * @return Created structure
4883  **/
4884 Interface* ProgramInterface::Structure(const GLchar* name)
4885 {
4886         return AddInterface(name, Interface::STRUCT);
4887 }
4888
4889 /** Replace "BINDING" token in qualifiers string to value specific for given stage
4890  *
4891  * @param variable Variable to modify
4892  * @param stage    Requested stage
4893  **/
4894 void ProgramInterface::replaceBinding(Variable& variable, Shader::STAGES stage)
4895 {
4896         GLchar binding[16];
4897         sprintf(binding, "%d", stage);
4898         replaceAllTokens("BINDING", binding, variable.m_descriptor.m_qualifiers);
4899 }
4900 } /* Utils namespace */
4901
4902 /** Debuging procedure. Logs parameters.
4903  *
4904  * @param source   As specified in GL spec.
4905  * @param type     As specified in GL spec.
4906  * @param id       As specified in GL spec.
4907  * @param severity As specified in GL spec.
4908  * @param ignored
4909  * @param message  As specified in GL spec.
4910  * @param info     Pointer to instance of Context used by test.
4911  */
4912 void GLW_APIENTRY debug_proc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /* length */,
4913                                                          const GLchar* message, void* info)
4914 {
4915         deqp::Context* ctx = (deqp::Context*)info;
4916
4917         const GLchar* source_str   = "Unknown";
4918         const GLchar* type_str   = "Unknown";
4919         const GLchar* severity_str = "Unknown";
4920
4921         switch (source)
4922         {
4923         case GL_DEBUG_SOURCE_API:
4924                 source_str = "API";
4925                 break;
4926         case GL_DEBUG_SOURCE_APPLICATION:
4927                 source_str = "APP";
4928                 break;
4929         case GL_DEBUG_SOURCE_OTHER:
4930                 source_str = "OTR";
4931                 break;
4932         case GL_DEBUG_SOURCE_SHADER_COMPILER:
4933                 source_str = "COM";
4934                 break;
4935         case GL_DEBUG_SOURCE_THIRD_PARTY:
4936                 source_str = "3RD";
4937                 break;
4938         case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
4939                 source_str = "WS";
4940                 break;
4941         default:
4942                 break;
4943         }
4944
4945         switch (type)
4946         {
4947         case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
4948                 type_str = "DEPRECATED_BEHAVIOR";
4949                 break;
4950         case GL_DEBUG_TYPE_ERROR:
4951                 type_str = "ERROR";
4952                 break;
4953         case GL_DEBUG_TYPE_MARKER:
4954                 type_str = "MARKER";
4955                 break;
4956         case GL_DEBUG_TYPE_OTHER:
4957                 type_str = "OTHER";
4958                 break;
4959         case GL_DEBUG_TYPE_PERFORMANCE:
4960                 type_str = "PERFORMANCE";
4961                 break;
4962         case GL_DEBUG_TYPE_POP_GROUP:
4963                 type_str = "POP_GROUP";
4964                 break;
4965         case GL_DEBUG_TYPE_PORTABILITY:
4966                 type_str = "PORTABILITY";
4967                 break;
4968         case GL_DEBUG_TYPE_PUSH_GROUP:
4969                 type_str = "PUSH_GROUP";
4970                 break;
4971         case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
4972                 type_str = "UNDEFINED_BEHAVIOR";
4973                 break;
4974         default:
4975                 break;
4976         }
4977
4978         switch (severity)
4979         {
4980         case GL_DEBUG_SEVERITY_HIGH:
4981                 severity_str = "H";
4982                 break;
4983         case GL_DEBUG_SEVERITY_LOW:
4984                 severity_str = "L";
4985                 break;
4986         case GL_DEBUG_SEVERITY_MEDIUM:
4987                 severity_str = "M";
4988                 break;
4989         case GL_DEBUG_SEVERITY_NOTIFICATION:
4990                 severity_str = "N";
4991                 break;
4992         default:
4993                 break;
4994         }
4995
4996         ctx->getTestContext().getLog() << tcu::TestLog::Message << "DEBUG_INFO: " << std::setw(3) << source_str << "|"
4997                                                                    << severity_str << "|" << std::setw(18) << type_str << "|" << std::setw(12) << id
4998                                                                    << ": " << message << tcu::TestLog::EndMessage;
4999 }
5000
5001 /** Constructor
5002  *
5003  * @param context          Test context
5004  * @param test_name        Test name
5005  * @param test_description Test description
5006  **/
5007 TestBase::TestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5008         : TestCase(context, test_name, test_description)
5009 {
5010         /* Nothing to be done here */
5011 }
5012
5013 /** Execute test
5014  *
5015  * @return tcu::TestNode::STOP otherwise
5016  **/
5017 tcu::TestNode::IterateResult TestBase::iterate()
5018 {
5019         bool test_result;
5020
5021 #if DEBUG_ENBALE_MESSAGE_CALLBACK
5022         const Functions& gl = m_context.getRenderContext().getFunctions();
5023
5024         gl.debugMessageCallback(debug_proc, &m_context);
5025         GLU_EXPECT_NO_ERROR(gl.getError(), "DebugMessageCallback");
5026 #endif /* DEBUG_ENBALE_MESSAGE_CALLBACK */
5027
5028         try
5029         {
5030                 /* Execute test */
5031                 test_result = test();
5032         }
5033         catch (std::exception& exc)
5034         {
5035                 TCU_FAIL(exc.what());
5036         }
5037
5038         /* Set result */
5039         if (true == test_result)
5040         {
5041                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
5042         }
5043         else
5044         {
5045                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5046         }
5047
5048         /* Done */
5049         return tcu::TestNode::STOP;
5050 }
5051
5052 /** Get last input location available for given type at specific stage
5053  *
5054  * @param stage        Shader stage
5055  * @param type         Input type
5056  * @param array_length Length of input array
5057  *
5058  * @return Last location index
5059  **/
5060 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5061 {
5062         GLint  divide = 4; /* 4 components per location */
5063         GLint  param  = 0;
5064         GLenum pname  = 0;
5065
5066         /* Select pnmae */
5067         switch (stage)
5068         {
5069         case Utils::Shader::FRAGMENT:
5070                 pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5071                 break;
5072         case Utils::Shader::GEOMETRY:
5073                 pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5074                 break;
5075         case Utils::Shader::TESS_CTRL:
5076                 pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5077                 break;
5078         case Utils::Shader::TESS_EVAL:
5079                 pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5080                 break;
5081         case Utils::Shader::VERTEX:
5082                 pname  = GL_MAX_VERTEX_ATTRIBS;
5083                 divide = 1;
5084                 break;
5085         default:
5086                 TCU_FAIL("Invalid enum");
5087                 break;
5088         }
5089
5090         /* Zero means no array, but 1 slot is required */
5091         if (0 == array_length)
5092         {
5093                 array_length += 1;
5094         }
5095
5096         /* Get MAX */
5097         const Functions& gl = m_context.getRenderContext().getFunctions();
5098
5099         gl.getIntegerv(pname, &param);
5100         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5101
5102 /* Calculate */
5103 #if WRKARD_VARYINGLOCATIONSTEST
5104
5105         const GLint n_avl_locations = 16;
5106
5107 #else
5108
5109         const GLint n_avl_locations = param / divide;
5110
5111 #endif
5112
5113         const GLuint n_req_location = type.GetLocations() * array_length;
5114
5115         return n_avl_locations - n_req_location; /* last is max - 1 */
5116 }
5117
5118 /** Get last input location available for given type at specific stage
5119  *
5120  * @param stage        Shader stage
5121  * @param type         Input type
5122  * @param array_length Length of input array
5123  *
5124  * @return Last location index
5125  **/
5126 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5127 {
5128         GLint  param = 0;
5129         GLenum pname = 0;
5130
5131         /* Select pnmae */
5132         switch (stage)
5133         {
5134         case Utils::Shader::GEOMETRY:
5135                 pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5136                 break;
5137         case Utils::Shader::TESS_CTRL:
5138                 pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5139                 break;
5140         case Utils::Shader::TESS_EVAL:
5141                 pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5142                 break;
5143         case Utils::Shader::VERTEX:
5144                 pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5145                 break;
5146         default:
5147                 TCU_FAIL("Invalid enum");
5148                 break;
5149         }
5150
5151         /* Zero means no array, but 1 slot is required */
5152         if (0 == array_length)
5153         {
5154                 array_length += 1;
5155         }
5156
5157         /* Get MAX */
5158         const Functions& gl = m_context.getRenderContext().getFunctions();
5159
5160         gl.getIntegerv(pname, &param);
5161         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5162
5163 /* Calculate */
5164 #if WRKARD_VARYINGLOCATIONSTEST
5165
5166         const GLint n_avl_locations = 16;
5167
5168 #else
5169
5170         const GLint n_avl_locations = param / 4; /* 4 components per location */
5171
5172 #endif
5173
5174         const GLuint n_req_location = type.GetLocations() * array_length;
5175
5176         return n_avl_locations - n_req_location; /* last is max - 1 */
5177 }
5178
5179 /** Basic implementation
5180  *
5181  * @param ignored
5182  *
5183  * @return Empty string
5184  **/
5185 std::string TestBase::getTestCaseName(GLuint /* test_case_index */)
5186 {
5187         std::string result;
5188
5189         return result;
5190 }
5191
5192 /** Basic implementation
5193  *
5194  * @return 1
5195  **/
5196 GLuint TestBase::getTestCaseNumber()
5197 {
5198         return 1;
5199 }
5200
5201 /** Check if flat qualifier is required for given type, stage and storage
5202  *
5203  * @param stage        Shader stage
5204  * @param type         Input type
5205  * @param storage      Storage of variable
5206  *
5207  * @return Last location index
5208  **/
5209 bool TestBase::isFlatRequired(Utils::Shader::STAGES stage, const Utils::Type& type,
5210                                                           Utils::Variable::STORAGE storage) const
5211 {
5212         /* Float types do not need flat at all */
5213         if (Utils::Type::Float == type.m_basic_type)
5214         {
5215                 return false;
5216         }
5217
5218         /* Inputs to fragment shader */
5219         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_INPUT == storage))
5220         {
5221                 return true;
5222         }
5223
5224         /* Outputs from geometry shader */
5225         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_OUTPUT == storage))
5226         {
5227                 return true;
5228         }
5229
5230         return false;
5231 }
5232
5233 /** Basic implementation of testInit method
5234  *
5235  **/
5236 void TestBase::testInit()
5237 {
5238 }
5239
5240 /** Calculate stride for interface
5241  *
5242  * @param interface Interface
5243  *
5244  * @return Calculated value
5245  **/
5246 GLuint TestBase::calculateStride(const Utils::Interface& interface) const
5247 {
5248         const size_t n_members = interface.m_members.size();
5249
5250         GLuint stride = 0;
5251
5252         for (size_t i = 0; i < n_members; ++i)
5253         {
5254                 const Utils::Variable::Descriptor& member                 = interface.m_members[i];
5255                 const GLuint                                       member_offset  = member.m_offset;
5256                 const GLuint                                       member_stride  = member.m_expected_stride_of_element;
5257                 const GLuint                                       member_ends_at = member_offset + member_stride;
5258
5259                 stride = std::max(stride, member_ends_at);
5260         }
5261
5262         return stride;
5263 }
5264
5265 /** Generate data for interface. This routine is recursive
5266  *
5267  * @param interface Interface
5268  * @param offset    Offset in out_data
5269  * @param out_data  Buffer to be filled
5270  **/
5271 void TestBase::generateData(const Utils::Interface& interface, GLuint offset, std::vector<GLubyte>& out_data) const
5272 {
5273         const size_t n_members = interface.m_members.size();
5274         GLubyte*         ptr       = &out_data[offset];
5275
5276         for (size_t i = 0; i < n_members; ++i)
5277         {
5278                 const Utils::Variable::Descriptor& member                = interface.m_members[i];
5279                 const GLuint                                       member_offset = member.m_offset;
5280                 const GLuint n_elements = (0 == member.m_n_array_elements) ? 1 : member.m_n_array_elements;
5281
5282                 for (GLuint element = 0; element < n_elements; ++element)
5283                 {
5284                         const GLuint element_offset = element * member.m_expected_stride_of_element;
5285                         const GLuint data_offfset   = member_offset + element_offset;
5286
5287                         if (Utils::Variable::BUILTIN == member.m_type)
5288                         {
5289                                 const std::vector<GLubyte>& data = member.m_builtin.GenerateData();
5290
5291                                 memcpy(ptr + data_offfset, &data[0], data.size());
5292                         }
5293                         else
5294                         {
5295                                 generateData(*member.m_interface, offset + data_offfset, out_data);
5296                         }
5297                 }
5298         }
5299 }
5300
5301 /** Get type at index
5302  *
5303  * @param index Index of requested type
5304  *
5305  * @return Type
5306  **/
5307 Utils::Type TestBase::getType(GLuint index) const
5308 {
5309         Utils::Type type;
5310
5311         switch (index)
5312         {
5313         case 0:
5314                 type = Utils::Type::_double;
5315                 break;
5316         case 1:
5317                 type = Utils::Type::dmat2;
5318                 break;
5319         case 2:
5320                 type = Utils::Type::dmat2x3;
5321                 break;
5322         case 3:
5323                 type = Utils::Type::dmat2x4;
5324                 break;
5325         case 4:
5326                 type = Utils::Type::dmat3;
5327                 break;
5328         case 5:
5329                 type = Utils::Type::dmat3x2;
5330                 break;
5331         case 6:
5332                 type = Utils::Type::dmat3x4;
5333                 break;
5334         case 7:
5335                 type = Utils::Type::dmat4;
5336                 break;
5337         case 8:
5338                 type = Utils::Type::dmat4x2;
5339                 break;
5340         case 9:
5341                 type = Utils::Type::dmat4x3;
5342                 break;
5343         case 10:
5344                 type = Utils::Type::dvec2;
5345                 break;
5346         case 11:
5347                 type = Utils::Type::dvec3;
5348                 break;
5349         case 12:
5350                 type = Utils::Type::dvec4;
5351                 break;
5352         case 13:
5353                 type = Utils::Type::_float;
5354                 break;
5355         case 14:
5356                 type = Utils::Type::mat2;
5357                 break;
5358         case 15:
5359                 type = Utils::Type::mat2x3;
5360                 break;
5361         case 16:
5362                 type = Utils::Type::mat2x4;
5363                 break;
5364         case 17:
5365                 type = Utils::Type::mat3;
5366                 break;
5367         case 18:
5368                 type = Utils::Type::mat3x2;
5369                 break;
5370         case 19:
5371                 type = Utils::Type::mat3x4;
5372                 break;
5373         case 20:
5374                 type = Utils::Type::mat4;
5375                 break;
5376         case 21:
5377                 type = Utils::Type::mat4x2;
5378                 break;
5379         case 22:
5380                 type = Utils::Type::mat4x3;
5381                 break;
5382         case 23:
5383                 type = Utils::Type::vec2;
5384                 break;
5385         case 24:
5386                 type = Utils::Type::vec3;
5387                 break;
5388         case 25:
5389                 type = Utils::Type::vec4;
5390                 break;
5391         case 26:
5392                 type = Utils::Type::_int;
5393                 break;
5394         case 27:
5395                 type = Utils::Type::ivec2;
5396                 break;
5397         case 28:
5398                 type = Utils::Type::ivec3;
5399                 break;
5400         case 29:
5401                 type = Utils::Type::ivec4;
5402                 break;
5403         case 30:
5404                 type = Utils::Type::uint;
5405                 break;
5406         case 31:
5407                 type = Utils::Type::uvec2;
5408                 break;
5409         case 32:
5410                 type = Utils::Type::uvec3;
5411                 break;
5412         case 33:
5413                 type = Utils::Type::uvec4;
5414                 break;
5415         default:
5416                 TCU_FAIL("invalid enum");
5417         }
5418
5419         return type;
5420 }
5421
5422 /** Get name of type at index
5423  *
5424  * @param index Index of type
5425  *
5426  * @return Name
5427  **/
5428 std::string TestBase::getTypeName(GLuint index) const
5429 {
5430         std::string name = getType(index).GetGLSLTypeName();
5431
5432         return name;
5433 }
5434
5435 /** Get number of types
5436  *
5437  * @return 34
5438  **/
5439 glw::GLuint TestBase::getTypesNumber() const
5440 {
5441         return 34;
5442 }
5443
5444 /** Execute test
5445  *
5446  * @return true if test pass, false otherwise
5447  **/
5448 bool TestBase::test()
5449 {
5450         bool   result           = true;
5451         GLuint n_test_cases = 0;
5452
5453         /* Prepare test */
5454         testInit();
5455
5456         /* GL entry points */
5457         const Functions& gl = m_context.getRenderContext().getFunctions();
5458
5459         /* Tesselation patch set up */
5460         gl.patchParameteri(GL_PATCH_VERTICES, 1);
5461         GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
5462
5463         /* Get number of test cases */
5464         n_test_cases = getTestCaseNumber();
5465
5466 #if DEBUG_REPEAT_TEST_CASE
5467
5468         while (1)
5469         {
5470                 GLuint test_case = DEBUG_REPEATED_TEST_CASE;
5471
5472 #else /* DEBUG_REPEAT_TEST_CASE */
5473
5474         for (GLuint test_case = 0; test_case < n_test_cases; ++test_case)
5475         {
5476
5477 #endif /* DEBUG_REPEAT_TEST_CASE */
5478
5479                 bool case_result = true;
5480
5481                 /* Execute case */
5482                 if (false == testCase(test_case))
5483                 {
5484                         case_result = false;
5485                 }
5486
5487                 /* Log failure */
5488                 if (false == case_result)
5489                 {
5490                         const std::string& test_case_name = getTestCaseName(test_case);
5491
5492                         if (false == test_case_name.empty())
5493                         {
5494                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5495                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5496                         }
5497                         else
5498                         {
5499                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5500                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5501                         }
5502
5503                         result = false;
5504                 }
5505         }
5506
5507         /* Done */
5508         return result;
5509 }
5510
5511 /* Constants used by BufferTestBase */
5512 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5513
5514 /** Constructor
5515  *
5516  * @param context          Test context
5517  * @param test_name        Name of test
5518  * @param test_description Description of test
5519  **/
5520 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5521         : TestBase(context, test_name, test_description)
5522 {
5523 }
5524
5525 /** Execute drawArrays for single vertex
5526  *
5527  * @param ignored
5528  *
5529  * @return true
5530  **/
5531 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5532 {
5533         const Functions& gl = m_context.getRenderContext().getFunctions();
5534
5535         gl.disable(GL_RASTERIZER_DISCARD);
5536         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5537
5538         gl.beginTransformFeedback(GL_POINTS);
5539         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5540
5541         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5542         if (tesEnabled == false)
5543         {
5544                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5545         }
5546         else
5547         {
5548                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5549         }
5550
5551         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5552
5553         gl.endTransformFeedback();
5554         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5555
5556         return true;
5557 }
5558
5559 /** Get descriptors of buffers necessary for test
5560  *
5561  * @param ignored
5562  * @param ignored
5563  **/
5564 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5565                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5566 {
5567         /* Nothhing to be done */
5568 }
5569
5570 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5571  *
5572  * @param ignored
5573  * @param ignored
5574  **/
5575 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5576                                                                                  Utils::Program::NameVector& /* captured_varyings */)
5577 {
5578         /* Nothing to be done */
5579 }
5580
5581 /** Get body of main function for given shader stage
5582  *
5583  * @param ignored
5584  * @param ignored
5585  * @param out_assignments  Set to empty
5586  * @param out_calculations Set to empty
5587  **/
5588 void BufferTestBase::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5589                                                                    std::string& out_assignments, std::string& out_calculations)
5590 {
5591         out_assignments  = "";
5592         out_calculations = "";
5593 }
5594
5595 /** Get interface of shader
5596  *
5597  * @param ignored
5598  * @param ignored
5599  * @param out_interface Set to ""
5600  **/
5601 void BufferTestBase::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5602                                                                                 std::string& out_interface)
5603 {
5604         out_interface = "";
5605 }
5606
5607 /** Get source code of shader
5608  *
5609  * @param test_case_index Index of test case
5610  * @param stage           Shader stage
5611  *
5612  * @return Source
5613  **/
5614 std::string BufferTestBase::getShaderSource(glw::GLuint test_case_index, Utils::Shader::STAGES stage)
5615 {
5616         std::string assignments;
5617         std::string calculations;
5618         std::string interface;
5619
5620         /* */
5621         getShaderBody(test_case_index, stage, assignments, calculations);
5622         getShaderInterface(test_case_index, stage, interface);
5623
5624         /* */
5625         std::string source = getShaderTemplate(stage);
5626
5627         /* */
5628         size_t position = 0;
5629         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
5630         Utils::replaceToken("CALCULATIONS", position, calculations.c_str(), source);
5631         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
5632
5633         /* */
5634         return source;
5635 }
5636
5637 /** Inspects program to check if all resources are as expected
5638  *
5639  * @param ignored
5640  * @param ignored
5641  * @param ignored
5642  *
5643  * @return true
5644  **/
5645 bool BufferTestBase::inspectProgram(GLuint /* test_case_index */, Utils::Program& /* program */,
5646                                                                         std::stringstream& /* out_stream */)
5647 {
5648         return true;
5649 }
5650
5651 /** Runs test case
5652  *
5653  * @param test_case_index Id of test case
5654  *
5655  * @return true if test case pass, false otherwise
5656  **/
5657 bool BufferTestBase::testCase(GLuint test_case_index)
5658 {
5659         try
5660         {
5661                 bufferCollection                   buffers;
5662                 Utils::Program::NameVector captured_varyings;
5663                 bufferDescriptor::Vector   descriptors;
5664                 Utils::Program                     program(m_context);
5665                 Utils::VertexArray                 vao(m_context);
5666
5667                 /* Get captured varyings */
5668                 getCapturedVaryings(test_case_index, captured_varyings);
5669
5670                 /* Get shader sources */
5671                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5672                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5673                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5674                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5675                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5676
5677                 /* Set up program */
5678                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5679                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5680
5681                 /* Inspection */
5682                 {
5683                         std::stringstream stream;
5684                         if (false == inspectProgram(test_case_index, program, stream))
5685                         {
5686                                 m_context.getTestContext().getLog()
5687                                         << tcu::TestLog::Message
5688                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5689                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5690                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5691                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5692                                         << tcu::TestLog::KernelSource(fragment_shader);
5693
5694                                 return false;
5695                         }
5696                 }
5697
5698                 program.Use();
5699
5700                 /* Set up buffers */
5701                 getBufferDescriptors(test_case_index, descriptors);
5702                 cleanBuffers();
5703                 prepareBuffers(descriptors, buffers);
5704
5705                 /* Set up vao */
5706                 vao.Init();
5707                 vao.Bind();
5708
5709                 /* Draw */
5710                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5711
5712 #if USE_NSIGHT
5713                 m_context.getRenderContext().postIterate();
5714 #endif
5715
5716                 if (false == result)
5717                 {
5718                         m_context.getTestContext().getLog()
5719                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5720                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5721                                 << tcu::TestLog::KernelSource(fragment_shader);
5722
5723                         return false;
5724                 }
5725
5726                 /* Verify result */
5727                 if (false == verifyBuffers(buffers))
5728                 {
5729                         m_context.getTestContext().getLog()
5730                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5731                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5732                                 << tcu::TestLog::KernelSource(fragment_shader);
5733
5734                         return false;
5735                 }
5736         }
5737         catch (Utils::Shader::InvalidSourceException& exc)
5738         {
5739                 exc.log(m_context);
5740                 TCU_FAIL(exc.what());
5741         }
5742         catch (Utils::Program::BuildException& exc)
5743         {
5744                 exc.log(m_context);
5745                 TCU_FAIL(exc.what());
5746         }
5747
5748         /* Done */
5749         return true;
5750 }
5751
5752 /** Verify contents of buffers
5753  *
5754  * @param buffers Collection of buffers to be verified
5755  *
5756  * @return true if everything is as expected, false otherwise
5757  **/
5758 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5759 {
5760         bool result = true;
5761
5762         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5763                  ++it)
5764         {
5765                 bufferCollection::pair& pair       = *it;
5766                 Utils::Buffer*                  buffer   = pair.m_buffer;
5767                 bufferDescriptor*               descriptor = pair.m_descriptor;
5768                 size_t                                  size       = descriptor->m_expected_data.size();
5769
5770                 /* Skip buffers that have no expected data */
5771                 if (0 == size)
5772                 {
5773                         continue;
5774                 }
5775
5776                 /* Get pointer to contents of buffer */
5777                 buffer->Bind();
5778                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5779
5780                 /* Get pointer to expected data */
5781                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5782
5783                 /* Compare */
5784                 int res = memcmp(buffer_data, expected_data, size);
5785
5786                 if (0 != res)
5787                 {
5788                         m_context.getTestContext().getLog()
5789                                 << tcu::TestLog::Message
5790                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5791                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5792
5793                         result = false;
5794                 }
5795
5796                 /* Release buffer mapping */
5797                 buffer->UnMap();
5798         }
5799
5800         return result;
5801 }
5802
5803 /** Unbinds all uniforms and xfb
5804  *
5805  **/
5806 void BufferTestBase::cleanBuffers()
5807 {
5808         const Functions& gl = m_context.getRenderContext().getFunctions();
5809
5810         GLint max_uni = 0;
5811         GLint max_xfb = 0;
5812
5813         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5814         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5815         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5816
5817         for (GLint i = 0; i < max_uni; ++i)
5818         {
5819                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5820         }
5821
5822         for (GLint i = 0; i < max_xfb; ++i)
5823         {
5824                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5825         }
5826 }
5827
5828 /** Get template of shader for given stage
5829  *
5830  * @param stage Stage
5831  *
5832  * @return Template of shader source
5833  **/
5834 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5835 {
5836         static const GLchar* compute_shader_template = "#version 430 core\n"
5837                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5838                                                                                                    "\n"
5839                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5840                                                                                                    "\n"
5841                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5842                                                                                                    "\n"
5843                                                                                                    "INTERFACE"
5844                                                                                                    "\n"
5845                                                                                                    "void main()\n"
5846                                                                                                    "{\n"
5847                                                                                                    "CALCULATIONS"
5848                                                                                                    "\n"
5849                                                                                                    "ASSIGNMENTS"
5850                                                                                                    "}\n"
5851                                                                                                    "\n";
5852
5853         static const GLchar* fragment_shader_template = "#version 430 core\n"
5854                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5855                                                                                                         "\n"
5856                                                                                                         "INTERFACE"
5857                                                                                                         "\n"
5858                                                                                                         "void main()\n"
5859                                                                                                         "{\n"
5860                                                                                                         "CALCULATIONS"
5861                                                                                                         "\n"
5862                                                                                                         "ASSIGNMENTS"
5863                                                                                                         "}\n"
5864                                                                                                         "\n";
5865
5866         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5867         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5868         static const GLchar* geometry_shader_template = "#version 430 core\n"
5869                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5870                                                                                                         "\n"
5871                                                                                                         "layout(points)                   in;\n"
5872                                                                                                         "layout(points, max_vertices = 3) out;\n"
5873                                                                                                         "\n"
5874                                                                                                         "INTERFACE"
5875                                                                                                         "\n"
5876                                                                                                         "void main()\n"
5877                                                                                                         "{\n"
5878                                                                                                         "CALCULATIONS"
5879                                                                                                         "\n"
5880                                                                                                         "\n"
5881                                                                                                         "ASSIGNMENTS"
5882                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5883                                                                                                         "    EmitVertex();\n"
5884                                                                                                         "}\n"
5885                                                                                                         "\n";
5886
5887         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5888                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5889                                                                                                          "\n"
5890                                                                                                          "layout(vertices = 1) out;\n"
5891                                                                                                          "\n"
5892                                                                                                          "INTERFACE"
5893                                                                                                          "\n"
5894                                                                                                          "void main()\n"
5895                                                                                                          "{\n"
5896                                                                                                          "CALCULATIONS"
5897                                                                                                          "\n"
5898                                                                                                          "ASSIGNMENTS"
5899                                                                                                          "\n"
5900                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5901                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5902                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5903                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5904                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5905                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5906                                                                                                          "}\n"
5907                                                                                                          "\n";
5908
5909         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5910                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5911                                                                                                          "\n"
5912                                                                                                          "layout(isolines, point_mode) in;\n"
5913                                                                                                          "\n"
5914                                                                                                          "INTERFACE"
5915                                                                                                          "\n"
5916                                                                                                          "void main()\n"
5917                                                                                                          "{\n"
5918                                                                                                          "CALCULATIONS"
5919                                                                                                          "\n"
5920                                                                                                          "ASSIGNMENTS"
5921                                                                                                          "}\n"
5922                                                                                                          "\n";
5923
5924         static const GLchar* vertex_shader_template = "#version 430 core\n"
5925                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5926                                                                                                   "\n"
5927                                                                                                   "INTERFACE"
5928                                                                                                   "\n"
5929                                                                                                   "void main()\n"
5930                                                                                                   "{\n"
5931                                                                                                   "CALCULATIONS"
5932                                                                                                   "\n"
5933                                                                                                   "ASSIGNMENTS"
5934                                                                                                   "}\n"
5935                                                                                                   "\n";
5936
5937         const GLchar* result = 0;
5938
5939         switch (stage)
5940         {
5941         case Utils::Shader::COMPUTE:
5942                 result = compute_shader_template;
5943                 break;
5944         case Utils::Shader::FRAGMENT:
5945                 result = fragment_shader_template;
5946                 break;
5947         case Utils::Shader::GEOMETRY:
5948                 result = geometry_shader_template;
5949                 break;
5950         case Utils::Shader::TESS_CTRL:
5951                 result = tess_ctrl_shader_template;
5952                 break;
5953         case Utils::Shader::TESS_EVAL:
5954                 result = tess_eval_shader_template;
5955                 break;
5956         case Utils::Shader::VERTEX:
5957                 result = vertex_shader_template;
5958                 break;
5959         default:
5960                 TCU_FAIL("Invalid enum");
5961         }
5962
5963         return result;
5964 }
5965
5966 /** Prepare buffer according to descriptor
5967  *
5968  * @param buffer Buffer to prepare
5969  * @param desc   Descriptor
5970  **/
5971 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
5972 {
5973         GLsizeiptr size = 0;
5974         GLvoid* data = 0;
5975
5976         if (false == desc.m_initial_data.empty())
5977         {
5978                 size = desc.m_initial_data.size();
5979                 data = &desc.m_initial_data[0];
5980         }
5981         else if (false == desc.m_expected_data.empty())
5982         {
5983                 size = desc.m_expected_data.size();
5984         }
5985
5986         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
5987
5988         if (bufferDescriptor::m_non_indexed != desc.m_index)
5989         {
5990                 buffer.BindBase(desc.m_index);
5991         }
5992         else
5993         {
5994                 buffer.Bind();
5995         }
5996 }
5997
5998 /** Prepare collection of buffer
5999  *
6000  * @param descriptors Collection of descriptors
6001  * @param out_buffers Collection of buffers
6002  **/
6003 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6004 {
6005         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6006         {
6007                 bufferCollection::pair pair;
6008
6009                 pair.m_buffer = new Utils::Buffer(m_context);
6010                 if (0 == pair.m_buffer)
6011                 {
6012                         TCU_FAIL("Memory allocation failed");
6013                 }
6014
6015                 pair.m_descriptor = &(*it);
6016
6017                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6018
6019                 out_buffers.m_vector.push_back(pair);
6020         }
6021 }
6022
6023 /** Destructor
6024  *
6025  **/
6026 BufferTestBase::bufferCollection::~bufferCollection()
6027 {
6028         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6029         {
6030                 if (0 != it->m_buffer)
6031                 {
6032                         delete it->m_buffer;
6033                         it->m_buffer = 0;
6034                 }
6035         }
6036 }
6037
6038 /** Constructor
6039  *
6040  * @param context          Test context
6041  * @param test_name        Name of test
6042  * @param test_description Description of test
6043  **/
6044 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6045         : TestBase(context, test_name, test_description)
6046 {
6047 }
6048
6049 /** Selects if "compute" stage is relevant for test
6050  *
6051  * @param ignored
6052  *
6053  * @return true
6054  **/
6055 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6056 {
6057         return true;
6058 }
6059
6060 /** Selects if compilation failure is expected result
6061  *
6062  * @param ignored
6063  *
6064  * @return true
6065  **/
6066 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6067 {
6068         return true;
6069 }
6070
6071 /** Runs test case
6072  *
6073  * @param test_case_index Id of test case
6074  *
6075  * @return true if test case pass, false otherwise
6076  **/
6077 bool NegativeTestBase::testCase(GLuint test_case_index)
6078 {
6079         bool test_case_result = true;
6080
6081         /* Compute */
6082         if (true == isComputeRelevant(test_case_index))
6083         {
6084                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6085                 bool                       is_build_error         = false;
6086                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6087                 Utils::Program   program(m_context);
6088
6089                 try
6090                 {
6091                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6092                                                  false /* separable */);
6093                 }
6094                 catch (Utils::Shader::InvalidSourceException& exc)
6095                 {
6096                         if (false == is_failure_expected)
6097                         {
6098                                 m_context.getTestContext().getLog()
6099                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6100                                 exc.log(m_context);
6101                         }
6102
6103 #if DEBUG_NEG_LOG_ERROR
6104
6105                         else
6106                         {
6107                                 m_context.getTestContext().getLog()
6108                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6109                                         << tcu::TestLog::EndMessage;
6110                                 exc.log(m_context);
6111                         }
6112
6113 #endif /* DEBUG_NEG_LOG_ERROR */
6114
6115                         is_build_error = true;
6116                 }
6117                 catch (Utils::Program::BuildException& exc)
6118                 {
6119                         if (false == is_failure_expected)
6120                         {
6121                                 m_context.getTestContext().getLog()
6122                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6123                                 exc.log(m_context);
6124                         }
6125
6126 #if DEBUG_NEG_LOG_ERROR
6127
6128                         else
6129                         {
6130                                 m_context.getTestContext().getLog()
6131                                         << tcu::TestLog::Message
6132                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6133                                 exc.log(m_context);
6134                         }
6135
6136 #endif /* DEBUG_NEG_LOG_ERROR */
6137
6138                         is_build_error = true;
6139                 }
6140
6141                 if (is_build_error != is_failure_expected)
6142                 {
6143                         test_case_result = false;
6144                 }
6145         }
6146         else /* Draw */
6147         {
6148                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6149                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6150                 bool                       is_build_error         = false;
6151                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6152                 Utils::Program   program(m_context);
6153                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6154                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6155                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6156
6157                 try
6158                 {
6159                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6160                 }
6161                 catch (Utils::Shader::InvalidSourceException& exc)
6162                 {
6163                         if (false == is_failure_expected)
6164                         {
6165                                 m_context.getTestContext().getLog()
6166                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6167                                 exc.log(m_context);
6168                         }
6169
6170 #if DEBUG_NEG_LOG_ERROR
6171
6172                         else
6173                         {
6174                                 m_context.getTestContext().getLog()
6175                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6176                                         << tcu::TestLog::EndMessage;
6177                                 exc.log(m_context);
6178                         }
6179
6180 #endif /* DEBUG_NEG_LOG_ERROR */
6181
6182                         is_build_error = true;
6183                 }
6184                 catch (Utils::Program::BuildException& exc)
6185                 {
6186                         if (false == is_failure_expected)
6187                         {
6188                                 m_context.getTestContext().getLog()
6189                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6190                                 exc.log(m_context);
6191                         }
6192
6193 #if DEBUG_NEG_LOG_ERROR
6194
6195                         else
6196                         {
6197                                 m_context.getTestContext().getLog()
6198                                         << tcu::TestLog::Message
6199                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6200                                 exc.log(m_context);
6201                         }
6202
6203 #endif /* DEBUG_NEG_LOG_ERROR */
6204
6205                         is_build_error = true;
6206                 }
6207
6208                 if (is_build_error != is_failure_expected)
6209                 {
6210                         test_case_result = false;
6211                 }
6212         }
6213
6214         return test_case_result;
6215 }
6216
6217 /* Constants used by TextureTestBase */
6218 const glw::GLuint TextureTestBase::m_width  = 16;
6219 const glw::GLuint TextureTestBase::m_height = 16;
6220
6221 /** Constructor
6222  *
6223  * @param context          Test context
6224  * @param test_name        Name of test
6225  * @param test_description Description of test
6226  **/
6227 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6228         : TestBase(context, test_name, test_description)
6229 {
6230 }
6231
6232 /** Get locations for all inputs with automatic_location
6233  *
6234  * @param program           Program object
6235  * @param program_interface Interface of program
6236  **/
6237 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6238 {
6239         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6240
6241         Utils::Variable::PtrVector& inputs = si.m_inputs;
6242
6243         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6244         {
6245                 /* Test does not specify location, query value and set */
6246                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6247                 {
6248                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6249                         GLint  location = 0;
6250
6251                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6252
6253                         (*it)->m_descriptor.m_expected_location = location;
6254                 }
6255         }
6256 }
6257
6258 /** Verifies contents of drawn image
6259  *
6260  * @param ignored
6261  * @param color_0 Verified image
6262  *
6263  * @return true if image is filled with 1, false otherwise
6264  **/
6265 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6266 {
6267         static const GLuint size                   = m_width * m_height;
6268         static const GLuint expected_color = 1;
6269
6270         std::vector<GLuint> data;
6271         data.resize(size);
6272
6273         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6274
6275         for (GLuint i = 0; i < size; ++i)
6276         {
6277                 const GLuint color = data[i];
6278
6279                 if (expected_color != color)
6280                 {
6281                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6282                                                                                                 << tcu::TestLog::EndMessage;
6283                         return false;
6284                 }
6285         }
6286
6287         return true;
6288 }
6289
6290 /** Execute dispatch compute for 16x16x1
6291  *
6292  * @param ignored
6293  **/
6294 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6295 {
6296         const Functions& gl = m_context.getRenderContext().getFunctions();
6297
6298         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6299         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6300 }
6301
6302 /** Execute drawArrays for single vertex
6303  *
6304  * @param ignored
6305  **/
6306 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6307 {
6308         const Functions& gl = m_context.getRenderContext().getFunctions();
6309
6310         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6311         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6312 }
6313
6314 /** Prepare code snippet that will pass in variables to out variables
6315  *
6316  * @param ignored
6317  * @param varying_passthrough Collection of connections between in and out variables
6318  * @param stage               Shader stage
6319  *
6320  * @return Code that pass in variables to next stage
6321  **/
6322 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6323                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6324 {
6325         static const GLchar* separator = "\n    ";
6326
6327         /* Skip for compute shader */
6328         if (Utils::Shader::COMPUTE == stage)
6329         {
6330                 return "";
6331         }
6332
6333         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6334
6335         std::string result   = Utils::g_list;
6336         size_t          position = 0;
6337
6338         for (GLuint i = 0; i < vector.size(); ++i)
6339         {
6340
6341                 Utils::VaryingConnection& connection = vector[i];
6342
6343                 Utils::Variable* in  = connection.m_in;
6344                 Utils::Variable* out = connection.m_out;
6345
6346                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6347                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6348
6349                 const std::string passthrough =
6350                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6351
6352                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6353         }
6354
6355         Utils::endList("", position, result);
6356
6357         return result;
6358 }
6359
6360 /** Basic implementation of method getProgramInterface
6361  *
6362  * @param ignored
6363  * @param ignored
6364  * @param ignored
6365  **/
6366 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6367                                                                                   Utils::ProgramInterface& /* program_interface */,
6368                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6369 {
6370 }
6371
6372 /** Prepare code snippet that will verify in and uniform variables
6373  *
6374  * @param ignored
6375  * @param program_interface Interface of program
6376  * @param stage             Shader stage
6377  *
6378  * @return Code that verify variables
6379  **/
6380 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6381                                                                                                         Utils::ProgramInterface& program_interface,
6382                                                                                                         Utils::Shader::STAGES   stage)
6383 {
6384         static const GLchar* separator = " ||\n        ";
6385
6386         std::string verification = "if (LIST)\n"
6387                                                            "    {\n"
6388                                                            "        result = 0u;\n"
6389                                                            "    }\n";
6390
6391         /* Get flavour of in and out variables */
6392         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6393
6394         /* Get interface for shader stage */
6395         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6396
6397         /* There are no varialbes to verify */
6398         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6399         {
6400                 return "";
6401         }
6402
6403         /* For each in variable insert verification code */
6404         size_t position = 0;
6405
6406         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6407         {
6408                 const Utils::Variable& var                              = *si.m_inputs[i];
6409                 const std::string&       var_verification = getVariableVerifcation("", var.m_data, var.m_descriptor, in_flavour);
6410
6411                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6412         }
6413
6414         /* For each unifrom variable insert verification code */
6415         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6416         {
6417                 const Utils::Variable& var = *si.m_uniforms[i];
6418                 const std::string&       var_verification =
6419                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6420
6421                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6422         }
6423
6424         /* For each ssb variable insert verification code */
6425         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6426         {
6427                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6428                 const std::string&       var_verification =
6429                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6430
6431                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6432         }
6433
6434         Utils::endList("", position, verification);
6435
6436 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6437
6438         {
6439                 GLchar buffer[16];
6440                 sprintf(buffer, "%d", stage + 10);
6441                 Utils::replaceToken("0u", position, buffer, verification);
6442         }
6443
6444 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6445
6446         if (Utils::Shader::VERTEX == stage)
6447         {
6448                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6449         }
6450         else
6451         {
6452                 Utils::replaceToken("0u", position, "31u", verification);
6453         }
6454
6455 #endif
6456
6457         /* Done */
6458         return verification;
6459 }
6460
6461 /** Selects if "compute" stage is relevant for test
6462  *
6463  * @param ignored
6464  *
6465  * @return true
6466  **/
6467 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6468 {
6469         return true;
6470 }
6471
6472 /** Selects if "draw" stages are relevant for test
6473  *
6474  * @param ignored
6475  *
6476  * @return true
6477  **/
6478 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6479 {
6480         return true;
6481 }
6482
6483 /** Prepare code that will do assignment of single in to single out
6484  *
6485  * @param in_parent_name  Name of parent in variable
6486  * @param in_variable     Descriptor of in variable
6487  * @param in_flavour      Flavoud of in variable
6488  * @param out_parent_name Name of parent out variable
6489  * @param out_variable    Descriptor of out variable
6490  * @param out_flavour     Flavoud of out variable
6491  *
6492  * @return Code that does OUT = IN
6493  **/
6494 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6495                                                                                                         const Utils::Variable::Descriptor& in_variable,
6496                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6497                                                                                                         const std::string&                                 out_parent_name,
6498                                                                                                         const Utils::Variable::Descriptor& out_variable,
6499                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6500 {
6501         bool                             done             = false;
6502         GLuint                           index            = 0;
6503         GLuint                           member_index = 0;
6504         size_t                           position        = 0;
6505         std::string                      result           = Utils::g_list;
6506         static const GLchar* separator  = ";\n    ";
6507
6508         /* For each member of each array element */
6509         do
6510         {
6511                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6512                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6513                 std::string               passthrough;
6514
6515                 /* Prepare verification */
6516                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6517                 {
6518                         size_t pass_position = 0;
6519
6520                         passthrough = "OUT = IN;";
6521
6522                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6523                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6524
6525                         /* Increment index */
6526                         ++index;
6527                 }
6528                 else
6529                 {
6530                         const Utils::Interface* in_interface  = in_variable.m_interface;
6531                         const Utils::Interface* out_interface = out_variable.m_interface;
6532
6533                         if ((0 == in_interface) || (0 == out_interface))
6534                         {
6535                                 TCU_FAIL("Nullptr");
6536                         }
6537
6538                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6539                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6540
6541                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6542                                                                                                  Utils::Variable::BASIC);
6543
6544                         /* Increment member_index */
6545                         ++member_index;
6546
6547                         /* Increment index and reset member_index if all members were processed */
6548                         if (in_interface->m_members.size() == member_index)
6549                         {
6550                                 ++index;
6551                                 member_index = 0;
6552                         }
6553                 }
6554
6555                 /* Check if loop should end */
6556                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6557                 {
6558                         done = true;
6559                 }
6560
6561                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6562
6563         } while (true != done);
6564
6565         Utils::endList("", position, result);
6566
6567         /* Done */
6568         return result;
6569 }
6570
6571 /** Get verification of single variable
6572  *
6573  * @param parent_name Name of parent variable
6574  * @param data        Data that should be used as EXPECTED
6575  * @param variable    Descriptor of variable
6576  * @param flavour     Flavour of variable
6577  *
6578  * @return Code that does (EXPECTED != VALUE) ||
6579  **/
6580 std::string TextureTestBase::getVariableVerifcation(const std::string& parent_name, const GLvoid* data,
6581                                                                                                         const Utils::Variable::Descriptor& variable,
6582                                                                                                         Utils::Variable::FLAVOUR                   flavour)
6583 {
6584         static const GLchar* logic_op   = " ||\n        ";
6585         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6586         size_t                           position   = 0;
6587         std::string                      result         = Utils::g_list;
6588         GLint                            stride         = variable.m_expected_stride_of_element;
6589
6590         /* For each each array element */
6591         for (GLuint element = 0; element < n_elements; ++element)
6592         {
6593                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6594
6595                 /* Calculate data pointer */
6596                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6597
6598                 /* Prepare verification */
6599                 if (Utils::Variable::BUILTIN == variable.m_type)
6600                 {
6601                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6602                         std::string                verification;
6603                         size_t                     verification_position = 0;
6604
6605                         verification = "(EXPECTED != NAME)";
6606
6607                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6608                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6609
6610                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6611                 }
6612                 else
6613                 {
6614                         const Utils::Interface* interface = variable.m_interface;
6615
6616                         if (0 == interface)
6617                         {
6618                                 TCU_FAIL("Nullptr");
6619                         }
6620
6621                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6622
6623                         /* for each member */
6624                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6625                         {
6626                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6627
6628                                 /* Get verification of member */
6629                                 const std::string& verification =
6630                                         getVariableVerifcation(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6631
6632                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6633                         }
6634                 }
6635         }
6636
6637         Utils::endList("", position, result);
6638
6639         return result;
6640 }
6641
6642 /** Prepare attributes, vertex array object and array buffer
6643  *
6644  * @param test_case_index   Index of test case
6645  * @param program_interface Interface of program
6646  * @param buffer            Array buffer
6647  * @param vao               Vertex array object
6648  **/
6649 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6650                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6651 {
6652         bool use_component_qualifier = useComponentQualifier(test_case_index);
6653
6654         /* Get shader interface */
6655         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6656
6657         /* Bind vao and buffer */
6658         vao.Bind();
6659         buffer.Bind();
6660
6661         /* Skip if there are no input variables in vertex shader */
6662         if (0 == si.m_inputs.size())
6663         {
6664                 return;
6665         }
6666
6667         /* Calculate vertex stride and check */
6668         GLint vertex_stride = 0;
6669
6670         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6671         {
6672                 Utils::Variable& variable = *si.m_inputs[i];
6673
6674                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6675
6676                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6677
6678                 vertex_stride = std::max(vertex_stride, ends_at);
6679         }
6680
6681         /* Prepare buffer data and set up vao */
6682         std::vector<GLubyte> buffer_data;
6683         buffer_data.resize(vertex_stride);
6684
6685         GLubyte* ptr = &buffer_data[0];
6686
6687         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6688         {
6689                 Utils::Variable& variable = *si.m_inputs[i];
6690
6691                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6692
6693                 if (false == use_component_qualifier)
6694                 {
6695                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6696                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6697                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6698                 }
6699                 else if (0 == variable.m_descriptor.m_expected_component)
6700                 {
6701                         /* Components can only be applied to vectors.
6702                          Assumption that test use all 4 components */
6703                         const Utils::Type& type =
6704                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6705
6706                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6707                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6708                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6709                 }
6710         }
6711
6712         /* Update buffer */
6713         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6714 }
6715
6716 /** Get locations for all outputs with automatic_location
6717  *
6718  * @param program           Program object
6719  * @param program_interface Interface of program
6720  **/
6721 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6722 {
6723         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6724         Utils::Variable::PtrVector& outputs = si.m_outputs;
6725
6726         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6727         {
6728                 /* Test does not specify location, query value and set */
6729                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6730                 {
6731                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6732                         GLint  location = 0;
6733
6734                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6735
6736                         (*it)->m_descriptor.m_expected_location = location;
6737                 }
6738         }
6739 }
6740
6741 /** Prepare framebuffer with single texture as color attachment
6742  *
6743  * @param framebuffer     Framebuffer
6744  * @param color_0_texture Texture that will used as color attachment
6745  **/
6746 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6747 {
6748         /* Prepare data */
6749         std::vector<GLuint> texture_data;
6750         texture_data.resize(m_width * m_height);
6751
6752         for (GLuint i = 0; i < texture_data.size(); ++i)
6753         {
6754                 texture_data[i] = 0x20406080;
6755         }
6756
6757         /* Prepare texture */
6758         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6759                                                  &texture_data[0]);
6760
6761         /* Prepare framebuffer */
6762         framebuffer.Init();
6763         framebuffer.Bind();
6764         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6765
6766         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6767         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6768 }
6769
6770 /** Prepare iamge unit for compute shader
6771  *
6772  * @param location      Uniform location
6773  * @param image_texture Texture that will used as color attachment
6774  **/
6775 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6776 {
6777         static const GLuint image_unit = 0;
6778
6779         std::vector<GLuint> texture_data;
6780         texture_data.resize(m_width * m_height);
6781
6782         for (GLuint i = 0; i < texture_data.size(); ++i)
6783         {
6784                 texture_data[i] = 0x20406080;
6785         }
6786
6787         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6788                                            &texture_data[0]);
6789
6790         const Functions& gl = m_context.getRenderContext().getFunctions();
6791
6792         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6793                                                 GL_WRITE_ONLY, GL_R32UI);
6794         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6795
6796         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6797 }
6798
6799 /** Basic implementation
6800  *
6801  * @param ignored
6802  * @param si        Shader interface
6803  * @param program   Program
6804  * @param cs_buffer Buffer for ssb blocks
6805  **/
6806 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6807                                                                   Utils::Buffer& buffer)
6808 {
6809         /* Skip if there are no input variables in vertex shader */
6810         if (0 == si.m_ssb_blocks.size())
6811         {
6812                 return;
6813         }
6814
6815         /* Calculate vertex stride */
6816         GLint ssbs_stride = 0;
6817
6818         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6819         {
6820                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6821
6822                 if (false == variable.IsBlock())
6823                 {
6824                         continue;
6825                 }
6826
6827                 GLint variable_stride = variable.GetStride();
6828
6829                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6830
6831                 ssbs_stride = std::max(ssbs_stride, ends_at);
6832         }
6833
6834         /* Set active program */
6835         program.Use();
6836
6837         /* Allocate */
6838         buffer.Bind();
6839         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6840
6841         /* Set up uniforms */
6842         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6843         {
6844                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6845
6846                 /* prepareUnifor should work fine for ssb blocks */
6847                 prepareUniform(program, variable, buffer);
6848         }
6849 }
6850
6851 /** Basic implementation
6852  *
6853  * @param test_case_index   Test case index
6854  * @param program_interface Program interface
6855  * @param program           Program
6856  * @param cs_buffer         Buffer for compute shader stage
6857  **/
6858 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6859                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6860 {
6861         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6862
6863         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6864
6865         prepareSSBs(test_case_index, cs, program, cs_buffer);
6866
6867         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6868 }
6869
6870 /** Basic implementation
6871  *
6872  * @param test_case_index   Test case index
6873  * @param program_interface Program interface
6874  * @param program           Program
6875  * @param fs_buffer         Buffer for fragment shader stage
6876  * @param gs_buffer         Buffer for geometry shader stage
6877  * @param tcs_buffer        Buffer for tesselation control shader stage
6878  * @param tes_buffer        Buffer for tesselation evaluation shader stage
6879  * @param vs_buffer         Buffer for vertex shader stage
6880  **/
6881 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6882                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6883                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6884 {
6885         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6886         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6887         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6888         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6889         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6890
6891         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6892         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6893         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6894         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6895         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6896
6897         prepareSSBs(test_case_index, fs, program, fs_buffer);
6898         prepareSSBs(test_case_index, gs, program, gs_buffer);
6899         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6900         prepareSSBs(test_case_index, tes, program, tes_buffer);
6901         prepareSSBs(test_case_index, vs, program, vs_buffer);
6902
6903         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6904         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6905         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6906         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6907         vs_buffer.BindBase(Utils::Shader::VERTEX);
6908 }
6909
6910 /** Updates buffer data with variable
6911  *
6912  * @param program  Program object
6913  * @param variable Variable
6914  * @param buffer   Buffer
6915  **/
6916 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6917 {
6918         const Functions& gl = m_context.getRenderContext().getFunctions();
6919
6920         GLsizei count = variable.m_descriptor.m_n_array_elements;
6921         if (0 == count)
6922         {
6923                 count = 1;
6924         }
6925
6926         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6927         {
6928                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6929                                                 variable.m_data);
6930         }
6931         else
6932         {
6933                 const bool is_block = variable.IsBlock();
6934
6935                 if (false == is_block)
6936                 {
6937                         TCU_FAIL("Not implemented");
6938                 }
6939                 else
6940                 {
6941                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6942                                                    variable.m_data);
6943                 }
6944         }
6945 }
6946
6947 /** Basic implementation
6948  *
6949  * @param ignored
6950  * @param si        Shader interface
6951  * @param program   Program
6952  * @param cs_buffer Buffer for uniform blocks
6953  **/
6954 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6955                                                                           Utils::Buffer& buffer)
6956 {
6957         /* Skip if there are no input variables in vertex shader */
6958         if (0 == si.m_uniforms.size())
6959         {
6960                 return;
6961         }
6962
6963         /* Calculate vertex stride */
6964         GLint uniforms_stride = 0;
6965
6966         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6967         {
6968                 Utils::Variable& variable = *si.m_uniforms[i];
6969
6970                 if (false == variable.IsBlock())
6971                 {
6972                         continue;
6973                 }
6974
6975                 GLint variable_stride = variable.GetStride();
6976
6977                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6978
6979                 uniforms_stride = std::max(uniforms_stride, ends_at);
6980         }
6981
6982         /* Set active program */
6983         program.Use();
6984
6985         /* Allocate */
6986         buffer.Bind();
6987         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
6988
6989         /* Set up uniforms */
6990         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6991         {
6992                 Utils::Variable& variable = *si.m_uniforms[i];
6993
6994                 prepareUniform(program, variable, buffer);
6995         }
6996 }
6997
6998 /** Basic implementation
6999  *
7000  * @param test_case_index   Test case index
7001  * @param program_interface Program interface
7002  * @param program           Program
7003  * @param cs_buffer         Buffer for compute shader stage
7004  **/
7005 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7006                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7007 {
7008         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7009
7010         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7011
7012         prepareUniforms(test_case_index, cs, program, cs_buffer);
7013
7014         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7015 }
7016
7017 /** Basic implementation
7018  *
7019  * @param test_case_index   Test case index
7020  * @param program_interface Program interface
7021  * @param program           Program
7022  * @param fs_buffer         Buffer for fragment shader stage
7023  * @param gs_buffer         Buffer for geometry shader stage
7024  * @param tcs_buffer        Buffer for tesselation control shader stage
7025  * @param tes_buffer        Buffer for tesselation evaluation shader stage
7026  * @param vs_buffer         Buffer for vertex shader stage
7027  **/
7028 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7029                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7030                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7031 {
7032         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7033         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7034         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7035         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7036         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7037
7038         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7039         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7040         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7041         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7042         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7043
7044         prepareUniforms(test_case_index, fs, program, fs_buffer);
7045         prepareUniforms(test_case_index, gs, program, gs_buffer);
7046         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7047         prepareUniforms(test_case_index, tes, program, tes_buffer);
7048         prepareUniforms(test_case_index, vs, program, vs_buffer);
7049
7050         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7051         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7052         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7053         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7054         vs_buffer.BindBase(Utils::Shader::VERTEX);
7055 }
7056
7057 /** Basic implementation
7058  *
7059  * @param test_case_index   Test case index
7060  * @param program_interface Program interface
7061  * @param program           Program
7062  * @param fs_buffer         Buffer for fragment shader stage
7063  * @param gs_buffer         Buffer for geometry shader stage
7064  * @param tcs_buffer        Buffer for tesselation control shader stage
7065  * @param tes_buffer        Buffer for tesselation evaluation shader stage
7066  * @param vs_buffer         Buffer for vertex shader stage
7067  **/
7068 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7069                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7070                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7071                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7072                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7073 {
7074         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7075         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7076         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7077         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7078         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7079
7080         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7081         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7082         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7083         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7084         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7085
7086         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7087         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7088
7089         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7090         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7091
7092         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7093         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7094
7095         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7096         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7097
7098         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7099         vs_buffer.BindBase(Utils::Shader::VERTEX);
7100 }
7101
7102 /** Prepare source for shader
7103  *
7104  * @param test_case_index     Index of test case
7105  * @param program_interface   Interface of program
7106  * @param varying_passthrough Collection of connection between in and out variables
7107  * @param stage               Shader stage
7108  *
7109  * @return Source of shader
7110  **/
7111 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7112                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7113                                                                                          Utils::Shader::STAGES          stage)
7114 {
7115         /* Get strings */
7116         const GLchar*     shader_template  = getShaderTemplate(stage);
7117         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7118
7119         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7120
7121         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7122
7123         const GLchar* per_vertex = "";
7124
7125         std::string source   = shader_template;
7126         size_t          position = 0;
7127
7128         /* Replace tokens in template */
7129         if (Utils::Shader::GEOMETRY == stage)
7130         {
7131                 if (false == useMonolithicProgram(test_case_index))
7132                 {
7133                         per_vertex = "out gl_PerVertex {\n"
7134                                                  "vec4 gl_Position;\n"
7135                                                  "};\n"
7136                                                  "\n";
7137                 }
7138
7139                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7140         }
7141
7142         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7143         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7144
7145         if (false == verification.empty())
7146         {
7147                 Utils::replaceAllTokens("ELSE", "    else ", source);
7148         }
7149         else
7150         {
7151                 Utils::replaceAllTokens("ELSE", "", source);
7152         }
7153
7154         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7155
7156         /* Done */
7157         return source;
7158 }
7159
7160 /** Returns template of shader for given stage
7161  *
7162  * @param stage Shade stage
7163  *
7164  * @return Proper template
7165  **/
7166 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7167 {
7168
7169         static const GLchar* compute_shader_template =
7170                 "#version 430 core\n"
7171                 "#extension GL_ARB_enhanced_layouts : require\n"
7172                 "\n"
7173                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7174                 "\n"
7175                 "writeonly uniform uimage2D uni_image;\n"
7176                 "\n"
7177                 "INTERFACE"
7178                 "\n"
7179                 "void main()\n"
7180                 "{\n"
7181                 "    uint result = 1u;\n"
7182                 "\n"
7183                 "    VERIFICATION"
7184                 "\n"
7185                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7186                 "}\n"
7187                 "\n";
7188
7189         static const GLchar* fragment_shader_template = "#version 430 core\n"
7190                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7191                                                                                                         "\n"
7192                                                                                                         "flat in  uint gs_fs_result;\n"
7193                                                                                                         "     out uint fs_out_result;\n"
7194                                                                                                         "\n"
7195                                                                                                         "INTERFACE"
7196                                                                                                         "\n"
7197                                                                                                         "void main()\n"
7198                                                                                                         "{\n"
7199                                                                                                         "    uint result = 1u;\n"
7200                                                                                                         "\n"
7201                                                                                                         "    if (1u != gs_fs_result)\n"
7202                                                                                                         "    {\n"
7203                                                                                                         "         result = gs_fs_result;\n"
7204                                                                                                         "    }\n"
7205                                                                                                         "ELSEVERIFICATION"
7206                                                                                                         "\n"
7207                                                                                                         "    fs_out_result = result;\n"
7208                                                                                                         "    PASSTHROUGH\n"
7209                                                                                                         "}\n"
7210                                                                                                         "\n";
7211
7212         static const GLchar* geometry_shader_template =
7213                 "#version 430 core\n"
7214                 "#extension GL_ARB_enhanced_layouts : require\n"
7215                 "\n"
7216                 "layout(points)                           in;\n"
7217                 "layout(triangle_strip, max_vertices = 4) out;\n"
7218                 "\n"
7219                 "     in  uint tes_gs_result[];\n"
7220                 "flat out uint gs_fs_result;\n"
7221                 "\n"
7222                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7223                 "INTERFACE"
7224                 "\n"
7225                 "void main()\n"
7226                 "{\n"
7227                 "    uint result = 1u;\n"
7228                 "\n"
7229                 "    if (1u != tes_gs_result[0])\n"
7230                 "    {\n"
7231                 "         result = tes_gs_result[0];\n"
7232                 "    }\n"
7233                 "ELSEVERIFICATION"
7234                 "\n"
7235                 "    gs_fs_result = result;\n"
7236                 "    PASSTHROUGH\n"
7237                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7238                 "    EmitVertex();\n"
7239                 "    gs_fs_result = result;\n"
7240                 "    PASSTHROUGH\n"
7241                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7242                 "    EmitVertex();\n"
7243                 "    gs_fs_result = result;\n"
7244                 "    PASSTHROUGH\n"
7245                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7246                 "    EmitVertex();\n"
7247                 "    gs_fs_result = result;\n"
7248                 "    PASSTHROUGH\n"
7249                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7250                 "    EmitVertex();\n"
7251                 "}\n"
7252                 "\n";
7253
7254         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7255                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7256                                                                                                          "\n"
7257                                                                                                          "layout(vertices = 1) out;\n"
7258                                                                                                          "\n"
7259                                                                                                          "in  uint vs_tcs_result[];\n"
7260                                                                                                          "out uint tcs_tes_result[];\n"
7261                                                                                                          "\n"
7262                                                                                                          "INTERFACE"
7263                                                                                                          "\n"
7264                                                                                                          "void main()\n"
7265                                                                                                          "{\n"
7266                                                                                                          "    uint result = 1u;\n"
7267                                                                                                          "\n"
7268                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7269                                                                                                          "    {\n"
7270                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7271                                                                                                          "    }\n"
7272                                                                                                          "ELSEVERIFICATION"
7273                                                                                                          "\n"
7274                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7275                                                                                                          "\n"
7276                                                                                                          "    PASSTHROUGH\n"
7277                                                                                                          "\n"
7278                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7279                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7280                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7281                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7282                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7283                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7284                                                                                                          "}\n"
7285                                                                                                          "\n";
7286
7287         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7288                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7289                                                                                                          "\n"
7290                                                                                                          "layout(isolines, point_mode) in;\n"
7291                                                                                                          "\n"
7292                                                                                                          "in  uint tcs_tes_result[];\n"
7293                                                                                                          "out uint tes_gs_result;\n"
7294                                                                                                          "\n"
7295                                                                                                          "INTERFACE"
7296                                                                                                          "\n"
7297                                                                                                          "void main()\n"
7298                                                                                                          "{\n"
7299                                                                                                          "    uint result = 1u;\n"
7300                                                                                                          "\n"
7301                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7302                                                                                                          "    {\n"
7303                                                                                                          "         result = tcs_tes_result[0];\n"
7304                                                                                                          "    }\n"
7305                                                                                                          "ELSEVERIFICATION"
7306                                                                                                          "\n"
7307                                                                                                          "    tes_gs_result = result;\n"
7308                                                                                                          "\n"
7309                                                                                                          "    PASSTHROUGH\n"
7310                                                                                                          "}\n"
7311                                                                                                          "\n";
7312
7313         static const GLchar* vertex_shader_template = "#version 430 core\n"
7314                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7315                                                                                                   "\n"
7316                                                                                                   "out uint vs_tcs_result;\n"
7317                                                                                                   "\n"
7318                                                                                                   "INTERFACE"
7319                                                                                                   "\n"
7320                                                                                                   "void main()\n"
7321                                                                                                   "{\n"
7322                                                                                                   "    uint result = 1u;\n"
7323                                                                                                   "\n"
7324                                                                                                   "    VERIFICATION\n"
7325                                                                                                   "\n"
7326                                                                                                   "    vs_tcs_result = result;\n"
7327                                                                                                   "\n"
7328                                                                                                   "    PASSTHROUGH\n"
7329                                                                                                   "}\n"
7330                                                                                                   "\n";
7331
7332         const GLchar* result = 0;
7333
7334         switch (stage)
7335         {
7336         case Utils::Shader::COMPUTE:
7337                 result = compute_shader_template;
7338                 break;
7339         case Utils::Shader::FRAGMENT:
7340                 result = fragment_shader_template;
7341                 break;
7342         case Utils::Shader::GEOMETRY:
7343                 result = geometry_shader_template;
7344                 break;
7345         case Utils::Shader::TESS_CTRL:
7346                 result = tess_ctrl_shader_template;
7347                 break;
7348         case Utils::Shader::TESS_EVAL:
7349                 result = tess_eval_shader_template;
7350                 break;
7351         case Utils::Shader::VERTEX:
7352                 result = vertex_shader_template;
7353                 break;
7354         default:
7355                 TCU_FAIL("Invalid enum");
7356         }
7357
7358         return result;
7359 }
7360
7361 /** Runs test case
7362  *
7363  * @param test_case_index Id of test case
7364  *
7365  * @return true if test case pass, false otherwise
7366  **/
7367 bool TextureTestBase::testCase(GLuint test_case_index)
7368 {
7369         try
7370         {
7371                 if (true == useMonolithicProgram(test_case_index))
7372                 {
7373                         return testMonolithic(test_case_index);
7374                 }
7375                 else
7376                 {
7377                         return testSeparable(test_case_index);
7378                 }
7379         }
7380         catch (Utils::Shader::InvalidSourceException& exc)
7381         {
7382                 exc.log(m_context);
7383                 TCU_FAIL(exc.what());
7384         }
7385         catch (Utils::Program::BuildException& exc)
7386         {
7387                 TCU_FAIL(exc.what());
7388         }
7389 }
7390
7391 /** Runs "draw" test with monolithic program
7392  *
7393  * @param test_case_index Id of test case
7394  **/
7395 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7396 {
7397         Utils::ProgramInterface   program_interface;
7398         Utils::VaryingPassthrough varying_passthrough;
7399
7400         /* */
7401         const std::string& test_name = getTestCaseName(test_case_index);
7402
7403         /* */
7404         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7405
7406         bool result = true;
7407         /* Draw */
7408         if (true == isDrawRelevant(test_case_index))
7409         {
7410                 Utils::Buffer     buffer_attr(m_context);
7411                 Utils::Buffer     buffer_ssb_fs(m_context);
7412                 Utils::Buffer     buffer_ssb_gs(m_context);
7413                 Utils::Buffer     buffer_ssb_tcs(m_context);
7414                 Utils::Buffer     buffer_ssb_tes(m_context);
7415                 Utils::Buffer     buffer_ssb_vs(m_context);
7416                 Utils::Buffer     buffer_u_fs(m_context);
7417                 Utils::Buffer     buffer_u_gs(m_context);
7418                 Utils::Buffer     buffer_u_tcs(m_context);
7419                 Utils::Buffer     buffer_u_tes(m_context);
7420                 Utils::Buffer     buffer_u_vs(m_context);
7421                 Utils::Framebuffer framebuffer(m_context);
7422                 Utils::Program   program(m_context);
7423                 Utils::Texture   texture_fb(m_context);
7424                 Utils::VertexArray vao(m_context);
7425
7426                 /* */
7427                 const std::string& fragment_shader =
7428                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7429                 const std::string& geometry_shader =
7430                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7431                 const std::string& tess_ctrl_shader =
7432                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7433                 const std::string& tess_eval_shader =
7434                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7435                 const std::string& vertex_shader =
7436                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7437
7438                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7439                                          vertex_shader, false /* is_separable */);
7440
7441                 /* */
7442                 prepareAttribLocation(program, program_interface);
7443                 prepareFragmentDataLoc(program, program_interface);
7444
7445                 /* */
7446                 std::stringstream stream;
7447                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7448                 {
7449                         m_context.getTestContext().getLog()
7450                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7451                                 << ". Inspection of draw program interface failed:\n"
7452                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7453                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7454                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7455
7456                         return false;
7457                 }
7458
7459                 /* */
7460                 program.Use();
7461
7462                 /* */
7463                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7464                 vao.Init();
7465                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7466
7467                 /* */
7468                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7469                                                 buffer_u_tes, buffer_u_vs);
7470
7471                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7472                                         buffer_ssb_tes, buffer_ssb_vs);
7473
7474                 /* */
7475                 prepareFramebuffer(framebuffer, texture_fb);
7476
7477                 /* Draw */
7478                 executeDrawCall(test_case_index);
7479
7480 #if USE_NSIGHT
7481                 m_context.getRenderContext().postIterate();
7482 #endif
7483
7484                 /* Check results */
7485                 if (false == checkResults(test_case_index, texture_fb))
7486                 {
7487                         m_context.getTestContext().getLog()
7488                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7489                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7490                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7491                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7492
7493                         result = false;
7494                 }
7495         }
7496
7497         /* Compute */
7498         if (true == isComputeRelevant(test_case_index))
7499         {
7500                 Utils::Buffer     buffer_ssb_cs(m_context);
7501                 Utils::Buffer     buffer_u_cs(m_context);
7502                 Utils::Program   program(m_context);
7503                 Utils::Texture   texture_im(m_context);
7504                 Utils::VertexArray vao(m_context);
7505
7506                 /* */
7507                 const std::string& compute_shader =
7508                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7509
7510                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7511                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7512
7513                 /* */
7514                 {
7515                         std::stringstream stream;
7516
7517                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7518                         {
7519                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7520                                                                                                         << ". Inspection of compute program interface failed:\n"
7521                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7522
7523                                 return false;
7524                         }
7525                 }
7526
7527                 /* */
7528                 program.Use();
7529
7530                 /* */
7531                 vao.Init();
7532                 vao.Bind();
7533
7534                 /* */
7535                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7536
7537                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7538
7539                 /* */
7540                 GLint image_location = program.GetUniformLocation("uni_image");
7541                 prepareImage(image_location, texture_im);
7542
7543                 /* Draw */
7544                 executeDispatchCall(test_case_index);
7545
7546 #if USE_NSIGHT
7547                 m_context.getRenderContext().postIterate();
7548 #endif
7549
7550                 /* Check results */
7551                 if (false == checkResults(test_case_index, texture_im))
7552                 {
7553                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7554                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7555                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7556
7557                         result = false;
7558                 }
7559         }
7560
7561         return result;
7562 }
7563
7564 /** Runs "draw" test with separable program
7565  *
7566  * @param test_case_index Id of test case
7567  **/
7568 bool TextureTestBase::testSeparable(GLuint test_case_index)
7569 {
7570         Utils::ProgramInterface   program_interface;
7571         Utils::VaryingPassthrough varying_passthrough;
7572
7573         /* */
7574         const std::string& test_name = getTestCaseName(test_case_index);
7575
7576         /* */
7577         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7578
7579         bool result = true;
7580         /* Draw */
7581         if (true == isDrawRelevant(test_case_index))
7582         {
7583                 Utils::Buffer     buffer_attr(m_context);
7584                 Utils::Buffer     buffer_u_fs(m_context);
7585                 Utils::Buffer     buffer_u_gs(m_context);
7586                 Utils::Buffer     buffer_u_tcs(m_context);
7587                 Utils::Buffer     buffer_u_tes(m_context);
7588                 Utils::Buffer     buffer_u_vs(m_context);
7589                 Utils::Framebuffer framebuffer(m_context);
7590                 Utils::Pipeline pipeline(m_context);
7591                 Utils::Program   program_fs(m_context);
7592                 Utils::Program   program_gs(m_context);
7593                 Utils::Program   program_tcs(m_context);
7594                 Utils::Program   program_tes(m_context);
7595                 Utils::Program   program_vs(m_context);
7596                 Utils::Texture   texture_fb(m_context);
7597                 Utils::VertexArray vao(m_context);
7598
7599                 /* */
7600                 const std::string& fs =
7601                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7602                 const std::string& gs =
7603                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7604                 const std::string& tcs =
7605                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7606                 const std::string& tes =
7607                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7608                 const std::string& vs =
7609                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7610
7611                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7612                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7613                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7614                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7615                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7616
7617                 /* */
7618                 prepareAttribLocation(program_vs, program_interface);
7619                 prepareFragmentDataLoc(program_vs, program_interface);
7620
7621                 /* */
7622                 std::stringstream stream;
7623                 if ((false ==
7624                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7625                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7626                                                                                                                                 stream)) ||
7627                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7628                                                                                                                                 stream)) ||
7629                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7630                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7631                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7632                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7633                 {
7634                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7635                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7636                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7637                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7638                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7639                                                                                                 << tcu::TestLog::KernelSource(fs);
7640
7641                         return false;
7642                 }
7643
7644                 /* */
7645                 pipeline.Init();
7646                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7647                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7648                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7649                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7650                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7651                 pipeline.Bind();
7652
7653                 /* */
7654
7655                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7656                 vao.Init();
7657                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7658
7659                 /* */
7660                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7661                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7662
7663                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7664
7665                 /* */
7666                 prepareFramebuffer(framebuffer, texture_fb);
7667
7668                 /* Draw */
7669                 executeDrawCall(test_case_index);
7670
7671 #if USE_NSIGHT
7672                 m_context.getRenderContext().postIterate();
7673 #endif
7674
7675                 /* Check results */
7676                 if (false == checkResults(test_case_index, texture_fb))
7677                 {
7678                         m_context.getTestContext().getLog()
7679                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7680                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7681                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7682
7683                         result = false;
7684                 }
7685         }
7686
7687         /* Compute */
7688         if (true == isComputeRelevant(test_case_index))
7689         {
7690                 Utils::Buffer     buffer_u_cs(m_context);
7691                 Utils::Program   program(m_context);
7692                 Utils::Texture   texture_im(m_context);
7693                 Utils::VertexArray vao(m_context);
7694
7695                 /* */
7696                 const std::string& compute_shader =
7697                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7698
7699                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7700                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7701
7702                 /* */
7703                 {
7704                         std::stringstream stream;
7705
7706                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7707                         {
7708                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7709                                                                                                         << ". Inspection of compute program interface failed:\n"
7710                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7711
7712                                 return false;
7713                         }
7714                 }
7715
7716                 /* */
7717                 program.Use();
7718
7719                 /* */
7720                 vao.Init();
7721                 vao.Bind();
7722
7723                 /* */
7724                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7725
7726                 /* */
7727                 GLint image_location = program.GetUniformLocation("uni_image");
7728                 prepareImage(image_location, texture_im);
7729
7730                 /* Draw */
7731                 executeDispatchCall(test_case_index);
7732
7733 #if USE_NSIGHT
7734                 m_context.getRenderContext().postIterate();
7735 #endif
7736
7737                 /* Check results */
7738                 if (false == checkResults(test_case_index, texture_im))
7739                 {
7740                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7741                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7742                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7743
7744                         result = false;
7745                 }
7746         }
7747
7748         return result;
7749 }
7750
7751 /** Basic implementation
7752  *
7753  * @param ignored
7754  *
7755  * @return false
7756  **/
7757 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7758 {
7759         return false;
7760 }
7761
7762 /** Basic implementation
7763  *
7764  * @param ignored
7765  *
7766  * @return true
7767  **/
7768 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7769 {
7770         return true;
7771 }
7772
7773 /** Constructor
7774  *
7775  * @param context Test framework context
7776  **/
7777 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7778         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7779 {
7780         /* Nothing to be done here */
7781 }
7782
7783 /** Execute test
7784  *
7785  * @return tcu::TestNode::STOP otherwise
7786  **/
7787 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7788 {
7789         static const GLuint expected_comp = 64;
7790         static const GLuint expected_xfb  = 4;
7791         static const GLuint expected_sep  = 4;
7792         GLint                           max_comp          = 0;
7793         GLint                           max_xfb           = 0;
7794         GLint                           max_sep           = 0;
7795         bool                            test_result   = true;
7796
7797         const Functions& gl = m_context.getRenderContext().getFunctions();
7798
7799         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7800         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7801         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7802         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7803         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7804         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7805
7806         if (expected_xfb > (GLuint)max_xfb)
7807         {
7808                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7809                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7810                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7811
7812                 test_result = false;
7813         }
7814
7815         if (expected_comp > (GLuint)max_comp)
7816         {
7817                 m_context.getTestContext().getLog()
7818                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7819                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7820
7821                 test_result = false;
7822         }
7823
7824         if (expected_sep > (GLuint)max_sep)
7825         {
7826                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7827                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7828                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7829
7830                 test_result = false;
7831         }
7832
7833         /* Set result */
7834         if (true == test_result)
7835         {
7836                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7837         }
7838         else
7839         {
7840                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7841         }
7842
7843         /* Done */
7844         return tcu::TestNode::STOP;
7845 }
7846
7847 /** Constructor
7848  *
7849  * @param context Test framework context
7850  **/
7851 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7852         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7853 {
7854         /* Nothing to be done here */
7855 }
7856
7857 /** Execute test
7858  *
7859  * @return tcu::TestNode::STOP otherwise
7860  **/
7861 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7862 {
7863         GLint              length = 0;
7864         GLchar             name[64];
7865         GLint              param = 0;
7866         Utils::Program program(m_context);
7867         bool               test_result = true;
7868
7869         const Functions& gl = m_context.getRenderContext().getFunctions();
7870
7871         try
7872         {
7873                 program.Init("" /* cs */, "#version 430 core\n"
7874                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7875                                                                   "\n"
7876                                                                   "in  vec4 vs_fs;\n"
7877                                                                   "out vec4 fs_out;\n"
7878                                                                   "\n"
7879                                                                   "void main()\n"
7880                                                                   "{\n"
7881                                                                   "    fs_out = vs_fs;\n"
7882                                                                   "}\n"
7883                                                                   "\n" /* fs */,
7884                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7885                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7886                                                                                                                           "\n"
7887                                                                                                                           "in  vec4 in_vs;\n"
7888                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7889                                                                                                                           "\n"
7890                                                                                                                           "void main()\n"
7891                                                                                                                           "{\n"
7892                                                                                                                           "    vs_fs = in_vs;\n"
7893                                                                                                                           "}\n"
7894                                                                                                                           "\n" /* vs */,
7895                                          false /* separable */);
7896         }
7897         catch (Utils::Shader::InvalidSourceException& exc)
7898         {
7899                 exc.log(m_context);
7900                 TCU_FAIL(exc.what());
7901         }
7902         catch (Utils::Program::BuildException& exc)
7903         {
7904                 TCU_FAIL(exc.what());
7905         }
7906
7907         /*
7908          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7909          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7910          * following:
7911          *   * MAX_NAME_LENGTH,
7912          *   * MAX_NUM_ACTIVE_VARIABLES;
7913          */
7914         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7915         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7916                            test_result);
7917
7918         /*
7919          * - GetProgramResourceIndex should generate INVALID_ENUM when
7920          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7921          */
7922         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7923         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7924         /*
7925          * - GetProgramResourceName should generate INVALID_ENUM when
7926          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7927          */
7928         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7929                                                           name);
7930         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7931
7932         /* Set result */
7933         if (true == test_result)
7934         {
7935                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7936         }
7937         else
7938         {
7939                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7940         }
7941
7942         /* Done */
7943         return tcu::TestNode::STOP;
7944 }
7945
7946 /** Check if error is the expected one.
7947  *
7948  * @param expected_error Expected error
7949  * @param message        Message to log in case of error
7950  * @param test_result    Test result, set to false in case of invalid error
7951  **/
7952 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
7953 {
7954         const Functions& gl = m_context.getRenderContext().getFunctions();
7955
7956         GLenum error = gl.getError();
7957
7958         if (error != expected_error)
7959         {
7960                 m_context.getTestContext().getLog()
7961                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
7962                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
7963
7964                 test_result = false;
7965         }
7966 }
7967
7968 /** Constructor
7969  *
7970  * @param context Test framework context
7971  **/
7972 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
7973         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
7974 {
7975         /* Nothing to be done here */
7976 }
7977
7978 /** Source for given test case and stage
7979  *
7980  * @param test_case_index Index of test case
7981  * @param stage           Shader stage
7982  *
7983  * @return Shader source
7984  **/
7985 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
7986 {
7987         static const GLchar* cs = "#version 430 core\n"
7988                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7989                                                           "\n"
7990                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7991                                                           "\n"
7992                                                           "writeonly uniform uimage2D uni_image;\n"
7993                                                           "\n"
7994                                                           "void main()\n"
7995                                                           "{\n"
7996                                                           "    uint result = 1u;\n"
7997                                                           "    CONSTANT = 3;\n"
7998                                                           "\n"
7999                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8000                                                           "}\n"
8001                                                           "\n";
8002         static const GLchar* fs = "#version 430 core\n"
8003                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8004                                                           "\n"
8005                                                           "in  vec4 gs_fs;\n"
8006                                                           "out vec4 fs_out;\n"
8007                                                           "\n"
8008                                                           "void main()\n"
8009                                                           "{\n"
8010                                                           "ASSIGNMENT"
8011                                                           "    fs_out = gs_fs;\n"
8012                                                           "}\n"
8013                                                           "\n";
8014         static const GLchar* gs = "#version 430 core\n"
8015                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8016                                                           "\n"
8017                                                           "layout(points)                           in;\n"
8018                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8019                                                           "\n"
8020                                                           "in  vec4 tes_gs[];\n"
8021                                                           "out vec4 gs_fs;\n"
8022                                                           "\n"
8023                                                           "void main()\n"
8024                                                           "{\n"
8025                                                           "ASSIGNMENT"
8026                                                           "    gs_fs = tes_gs[0];\n"
8027                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8028                                                           "    EmitVertex();\n"
8029                                                           "    gs_fs = tes_gs[0];\n"
8030                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8031                                                           "    EmitVertex();\n"
8032                                                           "    gs_fs = tes_gs[0];\n"
8033                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8034                                                           "    EmitVertex();\n"
8035                                                           "    gs_fs = tes_gs[0];\n"
8036                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8037                                                           "    EmitVertex();\n"
8038                                                           "}\n"
8039                                                           "\n";
8040         static const GLchar* tcs = "#version 430 core\n"
8041                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8042                                                            "\n"
8043                                                            "layout(vertices = 1) out;\n"
8044                                                            "\n"
8045                                                            "in  vec4 vs_tcs[];\n"
8046                                                            "out vec4 tcs_tes[];\n"
8047                                                            "\n"
8048                                                            "void main()\n"
8049                                                            "{\n"
8050                                                            "\n"
8051                                                            "ASSIGNMENT"
8052                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8053                                                            "\n"
8054                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8055                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8056                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8057                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8058                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8059                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8060                                                            "}\n"
8061                                                            "\n";
8062         static const GLchar* tes = "#version 430 core\n"
8063                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8064                                                            "\n"
8065                                                            "layout(isolines, point_mode) in;\n"
8066                                                            "\n"
8067                                                            "in  vec4 tcs_tes[];\n"
8068                                                            "out vec4 tes_gs;\n"
8069                                                            "\n"
8070                                                            "void main()\n"
8071                                                            "{\n"
8072                                                            "ASSIGNMENT"
8073                                                            "    tes_gs = tcs_tes[0];\n"
8074                                                            "}\n"
8075                                                            "\n";
8076         static const GLchar* vs = "#version 430 core\n"
8077                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8078                                                           "\n"
8079                                                           "in  vec4 in_vs;\n"
8080                                                           "out vec4 vs_tcs;\n"
8081                                                           "\n"
8082                                                           "void main()\n"
8083                                                           "{\n"
8084                                                           "ASSIGNMENT"
8085                                                           "    vs_tcs = in_vs;\n"
8086                                                           "}\n"
8087                                                           "\n";
8088
8089         std::string source;
8090         testCase&   test_case = m_test_cases[test_case_index];
8091
8092         if (Utils::Shader::COMPUTE == test_case.m_stage)
8093         {
8094                 size_t position = 0;
8095
8096                 source = cs;
8097
8098                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8099         }
8100         else
8101         {
8102                 std::string assignment = "    CONSTANT = 3;\n";
8103                 size_t          position   = 0;
8104
8105                 switch (stage)
8106                 {
8107                 case Utils::Shader::FRAGMENT:
8108                         source = fs;
8109                         break;
8110                 case Utils::Shader::GEOMETRY:
8111                         source = gs;
8112                         break;
8113                 case Utils::Shader::TESS_CTRL:
8114                         source = tcs;
8115                         break;
8116                 case Utils::Shader::TESS_EVAL:
8117                         source = tes;
8118                         break;
8119                 case Utils::Shader::VERTEX:
8120                         source = vs;
8121                         break;
8122                 default:
8123                         TCU_FAIL("Invalid enum");
8124                 }
8125
8126                 if (test_case.m_stage == stage)
8127                 {
8128                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8129                 }
8130                 else
8131                 {
8132                         assignment = "";
8133                 }
8134
8135                 position = 0;
8136                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8137         }
8138
8139         return source;
8140 }
8141
8142 /** Get description of test case
8143  *
8144  * @param test_case_index Index of test case
8145  *
8146  * @return Constant name
8147  **/
8148 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8149 {
8150         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8151
8152         return result;
8153 }
8154
8155 /** Get number of test cases
8156  *
8157  * @return Number of test cases
8158  **/
8159 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8160 {
8161         return static_cast<GLuint>(m_test_cases.size());
8162 }
8163
8164 /** Selects if "compute" stage is relevant for test
8165  *
8166  * @param test_case_index Index of test case
8167  *
8168  * @return true when tested stage is compute
8169  **/
8170 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8171 {
8172         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8173 }
8174
8175 /** Prepare all test cases
8176  *
8177  **/
8178 void GLSLContantImmutablityTest::testInit()
8179 {
8180         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8181         {
8182                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8183                 {
8184                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8185
8186                         m_test_cases.push_back(test_case);
8187                 }
8188         }
8189 }
8190
8191 /** Get name of glsl constant
8192  *
8193  * @param Constant id
8194  *
8195  * @return Name of constant used in GLSL
8196  **/
8197 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8198 {
8199         const GLchar* name = "";
8200
8201         switch (constant)
8202         {
8203         case GL_ARB_ENHANCED_LAYOUTS:
8204                 name = "GL_ARB_enhanced_layouts";
8205                 break;
8206         case GL_MAX_XFB:
8207                 name = "gl_MaxTransformFeedbackBuffers";
8208                 break;
8209         case GL_MAX_XFB_INT_COMP:
8210                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8211                 break;
8212         default:
8213                 TCU_FAIL("Invalid enum");
8214         }
8215
8216         return name;
8217 }
8218
8219 /** Constructor
8220  *
8221  * @param context Test framework context
8222  **/
8223 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8224         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8225 {
8226 }
8227
8228 /** Selects if "compute" stage is relevant for test
8229  *
8230  * @param ignored
8231  *
8232  * @return false
8233  **/
8234 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8235 {
8236         return false;
8237 }
8238
8239 /** Prepare code snippet that will verify in and uniform variables
8240  *
8241  * @param ignored
8242  * @param ignored
8243  * @param stage   Shader stage
8244  *
8245  * @return Code that verify variables
8246  **/
8247 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8248                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8249                                                                                                                   Utils::Shader::STAGES stage)
8250 {
8251         /* Get constants */
8252         const Functions& gl = m_context.getRenderContext().getFunctions();
8253
8254         GLint max_transform_feedback_buffers                            = 0;
8255         GLint max_transform_feedback_interleaved_components = 0;
8256
8257         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8258         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8259         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8260         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8261
8262         std::string verification;
8263
8264         if (Utils::Shader::VERTEX == stage)
8265         {
8266                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8267                                            "    {\n"
8268                                            "        result = 0;\n"
8269                                            "    }\n"
8270                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8271                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8272                                            "    {\n"
8273                                            "        result = 0;\n"
8274                                            "    }\n"
8275                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8276                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8277                                            "    {\n"
8278                                            "        result = 0;\n"
8279                                            "    }\n";
8280
8281                 size_t position = 0;
8282                 GLchar buffer[16];
8283
8284                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8285                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8286
8287                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8288                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8289         }
8290         else
8291         {
8292                 verification = "";
8293         }
8294
8295         return verification;
8296 }
8297
8298 /** Constructor
8299  *
8300  * @param context Test framework context
8301  **/
8302 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8303         : TextureTestBase(context, "glsl_constant_integral_expression",
8304                                           "Test verifies that symbols can be used as constant integral expressions")
8305 {
8306 }
8307
8308 /** Get interface of program
8309  *
8310  * @param ignored
8311  * @param program_interface Interface of program
8312  * @param ignored
8313  **/
8314 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8315                                                                                                                          Utils::ProgramInterface& program_interface,
8316                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8317 {
8318         /* Get constants */
8319         const Functions& gl = m_context.getRenderContext().getFunctions();
8320
8321         GLint max_transform_feedback_buffers                            = 0;
8322         GLint max_transform_feedback_interleaved_components = 0;
8323
8324         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8325         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8326         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8327         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8328
8329         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8330         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8331
8332         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8333         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8334
8335         /* Globals */
8336         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8337                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8338                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8339
8340         size_t position = 0;
8341         GLchar buffer[16];
8342
8343         sprintf(buffer, "%d", gohan_div);
8344         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8345
8346         sprintf(buffer, "%d", goten_div);
8347         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8348
8349         program_interface.m_vertex.m_globals    = globals;
8350         program_interface.m_tess_ctrl.m_globals = globals;
8351         program_interface.m_tess_eval.m_globals = globals;
8352         program_interface.m_geometry.m_globals  = globals;
8353         program_interface.m_fragment.m_globals  = globals;
8354         program_interface.m_compute.m_globals   = globals;
8355 }
8356
8357 /** Prepare code snippet that will verify in and uniform variables
8358  *
8359  * @param ignored
8360  * @param ignored
8361  * @param ignored
8362  *
8363  * @return Code that verify variables
8364  **/
8365 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8366                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8367                                                                                                                                            Utils::Shader::STAGES /* stage */)
8368 {
8369         std::string verification = "{\n"
8370                                                            "        uint goku_sum = 0;\n"
8371                                                            "        uint gohan_sum = 0;\n"
8372                                                            "        uint goten_sum = 0;\n"
8373                                                            "\n"
8374                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8375                                                            "        {\n"
8376                                                            "            goku_sum += goku[i];\n"
8377                                                            "        }\n"
8378                                                            "\n"
8379                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8380                                                            "        {\n"
8381                                                            "            gohan_sum += gohan[i];\n"
8382                                                            "        }\n"
8383                                                            "\n"
8384                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8385                                                            "        {\n"
8386                                                            "            goten_sum += goten[i];\n"
8387                                                            "        }\n"
8388                                                            "\n"
8389                                                            "        if ( (1u != goku_sum)  &&\n"
8390                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8391                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8392                                                            "        {\n"
8393                                                            "            result = 0u;\n"
8394                                                            "        }\n"
8395                                                            "    }\n";
8396
8397         size_t position = 0;
8398         GLchar buffer[16];
8399
8400         sprintf(buffer, "%d", m_gohan_length);
8401         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8402
8403         sprintf(buffer, "%d", m_goten_length);
8404         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8405
8406         return verification;
8407 }
8408
8409 /** Prepare unifroms
8410  *
8411  * @param ignored
8412  * @param ignored
8413  * @param program Program object
8414  * @param ignored
8415  **/
8416 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8417                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8418                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8419 {
8420         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8421
8422         const Functions& gl = m_context.getRenderContext().getFunctions();
8423
8424         GLint goku_location  = program.GetUniformLocation("goku");
8425         GLint gohan_location = program.GetUniformLocation("gohan");
8426         GLint goten_location = program.GetUniformLocation("goten");
8427
8428         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8429         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8430         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8431 }
8432
8433 /** Prepare unifroms
8434  *
8435  * @param test_case_index   Pass as param to first implemetnation
8436  * @param program_interface Pass as param to first implemetnation
8437  * @param program           Pass as param to first implemetnation
8438  * @param ignored
8439  * @param ignored
8440  * @param ignored
8441  * @param ignored
8442  * @param vs_buffer         Pass as param to first implemetnation
8443  **/
8444 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8445                                                                                                                  Utils::ProgramInterface& program_interface,
8446                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8447                                                                                                                  Utils::Buffer& /* gs_buffer */,
8448                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8449                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8450 {
8451         /* Call first implementation */
8452         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8453 }
8454
8455 /** Constructor
8456  *
8457  * @param context Test framework context
8458  **/
8459 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8460         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8461                                           "Test verifies offsets and alignment of uniform buffer members")
8462 {
8463 }
8464
8465 /** Get interface of program
8466  *
8467  * @param test_case_index     Test case index
8468  * @param program_interface   Interface of program
8469  * @param varying_passthrough Collection of connections between in and out variables
8470  **/
8471 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8472                                                                                                                            Utils::ProgramInterface&   program_interface,
8473                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8474 {
8475         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8476                                                   "const int type_align = TYPE_ALIGN;\n"
8477                                                   "const int type_size  = TYPE_SIZE;\n";
8478
8479         Utils::Type  type                = getType(test_case_index);
8480         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8481         const GLuint base_align  = type.GetBaseAlignment(false);
8482         const GLuint array_align = type.GetBaseAlignment(true);
8483         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8484         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8485
8486         /* Calculate offsets */
8487         const GLuint first_offset  = 0;
8488         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8489
8490 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8491
8492         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8493         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8494         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8495         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8496         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8497         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8498
8499 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8500
8501         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8502         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8503         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8504         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8505         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8506         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8507
8508 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8509
8510         /* Prepare data */
8511         const std::vector<GLubyte>& first  = type.GenerateData();
8512         const std::vector<GLubyte>& second = type.GenerateData();
8513         const std::vector<GLubyte>& third  = type.GenerateData();
8514         const std::vector<GLubyte>& fourth = type.GenerateData();
8515
8516         m_data.resize(eigth_offset + base_stride);
8517         GLubyte* ptr = &m_data[0];
8518         memcpy(ptr + first_offset, &first[0], first.size());
8519         memcpy(ptr + second_offset, &second[0], second.size());
8520         memcpy(ptr + third_offset, &third[0], third.size());
8521         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8522         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8523         memcpy(ptr + sixth_offset, &third[0], third.size());
8524         memcpy(ptr + seventh_offset, &second[0], second.size());
8525         memcpy(ptr + eigth_offset, &first[0], first.size());
8526
8527         /* Prepare globals */
8528         size_t position = 0;
8529         GLchar buffer[16];
8530
8531         sprintf(buffer, "%d", basic_size);
8532         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8533
8534         sprintf(buffer, "%d", type_align);
8535         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8536
8537         sprintf(buffer, "%d", base_stride);
8538         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8539
8540         /* Prepare Block */
8541         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8542
8543         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8544                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8545                                                  first_offset);
8546
8547         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8548                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8549                                                  0 /* n_array_elements */, base_stride, second_offset);
8550
8551         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8552                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8553                                                  third_offset);
8554
8555         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8556                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8557                                                  fourth_offset);
8558
8559         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8560                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8561
8562         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8563                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8564
8565         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8566                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8567                                                  eigth_offset);
8568
8569         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8570
8571         /* Add globals */
8572         vs_si.m_globals = globals;
8573
8574         /* Add uniform BLOCK */
8575         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8576                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8577
8578         /* */
8579         program_interface.CloneVertexInterface(varying_passthrough);
8580 }
8581
8582 /** Get type name
8583  *
8584  * @param test_case_index Index of test case
8585  *
8586  * @return Name of type test in test_case_index
8587  **/
8588 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8589 {
8590         return getTypeName(test_case_index);
8591 }
8592
8593 /** Returns number of types to test
8594  *
8595  * @return Number of types, 34
8596  **/
8597 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8598 {
8599         return getTypesNumber();
8600 }
8601
8602 /** Prepare code snippet that will verify in and uniform variables
8603  *
8604  * @param ignored
8605  * @param ignored
8606  * @param stage   Shader stage
8607  *
8608  * @return Code that verify variables
8609  **/
8610 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8611         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8612 {
8613         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8614                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8615                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8616                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8617                                                            "    {\n"
8618                                                            "        result = 0;\n"
8619                                                            "    }";
8620
8621         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8622
8623         Utils::replaceAllTokens("PREFIX", prefix, verification);
8624
8625         return verification;
8626 }
8627
8628 /** Constructor
8629  *
8630  * @param context Test framework context
8631  **/
8632 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8633         : NegativeTestBase(
8634                   context, "uniform_block_layout_qualifier_conflict",
8635                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8636 {
8637         /* Nothing to be done here */
8638 }
8639
8640 /** Source for given test case and stage
8641  *
8642  * @param test_case_index Index of test case
8643  * @param stage           Shader stage
8644  *
8645  * @return Shader source
8646  **/
8647 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8648                                                                                                                                          Utils::Shader::STAGES stage)
8649 {
8650         static const GLchar* cs = "#version 430 core\n"
8651                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8652                                                           "\n"
8653                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8654                                                           "\n"
8655                                                           "LAYOUTuniform Block {\n"
8656                                                           "    layout(offset = 16) vec4 boy;\n"
8657                                                           "    layout(align  = 64) vec4 man;\n"
8658                                                           "} uni_block;\n"
8659                                                           "\n"
8660                                                           "writeonly uniform image2D uni_image;\n"
8661                                                           "\n"
8662                                                           "void main()\n"
8663                                                           "{\n"
8664                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8665                                                           "\n"
8666                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8667                                                           "}\n"
8668                                                           "\n";
8669         static const GLchar* fs = "#version 430 core\n"
8670                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8671                                                           "\n"
8672                                                           "LAYOUTuniform Block {\n"
8673                                                           "    layout(offset = 16) vec4 boy;\n"
8674                                                           "    layout(align  = 64) vec4 man;\n"
8675                                                           "} uni_block;\n"
8676                                                           "\n"
8677                                                           "in  vec4 gs_fs;\n"
8678                                                           "out vec4 fs_out;\n"
8679                                                           "\n"
8680                                                           "void main()\n"
8681                                                           "{\n"
8682                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8683                                                           "}\n"
8684                                                           "\n";
8685         static const GLchar* gs = "#version 430 core\n"
8686                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8687                                                           "\n"
8688                                                           "layout(points)                           in;\n"
8689                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8690                                                           "\n"
8691                                                           "LAYOUTuniform Block {\n"
8692                                                           "    layout(offset = 16) vec4 boy;\n"
8693                                                           "    layout(align  = 64) vec4 man;\n"
8694                                                           "} uni_block;\n"
8695                                                           "\n"
8696                                                           "in  vec4 tes_gs[];\n"
8697                                                           "out vec4 gs_fs;\n"
8698                                                           "\n"
8699                                                           "void main()\n"
8700                                                           "{\n"
8701                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8702                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8703                                                           "    EmitVertex();\n"
8704                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8705                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8706                                                           "    EmitVertex();\n"
8707                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8708                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8709                                                           "    EmitVertex();\n"
8710                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8711                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8712                                                           "    EmitVertex();\n"
8713                                                           "}\n"
8714                                                           "\n";
8715         static const GLchar* tcs =
8716                 "#version 430 core\n"
8717                 "#extension GL_ARB_enhanced_layouts : require\n"
8718                 "\n"
8719                 "layout(vertices = 1) out;\n"
8720                 "\n"
8721                 "LAYOUTuniform Block {\n"
8722                 "    layout(offset = 16) vec4 boy;\n"
8723                 "    layout(align  = 64) vec4 man;\n"
8724                 "} uni_block;\n"
8725                 "\n"
8726                 "in  vec4 vs_tcs[];\n"
8727                 "out vec4 tcs_tes[];\n"
8728                 "\n"
8729                 "void main()\n"
8730                 "{\n"
8731                 "\n"
8732                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8733                 "\n"
8734                 "    gl_TessLevelOuter[0] = 1.0;\n"
8735                 "    gl_TessLevelOuter[1] = 1.0;\n"
8736                 "    gl_TessLevelOuter[2] = 1.0;\n"
8737                 "    gl_TessLevelOuter[3] = 1.0;\n"
8738                 "    gl_TessLevelInner[0] = 1.0;\n"
8739                 "    gl_TessLevelInner[1] = 1.0;\n"
8740                 "}\n"
8741                 "\n";
8742         static const GLchar* tes = "#version 430 core\n"
8743                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8744                                                            "\n"
8745                                                            "layout(isolines, point_mode) in;\n"
8746                                                            "\n"
8747                                                            "LAYOUTuniform Block {\n"
8748                                                            "    layout(offset = 16) vec4 boy;\n"
8749                                                            "    layout(align  = 64) vec4 man;\n"
8750                                                            "} uni_block;\n"
8751                                                            "\n"
8752                                                            "in  vec4 tcs_tes[];\n"
8753                                                            "out vec4 tes_gs;\n"
8754                                                            "\n"
8755                                                            "void main()\n"
8756                                                            "{\n"
8757                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8758                                                            "}\n"
8759                                                            "\n";
8760         static const GLchar* vs = "#version 430 core\n"
8761                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8762                                                           "\n"
8763                                                           "LAYOUTuniform Block {\n"
8764                                                           "    layout(offset = 16) vec4 boy;\n"
8765                                                           "    layout(align  = 64) vec4 man;\n"
8766                                                           "} uni_block;\n"
8767                                                           "\n"
8768                                                           "in  vec4 in_vs;\n"
8769                                                           "out vec4 vs_tcs;\n"
8770                                                           "\n"
8771                                                           "void main()\n"
8772                                                           "{\n"
8773                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8774                                                           "}\n"
8775                                                           "\n";
8776
8777         std::string   layout    = "";
8778         size_t            position  = 0;
8779         testCase&        test_case = m_test_cases[test_case_index];
8780         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8781         std::string   source;
8782
8783         if (0 != qualifier[0])
8784         {
8785                 size_t layout_position = 0;
8786
8787                 layout = "layout (QUALIFIER) ";
8788
8789                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8790         }
8791
8792         switch (stage)
8793         {
8794         case Utils::Shader::COMPUTE:
8795                 source = cs;
8796                 break;
8797         case Utils::Shader::FRAGMENT:
8798                 source = fs;
8799                 break;
8800         case Utils::Shader::GEOMETRY:
8801                 source = gs;
8802                 break;
8803         case Utils::Shader::TESS_CTRL:
8804                 source = tcs;
8805                 break;
8806         case Utils::Shader::TESS_EVAL:
8807                 source = tes;
8808                 break;
8809         case Utils::Shader::VERTEX:
8810                 source = vs;
8811                 break;
8812         default:
8813                 TCU_FAIL("Invalid enum");
8814         }
8815
8816         if (test_case.m_stage == stage)
8817         {
8818                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8819         }
8820         else
8821         {
8822                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8823         }
8824
8825         return source;
8826 }
8827
8828 /** Get description of test case
8829  *
8830  * @param test_case_index Index of test case
8831  *
8832  * @return Qualifier name
8833  **/
8834 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8835 {
8836         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8837
8838         return result;
8839 }
8840
8841 /** Get number of test cases
8842  *
8843  * @return Number of test cases
8844  **/
8845 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8846 {
8847         return static_cast<GLuint>(m_test_cases.size());
8848 }
8849
8850 /** Selects if "compute" stage is relevant for test
8851  *
8852  * @param test_case_index Index of test case
8853  *
8854  * @return true when tested stage is compute
8855  **/
8856 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8857 {
8858         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8859 }
8860
8861 /** Selects if compilation failure is expected result
8862  *
8863  * @param test_case_index Index of test case
8864  *
8865  * @return false for STD140 cases, true otherwise
8866  **/
8867 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8868 {
8869         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8870 }
8871
8872 /** Prepare all test cases
8873  *
8874  **/
8875 void UniformBlockLayoutQualifierConflictTest::testInit()
8876 {
8877         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8878         {
8879                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8880                 {
8881                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8882
8883                         m_test_cases.push_back(test_case);
8884                 }
8885         }
8886 }
8887
8888 /** Get name of glsl constant
8889  *
8890  * @param Constant id
8891  *
8892  * @return Name of constant used in GLSL
8893  **/
8894 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8895 {
8896         const GLchar* name = "";
8897
8898         switch (qualifier)
8899         {
8900         case DEFAULT:
8901                 name = "";
8902                 break;
8903         case STD140:
8904                 name = "std140";
8905                 break;
8906         case SHARED:
8907                 name = "shared";
8908                 break;
8909         case PACKED:
8910                 name = "packed";
8911                 break;
8912         default:
8913                 TCU_FAIL("Invalid enum");
8914         }
8915
8916         return name;
8917 }
8918
8919 /** Constructor
8920  *
8921  * @param context Test framework context
8922  **/
8923 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8924         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8925                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8926 {
8927         /* Nothing to be done here */
8928 }
8929
8930 /** Constructor
8931  *
8932  * @param context     Test framework context
8933  * @param name        Test name
8934  * @param description Test description
8935  **/
8936 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8937         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8938         : NegativeTestBase(context, name, description)
8939 {
8940         /* Nothing to be done here */
8941 }
8942
8943 /** Source for given test case and stage
8944  *
8945  * @param test_case_index Index of test case
8946  * @param stage           Shader stage
8947  *
8948  * @return Shader source
8949  **/
8950 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
8951                                                                                                                                                   Utils::Shader::STAGES stage)
8952 {
8953         static const GLchar* cs = "#version 430 core\n"
8954                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8955                                                           "\n"
8956                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8957                                                           "\n"
8958                                                           "layout (std140) uniform Block {\n"
8959                                                           "    layout (offset = OFFSET) TYPE member;\n"
8960                                                           "} block;\n"
8961                                                           "\n"
8962                                                           "writeonly uniform image2D uni_image;\n"
8963                                                           "\n"
8964                                                           "void main()\n"
8965                                                           "{\n"
8966                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
8967                                                           "\n"
8968                                                           "    if (TYPE(1) == block.member)\n"
8969                                                           "    {\n"
8970                                                           "        result = vec4(1, 1, 1, 1);\n"
8971                                                           "    }\n"
8972                                                           "\n"
8973                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8974                                                           "}\n"
8975                                                           "\n";
8976         static const GLchar* fs = "#version 430 core\n"
8977                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8978                                                           "\n"
8979                                                           "in  vec4 gs_fs;\n"
8980                                                           "out vec4 fs_out;\n"
8981                                                           "\n"
8982                                                           "void main()\n"
8983                                                           "{\n"
8984                                                           "    fs_out = gs_fs;\n"
8985                                                           "}\n"
8986                                                           "\n";
8987         static const GLchar* fs_tested = "#version 430 core\n"
8988                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
8989                                                                          "\n"
8990                                                                          "layout (std140) uniform Block {\n"
8991                                                                          "    layout (offset = OFFSET) TYPE member;\n"
8992                                                                          "} block;\n"
8993                                                                          "\n"
8994                                                                          "in  vec4 gs_fs;\n"
8995                                                                          "out vec4 fs_out;\n"
8996                                                                          "\n"
8997                                                                          "void main()\n"
8998                                                                          "{\n"
8999                                                                          "    if (TYPE(1) == block.member)\n"
9000                                                                          "    {\n"
9001                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9002                                                                          "    }\n"
9003                                                                          "\n"
9004                                                                          "    fs_out += gs_fs;\n"
9005                                                                          "}\n"
9006                                                                          "\n";
9007         static const GLchar* gs = "#version 430 core\n"
9008                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9009                                                           "\n"
9010                                                           "layout(points)                           in;\n"
9011                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9012                                                           "\n"
9013                                                           "in  vec4 tes_gs[];\n"
9014                                                           "out vec4 gs_fs;\n"
9015                                                           "\n"
9016                                                           "void main()\n"
9017                                                           "{\n"
9018                                                           "    gs_fs = tes_gs[0];\n"
9019                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9020                                                           "    EmitVertex();\n"
9021                                                           "    gs_fs = tes_gs[0];\n"
9022                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9023                                                           "    EmitVertex();\n"
9024                                                           "    gs_fs = tes_gs[0];\n"
9025                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9026                                                           "    EmitVertex();\n"
9027                                                           "    gs_fs = tes_gs[0];\n"
9028                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9029                                                           "    EmitVertex();\n"
9030                                                           "}\n"
9031                                                           "\n";
9032         static const GLchar* gs_tested = "#version 430 core\n"
9033                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9034                                                                          "\n"
9035                                                                          "layout(points)                           in;\n"
9036                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9037                                                                          "\n"
9038                                                                          "layout (std140) uniform Block {\n"
9039                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9040                                                                          "} block;\n"
9041                                                                          "\n"
9042                                                                          "in  vec4 tes_gs[];\n"
9043                                                                          "out vec4 gs_fs;\n"
9044                                                                          "\n"
9045                                                                          "void main()\n"
9046                                                                          "{\n"
9047                                                                          "    if (TYPE(1) == block.member)\n"
9048                                                                          "    {\n"
9049                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9050                                                                          "    }\n"
9051                                                                          "\n"
9052                                                                          "    gs_fs += tes_gs[0];\n"
9053                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9054                                                                          "    EmitVertex();\n"
9055                                                                          "    gs_fs += tes_gs[0];\n"
9056                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9057                                                                          "    EmitVertex();\n"
9058                                                                          "    gs_fs += tes_gs[0];\n"
9059                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9060                                                                          "    EmitVertex();\n"
9061                                                                          "    gs_fs += tes_gs[0];\n"
9062                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9063                                                                          "    EmitVertex();\n"
9064                                                                          "}\n"
9065                                                                          "\n";
9066         static const GLchar* tcs = "#version 430 core\n"
9067                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9068                                                            "\n"
9069                                                            "layout(vertices = 1) out;\n"
9070                                                            "\n"
9071                                                            "in  vec4 vs_tcs[];\n"
9072                                                            "out vec4 tcs_tes[];\n"
9073                                                            "\n"
9074                                                            "void main()\n"
9075                                                            "{\n"
9076                                                            "\n"
9077                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9078                                                            "\n"
9079                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9080                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9081                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9082                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9083                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9084                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9085                                                            "}\n"
9086                                                            "\n";
9087         static const GLchar* tcs_tested = "#version 430 core\n"
9088                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9089                                                                           "\n"
9090                                                                           "layout(vertices = 1) out;\n"
9091                                                                           "\n"
9092                                                                           "layout (std140) uniform Block {\n"
9093                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9094                                                                           "} block;\n"
9095                                                                           "\n"
9096                                                                           "in  vec4 vs_tcs[];\n"
9097                                                                           "out vec4 tcs_tes[];\n"
9098                                                                           "\n"
9099                                                                           "void main()\n"
9100                                                                           "{\n"
9101                                                                           "    if (TYPE(1) == block.member)\n"
9102                                                                           "    {\n"
9103                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9104                                                                           "    }\n"
9105                                                                           "\n"
9106                                                                           "\n"
9107                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9108                                                                           "\n"
9109                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9110                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9111                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9112                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9113                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9114                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9115                                                                           "}\n"
9116                                                                           "\n";
9117         static const GLchar* tes = "#version 430 core\n"
9118                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9119                                                            "\n"
9120                                                            "layout(isolines, point_mode) in;\n"
9121                                                            "\n"
9122                                                            "in  vec4 tcs_tes[];\n"
9123                                                            "out vec4 tes_gs;\n"
9124                                                            "\n"
9125                                                            "void main()\n"
9126                                                            "{\n"
9127                                                            "    tes_gs = tcs_tes[0];\n"
9128                                                            "}\n"
9129                                                            "\n";
9130         static const GLchar* tes_tested = "#version 430 core\n"
9131                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9132                                                                           "\n"
9133                                                                           "layout(isolines, point_mode) in;\n"
9134                                                                           "\n"
9135                                                                           "layout (std140) uniform Block {\n"
9136                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9137                                                                           "} block;\n"
9138                                                                           "\n"
9139                                                                           "in  vec4 tcs_tes[];\n"
9140                                                                           "out vec4 tes_gs;\n"
9141                                                                           "\n"
9142                                                                           "void main()\n"
9143                                                                           "{\n"
9144                                                                           "    if (TYPE(1) == block.member)\n"
9145                                                                           "    {\n"
9146                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9147                                                                           "    }\n"
9148                                                                           "\n"
9149                                                                           "    tes_gs += tcs_tes[0];\n"
9150                                                                           "}\n"
9151                                                                           "\n";
9152         static const GLchar* vs = "#version 430 core\n"
9153                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9154                                                           "\n"
9155                                                           "in  vec4 in_vs;\n"
9156                                                           "out vec4 vs_tcs;\n"
9157                                                           "\n"
9158                                                           "void main()\n"
9159                                                           "{\n"
9160                                                           "    vs_tcs = in_vs;\n"
9161                                                           "}\n"
9162                                                           "\n";
9163         static const GLchar* vs_tested = "#version 430 core\n"
9164                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9165                                                                          "\n"
9166                                                                          "layout (std140) uniform Block {\n"
9167                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9168                                                                          "} block;\n"
9169                                                                          "\n"
9170                                                                          "in  vec4 in_vs;\n"
9171                                                                          "out vec4 vs_tcs;\n"
9172                                                                          "\n"
9173                                                                          "void main()\n"
9174                                                                          "{\n"
9175                                                                          "    if (TYPE(1) == block.member)\n"
9176                                                                          "    {\n"
9177                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9178                                                                          "    }\n"
9179                                                                          "\n"
9180                                                                          "    vs_tcs += in_vs;\n"
9181                                                                          "}\n"
9182                                                                          "\n";
9183
9184         std::string source;
9185         testCase&   test_case = m_test_cases[test_case_index];
9186
9187         if (test_case.m_stage == stage)
9188         {
9189                 GLchar                     buffer[16];
9190                 const GLuint       offset       = test_case.m_offset;
9191                 size_t                     position  = 0;
9192                 const Utils::Type& type          = test_case.m_type;
9193                 const GLchar*     type_name = type.GetGLSLTypeName();
9194
9195                 sprintf(buffer, "%d", offset);
9196
9197                 switch (stage)
9198                 {
9199                 case Utils::Shader::COMPUTE:
9200                         source = cs;
9201                         break;
9202                 case Utils::Shader::FRAGMENT:
9203                         source = fs_tested;
9204                         break;
9205                 case Utils::Shader::GEOMETRY:
9206                         source = gs_tested;
9207                         break;
9208                 case Utils::Shader::TESS_CTRL:
9209                         source = tcs_tested;
9210                         break;
9211                 case Utils::Shader::TESS_EVAL:
9212                         source = tes_tested;
9213                         break;
9214                 case Utils::Shader::VERTEX:
9215                         source = vs_tested;
9216                         break;
9217                 default:
9218                         TCU_FAIL("Invalid enum");
9219                 }
9220
9221                 Utils::replaceToken("OFFSET", position, buffer, source);
9222                 Utils::replaceToken("TYPE", position, type_name, source);
9223                 Utils::replaceToken("TYPE", position, type_name, source);
9224         }
9225         else
9226         {
9227                 switch (stage)
9228                 {
9229                 case Utils::Shader::FRAGMENT:
9230                         source = fs;
9231                         break;
9232                 case Utils::Shader::GEOMETRY:
9233                         source = gs;
9234                         break;
9235                 case Utils::Shader::TESS_CTRL:
9236                         source = tcs;
9237                         break;
9238                 case Utils::Shader::TESS_EVAL:
9239                         source = tes;
9240                         break;
9241                 case Utils::Shader::VERTEX:
9242                         source = vs;
9243                         break;
9244                 default:
9245                         TCU_FAIL("Invalid enum");
9246                 }
9247         }
9248
9249         return source;
9250 }
9251
9252 /** Get description of test case
9253  *
9254  * @param test_case_index Index of test case
9255  *
9256  * @return Type name and offset
9257  **/
9258 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9259 {
9260         std::stringstream stream;
9261         testCase&                 test_case = m_test_cases[test_case_index];
9262
9263         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9264
9265         return stream.str();
9266 }
9267
9268 /** Get number of test cases
9269  *
9270  * @return Number of test cases
9271  **/
9272 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9273 {
9274         return static_cast<GLuint>(m_test_cases.size());
9275 }
9276
9277 /** Selects if "compute" stage is relevant for test
9278  *
9279  * @param test_case_index Index of test case
9280  *
9281  * @return true when tested stage is compute
9282  **/
9283 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9284 {
9285         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9286 }
9287
9288 /** Selects if compilation failure is expected result
9289  *
9290  * @param test_case_index Index of test case
9291  *
9292  * @return should_fail field from testCase
9293  **/
9294 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9295 {
9296         return m_test_cases[test_case_index].m_should_fail;
9297 }
9298
9299 /** Checks if stage is supported
9300  *
9301  * @param stage ignored
9302  *
9303  * @return true
9304  **/
9305 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9306 {
9307         return true;
9308 }
9309
9310 /** Prepare all test cases
9311  *
9312  **/
9313 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9314 {
9315         const Functions& gl               = m_context.getRenderContext().getFunctions();
9316         GLint                    max_size = 0;
9317         const GLuint     n_types  = getTypesNumber();
9318         bool                     stage_support[Utils::Shader::STAGE_MAX];
9319
9320         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9321         {
9322                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9323         }
9324
9325         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9326         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9327
9328         for (GLuint i = 0; i < n_types; ++i)
9329         {
9330                 const Utils::Type& type           = getType(i);
9331                 const GLuint       alignment  = type.GetBaseAlignment(false);
9332                 const GLuint       type_size  = type.GetSize();
9333                 const GLuint       sec_to_end = max_size - 2 * type_size;
9334
9335                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9336                 {
9337                         if (false == stage_support[stage])
9338                         {
9339                                 continue;
9340                         }
9341
9342                         for (GLuint offset = 0; offset <= type_size; ++offset)
9343                         {
9344                                 const GLuint modulo              = offset % alignment;
9345                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9346                                 const bool   should_fail = !is_aligned;
9347
9348                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9349
9350                                 m_test_cases.push_back(test_case);
9351                         }
9352
9353                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9354                         {
9355                                 const GLuint modulo              = offset % alignment;
9356                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9357                                 const bool   should_fail = !is_aligned;
9358
9359                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9360
9361                                 m_test_cases.push_back(test_case);
9362                         }
9363                 }
9364         }
9365 }
9366
9367 /** Constructor
9368  *
9369  * @param context Test framework context
9370  **/
9371 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9372         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9373                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9374 {
9375         /* Nothing to be done here */
9376 }
9377
9378 /** Constructor
9379  *
9380  * @param context Test framework context
9381  * @param name        Test name
9382  * @param description Test description
9383  **/
9384 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9385                                                                                                                                                                    const glw::GLchar* name,
9386                                                                                                                                                                    const glw::GLchar* description)
9387         : NegativeTestBase(context, name, description)
9388 {
9389         /* Nothing to be done here */
9390 }
9391
9392 /** Source for given test case and stage
9393  *
9394  * @param test_case_index Index of test case
9395  * @param stage           Shader stage
9396  *
9397  * @return Shader source
9398  **/
9399 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9400                                                                                                                                           Utils::Shader::STAGES stage)
9401 {
9402         static const GLchar* cs = "#version 430 core\n"
9403                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9404                                                           "\n"
9405                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9406                                                           "\n"
9407                                                           "layout (std140) uniform Block {\n"
9408                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9409                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9410                                                           "} block;\n"
9411                                                           "\n"
9412                                                           "writeonly uniform image2D uni_image;\n"
9413                                                           "\n"
9414                                                           "void main()\n"
9415                                                           "{\n"
9416                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9417                                                           "\n"
9418                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9419                                                           "        (MAN_TYPE(0) == block.man) )\n"
9420                                                           "    {\n"
9421                                                           "        result = vec4(1, 1, 1, 1);\n"
9422                                                           "    }\n"
9423                                                           "\n"
9424                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9425                                                           "}\n"
9426                                                           "\n";
9427         static const GLchar* fs = "#version 430 core\n"
9428                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9429                                                           "\n"
9430                                                           "in  vec4 gs_fs;\n"
9431                                                           "out vec4 fs_out;\n"
9432                                                           "\n"
9433                                                           "void main()\n"
9434                                                           "{\n"
9435                                                           "    fs_out = gs_fs;\n"
9436                                                           "}\n"
9437                                                           "\n";
9438         static const GLchar* fs_tested = "#version 430 core\n"
9439                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9440                                                                          "\n"
9441                                                                          "layout (std140) uniform Block {\n"
9442                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9443                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9444                                                                          "} block;\n"
9445                                                                          "\n"
9446                                                                          "in  vec4 gs_fs;\n"
9447                                                                          "out vec4 fs_out;\n"
9448                                                                          "\n"
9449                                                                          "void main()\n"
9450                                                                          "{\n"
9451                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9452                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9453                                                                          "    {\n"
9454                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9455                                                                          "    }\n"
9456                                                                          "\n"
9457                                                                          "    fs_out += gs_fs;\n"
9458                                                                          "}\n"
9459                                                                          "\n";
9460         static const GLchar* gs = "#version 430 core\n"
9461                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9462                                                           "\n"
9463                                                           "layout(points)                           in;\n"
9464                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9465                                                           "\n"
9466                                                           "in  vec4 tes_gs[];\n"
9467                                                           "out vec4 gs_fs;\n"
9468                                                           "\n"
9469                                                           "void main()\n"
9470                                                           "{\n"
9471                                                           "    gs_fs = tes_gs[0];\n"
9472                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9473                                                           "    EmitVertex();\n"
9474                                                           "    gs_fs = tes_gs[0];\n"
9475                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9476                                                           "    EmitVertex();\n"
9477                                                           "    gs_fs = tes_gs[0];\n"
9478                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9479                                                           "    EmitVertex();\n"
9480                                                           "    gs_fs = tes_gs[0];\n"
9481                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9482                                                           "    EmitVertex();\n"
9483                                                           "}\n"
9484                                                           "\n";
9485         static const GLchar* gs_tested = "#version 430 core\n"
9486                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9487                                                                          "\n"
9488                                                                          "layout(points)                           in;\n"
9489                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9490                                                                          "\n"
9491                                                                          "layout (std140) uniform Block {\n"
9492                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9493                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9494                                                                          "} block;\n"
9495                                                                          "\n"
9496                                                                          "in  vec4 tes_gs[];\n"
9497                                                                          "out vec4 gs_fs;\n"
9498                                                                          "\n"
9499                                                                          "void main()\n"
9500                                                                          "{\n"
9501                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9502                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9503                                                                          "    {\n"
9504                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9505                                                                          "    }\n"
9506                                                                          "\n"
9507                                                                          "    gs_fs += tes_gs[0];\n"
9508                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9509                                                                          "    EmitVertex();\n"
9510                                                                          "    gs_fs += tes_gs[0];\n"
9511                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9512                                                                          "    EmitVertex();\n"
9513                                                                          "    gs_fs += tes_gs[0];\n"
9514                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9515                                                                          "    EmitVertex();\n"
9516                                                                          "    gs_fs += tes_gs[0];\n"
9517                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9518                                                                          "    EmitVertex();\n"
9519                                                                          "}\n"
9520                                                                          "\n";
9521         static const GLchar* tcs = "#version 430 core\n"
9522                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9523                                                            "\n"
9524                                                            "layout(vertices = 1) out;\n"
9525                                                            "\n"
9526                                                            "in  vec4 vs_tcs[];\n"
9527                                                            "out vec4 tcs_tes[];\n"
9528                                                            "\n"
9529                                                            "void main()\n"
9530                                                            "{\n"
9531                                                            "\n"
9532                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9533                                                            "\n"
9534                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9535                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9536                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9537                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9538                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9539                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9540                                                            "}\n"
9541                                                            "\n";
9542         static const GLchar* tcs_tested = "#version 430 core\n"
9543                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9544                                                                           "\n"
9545                                                                           "layout(vertices = 1) out;\n"
9546                                                                           "\n"
9547                                                                           "layout (std140) uniform Block {\n"
9548                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9549                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9550                                                                           "} block;\n"
9551                                                                           "\n"
9552                                                                           "in  vec4 vs_tcs[];\n"
9553                                                                           "out vec4 tcs_tes[];\n"
9554                                                                           "\n"
9555                                                                           "void main()\n"
9556                                                                           "{\n"
9557                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9558                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9559                                                                           "    {\n"
9560                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9561                                                                           "    }\n"
9562                                                                           "\n"
9563                                                                           "\n"
9564                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9565                                                                           "\n"
9566                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9567                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9568                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9569                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9570                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9571                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9572                                                                           "}\n"
9573                                                                           "\n";
9574         static const GLchar* tes = "#version 430 core\n"
9575                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9576                                                            "\n"
9577                                                            "layout(isolines, point_mode) in;\n"
9578                                                            "\n"
9579                                                            "in  vec4 tcs_tes[];\n"
9580                                                            "out vec4 tes_gs;\n"
9581                                                            "\n"
9582                                                            "void main()\n"
9583                                                            "{\n"
9584                                                            "    tes_gs = tcs_tes[0];\n"
9585                                                            "}\n"
9586                                                            "\n";
9587         static const GLchar* tes_tested = "#version 430 core\n"
9588                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9589                                                                           "\n"
9590                                                                           "layout(isolines, point_mode) in;\n"
9591                                                                           "\n"
9592                                                                           "layout (std140) uniform Block {\n"
9593                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9594                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9595                                                                           "} block;\n"
9596                                                                           "\n"
9597                                                                           "in  vec4 tcs_tes[];\n"
9598                                                                           "out vec4 tes_gs;\n"
9599                                                                           "\n"
9600                                                                           "void main()\n"
9601                                                                           "{\n"
9602                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9603                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9604                                                                           "    {\n"
9605                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9606                                                                           "    }\n"
9607                                                                           "\n"
9608                                                                           "    tes_gs += tcs_tes[0];\n"
9609                                                                           "}\n"
9610                                                                           "\n";
9611         static const GLchar* vs = "#version 430 core\n"
9612                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9613                                                           "\n"
9614                                                           "in  vec4 in_vs;\n"
9615                                                           "out vec4 vs_tcs;\n"
9616                                                           "\n"
9617                                                           "void main()\n"
9618                                                           "{\n"
9619                                                           "    vs_tcs = in_vs;\n"
9620                                                           "}\n"
9621                                                           "\n";
9622         static const GLchar* vs_tested = "#version 430 core\n"
9623                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9624                                                                          "\n"
9625                                                                          "layout (std140) uniform Block {\n"
9626                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9627                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9628                                                                          "} block;\n"
9629                                                                          "\n"
9630                                                                          "in  vec4 in_vs;\n"
9631                                                                          "out vec4 vs_tcs;\n"
9632                                                                          "\n"
9633                                                                          "void main()\n"
9634                                                                          "{\n"
9635                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9636                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9637                                                                          "    {\n"
9638                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9639                                                                          "    }\n"
9640                                                                          "\n"
9641                                                                          "    vs_tcs += in_vs;\n"
9642                                                                          "}\n"
9643                                                                          "\n";
9644
9645         std::string source;
9646         testCase&   test_case = m_test_cases[test_case_index];
9647
9648         if (test_case.m_stage == stage)
9649         {
9650                 GLchar                     buffer[16];
9651                 const GLuint       boy_offset   = test_case.m_boy_offset;
9652                 const Utils::Type& boy_type              = test_case.m_boy_type;
9653                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9654                 const GLuint       man_offset   = test_case.m_man_offset;
9655                 const Utils::Type& man_type              = test_case.m_man_type;
9656                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9657                 size_t                     position              = 0;
9658
9659                 switch (stage)
9660                 {
9661                 case Utils::Shader::COMPUTE:
9662                         source = cs;
9663                         break;
9664                 case Utils::Shader::FRAGMENT:
9665                         source = fs_tested;
9666                         break;
9667                 case Utils::Shader::GEOMETRY:
9668                         source = gs_tested;
9669                         break;
9670                 case Utils::Shader::TESS_CTRL:
9671                         source = tcs_tested;
9672                         break;
9673                 case Utils::Shader::TESS_EVAL:
9674                         source = tes_tested;
9675                         break;
9676                 case Utils::Shader::VERTEX:
9677                         source = vs_tested;
9678                         break;
9679                 default:
9680                         TCU_FAIL("Invalid enum");
9681                 }
9682
9683                 sprintf(buffer, "%d", boy_offset);
9684                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9685                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9686                 sprintf(buffer, "%d", man_offset);
9687                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9688                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9689                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9690                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9691         }
9692         else
9693         {
9694                 switch (stage)
9695                 {
9696                 case Utils::Shader::FRAGMENT:
9697                         source = fs;
9698                         break;
9699                 case Utils::Shader::GEOMETRY:
9700                         source = gs;
9701                         break;
9702                 case Utils::Shader::TESS_CTRL:
9703                         source = tcs;
9704                         break;
9705                 case Utils::Shader::TESS_EVAL:
9706                         source = tes;
9707                         break;
9708                 case Utils::Shader::VERTEX:
9709                         source = vs;
9710                         break;
9711                 default:
9712                         TCU_FAIL("Invalid enum");
9713                 }
9714         }
9715
9716         return source;
9717 }
9718
9719 /** Get description of test case
9720  *
9721  * @param test_case_index Index of test case
9722  *
9723  * @return Type name and offset
9724  **/
9725 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9726 {
9727         std::stringstream stream;
9728         testCase&                 test_case = m_test_cases[test_case_index];
9729
9730         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9731                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9732
9733         return stream.str();
9734 }
9735
9736 /** Get number of test cases
9737  *
9738  * @return Number of test cases
9739  **/
9740 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9741 {
9742         return static_cast<GLuint>(m_test_cases.size());
9743 }
9744
9745 /** Selects if "compute" stage is relevant for test
9746  *
9747  * @param test_case_index Index of test case
9748  *
9749  * @return true when tested stage is compute
9750  **/
9751 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9752 {
9753         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9754 }
9755
9756 /** Checks if stage is supported
9757  *
9758  * @param stage ignored
9759  *
9760  * @return true
9761  **/
9762 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9763 {
9764         return true;
9765 }
9766
9767 /** Prepare all test cases
9768  *
9769  **/
9770 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9771 {
9772         const GLuint n_types = getTypesNumber();
9773         bool             stage_support[Utils::Shader::STAGE_MAX];
9774
9775         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9776         {
9777                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9778         }
9779
9780         for (GLuint i = 0; i < n_types; ++i)
9781         {
9782                 const Utils::Type& boy_type = getType(i);
9783                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9784
9785                 for (GLuint j = 0; j < n_types; ++j)
9786                 {
9787                         const Utils::Type& man_type  = getType(j);
9788                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9789                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9790
9791                         const GLuint boy_offset           = lcm(boy_size, man_size);
9792                         const GLuint man_after_start  = boy_offset + 1;
9793                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9794                         const GLuint man_before_start = boy_offset - man_align;
9795                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9796
9797                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9798                         {
9799                                 if (false == stage_support[stage])
9800                                 {
9801                                         continue;
9802                                 }
9803
9804                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9805                                 {
9806                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9807                                                                                    (Utils::Shader::STAGES)stage };
9808
9809                                         m_test_cases.push_back(test_case);
9810                                 }
9811
9812                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9813                                 {
9814                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9815                                                                                    (Utils::Shader::STAGES)stage };
9816
9817                                         m_test_cases.push_back(test_case);
9818                                 }
9819
9820                                 /* Boy offset, should be fine for both types */
9821                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9822
9823                                 m_test_cases.push_back(test_case);
9824                         }
9825                 }
9826         }
9827 }
9828
9829 /** Find greatest common divisor for a and b
9830  *
9831  * @param a A argument
9832  * @param b B argument
9833  *
9834  * @return Found gcd value
9835  **/
9836 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9837 {
9838         if ((0 != a) && (0 == b))
9839         {
9840                 return a;
9841         }
9842         else
9843         {
9844                 GLuint greater = std::max(a, b);
9845                 GLuint lesser  = std::min(a, b);
9846
9847                 return gcd(lesser, greater % lesser);
9848         }
9849 }
9850
9851 /** Find lowest common multiple for a and b
9852  *
9853  * @param a A argument
9854  * @param b B argument
9855  *
9856  * @return Found gcd value
9857  **/
9858 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9859 {
9860         return (a * b) / gcd(a, b);
9861 }
9862
9863 /** Constructor
9864  *
9865  * @param context Test framework context
9866  **/
9867 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9868         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9869                                            "Test verifies that align qualifier requires value that is a power of 2")
9870 {
9871         /* Nothing to be done here */
9872 }
9873
9874 /** Constructor
9875  *
9876  * @param context Test framework context
9877  * @param name        Test name
9878  * @param description Test description
9879  **/
9880 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9881                                                                                                                                                            const glw::GLchar* name,
9882                                                                                                                                                            const glw::GLchar* description)
9883         : NegativeTestBase(context, name, description)
9884 {
9885         /* Nothing to be done here */
9886 }
9887
9888 /** Source for given test case and stage
9889  *
9890  * @param test_case_index Index of test case
9891  * @param stage           Shader stage
9892  *
9893  * @return Shader source
9894  **/
9895 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9896 {
9897         static const GLchar* cs = "#version 430 core\n"
9898                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9899                                                           "\n"
9900                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9901                                                           "\n"
9902                                                           "layout (std140) uniform Block {\n"
9903                                                           "    vec4 boy;\n"
9904                                                           "    layout (align = ALIGN) TYPE man;\n"
9905                                                           "} block;\n"
9906                                                           "\n"
9907                                                           "writeonly uniform image2D uni_image;\n"
9908                                                           "\n"
9909                                                           "void main()\n"
9910                                                           "{\n"
9911                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9912                                                           "\n"
9913                                                           "    if (TYPE(0) == block.man)\n"
9914                                                           "    {\n"
9915                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9916                                                           "    }\n"
9917                                                           "\n"
9918                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9919                                                           "}\n"
9920                                                           "\n";
9921         static const GLchar* fs = "#version 430 core\n"
9922                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9923                                                           "\n"
9924                                                           "in  vec4 gs_fs;\n"
9925                                                           "out vec4 fs_out;\n"
9926                                                           "\n"
9927                                                           "void main()\n"
9928                                                           "{\n"
9929                                                           "    fs_out = gs_fs;\n"
9930                                                           "}\n"
9931                                                           "\n";
9932         static const GLchar* fs_tested = "#version 430 core\n"
9933                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9934                                                                          "\n"
9935                                                                          "layout (std140) uniform Block {\n"
9936                                                                          "    vec4 boy;\n"
9937                                                                          "    layout (align = ALIGN) TYPE man;\n"
9938                                                                          "} block;\n"
9939                                                                          "\n"
9940                                                                          "in  vec4 gs_fs;\n"
9941                                                                          "out vec4 fs_out;\n"
9942                                                                          "\n"
9943                                                                          "void main()\n"
9944                                                                          "{\n"
9945                                                                          "    if (TYPE(0) == block.man)\n"
9946                                                                          "    {\n"
9947                                                                          "        fs_out = block.boy;\n"
9948                                                                          "    }\n"
9949                                                                          "\n"
9950                                                                          "    fs_out += gs_fs;\n"
9951                                                                          "}\n"
9952                                                                          "\n";
9953         static const GLchar* gs = "#version 430 core\n"
9954                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9955                                                           "\n"
9956                                                           "layout(points)                           in;\n"
9957                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9958                                                           "\n"
9959                                                           "in  vec4 tes_gs[];\n"
9960                                                           "out vec4 gs_fs;\n"
9961                                                           "\n"
9962                                                           "void main()\n"
9963                                                           "{\n"
9964                                                           "    gs_fs = tes_gs[0];\n"
9965                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9966                                                           "    EmitVertex();\n"
9967                                                           "    gs_fs = tes_gs[0];\n"
9968                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9969                                                           "    EmitVertex();\n"
9970                                                           "    gs_fs = tes_gs[0];\n"
9971                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9972                                                           "    EmitVertex();\n"
9973                                                           "    gs_fs = tes_gs[0];\n"
9974                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9975                                                           "    EmitVertex();\n"
9976                                                           "}\n"
9977                                                           "\n";
9978         static const GLchar* gs_tested = "#version 430 core\n"
9979                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9980                                                                          "\n"
9981                                                                          "layout(points)                           in;\n"
9982                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9983                                                                          "\n"
9984                                                                          "layout (std140) uniform Block {\n"
9985                                                                          "    vec4 boy;\n"
9986                                                                          "    layout (align = ALIGN) TYPE man;\n"
9987                                                                          "} block;\n"
9988                                                                          "\n"
9989                                                                          "in  vec4 tes_gs[];\n"
9990                                                                          "out vec4 gs_fs;\n"
9991                                                                          "\n"
9992                                                                          "void main()\n"
9993                                                                          "{\n"
9994                                                                          "    if (TYPE(0) == block.man)\n"
9995                                                                          "    {\n"
9996                                                                          "        gs_fs = block.boy;\n"
9997                                                                          "    }\n"
9998                                                                          "\n"
9999                                                                          "    gs_fs += tes_gs[0];\n"
10000                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10001                                                                          "    EmitVertex();\n"
10002                                                                          "    gs_fs += tes_gs[0];\n"
10003                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10004                                                                          "    EmitVertex();\n"
10005                                                                          "    gs_fs += tes_gs[0];\n"
10006                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10007                                                                          "    EmitVertex();\n"
10008                                                                          "    gs_fs += tes_gs[0];\n"
10009                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10010                                                                          "    EmitVertex();\n"
10011                                                                          "}\n"
10012                                                                          "\n";
10013         static const GLchar* tcs = "#version 430 core\n"
10014                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10015                                                            "\n"
10016                                                            "layout(vertices = 1) out;\n"
10017                                                            "\n"
10018                                                            "in  vec4 vs_tcs[];\n"
10019                                                            "out vec4 tcs_tes[];\n"
10020                                                            "\n"
10021                                                            "void main()\n"
10022                                                            "{\n"
10023                                                            "\n"
10024                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10025                                                            "\n"
10026                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10027                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10028                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10029                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10030                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10031                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10032                                                            "}\n"
10033                                                            "\n";
10034         static const GLchar* tcs_tested = "#version 430 core\n"
10035                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10036                                                                           "\n"
10037                                                                           "layout(vertices = 1) out;\n"
10038                                                                           "\n"
10039                                                                           "layout (std140) uniform Block {\n"
10040                                                                           "    vec4 boy;\n"
10041                                                                           "    layout (align = ALIGN) TYPE man;\n"
10042                                                                           "} block;\n"
10043                                                                           "\n"
10044                                                                           "in  vec4 vs_tcs[];\n"
10045                                                                           "out vec4 tcs_tes[];\n"
10046                                                                           "\n"
10047                                                                           "void main()\n"
10048                                                                           "{\n"
10049                                                                           "    if (TYPE(0) == block.man)\n"
10050                                                                           "    {\n"
10051                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10052                                                                           "    }\n"
10053                                                                           "\n"
10054                                                                           "\n"
10055                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10056                                                                           "\n"
10057                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10058                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10059                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10060                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10061                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10062                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10063                                                                           "}\n"
10064                                                                           "\n";
10065         static const GLchar* tes = "#version 430 core\n"
10066                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10067                                                            "\n"
10068                                                            "layout(isolines, point_mode) in;\n"
10069                                                            "\n"
10070                                                            "in  vec4 tcs_tes[];\n"
10071                                                            "out vec4 tes_gs;\n"
10072                                                            "\n"
10073                                                            "void main()\n"
10074                                                            "{\n"
10075                                                            "    tes_gs = tcs_tes[0];\n"
10076                                                            "}\n"
10077                                                            "\n";
10078         static const GLchar* tes_tested = "#version 430 core\n"
10079                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10080                                                                           "\n"
10081                                                                           "layout(isolines, point_mode) in;\n"
10082                                                                           "\n"
10083                                                                           "layout (std140) uniform Block {\n"
10084                                                                           "    vec4 boy;\n"
10085                                                                           "    layout (align = ALIGN) TYPE man;\n"
10086                                                                           "} block;\n"
10087                                                                           "\n"
10088                                                                           "in  vec4 tcs_tes[];\n"
10089                                                                           "out vec4 tes_gs;\n"
10090                                                                           "\n"
10091                                                                           "void main()\n"
10092                                                                           "{\n"
10093                                                                           "    if (TYPE(0) == block.man)\n"
10094                                                                           "    {\n"
10095                                                                           "        tes_gs = block.boy;\n"
10096                                                                           "    }\n"
10097                                                                           "\n"
10098                                                                           "    tes_gs += tcs_tes[0];\n"
10099                                                                           "}\n"
10100                                                                           "\n";
10101         static const GLchar* vs = "#version 430 core\n"
10102                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10103                                                           "\n"
10104                                                           "in  vec4 in_vs;\n"
10105                                                           "out vec4 vs_tcs;\n"
10106                                                           "\n"
10107                                                           "void main()\n"
10108                                                           "{\n"
10109                                                           "    vs_tcs = in_vs;\n"
10110                                                           "}\n"
10111                                                           "\n";
10112         static const GLchar* vs_tested = "#version 430 core\n"
10113                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10114                                                                          "\n"
10115                                                                          "layout (std140) uniform Block {\n"
10116                                                                          "    vec4 boy;\n"
10117                                                                          "    layout (align = ALIGN) TYPE man;\n"
10118                                                                          "} block;\n"
10119                                                                          "\n"
10120                                                                          "in  vec4 in_vs;\n"
10121                                                                          "out vec4 vs_tcs;\n"
10122                                                                          "\n"
10123                                                                          "void main()\n"
10124                                                                          "{\n"
10125                                                                          "    if (TYPE(0) == block.man)\n"
10126                                                                          "    {\n"
10127                                                                          "        vs_tcs = block.boy;\n"
10128                                                                          "    }\n"
10129                                                                          "\n"
10130                                                                          "    vs_tcs += in_vs;\n"
10131                                                                          "}\n"
10132                                                                          "\n";
10133
10134         std::string source;
10135         testCase&   test_case = m_test_cases[test_case_index];
10136
10137         if (test_case.m_stage == stage)
10138         {
10139                 GLchar                     buffer[16];
10140                 const GLuint       alignment = test_case.m_alignment;
10141                 const Utils::Type& type          = test_case.m_type;
10142                 const GLchar*     type_name = type.GetGLSLTypeName();
10143                 size_t                     position  = 0;
10144
10145                 switch (stage)
10146                 {
10147                 case Utils::Shader::COMPUTE:
10148                         source = cs;
10149                         break;
10150                 case Utils::Shader::FRAGMENT:
10151                         source = fs_tested;
10152                         break;
10153                 case Utils::Shader::GEOMETRY:
10154                         source = gs_tested;
10155                         break;
10156                 case Utils::Shader::TESS_CTRL:
10157                         source = tcs_tested;
10158                         break;
10159                 case Utils::Shader::TESS_EVAL:
10160                         source = tes_tested;
10161                         break;
10162                 case Utils::Shader::VERTEX:
10163                         source = vs_tested;
10164                         break;
10165                 default:
10166                         TCU_FAIL("Invalid enum");
10167                 }
10168
10169                 sprintf(buffer, "%d", alignment);
10170                 Utils::replaceToken("ALIGN", position, buffer, source);
10171                 Utils::replaceToken("TYPE", position, type_name, source);
10172                 Utils::replaceToken("TYPE", position, type_name, source);
10173         }
10174         else
10175         {
10176                 switch (stage)
10177                 {
10178                 case Utils::Shader::FRAGMENT:
10179                         source = fs;
10180                         break;
10181                 case Utils::Shader::GEOMETRY:
10182                         source = gs;
10183                         break;
10184                 case Utils::Shader::TESS_CTRL:
10185                         source = tcs;
10186                         break;
10187                 case Utils::Shader::TESS_EVAL:
10188                         source = tes;
10189                         break;
10190                 case Utils::Shader::VERTEX:
10191                         source = vs;
10192                         break;
10193                 default:
10194                         TCU_FAIL("Invalid enum");
10195                 }
10196         }
10197
10198         return source;
10199 }
10200
10201 /** Get description of test case
10202  *
10203  * @param test_case_index Index of test case
10204  *
10205  * @return Type name and offset
10206  **/
10207 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10208 {
10209         std::stringstream stream;
10210         testCase&                 test_case = m_test_cases[test_case_index];
10211
10212         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10213
10214         return stream.str();
10215 }
10216
10217 /** Get number of test cases
10218  *
10219  * @return Number of test cases
10220  **/
10221 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10222 {
10223         return static_cast<GLuint>(m_test_cases.size());
10224 }
10225
10226 /** Selects if "compute" stage is relevant for test
10227  *
10228  * @param test_case_index Index of test case
10229  *
10230  * @return true when tested stage is compute
10231  **/
10232 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10233 {
10234         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10235 }
10236
10237 /** Checks if stage is supported
10238  *
10239  * @param ignored
10240  *
10241  * @return true
10242  **/
10243 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10244 {
10245         return true;
10246 }
10247
10248 /** Selects if compilation failure is expected result
10249  *
10250  * @param test_case_index Index of test case
10251  *
10252  * @return should_fail field from testCase
10253  **/
10254 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10255 {
10256         return m_test_cases[test_case_index].m_should_fail;
10257 }
10258
10259 /** Prepare all test cases
10260  *
10261  **/
10262 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10263 {
10264         static const GLuint dmat4_size = 128;
10265         const GLuint            n_types = getTypesNumber();
10266         bool                            stage_support[Utils::Shader::STAGE_MAX];
10267
10268         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10269         {
10270                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10271         }
10272
10273         for (GLuint j = 0; j < n_types; ++j)
10274         {
10275                 const Utils::Type& type = getType(j);
10276
10277                 for (GLuint align = 0; align <= dmat4_size; ++align)
10278                 {
10279
10280 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10281
10282                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10283
10284 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10285
10286                         const bool should_fail = !isPowerOf2(align);
10287
10288 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10289
10290                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10291                         {
10292                                 if (false == stage_support[stage])
10293                                 {
10294                                         continue;
10295                                 }
10296
10297                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10298
10299                                 m_test_cases.push_back(test_case);
10300                         }
10301                 }
10302         }
10303 }
10304
10305 /** Check if value is power of 2
10306  *
10307  * @param val Tested value
10308  *
10309  * @return true if val is power of 2, false otherwise
10310  **/
10311 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10312 {
10313         if (0 == val)
10314         {
10315                 return false;
10316         }
10317
10318         return (0 == (val & (val - 1)));
10319 }
10320
10321 /** Constructor
10322  *
10323  * @param context Test framework context
10324  **/
10325 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10326         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10327 {
10328 }
10329
10330 /** Get interface of program
10331  *
10332  * @param ignored
10333  * @param program_interface Interface of program
10334  * @param varying_passthrough Collection of connections between in and out variables
10335  **/
10336 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10337                                                                                                         Utils::ProgramInterface&   program_interface,
10338                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10339 {
10340         static const Utils::Type vec4 = Utils::Type::vec4;
10341
10342 #if WRKARD_UNIFORMBLOCKALIGNMENT
10343
10344         static const GLuint block_align = 16;
10345
10346 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10347
10348         static const GLuint block_align = 64;
10349
10350 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10351
10352         static const GLuint vec4_stride = 16;
10353         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10354
10355         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10356          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10357          */
10358         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10359         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10360         const GLuint third_offset =
10361                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10362         const GLuint fourth_offset =
10363                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10364         const GLuint fifth_offset =
10365                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10366         const GLuint sixth_offset =
10367                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10368
10369         Utils::Interface* structure = program_interface.Structure("Data");
10370
10371         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10372                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10373
10374         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10375                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10376                                           Utils::Type::vec4.GetSize() /* offset */);
10377
10378         /* Prepare Block */
10379         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10380
10381         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10382                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10383
10384         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10385                                                  0 /* n_array_elements */, data_stride, second_offset);
10386
10387         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10388                                                  2 /* n_array_elements */, data_stride, third_offset);
10389
10390         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10391                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10392
10393         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10394                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10395
10396         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10397                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10398
10399         const GLuint stride = calculateStride(*vs_uni_block);
10400         m_data.resize(stride);
10401         generateData(*vs_uni_block, 0, m_data);
10402
10403         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10404
10405 /* Add uniform BLOCK */
10406 #if WRKARD_UNIFORMBLOCKALIGNMENT
10407         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10408                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10409 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10410         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10411                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10412 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10413
10414         program_interface.CloneVertexInterface(varying_passthrough);
10415 }
10416
10417 /** Constructor
10418  *
10419  * @param context Test framework context
10420  **/
10421 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10422         : TextureTestBase(context, "ssb_member_offset_and_align",
10423                                           "Test verifies offsets and alignment of storage buffer members")
10424 {
10425 }
10426
10427 /** Get interface of program
10428  *
10429  * @param test_case_index     Test case index
10430  * @param program_interface   Interface of program
10431  * @param varying_passthrough Collection of connections between in and out variables
10432  **/
10433 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10434                                                                                                           Utils::ProgramInterface&   program_interface,
10435                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10436 {
10437         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10438                                                   "const int type_align = TYPE_ALIGN;\n"
10439                                                   "const int type_size  = TYPE_SIZE;\n";
10440
10441         Utils::Type  type                = getType(test_case_index);
10442         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10443         const GLuint base_align  = type.GetBaseAlignment(false);
10444         const GLuint array_align = type.GetBaseAlignment(true);
10445         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10446         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10447
10448         /* Calculate offsets */
10449         const GLuint first_offset  = 0;
10450         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10451
10452 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10453
10454         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10455         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10456         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10457         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10458         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10459         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10460
10461 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10462
10463         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10464         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10465         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10466         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10467         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10468         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10469
10470 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10471
10472         /* Prepare data */
10473         const std::vector<GLubyte>& first  = type.GenerateData();
10474         const std::vector<GLubyte>& second = type.GenerateData();
10475         const std::vector<GLubyte>& third  = type.GenerateData();
10476         const std::vector<GLubyte>& fourth = type.GenerateData();
10477
10478         m_data.resize(eigth_offset + base_stride);
10479         GLubyte* ptr = &m_data[0];
10480         memcpy(ptr + first_offset, &first[0], first.size());
10481         memcpy(ptr + second_offset, &second[0], second.size());
10482         memcpy(ptr + third_offset, &third[0], third.size());
10483         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10484         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10485         memcpy(ptr + sixth_offset, &third[0], third.size());
10486         memcpy(ptr + seventh_offset, &second[0], second.size());
10487         memcpy(ptr + eigth_offset, &first[0], first.size());
10488
10489         /* Prepare globals */
10490         size_t position = 0;
10491         GLchar buffer[16];
10492
10493         sprintf(buffer, "%d", basic_size);
10494         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10495
10496         sprintf(buffer, "%d", type_align);
10497         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10498
10499         sprintf(buffer, "%d", base_stride);
10500         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10501
10502         /* Prepare Block */
10503         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10504
10505         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10506                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10507                                                  first_offset);
10508
10509         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10510                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10511                                                  0 /* n_array_elements */, base_stride, second_offset);
10512
10513         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10514                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10515                                                  third_offset);
10516
10517         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10518                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10519                                                  fourth_offset);
10520
10521         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10522                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10523
10524         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10525                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10526
10527         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10528                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10529                                                  eigth_offset);
10530
10531         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10532
10533         /* Add globals */
10534         vs_si.m_globals = globals;
10535
10536         /* Add uniform BLOCK */
10537         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10538                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10539
10540         /* */
10541         program_interface.CloneVertexInterface(varying_passthrough);
10542 }
10543
10544 /** Get type name
10545  *
10546  * @param test_case_index Index of test case
10547  *
10548  * @return Name of type test in test_case_index
10549  **/
10550 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10551 {
10552         return getTypeName(test_case_index);
10553 }
10554
10555 /** Returns number of types to test
10556  *
10557  * @return Number of types, 34
10558  **/
10559 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10560 {
10561         return getTypesNumber();
10562 }
10563
10564 /** Prepare code snippet that will verify in and uniform variables
10565  *
10566  * @param ignored
10567  * @param ignored
10568  * @param stage   Shader stage
10569  *
10570  * @return Code that verify variables
10571  **/
10572 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10573                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10574                                                                                                                                 Utils::Shader::STAGES stage)
10575 {
10576         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10577                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10578                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10579                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10580                                                            "    {\n"
10581                                                            "        result = 0;\n"
10582                                                            "    }";
10583
10584         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10585
10586         Utils::replaceAllTokens("PREFIX", prefix, verification);
10587
10588         return verification;
10589 }
10590
10591 /** Selects if "draw" stages are relevant for test
10592  *
10593  * @param ignored
10594  *
10595  * @return true if all stages support shader storage buffers, false otherwise
10596  **/
10597 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10598 {
10599         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10600         GLint                    gs_supported_buffers  = 0;
10601         GLint                    tcs_supported_buffers = 0;
10602         GLint                    tes_supported_buffers = 0;
10603         GLint                    vs_supported_buffers  = 0;
10604
10605         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10606         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10607         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10608         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10609
10610         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10611
10612         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10613                         (1 <= vs_supported_buffers));
10614 }
10615
10616 /** Constructor
10617  *
10618  * @param context Test framework context
10619  **/
10620 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10621         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10622                                                                                                                                  "offset and/or align qualifiers are used with storage "
10623                                                                                                                                  "block")
10624 {
10625         /* Nothing to be done here */
10626 }
10627
10628 /** Source for given test case and stage
10629  *
10630  * @param test_case_index Index of test case
10631  * @param stage           Shader stage
10632  *
10633  * @return Shader source
10634  **/
10635 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10636 {
10637         static const GLchar* cs = "#version 430 core\n"
10638                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10639                                                           "\n"
10640                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10641                                                           "\n"
10642                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10643                                                           "    layout(offset = 16) vec4 boy;\n"
10644                                                           "    layout(align  = 64) vec4 man;\n"
10645                                                           "} uni_block;\n"
10646                                                           "\n"
10647                                                           "writeonly uniform image2D uni_image;\n"
10648                                                           "\n"
10649                                                           "void main()\n"
10650                                                           "{\n"
10651                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10652                                                           "\n"
10653                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10654                                                           "}\n"
10655                                                           "\n";
10656         static const GLchar* fs = "#version 430 core\n"
10657                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10658                                                           "\n"
10659                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10660                                                           "    layout(offset = 16) vec4 boy;\n"
10661                                                           "    layout(align  = 64) vec4 man;\n"
10662                                                           "} uni_block;\n"
10663                                                           "\n"
10664                                                           "in  vec4 gs_fs;\n"
10665                                                           "out vec4 fs_out;\n"
10666                                                           "\n"
10667                                                           "void main()\n"
10668                                                           "{\n"
10669                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10670                                                           "}\n"
10671                                                           "\n";
10672         static const GLchar* gs = "#version 430 core\n"
10673                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10674                                                           "\n"
10675                                                           "layout(points)                           in;\n"
10676                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10677                                                           "\n"
10678                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10679                                                           "    layout(offset = 16) vec4 boy;\n"
10680                                                           "    layout(align  = 64) vec4 man;\n"
10681                                                           "} uni_block;\n"
10682                                                           "\n"
10683                                                           "in  vec4 tes_gs[];\n"
10684                                                           "out vec4 gs_fs;\n"
10685                                                           "\n"
10686                                                           "void main()\n"
10687                                                           "{\n"
10688                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10689                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10690                                                           "    EmitVertex();\n"
10691                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10692                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10693                                                           "    EmitVertex();\n"
10694                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10695                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10696                                                           "    EmitVertex();\n"
10697                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10698                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10699                                                           "    EmitVertex();\n"
10700                                                           "}\n"
10701                                                           "\n";
10702         static const GLchar* tcs =
10703                 "#version 430 core\n"
10704                 "#extension GL_ARB_enhanced_layouts : require\n"
10705                 "\n"
10706                 "layout(vertices = 1) out;\n"
10707                 "\n"
10708                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10709                 "    layout(offset = 16) vec4 boy;\n"
10710                 "    layout(align  = 64) vec4 man;\n"
10711                 "} uni_block;\n"
10712                 "\n"
10713                 "in  vec4 vs_tcs[];\n"
10714                 "out vec4 tcs_tes[];\n"
10715                 "\n"
10716                 "void main()\n"
10717                 "{\n"
10718                 "\n"
10719                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10720                 "\n"
10721                 "    gl_TessLevelOuter[0] = 1.0;\n"
10722                 "    gl_TessLevelOuter[1] = 1.0;\n"
10723                 "    gl_TessLevelOuter[2] = 1.0;\n"
10724                 "    gl_TessLevelOuter[3] = 1.0;\n"
10725                 "    gl_TessLevelInner[0] = 1.0;\n"
10726                 "    gl_TessLevelInner[1] = 1.0;\n"
10727                 "}\n"
10728                 "\n";
10729         static const GLchar* tes = "#version 430 core\n"
10730                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10731                                                            "\n"
10732                                                            "layout(isolines, point_mode) in;\n"
10733                                                            "\n"
10734                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10735                                                            "    layout(offset = 16) vec4 boy;\n"
10736                                                            "    layout(align  = 64) vec4 man;\n"
10737                                                            "} uni_block;\n"
10738                                                            "\n"
10739                                                            "in  vec4 tcs_tes[];\n"
10740                                                            "out vec4 tes_gs;\n"
10741                                                            "\n"
10742                                                            "void main()\n"
10743                                                            "{\n"
10744                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10745                                                            "}\n"
10746                                                            "\n";
10747         static const GLchar* vs = "#version 430 core\n"
10748                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10749                                                           "\n"
10750                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10751                                                           "    layout(offset = 16) vec4 boy;\n"
10752                                                           "    layout(align  = 64) vec4 man;\n"
10753                                                           "} uni_block;\n"
10754                                                           "\n"
10755                                                           "in  vec4 in_vs;\n"
10756                                                           "out vec4 vs_tcs;\n"
10757                                                           "\n"
10758                                                           "void main()\n"
10759                                                           "{\n"
10760                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10761                                                           "}\n"
10762                                                           "\n";
10763
10764         GLchar          buffer[16];
10765         size_t          position = 0;
10766         std::string source;
10767         testCase&   test_case = m_test_cases[test_case_index];
10768         std::string qualifier = getQualifierName(test_case.m_qualifier);
10769
10770         if (false == qualifier.empty())
10771         {
10772                 qualifier.append(", ");
10773         }
10774
10775         sprintf(buffer, "%d", stage);
10776
10777         switch (stage)
10778         {
10779         case Utils::Shader::COMPUTE:
10780                 source = cs;
10781                 break;
10782         case Utils::Shader::FRAGMENT:
10783                 source = fs;
10784                 break;
10785         case Utils::Shader::GEOMETRY:
10786                 source = gs;
10787                 break;
10788         case Utils::Shader::TESS_CTRL:
10789                 source = tcs;
10790                 break;
10791         case Utils::Shader::TESS_EVAL:
10792                 source = tes;
10793                 break;
10794         case Utils::Shader::VERTEX:
10795                 source = vs;
10796                 break;
10797         default:
10798                 TCU_FAIL("Invalid enum");
10799         }
10800
10801         if (test_case.m_stage == stage)
10802         {
10803                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10804         }
10805         else
10806         {
10807                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10808         }
10809
10810         Utils::replaceToken("BINDING", position, buffer, source);
10811
10812         return source;
10813 }
10814
10815 /** Get description of test case
10816  *
10817  * @param test_case_index Index of test case
10818  *
10819  * @return Qualifier name
10820  **/
10821 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10822 {
10823         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10824
10825         return result;
10826 }
10827
10828 /** Get number of test cases
10829  *
10830  * @return Number of test cases
10831  **/
10832 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10833 {
10834         return static_cast<GLuint>(m_test_cases.size());
10835 }
10836
10837 /** Selects if "compute" stage is relevant for test
10838  *
10839  * @param test_case_index Index of test case
10840  *
10841  * @return true when tested stage is compute
10842  **/
10843 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10844 {
10845         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10846 }
10847
10848 /** Selects if compilation failure is expected result
10849  *
10850  * @param test_case_index Index of test case
10851  *
10852  * @return false for STD140 and STD430 cases, true otherwise
10853  **/
10854 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10855 {
10856         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10857
10858         return !((STD140 == qualifier) || (STD430 == qualifier));
10859 }
10860
10861 /** Checks if stage is supported
10862  *
10863  * @param stage Shader stage
10864  *
10865  * @return true if supported, false otherwise
10866  **/
10867 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10868 {
10869         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10870         GLint                    max_supported_buffers = 0;
10871         GLenum                   pname                             = 0;
10872
10873         switch (stage)
10874         {
10875         case Utils::Shader::COMPUTE:
10876                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10877                 break;
10878         case Utils::Shader::FRAGMENT:
10879                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10880                 break;
10881         case Utils::Shader::GEOMETRY:
10882                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10883                 break;
10884         case Utils::Shader::TESS_CTRL:
10885                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10886                 break;
10887         case Utils::Shader::TESS_EVAL:
10888                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10889                 break;
10890         case Utils::Shader::VERTEX:
10891                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10892                 break;
10893         default:
10894                 TCU_FAIL("Invalid enum");
10895         }
10896
10897         gl.getIntegerv(pname, &max_supported_buffers);
10898         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10899
10900         return 1 <= max_supported_buffers;
10901 }
10902
10903 /** Prepare all test cases
10904  *
10905  **/
10906 void SSBLayoutQualifierConflictTest::testInit()
10907 {
10908         bool stage_support[Utils::Shader::STAGE_MAX];
10909
10910         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10911         {
10912                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10913         }
10914
10915         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10916         {
10917                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10918                 {
10919                         if (false == stage_support[stage])
10920                         {
10921                                 continue;
10922                         }
10923
10924                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10925
10926                         m_test_cases.push_back(test_case);
10927                 }
10928         }
10929 }
10930
10931 /** Get name of glsl constant
10932  *
10933  * @param Constant id
10934  *
10935  * @return Name of constant used in GLSL
10936  **/
10937 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
10938 {
10939         const GLchar* name = "";
10940
10941         switch (qualifier)
10942         {
10943         case DEFAULT:
10944                 name = "";
10945                 break;
10946         case STD140:
10947                 name = "std140";
10948                 break;
10949         case STD430:
10950                 name = "std430";
10951                 break;
10952         case SHARED:
10953                 name = "shared";
10954                 break;
10955         case PACKED:
10956                 name = "packed";
10957                 break;
10958         default:
10959                 TCU_FAIL("Invalid enum");
10960         }
10961
10962         return name;
10963 }
10964
10965 /** Constructor
10966  *
10967  * @param context Test framework context
10968  **/
10969 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
10970         : UniformBlockMemberInvalidOffsetAlignmentTest(
10971                   context, "ssb_member_invalid_offset_alignment",
10972                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
10973 {
10974         /* Nothing to be done here */
10975 }
10976
10977 /** Source for given test case and stage
10978  *
10979  * @param test_case_index Index of test case
10980  * @param stage           Shader stage
10981  *
10982  * @return Shader source
10983  **/
10984 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10985 {
10986         static const GLchar* cs = "#version 430 core\n"
10987                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10988                                                           "\n"
10989                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10990                                                           "\n"
10991                                                           "layout (std140) buffer Block {\n"
10992                                                           "    layout (offset = OFFSET) TYPE member;\n"
10993                                                           "} block;\n"
10994                                                           "\n"
10995                                                           "writeonly uniform image2D uni_image;\n"
10996                                                           "\n"
10997                                                           "void main()\n"
10998                                                           "{\n"
10999                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11000                                                           "\n"
11001                                                           "    if (TYPE(1) == block.member)\n"
11002                                                           "    {\n"
11003                                                           "        result = vec4(1, 1, 1, 1);\n"
11004                                                           "    }\n"
11005                                                           "\n"
11006                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11007                                                           "}\n"
11008                                                           "\n";
11009         static const GLchar* fs = "#version 430 core\n"
11010                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11011                                                           "\n"
11012                                                           "in  vec4 gs_fs;\n"
11013                                                           "out vec4 fs_out;\n"
11014                                                           "\n"
11015                                                           "void main()\n"
11016                                                           "{\n"
11017                                                           "    fs_out = gs_fs;\n"
11018                                                           "}\n"
11019                                                           "\n";
11020         static const GLchar* fs_tested = "#version 430 core\n"
11021                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11022                                                                          "\n"
11023                                                                          "layout (std140) buffer Block {\n"
11024                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11025                                                                          "} block;\n"
11026                                                                          "\n"
11027                                                                          "in  vec4 gs_fs;\n"
11028                                                                          "out vec4 fs_out;\n"
11029                                                                          "\n"
11030                                                                          "void main()\n"
11031                                                                          "{\n"
11032                                                                          "    if (TYPE(1) == block.member)\n"
11033                                                                          "    {\n"
11034                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11035                                                                          "    }\n"
11036                                                                          "\n"
11037                                                                          "    fs_out += gs_fs;\n"
11038                                                                          "}\n"
11039                                                                          "\n";
11040         static const GLchar* gs = "#version 430 core\n"
11041                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11042                                                           "\n"
11043                                                           "layout(points)                           in;\n"
11044                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11045                                                           "\n"
11046                                                           "in  vec4 tes_gs[];\n"
11047                                                           "out vec4 gs_fs;\n"
11048                                                           "\n"
11049                                                           "void main()\n"
11050                                                           "{\n"
11051                                                           "    gs_fs = tes_gs[0];\n"
11052                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11053                                                           "    EmitVertex();\n"
11054                                                           "    gs_fs = tes_gs[0];\n"
11055                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11056                                                           "    EmitVertex();\n"
11057                                                           "    gs_fs = tes_gs[0];\n"
11058                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11059                                                           "    EmitVertex();\n"
11060                                                           "    gs_fs = tes_gs[0];\n"
11061                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11062                                                           "    EmitVertex();\n"
11063                                                           "}\n"
11064                                                           "\n";
11065         static const GLchar* gs_tested = "#version 430 core\n"
11066                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11067                                                                          "\n"
11068                                                                          "layout(points)                           in;\n"
11069                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11070                                                                          "\n"
11071                                                                          "layout (std140) buffer Block {\n"
11072                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11073                                                                          "} block;\n"
11074                                                                          "\n"
11075                                                                          "in  vec4 tes_gs[];\n"
11076                                                                          "out vec4 gs_fs;\n"
11077                                                                          "\n"
11078                                                                          "void main()\n"
11079                                                                          "{\n"
11080                                                                          "    if (TYPE(1) == block.member)\n"
11081                                                                          "    {\n"
11082                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11083                                                                          "    }\n"
11084                                                                          "\n"
11085                                                                          "    gs_fs += tes_gs[0];\n"
11086                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11087                                                                          "    EmitVertex();\n"
11088                                                                          "    gs_fs += tes_gs[0];\n"
11089                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11090                                                                          "    EmitVertex();\n"
11091                                                                          "    gs_fs += tes_gs[0];\n"
11092                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11093                                                                          "    EmitVertex();\n"
11094                                                                          "    gs_fs += tes_gs[0];\n"
11095                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11096                                                                          "    EmitVertex();\n"
11097                                                                          "}\n"
11098                                                                          "\n";
11099         static const GLchar* tcs = "#version 430 core\n"
11100                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11101                                                            "\n"
11102                                                            "layout(vertices = 1) out;\n"
11103                                                            "\n"
11104                                                            "in  vec4 vs_tcs[];\n"
11105                                                            "out vec4 tcs_tes[];\n"
11106                                                            "\n"
11107                                                            "void main()\n"
11108                                                            "{\n"
11109                                                            "\n"
11110                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11111                                                            "\n"
11112                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11113                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11114                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11115                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11116                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11117                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11118                                                            "}\n"
11119                                                            "\n";
11120         static const GLchar* tcs_tested = "#version 430 core\n"
11121                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11122                                                                           "\n"
11123                                                                           "layout(vertices = 1) out;\n"
11124                                                                           "\n"
11125                                                                           "layout (std140) buffer Block {\n"
11126                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11127                                                                           "} block;\n"
11128                                                                           "\n"
11129                                                                           "in  vec4 vs_tcs[];\n"
11130                                                                           "out vec4 tcs_tes[];\n"
11131                                                                           "\n"
11132                                                                           "void main()\n"
11133                                                                           "{\n"
11134                                                                           "    if (TYPE(1) == block.member)\n"
11135                                                                           "    {\n"
11136                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11137                                                                           "    }\n"
11138                                                                           "\n"
11139                                                                           "\n"
11140                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11141                                                                           "\n"
11142                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11143                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11144                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11145                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11146                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11147                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11148                                                                           "}\n"
11149                                                                           "\n";
11150         static const GLchar* tes = "#version 430 core\n"
11151                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11152                                                            "\n"
11153                                                            "layout(isolines, point_mode) in;\n"
11154                                                            "\n"
11155                                                            "in  vec4 tcs_tes[];\n"
11156                                                            "out vec4 tes_gs;\n"
11157                                                            "\n"
11158                                                            "void main()\n"
11159                                                            "{\n"
11160                                                            "    tes_gs = tcs_tes[0];\n"
11161                                                            "}\n"
11162                                                            "\n";
11163         static const GLchar* tes_tested = "#version 430 core\n"
11164                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11165                                                                           "\n"
11166                                                                           "layout(isolines, point_mode) in;\n"
11167                                                                           "\n"
11168                                                                           "layout (std140) buffer Block {\n"
11169                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11170                                                                           "} block;\n"
11171                                                                           "\n"
11172                                                                           "in  vec4 tcs_tes[];\n"
11173                                                                           "out vec4 tes_gs;\n"
11174                                                                           "\n"
11175                                                                           "void main()\n"
11176                                                                           "{\n"
11177                                                                           "    if (TYPE(1) == block.member)\n"
11178                                                                           "    {\n"
11179                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11180                                                                           "    }\n"
11181                                                                           "\n"
11182                                                                           "    tes_gs += tcs_tes[0];\n"
11183                                                                           "}\n"
11184                                                                           "\n";
11185         static const GLchar* vs = "#version 430 core\n"
11186                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11187                                                           "\n"
11188                                                           "in  vec4 in_vs;\n"
11189                                                           "out vec4 vs_tcs;\n"
11190                                                           "\n"
11191                                                           "void main()\n"
11192                                                           "{\n"
11193                                                           "    vs_tcs = in_vs;\n"
11194                                                           "}\n"
11195                                                           "\n";
11196         static const GLchar* vs_tested = "#version 430 core\n"
11197                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11198                                                                          "\n"
11199                                                                          "layout (std140) buffer Block {\n"
11200                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11201                                                                          "} block;\n"
11202                                                                          "\n"
11203                                                                          "in  vec4 in_vs;\n"
11204                                                                          "out vec4 vs_tcs;\n"
11205                                                                          "\n"
11206                                                                          "void main()\n"
11207                                                                          "{\n"
11208                                                                          "    if (TYPE(1) == block.member)\n"
11209                                                                          "    {\n"
11210                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11211                                                                          "    }\n"
11212                                                                          "\n"
11213                                                                          "    vs_tcs += in_vs;\n"
11214                                                                          "}\n"
11215                                                                          "\n";
11216
11217         std::string source;
11218         testCase&   test_case = m_test_cases[test_case_index];
11219
11220         if (test_case.m_stage == stage)
11221         {
11222                 GLchar                     buffer[16];
11223                 const GLuint       offset       = test_case.m_offset;
11224                 size_t                     position  = 0;
11225                 const Utils::Type& type          = test_case.m_type;
11226                 const GLchar*     type_name = type.GetGLSLTypeName();
11227
11228                 sprintf(buffer, "%d", offset);
11229
11230                 switch (stage)
11231                 {
11232                 case Utils::Shader::COMPUTE:
11233                         source = cs;
11234                         break;
11235                 case Utils::Shader::FRAGMENT:
11236                         source = fs_tested;
11237                         break;
11238                 case Utils::Shader::GEOMETRY:
11239                         source = gs_tested;
11240                         break;
11241                 case Utils::Shader::TESS_CTRL:
11242                         source = tcs_tested;
11243                         break;
11244                 case Utils::Shader::TESS_EVAL:
11245                         source = tes_tested;
11246                         break;
11247                 case Utils::Shader::VERTEX:
11248                         source = vs_tested;
11249                         break;
11250                 default:
11251                         TCU_FAIL("Invalid enum");
11252                 }
11253
11254                 Utils::replaceToken("OFFSET", position, buffer, source);
11255                 Utils::replaceToken("TYPE", position, type_name, source);
11256                 Utils::replaceToken("TYPE", position, type_name, source);
11257         }
11258         else
11259         {
11260                 switch (stage)
11261                 {
11262                 case Utils::Shader::FRAGMENT:
11263                         source = fs;
11264                         break;
11265                 case Utils::Shader::GEOMETRY:
11266                         source = gs;
11267                         break;
11268                 case Utils::Shader::TESS_CTRL:
11269                         source = tcs;
11270                         break;
11271                 case Utils::Shader::TESS_EVAL:
11272                         source = tes;
11273                         break;
11274                 case Utils::Shader::VERTEX:
11275                         source = vs;
11276                         break;
11277                 default:
11278                         TCU_FAIL("Invalid enum");
11279                 }
11280         }
11281
11282         return source;
11283 }
11284
11285 /** Checks if stage is supported
11286  *
11287  * @param stage Shader stage
11288  *
11289  * @return true if supported, false otherwise
11290  **/
11291 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11292 {
11293         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11294         GLint                    max_supported_buffers = 0;
11295         GLenum                   pname                             = 0;
11296
11297         switch (stage)
11298         {
11299         case Utils::Shader::COMPUTE:
11300                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11301                 break;
11302         case Utils::Shader::FRAGMENT:
11303                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11304                 break;
11305         case Utils::Shader::GEOMETRY:
11306                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11307                 break;
11308         case Utils::Shader::TESS_CTRL:
11309                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11310                 break;
11311         case Utils::Shader::TESS_EVAL:
11312                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11313                 break;
11314         case Utils::Shader::VERTEX:
11315                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11316                 break;
11317         default:
11318                 TCU_FAIL("Invalid enum");
11319         }
11320
11321         gl.getIntegerv(pname, &max_supported_buffers);
11322         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11323
11324         return 1 <= max_supported_buffers;
11325 }
11326
11327 /** Constructor
11328  *
11329  * @param context Test framework context
11330  **/
11331 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11332         : UniformBlockMemberOverlappingOffsetsTest(
11333                   context, "ssb_member_overlapping_offsets",
11334                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11335 {
11336         /* Nothing to be done here */
11337 }
11338
11339 /** Source for given test case and stage
11340  *
11341  * @param test_case_index Index of test case
11342  * @param stage           Shader stage
11343  *
11344  * @return Shader source
11345  **/
11346 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11347 {
11348         static const GLchar* cs = "#version 430 core\n"
11349                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11350                                                           "\n"
11351                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11352                                                           "\n"
11353                                                           "layout (std140) buffer Block {\n"
11354                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11355                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11356                                                           "} block;\n"
11357                                                           "\n"
11358                                                           "writeonly uniform image2D uni_image;\n"
11359                                                           "\n"
11360                                                           "void main()\n"
11361                                                           "{\n"
11362                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11363                                                           "\n"
11364                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11365                                                           "        (MAN_TYPE(0) == block.man) )\n"
11366                                                           "    {\n"
11367                                                           "        result = vec4(1, 1, 1, 1);\n"
11368                                                           "    }\n"
11369                                                           "\n"
11370                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11371                                                           "}\n"
11372                                                           "\n";
11373         static const GLchar* fs = "#version 430 core\n"
11374                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11375                                                           "\n"
11376                                                           "in  vec4 gs_fs;\n"
11377                                                           "out vec4 fs_out;\n"
11378                                                           "\n"
11379                                                           "void main()\n"
11380                                                           "{\n"
11381                                                           "    fs_out = gs_fs;\n"
11382                                                           "}\n"
11383                                                           "\n";
11384         static const GLchar* fs_tested = "#version 430 core\n"
11385                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11386                                                                          "\n"
11387                                                                          "layout (std140) buffer Block {\n"
11388                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11389                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11390                                                                          "} block;\n"
11391                                                                          "\n"
11392                                                                          "in  vec4 gs_fs;\n"
11393                                                                          "out vec4 fs_out;\n"
11394                                                                          "\n"
11395                                                                          "void main()\n"
11396                                                                          "{\n"
11397                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11398                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11399                                                                          "    {\n"
11400                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11401                                                                          "    }\n"
11402                                                                          "\n"
11403                                                                          "    fs_out += gs_fs;\n"
11404                                                                          "}\n"
11405                                                                          "\n";
11406         static const GLchar* gs = "#version 430 core\n"
11407                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11408                                                           "\n"
11409                                                           "layout(points)                           in;\n"
11410                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11411                                                           "\n"
11412                                                           "in  vec4 tes_gs[];\n"
11413                                                           "out vec4 gs_fs;\n"
11414                                                           "\n"
11415                                                           "void main()\n"
11416                                                           "{\n"
11417                                                           "    gs_fs = tes_gs[0];\n"
11418                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11419                                                           "    EmitVertex();\n"
11420                                                           "    gs_fs = tes_gs[0];\n"
11421                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11422                                                           "    EmitVertex();\n"
11423                                                           "    gs_fs = tes_gs[0];\n"
11424                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11425                                                           "    EmitVertex();\n"
11426                                                           "    gs_fs = tes_gs[0];\n"
11427                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11428                                                           "    EmitVertex();\n"
11429                                                           "}\n"
11430                                                           "\n";
11431         static const GLchar* gs_tested = "#version 430 core\n"
11432                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11433                                                                          "\n"
11434                                                                          "layout(points)                           in;\n"
11435                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11436                                                                          "\n"
11437                                                                          "layout (std140) buffer Block {\n"
11438                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11439                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11440                                                                          "} block;\n"
11441                                                                          "\n"
11442                                                                          "in  vec4 tes_gs[];\n"
11443                                                                          "out vec4 gs_fs;\n"
11444                                                                          "\n"
11445                                                                          "void main()\n"
11446                                                                          "{\n"
11447                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11448                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11449                                                                          "    {\n"
11450                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11451                                                                          "    }\n"
11452                                                                          "\n"
11453                                                                          "    gs_fs += tes_gs[0];\n"
11454                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11455                                                                          "    EmitVertex();\n"
11456                                                                          "    gs_fs += tes_gs[0];\n"
11457                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11458                                                                          "    EmitVertex();\n"
11459                                                                          "    gs_fs += tes_gs[0];\n"
11460                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11461                                                                          "    EmitVertex();\n"
11462                                                                          "    gs_fs += tes_gs[0];\n"
11463                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11464                                                                          "    EmitVertex();\n"
11465                                                                          "}\n"
11466                                                                          "\n";
11467         static const GLchar* tcs = "#version 430 core\n"
11468                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11469                                                            "\n"
11470                                                            "layout(vertices = 1) out;\n"
11471                                                            "\n"
11472                                                            "in  vec4 vs_tcs[];\n"
11473                                                            "out vec4 tcs_tes[];\n"
11474                                                            "\n"
11475                                                            "void main()\n"
11476                                                            "{\n"
11477                                                            "\n"
11478                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11479                                                            "\n"
11480                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11481                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11482                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11483                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11484                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11485                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11486                                                            "}\n"
11487                                                            "\n";
11488         static const GLchar* tcs_tested = "#version 430 core\n"
11489                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11490                                                                           "\n"
11491                                                                           "layout(vertices = 1) out;\n"
11492                                                                           "\n"
11493                                                                           "layout (std140) buffer Block {\n"
11494                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11495                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11496                                                                           "} block;\n"
11497                                                                           "\n"
11498                                                                           "in  vec4 vs_tcs[];\n"
11499                                                                           "out vec4 tcs_tes[];\n"
11500                                                                           "\n"
11501                                                                           "void main()\n"
11502                                                                           "{\n"
11503                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11504                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11505                                                                           "    {\n"
11506                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11507                                                                           "    }\n"
11508                                                                           "\n"
11509                                                                           "\n"
11510                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11511                                                                           "\n"
11512                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11513                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11514                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11515                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11516                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11517                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11518                                                                           "}\n"
11519                                                                           "\n";
11520         static const GLchar* tes = "#version 430 core\n"
11521                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11522                                                            "\n"
11523                                                            "layout(isolines, point_mode) in;\n"
11524                                                            "\n"
11525                                                            "in  vec4 tcs_tes[];\n"
11526                                                            "out vec4 tes_gs;\n"
11527                                                            "\n"
11528                                                            "void main()\n"
11529                                                            "{\n"
11530                                                            "    tes_gs = tcs_tes[0];\n"
11531                                                            "}\n"
11532                                                            "\n";
11533         static const GLchar* tes_tested = "#version 430 core\n"
11534                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11535                                                                           "\n"
11536                                                                           "layout(isolines, point_mode) in;\n"
11537                                                                           "\n"
11538                                                                           "layout (std140) buffer Block {\n"
11539                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11540                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11541                                                                           "} block;\n"
11542                                                                           "\n"
11543                                                                           "in  vec4 tcs_tes[];\n"
11544                                                                           "out vec4 tes_gs;\n"
11545                                                                           "\n"
11546                                                                           "void main()\n"
11547                                                                           "{\n"
11548                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11549                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11550                                                                           "    {\n"
11551                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11552                                                                           "    }\n"
11553                                                                           "\n"
11554                                                                           "    tes_gs += tcs_tes[0];\n"
11555                                                                           "}\n"
11556                                                                           "\n";
11557         static const GLchar* vs = "#version 430 core\n"
11558                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11559                                                           "\n"
11560                                                           "in  vec4 in_vs;\n"
11561                                                           "out vec4 vs_tcs;\n"
11562                                                           "\n"
11563                                                           "void main()\n"
11564                                                           "{\n"
11565                                                           "    vs_tcs = in_vs;\n"
11566                                                           "}\n"
11567                                                           "\n";
11568         static const GLchar* vs_tested = "#version 430 core\n"
11569                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11570                                                                          "\n"
11571                                                                          "layout (std140) buffer Block {\n"
11572                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11573                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11574                                                                          "} block;\n"
11575                                                                          "\n"
11576                                                                          "in  vec4 in_vs;\n"
11577                                                                          "out vec4 vs_tcs;\n"
11578                                                                          "\n"
11579                                                                          "void main()\n"
11580                                                                          "{\n"
11581                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11582                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11583                                                                          "    {\n"
11584                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11585                                                                          "    }\n"
11586                                                                          "\n"
11587                                                                          "    vs_tcs += in_vs;\n"
11588                                                                          "}\n"
11589                                                                          "\n";
11590
11591         std::string source;
11592         testCase&   test_case = m_test_cases[test_case_index];
11593
11594         if (test_case.m_stage == stage)
11595         {
11596                 GLchar                     buffer[16];
11597                 const GLuint       boy_offset   = test_case.m_boy_offset;
11598                 const Utils::Type& boy_type              = test_case.m_boy_type;
11599                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11600                 const GLuint       man_offset   = test_case.m_man_offset;
11601                 const Utils::Type& man_type              = test_case.m_man_type;
11602                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11603                 size_t                     position              = 0;
11604
11605                 switch (stage)
11606                 {
11607                 case Utils::Shader::COMPUTE:
11608                         source = cs;
11609                         break;
11610                 case Utils::Shader::FRAGMENT:
11611                         source = fs_tested;
11612                         break;
11613                 case Utils::Shader::GEOMETRY:
11614                         source = gs_tested;
11615                         break;
11616                 case Utils::Shader::TESS_CTRL:
11617                         source = tcs_tested;
11618                         break;
11619                 case Utils::Shader::TESS_EVAL:
11620                         source = tes_tested;
11621                         break;
11622                 case Utils::Shader::VERTEX:
11623                         source = vs_tested;
11624                         break;
11625                 default:
11626                         TCU_FAIL("Invalid enum");
11627                 }
11628
11629                 sprintf(buffer, "%d", boy_offset);
11630                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11631                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11632                 sprintf(buffer, "%d", man_offset);
11633                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11634                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11635                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11636                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11637         }
11638         else
11639         {
11640                 switch (stage)
11641                 {
11642                 case Utils::Shader::FRAGMENT:
11643                         source = fs;
11644                         break;
11645                 case Utils::Shader::GEOMETRY:
11646                         source = gs;
11647                         break;
11648                 case Utils::Shader::TESS_CTRL:
11649                         source = tcs;
11650                         break;
11651                 case Utils::Shader::TESS_EVAL:
11652                         source = tes;
11653                         break;
11654                 case Utils::Shader::VERTEX:
11655                         source = vs;
11656                         break;
11657                 default:
11658                         TCU_FAIL("Invalid enum");
11659                 }
11660         }
11661
11662         return source;
11663 }
11664
11665 /** Checks if stage is supported
11666  *
11667  * @param stage Shader stage
11668  *
11669  * @return true if supported, false otherwise
11670  **/
11671 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11672 {
11673         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11674         GLint                    max_supported_buffers = 0;
11675         GLenum                   pname                             = 0;
11676
11677         switch (stage)
11678         {
11679         case Utils::Shader::COMPUTE:
11680                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11681                 break;
11682         case Utils::Shader::FRAGMENT:
11683                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11684                 break;
11685         case Utils::Shader::GEOMETRY:
11686                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11687                 break;
11688         case Utils::Shader::TESS_CTRL:
11689                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11690                 break;
11691         case Utils::Shader::TESS_EVAL:
11692                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11693                 break;
11694         case Utils::Shader::VERTEX:
11695                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11696                 break;
11697         default:
11698                 TCU_FAIL("Invalid enum");
11699         }
11700
11701         gl.getIntegerv(pname, &max_supported_buffers);
11702         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11703
11704         return 1 <= max_supported_buffers;
11705 }
11706
11707 /** Constructor
11708  *
11709  * @param context Test framework context
11710  **/
11711 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11712         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11713                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11714 {
11715         /* Nothing to be done here */
11716 }
11717
11718 /** Source for given test case and stage
11719  *
11720  * @param test_case_index Index of test case
11721  * @param stage           Shader stage
11722  *
11723  * @return Shader source
11724  **/
11725 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11726 {
11727         static const GLchar* cs = "#version 430 core\n"
11728                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11729                                                           "\n"
11730                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11731                                                           "\n"
11732                                                           "layout (std140) buffer Block {\n"
11733                                                           "    vec4 boy;\n"
11734                                                           "    layout (align = ALIGN) TYPE man;\n"
11735                                                           "} block;\n"
11736                                                           "\n"
11737                                                           "writeonly uniform image2D uni_image;\n"
11738                                                           "\n"
11739                                                           "void main()\n"
11740                                                           "{\n"
11741                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11742                                                           "\n"
11743                                                           "    if (TYPE(0) == block.man)\n"
11744                                                           "    {\n"
11745                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11746                                                           "    }\n"
11747                                                           "\n"
11748                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11749                                                           "}\n"
11750                                                           "\n";
11751         static const GLchar* fs = "#version 430 core\n"
11752                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11753                                                           "\n"
11754                                                           "in  vec4 gs_fs;\n"
11755                                                           "out vec4 fs_out;\n"
11756                                                           "\n"
11757                                                           "void main()\n"
11758                                                           "{\n"
11759                                                           "    fs_out = gs_fs;\n"
11760                                                           "}\n"
11761                                                           "\n";
11762         static const GLchar* fs_tested = "#version 430 core\n"
11763                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11764                                                                          "\n"
11765                                                                          "layout (std140) buffer Block {\n"
11766                                                                          "    vec4 boy;\n"
11767                                                                          "    layout (align = ALIGN) TYPE man;\n"
11768                                                                          "} block;\n"
11769                                                                          "\n"
11770                                                                          "in  vec4 gs_fs;\n"
11771                                                                          "out vec4 fs_out;\n"
11772                                                                          "\n"
11773                                                                          "void main()\n"
11774                                                                          "{\n"
11775                                                                          "    if (TYPE(0) == block.man)\n"
11776                                                                          "    {\n"
11777                                                                          "        fs_out = block.boy;\n"
11778                                                                          "    }\n"
11779                                                                          "\n"
11780                                                                          "    fs_out += gs_fs;\n"
11781                                                                          "}\n"
11782                                                                          "\n";
11783         static const GLchar* gs = "#version 430 core\n"
11784                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11785                                                           "\n"
11786                                                           "layout(points)                           in;\n"
11787                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11788                                                           "\n"
11789                                                           "in  vec4 tes_gs[];\n"
11790                                                           "out vec4 gs_fs;\n"
11791                                                           "\n"
11792                                                           "void main()\n"
11793                                                           "{\n"
11794                                                           "    gs_fs = tes_gs[0];\n"
11795                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11796                                                           "    EmitVertex();\n"
11797                                                           "    gs_fs = tes_gs[0];\n"
11798                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11799                                                           "    EmitVertex();\n"
11800                                                           "    gs_fs = tes_gs[0];\n"
11801                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11802                                                           "    EmitVertex();\n"
11803                                                           "    gs_fs = tes_gs[0];\n"
11804                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11805                                                           "    EmitVertex();\n"
11806                                                           "}\n"
11807                                                           "\n";
11808         static const GLchar* gs_tested = "#version 430 core\n"
11809                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11810                                                                          "\n"
11811                                                                          "layout(points)                           in;\n"
11812                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11813                                                                          "\n"
11814                                                                          "layout (std140) buffer Block {\n"
11815                                                                          "    vec4 boy;\n"
11816                                                                          "    layout (align = ALIGN) TYPE man;\n"
11817                                                                          "} block;\n"
11818                                                                          "\n"
11819                                                                          "in  vec4 tes_gs[];\n"
11820                                                                          "out vec4 gs_fs;\n"
11821                                                                          "\n"
11822                                                                          "void main()\n"
11823                                                                          "{\n"
11824                                                                          "    if (TYPE(0) == block.man)\n"
11825                                                                          "    {\n"
11826                                                                          "        gs_fs = block.boy;\n"
11827                                                                          "    }\n"
11828                                                                          "\n"
11829                                                                          "    gs_fs += tes_gs[0];\n"
11830                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11831                                                                          "    EmitVertex();\n"
11832                                                                          "    gs_fs += tes_gs[0];\n"
11833                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11834                                                                          "    EmitVertex();\n"
11835                                                                          "    gs_fs += tes_gs[0];\n"
11836                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11837                                                                          "    EmitVertex();\n"
11838                                                                          "    gs_fs += tes_gs[0];\n"
11839                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11840                                                                          "    EmitVertex();\n"
11841                                                                          "}\n"
11842                                                                          "\n";
11843         static const GLchar* tcs = "#version 430 core\n"
11844                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11845                                                            "\n"
11846                                                            "layout(vertices = 1) out;\n"
11847                                                            "\n"
11848                                                            "in  vec4 vs_tcs[];\n"
11849                                                            "out vec4 tcs_tes[];\n"
11850                                                            "\n"
11851                                                            "void main()\n"
11852                                                            "{\n"
11853                                                            "\n"
11854                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11855                                                            "\n"
11856                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11857                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11858                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11859                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11860                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11861                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11862                                                            "}\n"
11863                                                            "\n";
11864         static const GLchar* tcs_tested = "#version 430 core\n"
11865                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11866                                                                           "\n"
11867                                                                           "layout(vertices = 1) out;\n"
11868                                                                           "\n"
11869                                                                           "layout (std140) buffer Block {\n"
11870                                                                           "    vec4 boy;\n"
11871                                                                           "    layout (align = ALIGN) TYPE man;\n"
11872                                                                           "} block;\n"
11873                                                                           "\n"
11874                                                                           "in  vec4 vs_tcs[];\n"
11875                                                                           "out vec4 tcs_tes[];\n"
11876                                                                           "\n"
11877                                                                           "void main()\n"
11878                                                                           "{\n"
11879                                                                           "    if (TYPE(0) == block.man)\n"
11880                                                                           "    {\n"
11881                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11882                                                                           "    }\n"
11883                                                                           "\n"
11884                                                                           "\n"
11885                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11886                                                                           "\n"
11887                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11888                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11889                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11890                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11891                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11892                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11893                                                                           "}\n"
11894                                                                           "\n";
11895         static const GLchar* tes = "#version 430 core\n"
11896                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11897                                                            "\n"
11898                                                            "layout(isolines, point_mode) in;\n"
11899                                                            "\n"
11900                                                            "in  vec4 tcs_tes[];\n"
11901                                                            "out vec4 tes_gs;\n"
11902                                                            "\n"
11903                                                            "void main()\n"
11904                                                            "{\n"
11905                                                            "    tes_gs = tcs_tes[0];\n"
11906                                                            "}\n"
11907                                                            "\n";
11908         static const GLchar* tes_tested = "#version 430 core\n"
11909                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11910                                                                           "\n"
11911                                                                           "layout(isolines, point_mode) in;\n"
11912                                                                           "\n"
11913                                                                           "layout (std140) buffer Block {\n"
11914                                                                           "    vec4 boy;\n"
11915                                                                           "    layout (align = ALIGN) TYPE man;\n"
11916                                                                           "} block;\n"
11917                                                                           "\n"
11918                                                                           "in  vec4 tcs_tes[];\n"
11919                                                                           "out vec4 tes_gs;\n"
11920                                                                           "\n"
11921                                                                           "void main()\n"
11922                                                                           "{\n"
11923                                                                           "    if (TYPE(0) == block.man)\n"
11924                                                                           "    {\n"
11925                                                                           "        tes_gs = block.boy;\n"
11926                                                                           "    }\n"
11927                                                                           "\n"
11928                                                                           "    tes_gs += tcs_tes[0];\n"
11929                                                                           "}\n"
11930                                                                           "\n";
11931         static const GLchar* vs = "#version 430 core\n"
11932                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11933                                                           "\n"
11934                                                           "in  vec4 in_vs;\n"
11935                                                           "out vec4 vs_tcs;\n"
11936                                                           "\n"
11937                                                           "void main()\n"
11938                                                           "{\n"
11939                                                           "    vs_tcs = in_vs;\n"
11940                                                           "}\n"
11941                                                           "\n";
11942         static const GLchar* vs_tested = "#version 430 core\n"
11943                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11944                                                                          "\n"
11945                                                                          "layout (std140) buffer Block {\n"
11946                                                                          "    vec4 boy;\n"
11947                                                                          "    layout (align = ALIGN) TYPE man;\n"
11948                                                                          "} block;\n"
11949                                                                          "\n"
11950                                                                          "in  vec4 in_vs;\n"
11951                                                                          "out vec4 vs_tcs;\n"
11952                                                                          "\n"
11953                                                                          "void main()\n"
11954                                                                          "{\n"
11955                                                                          "    if (TYPE(0) == block.man)\n"
11956                                                                          "    {\n"
11957                                                                          "        vs_tcs = block.boy;\n"
11958                                                                          "    }\n"
11959                                                                          "\n"
11960                                                                          "    vs_tcs += in_vs;\n"
11961                                                                          "}\n"
11962                                                                          "\n";
11963
11964         std::string source;
11965         testCase&   test_case = m_test_cases[test_case_index];
11966
11967         if (test_case.m_stage == stage)
11968         {
11969                 GLchar                     buffer[16];
11970                 const GLuint       alignment = test_case.m_alignment;
11971                 const Utils::Type& type          = test_case.m_type;
11972                 const GLchar*     type_name = type.GetGLSLTypeName();
11973                 size_t                     position  = 0;
11974
11975                 switch (stage)
11976                 {
11977                 case Utils::Shader::COMPUTE:
11978                         source = cs;
11979                         break;
11980                 case Utils::Shader::FRAGMENT:
11981                         source = fs_tested;
11982                         break;
11983                 case Utils::Shader::GEOMETRY:
11984                         source = gs_tested;
11985                         break;
11986                 case Utils::Shader::TESS_CTRL:
11987                         source = tcs_tested;
11988                         break;
11989                 case Utils::Shader::TESS_EVAL:
11990                         source = tes_tested;
11991                         break;
11992                 case Utils::Shader::VERTEX:
11993                         source = vs_tested;
11994                         break;
11995                 default:
11996                         TCU_FAIL("Invalid enum");
11997                 }
11998
11999                 sprintf(buffer, "%d", alignment);
12000                 Utils::replaceToken("ALIGN", position, buffer, source);
12001                 Utils::replaceToken("TYPE", position, type_name, source);
12002                 Utils::replaceToken("TYPE", position, type_name, source);
12003         }
12004         else
12005         {
12006                 switch (stage)
12007                 {
12008                 case Utils::Shader::FRAGMENT:
12009                         source = fs;
12010                         break;
12011                 case Utils::Shader::GEOMETRY:
12012                         source = gs;
12013                         break;
12014                 case Utils::Shader::TESS_CTRL:
12015                         source = tcs;
12016                         break;
12017                 case Utils::Shader::TESS_EVAL:
12018                         source = tes;
12019                         break;
12020                 case Utils::Shader::VERTEX:
12021                         source = vs;
12022                         break;
12023                 default:
12024                         TCU_FAIL("Invalid enum");
12025                 }
12026         }
12027
12028         return source;
12029 }
12030
12031 /** Checks if stage is supported
12032  *
12033  * @param stage Shader stage
12034  *
12035  * @return true if supported, false otherwise
12036  **/
12037 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12038 {
12039         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12040         GLint                    max_supported_buffers = 0;
12041         GLenum                   pname                             = 0;
12042
12043         switch (stage)
12044         {
12045         case Utils::Shader::COMPUTE:
12046                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12047                 break;
12048         case Utils::Shader::FRAGMENT:
12049                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12050                 break;
12051         case Utils::Shader::GEOMETRY:
12052                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12053                 break;
12054         case Utils::Shader::TESS_CTRL:
12055                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12056                 break;
12057         case Utils::Shader::TESS_EVAL:
12058                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12059                 break;
12060         case Utils::Shader::VERTEX:
12061                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12062                 break;
12063         default:
12064                 TCU_FAIL("Invalid enum");
12065         }
12066
12067         gl.getIntegerv(pname, &max_supported_buffers);
12068         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12069
12070         return 1 <= max_supported_buffers;
12071 }
12072
12073 /** Constructor
12074  *
12075  * @param context Test framework context
12076  **/
12077 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12078         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12079 {
12080 }
12081
12082 /** Get interface of program
12083  *
12084  * @param ignored
12085  * @param program_interface Interface of program
12086  * @param varying_passthrough Collection of connections between in and out variables
12087  **/
12088 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12089                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12090 {
12091         static const Utils::Type vec4 = Utils::Type::vec4;
12092
12093 #if WRKARD_UNIFORMBLOCKALIGNMENT
12094
12095         static const GLuint block_align = 16;
12096
12097 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12098
12099         static const GLuint block_align = 64;
12100
12101 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12102
12103         static const GLuint fifth_align = 16;
12104         static const GLuint vec4_stride = 16;
12105         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12106
12107         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12108         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12109         const GLuint third_offset =
12110                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12111         const GLuint fourth_offset =
12112                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12113         const GLuint fifth_offset =
12114                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12115         const GLuint sixth_offset =
12116                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12117
12118         Utils::Interface* structure = program_interface.Structure("Data");
12119
12120         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12121                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12122
12123         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12124                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12125                                           Utils::Type::vec4.GetSize() /* offset */);
12126
12127         /* Prepare Block */
12128         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12129
12130         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12131                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12132
12133         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12134                                                  0 /* n_array_elements */, data_stride, second_offset);
12135
12136         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12137                                                  2 /* n_array_elements */, data_stride, third_offset);
12138
12139         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12140                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12141
12142         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12143                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12144
12145         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12146                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12147
12148         const GLuint stride = calculateStride(*vs_buf_Block);
12149         m_data.resize(stride);
12150         generateData(*vs_buf_Block, 0, m_data);
12151
12152         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12153
12154 /* Add uniform BLOCK */
12155 #if WRKARD_UNIFORMBLOCKALIGNMENT
12156         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12157                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12158 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12159         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12160                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12161 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12162
12163         program_interface.CloneVertexInterface(varying_passthrough);
12164 }
12165
12166 /** Selects if "draw" stages are relevant for test
12167  *
12168  * @param ignored
12169  *
12170  * @return true if all stages support shader storage buffers, false otherwise
12171  **/
12172 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12173 {
12174         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12175         GLint                    gs_supported_buffers  = 0;
12176         GLint                    tcs_supported_buffers = 0;
12177         GLint                    tes_supported_buffers = 0;
12178         GLint                    vs_supported_buffers  = 0;
12179
12180         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12181         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12182         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12183         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12184
12185         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12186
12187         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12188                         (1 <= vs_supported_buffers));
12189 }
12190
12191 /** Constructor
12192  *
12193  * @param context Test framework context
12194  **/
12195 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12196         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12197 {
12198 }
12199
12200 /** Constructor
12201  *
12202  * @param context          Test context
12203  * @param test_name        Name of test
12204  * @param test_description Description of test
12205  **/
12206 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12207                                                                                    const glw::GLchar* test_description)
12208         : TextureTestBase(context, test_name, test_description)
12209 {
12210 }
12211
12212 /** Get interface of program
12213  *
12214  * @param test_case_index     Test case
12215  * @param program_interface   Interface of program
12216  * @param varying_passthrough Collection of connections between in and out variables
12217  **/
12218 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12219                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12220 {
12221         const Utils::Type type = getType(test_case_index);
12222
12223         m_first_data = type.GenerateDataPacked();
12224         m_last_data  = type.GenerateDataPacked();
12225
12226         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12227         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12228         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12229         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12230         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12231 }
12232
12233 /** Get type name
12234  *
12235  * @param test_case_index Index of test case
12236  *
12237  * @return Name of type test in test_case_index
12238  **/
12239 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12240 {
12241         return getTypeName(test_case_index);
12242 }
12243
12244 /** Returns number of types to test
12245  *
12246  * @return Number of types, 34
12247  **/
12248 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12249 {
12250         return getTypesNumber();
12251 }
12252
12253 /** Selects if "compute" stage is relevant for test
12254  *
12255  * @param ignored
12256  *
12257  * @return false
12258  **/
12259 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12260 {
12261         return false;
12262 }
12263
12264 /**
12265  *
12266  *
12267  **/
12268 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12269 {
12270         GLchar          buffer[16];
12271         std::string globals = "const uint first_input_location  = 0u;\n"
12272                                                   "const uint first_output_location = 0u;\n"
12273                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12274                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12275         size_t position = 100; /* Skip first part */
12276
12277         sprintf(buffer, "%d", last_in_loc);
12278         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12279
12280         sprintf(buffer, "%d", last_out_loc);
12281         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12282
12283         return globals;
12284 }
12285
12286 /**
12287  *
12288  **/
12289 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12290                                                                                           Utils::ProgramInterface&   program_interface,
12291                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12292 {
12293         const GLuint array_length  = 1;
12294         const GLuint first_in_loc  = 0;
12295         const GLuint first_out_loc = 0;
12296         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12297         size_t           position         = 0;
12298
12299         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12300
12301         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12302
12303         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12304         const GLchar* qual_first_out = "layout (location = first_output_location)";
12305         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12306         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12307
12308         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12309         const GLuint                    type_size = type.GetSize();
12310
12311         std::string first_in_name  = "PREFIXfirst";
12312         std::string first_out_name = "PREFIXfirst";
12313         std::string last_in_name   = "PREFIXlast";
12314         std::string last_out_name  = "PREFIXlast";
12315
12316         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12317         position = 0;
12318         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12319         position = 0;
12320         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12321         position = 0;
12322         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12323
12324         if (Utils::Shader::FRAGMENT == stage)
12325         {
12326                 qual_first_in = "layout (location = first_input_location) flat";
12327                 qual_last_in  = "layout (location = last_input_location)  flat";
12328         }
12329         if (Utils::Shader::GEOMETRY == stage)
12330         {
12331                 qual_first_out = "layout (location = first_output_location) flat";
12332                 qual_last_out  = "layout (location = last_output_location)  flat";
12333         }
12334
12335         Utils::Variable* first_in = si.Input(
12336                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12337                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12338                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12339
12340         Utils::Variable* last_in =
12341                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12342                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12343                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12344                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12345
12346         if (Utils::Shader::FRAGMENT != stage)
12347         {
12348                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12349
12350                 Utils::Variable* first_out =
12351                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12352                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12353                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12354                                           m_first_data.size() /* data_size */);
12355
12356                 Utils::Variable* last_out = si.Output(
12357                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12358                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12359                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12360
12361                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12362
12363                 varying_passthrough.Add(stage, first_in, first_out);
12364                 varying_passthrough.Add(stage, last_in, last_out);
12365         }
12366         else
12367         {
12368                 /* No outputs for fragment shader, so last_output_location can be 0 */
12369                 si.m_globals = prepareGlobals(last_in_loc, 0);
12370         }
12371 }
12372
12373 /** This test should be run with separable programs
12374  *
12375  * @param ignored
12376  *
12377  * @return true
12378  **/
12379 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12380 {
12381         return false;
12382 }
12383
12384 /* Constants used by VertexAttribLocationsTest */
12385 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12386 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12387 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12388 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12389 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12390
12391 /** Constructor
12392  *
12393  * @param context Test framework context
12394  **/
12395 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12396         : TextureTestBase(context, "vertex_attrib_locations",
12397                                           "Test verifies that attribute locations are respected by drawing operations")
12398 {
12399 }
12400
12401 /** Execute proper draw command for test case
12402  *
12403  * @param test_case_index Index of test case
12404  **/
12405 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12406 {
12407         static const GLubyte indices[8] = { 0 };
12408
12409         const Functions& gl = m_context.getRenderContext().getFunctions();
12410
12411         switch (test_case_index)
12412         {
12413         case DRAWARRAYS:
12414                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12415                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12416                 break;
12417         case DRAWARRAYSINSTANCED:
12418                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12419                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12420                 break;
12421         case DRAWELEMENTS:
12422                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices);
12423                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12424                 break;
12425         case DRAWELEMENTSBASEVERTEX:
12426                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices, m_base_vertex);
12427                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12428                 break;
12429         case DRAWELEMENTSINSTANCED:
12430                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices, m_n_instances);
12431                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12432                 break;
12433         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12434                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices, m_n_instances,
12435                                                                                          m_base_instance);
12436                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12437                 break;
12438         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12439                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices, m_n_instances,
12440                                                                                    m_base_vertex);
12441                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12442                 break;
12443         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12444                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, indices,
12445                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12446                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12447                 break;
12448         default:
12449                 TCU_FAIL("Invalid enum");
12450         }
12451 }
12452
12453 /** Get interface of program
12454  *
12455  * @param ignored
12456  * @param program_interface   Interface of program
12457  * @param ignored
12458  **/
12459 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12460                                                                                                         Utils::ProgramInterface& program_interface,
12461                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12462 {
12463         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12464
12465         /* Globals */
12466         si.m_globals = "const uint vertex_index_location   = 2;\n"
12467                                    "const uint instance_index_location = 5;\n";
12468
12469         /* Attributes */
12470         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12471                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12472                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12473                          (GLvoid*)0 /* data */, 0 /* data_size */);
12474         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12475                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12476                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12477                          (GLvoid*)0 /* data */, 0 /* data_size */);
12478 }
12479
12480 /** Get name of test case
12481  *
12482  * @param test_case_index Index of test case
12483  *
12484  * @return Name of test case
12485  **/
12486 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12487 {
12488         std::string result;
12489
12490         switch (test_case_index)
12491         {
12492         case DRAWARRAYS:
12493                 result = "DrawArrays";
12494                 break;
12495         case DRAWARRAYSINSTANCED:
12496                 result = "DrawArraysInstanced";
12497                 break;
12498         case DRAWELEMENTS:
12499                 result = "DrawElements";
12500                 break;
12501         case DRAWELEMENTSBASEVERTEX:
12502                 result = "DrawElementsBaseVertex";
12503                 break;
12504         case DRAWELEMENTSINSTANCED:
12505                 result = "DrawElementsInstanced";
12506                 break;
12507         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12508                 result = "DrawElementsInstancedBaseInstance";
12509                 break;
12510         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12511                 result = "DrawElementsInstancedBaseVertex";
12512                 break;
12513         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12514                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12515                 break;
12516         default:
12517                 TCU_FAIL("Invalid enum");
12518         }
12519
12520         return result;
12521 }
12522
12523 /** Get number of test cases
12524  *
12525  * @return Number of test cases
12526  **/
12527 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12528 {
12529         return TESTCASES_MAX;
12530 }
12531
12532 /** Prepare code snippet that will verify in and uniform variables
12533  *
12534  * @param ignored
12535  * @param ignored
12536  * @param stage   Shader stage
12537  *
12538  * @return Code that verify variables
12539  **/
12540 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12541                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12542                                                                                                                           Utils::Shader::STAGES stage)
12543 {
12544         std::string verification;
12545
12546         if (Utils::Shader::VERTEX == stage)
12547         {
12548
12549 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12550
12551                 verification = "if (gl_InstanceID != instance_index)\n"
12552                                            "    {\n"
12553                                            "        result = 12u;\n"
12554                                            "    }\n"
12555                                            "    else if (gl_VertexID != vertex_index)\n"
12556                                            "    {\n"
12557                                            "        result = 11u;\n"
12558                                            "    }\n";
12559
12560 #else
12561
12562                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12563                                            "        (gl_InstanceID != instance_index) )\n"
12564                                            "    {\n"
12565                                            "        result = 0u;\n"
12566                                            "    }\n";
12567
12568 #endif
12569         }
12570         else
12571         {
12572                 verification = "";
12573         }
12574
12575         return verification;
12576 }
12577
12578 /** Selects if "compute" stage is relevant for test
12579  *
12580  * @param ignored
12581  *
12582  * @return false
12583  **/
12584 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12585 {
12586         return false;
12587 }
12588
12589 /** Prepare attributes, vertex array object and array buffer
12590  *
12591  * @param ignored
12592  * @param ignored Interface of program
12593  * @param buffer  Array buffer
12594  * @param vao     Vertex array object
12595  **/
12596 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12597                                                                                                   Utils::ProgramInterface& /* program_interface */,
12598                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12599 {
12600         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12601         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12602
12603         std::vector<GLuint> buffer_data;
12604         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12605
12606         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12607
12608         /*
12609          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12610          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12611          */
12612         if (test_case_index >= 2)
12613         {
12614                 buffer.m_buffer = Utils::Buffer::Element;
12615         }
12616         vao.Bind();
12617         buffer.Bind();
12618
12619         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12620                                   0 /* stride */, 0 /* offset */);
12621
12622         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12623                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12624         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12625         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12626         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12627                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12628         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12629                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12630
12631         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12632         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12633
12634         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12635 }
12636
12637 /** This test should be run with separable programs
12638  *
12639  * @param ignored
12640  *
12641  * @return true
12642  **/
12643 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12644 {
12645         return false;
12646 }
12647
12648 /** Constructor
12649  *
12650  * @param context Test framework context
12651  **/
12652 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12653         : VaryingLocationsTest(context, "varying_array_locations",
12654                                                    "Test verifies that input and output locations are respected for arrays")
12655 {
12656 }
12657
12658 /**
12659  *
12660  **/
12661 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12662                                                                                                    Utils::ProgramInterface&   program_interface,
12663                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12664 {
12665         const GLuint array_length  = 1u;
12666         const GLuint first_in_loc  = 0;
12667         const GLuint first_out_loc = 0;
12668         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12669         size_t           position         = 0;
12670
12671         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12672
12673         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12674
12675         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12676         const GLchar* qual_first_out = "layout (location = first_output_location)";
12677         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12678         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12679
12680         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12681         const GLuint                    type_size = type.GetSize();
12682
12683         std::string first_in_name  = "PREFIXfirst";
12684         std::string first_out_name = "PREFIXfirst";
12685         std::string last_in_name   = "PREFIXlast";
12686         std::string last_out_name  = "PREFIXlast";
12687
12688         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12689         position = 0;
12690         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12691         position = 0;
12692         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12693         position = 0;
12694         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12695
12696         if (Utils::Shader::FRAGMENT == stage)
12697         {
12698                 qual_first_in = "layout (location = first_input_location) flat";
12699                 qual_last_in  = "layout (location = last_input_location)  flat";
12700         }
12701         if (Utils::Shader::GEOMETRY == stage)
12702         {
12703                 qual_first_out = "layout (location = first_output_location) flat";
12704                 qual_last_out  = "layout (location = last_output_location)  flat";
12705         }
12706
12707         Utils::Variable* first_in =
12708                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12709                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12710                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12711                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12712
12713         Utils::Variable* last_in =
12714                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12715                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12716                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12717                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12718
12719         if (Utils::Shader::FRAGMENT != stage)
12720         {
12721                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12722
12723                 Utils::Variable* first_out =
12724                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12725                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12726                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12727                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12728
12729                 Utils::Variable* last_out =
12730                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12731                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12732                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12733                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12734
12735                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12736
12737                 varying_passthrough.Add(stage, first_in, first_out);
12738                 varying_passthrough.Add(stage, last_in, last_out);
12739         }
12740         else
12741         {
12742                 /* No outputs for fragment shader, so last_output_location can be 0 */
12743                 si.m_globals = prepareGlobals(last_in_loc, 0);
12744         }
12745 }
12746
12747 /** Constructor
12748  *
12749  * @param context Test framework context
12750  **/
12751 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12752         : TextureTestBase(context, "varying_structure_locations",
12753                                           "Test verifies that locations are respected when structures are used as in and out ")
12754 {
12755 }
12756
12757 /** Prepare code snippet that will pass in variables to out variables
12758  *
12759  * @param ignored
12760  * @param varying_passthrough Collection of connections between in and out variables
12761  * @param stage               Shader stage
12762  *
12763  * @return Code that pass in variables to next stage
12764  **/
12765 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12766                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12767                                                                                                                   Utils::Shader::STAGES          stage)
12768 {
12769         std::string result;
12770
12771         if (Utils::Shader::VERTEX != stage)
12772         {
12773                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12774         }
12775         else
12776         {
12777                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12778                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12779         }
12780
12781         return result;
12782 }
12783
12784 /** Get interface of program
12785  *
12786  * @param test_case_index     Test case
12787  * @param program_interface   Interface of program
12788  * @param varying_passthrough Collection of connections between in and out variables
12789  **/
12790 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12791                                                                                                                 Utils::ProgramInterface&   program_interface,
12792                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12793 {
12794         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12795         const Utils::Type               type = getType(test_case_index);
12796
12797         /* Prepare data */
12798         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12799         m_single_data = type.GenerateDataPacked();
12800         m_array_data  = type.GenerateDataPacked();
12801
12802         m_data.resize(m_single_data.size() + m_array_data.size());
12803         GLubyte* ptr = (GLubyte*)&m_data[0];
12804         memcpy(ptr, &m_single_data[0], m_single_data.size());
12805         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12806
12807         Utils::Interface* structure = program_interface.Structure("Data");
12808
12809         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12810                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12811
12812         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12813         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12814                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12815
12816         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12817                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12818                          m_single_data.size() /* data_size */);
12819
12820         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12821                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12822                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12823
12824         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12825                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12826                           m_data.size() /* data_size */);
12827
12828         program_interface.CloneVertexInterface(varying_passthrough);
12829 }
12830
12831 /** Get type name
12832  *
12833  * @param test_case_index Index of test case
12834  *
12835  * @return Name of type test in test_case_index
12836  **/
12837 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12838 {
12839         return getTypeName(test_case_index);
12840 }
12841
12842 /** Returns number of types to test
12843  *
12844  * @return Number of types, 34
12845  **/
12846 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12847 {
12848         return getTypesNumber();
12849 }
12850
12851 /** Selects if "compute" stage is relevant for test
12852  *
12853  * @param ignored
12854  *
12855  * @return false
12856  **/
12857 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12858 {
12859         return false;
12860 }
12861
12862 /** This test should be run with separable programs
12863  *
12864  * @param ignored
12865  *
12866  * @return true
12867  **/
12868 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12869 {
12870         return false;
12871 }
12872
12873 /** Constructor
12874  *
12875  * @param context          Test context
12876  * @param test_name        Name of test
12877  * @param test_description Description of test
12878  **/
12879 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12880         : NegativeTestBase(context, "varying_structure_member_location",
12881                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12882 {
12883 }
12884
12885 /** Source for given test case and stage
12886  *
12887  * @param test_case_index Index of test case
12888  * @param stage           Shader stage
12889  *
12890  * @return Shader source
12891  **/
12892 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12893 {
12894         static const GLchar* struct_definition = "struct Data {\n"
12895                                                                                          "    vec4 gohan;\n"
12896                                                                                          "    layout (location = 4) vec4 goten;\n"
12897                                                                                          "};\n";
12898         static const GLchar* input_var  = "in Data data;\n";
12899         static const GLchar* output_var = "out Data data;\n";
12900         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12901         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12902                                                                           "    data.goten = result / 4 - data.gohan;\n";
12903         static const GLchar* fs = "#version 430 core\n"
12904                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12905                                                           "\n"
12906                                                           "in  vec4 gs_fs;\n"
12907                                                           "out vec4 fs_out;\n"
12908                                                           "\n"
12909                                                           "void main()\n"
12910                                                           "{\n"
12911                                                           "    fs_out = gs_fs;\n"
12912                                                           "}\n"
12913                                                           "\n";
12914         static const GLchar* fs_tested = "#version 430 core\n"
12915                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12916                                                                          "\n"
12917                                                                          "STRUCT_DEFINITION"
12918                                                                          "\n"
12919                                                                          "VARIABLE_DEFINITION"
12920                                                                          "\n"
12921                                                                          "in  vec4 gs_fs;\n"
12922                                                                          "out vec4 fs_out;\n"
12923                                                                          "\n"
12924                                                                          "void main()\n"
12925                                                                          "{\n"
12926                                                                          "    vec4 result = gs_fs;\n"
12927                                                                          "\n"
12928                                                                          "VARIABLE_USE"
12929                                                                          "\n"
12930                                                                          "    fs_out += result;\n"
12931                                                                          "}\n"
12932                                                                          "\n";
12933         static const GLchar* gs = "#version 430 core\n"
12934                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12935                                                           "\n"
12936                                                           "layout(points)                           in;\n"
12937                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
12938                                                           "\n"
12939                                                           "in  vec4 tes_gs[];\n"
12940                                                           "out vec4 gs_fs;\n"
12941                                                           "\n"
12942                                                           "void main()\n"
12943                                                           "{\n"
12944                                                           "    gs_fs = tes_gs[0];\n"
12945                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12946                                                           "    EmitVertex();\n"
12947                                                           "    gs_fs = tes_gs[0];\n"
12948                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12949                                                           "    EmitVertex();\n"
12950                                                           "    gs_fs = tes_gs[0];\n"
12951                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
12952                                                           "    EmitVertex();\n"
12953                                                           "    gs_fs = tes_gs[0];\n"
12954                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
12955                                                           "    EmitVertex();\n"
12956                                                           "}\n"
12957                                                           "\n";
12958         static const GLchar* gs_tested = "#version 430 core\n"
12959                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12960                                                                          "\n"
12961                                                                          "layout(points)                           in;\n"
12962                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
12963                                                                          "\n"
12964                                                                          "STRUCT_DEFINITION"
12965                                                                          "\n"
12966                                                                          "VARIABLE_DEFINITION"
12967                                                                          "\n"
12968                                                                          "in  vec4 tes_gs[];\n"
12969                                                                          "out vec4 gs_fs;\n"
12970                                                                          "\n"
12971                                                                          "void main()\n"
12972                                                                          "{\n"
12973                                                                          "    vec4 result = tes_gs[0];\n"
12974                                                                          "\n"
12975                                                                          "VARIABLE_USE"
12976                                                                          "\n"
12977                                                                          "    gs_fs = result;\n"
12978                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12979                                                                          "    EmitVertex();\n"
12980                                                                          "    gs_fs = result;\n"
12981                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12982                                                                          "    EmitVertex();\n"
12983                                                                          "    gs_fs = result;\n"
12984                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
12985                                                                          "    EmitVertex();\n"
12986                                                                          "    gs_fs = result;\n"
12987                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
12988                                                                          "    EmitVertex();\n"
12989                                                                          "}\n"
12990                                                                          "\n";
12991         static const GLchar* tcs = "#version 430 core\n"
12992                                                            "#extension GL_ARB_enhanced_layouts : require\n"
12993                                                            "\n"
12994                                                            "layout(vertices = 1) out;\n"
12995                                                            "\n"
12996                                                            "in  vec4 vs_tcs[];\n"
12997                                                            "out vec4 tcs_tes[];\n"
12998                                                            "\n"
12999                                                            "void main()\n"
13000                                                            "{\n"
13001                                                            "\n"
13002                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13003                                                            "\n"
13004                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13005                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13006                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13007                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13008                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13009                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13010                                                            "}\n"
13011                                                            "\n";
13012         static const GLchar* tcs_tested = "#version 430 core\n"
13013                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13014                                                                           "\n"
13015                                                                           "layout(vertices = 1) out;\n"
13016                                                                           "\n"
13017                                                                           "STRUCT_DEFINITION"
13018                                                                           "\n"
13019                                                                           "VARIABLE_DEFINITION"
13020                                                                           "\n"
13021                                                                           "in  vec4 vs_tcs[];\n"
13022                                                                           "out vec4 tcs_tes[];\n"
13023                                                                           "\n"
13024                                                                           "void main()\n"
13025                                                                           "{\n"
13026                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13027                                                                           "\n"
13028                                                                           "VARIABLE_USE"
13029                                                                           "\n"
13030                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13031                                                                           "\n"
13032                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13033                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13034                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13035                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13036                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13037                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13038                                                                           "}\n"
13039                                                                           "\n";
13040         static const GLchar* tes = "#version 430 core\n"
13041                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13042                                                            "\n"
13043                                                            "layout(isolines, point_mode) in;\n"
13044                                                            "\n"
13045                                                            "in  vec4 tcs_tes[];\n"
13046                                                            "out vec4 tes_gs;\n"
13047                                                            "\n"
13048                                                            "void main()\n"
13049                                                            "{\n"
13050                                                            "    tes_gs = tcs_tes[0];\n"
13051                                                            "}\n"
13052                                                            "\n";
13053         static const GLchar* tes_tested = "#version 430 core\n"
13054                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13055                                                                           "\n"
13056                                                                           "layout(isolines, point_mode) in;\n"
13057                                                                           "\n"
13058                                                                           "STRUCT_DEFINITION"
13059                                                                           "\n"
13060                                                                           "VARIABLE_DEFINITION"
13061                                                                           "\n"
13062                                                                           "in  vec4 tcs_tes[];\n"
13063                                                                           "out vec4 tes_gs;\n"
13064                                                                           "\n"
13065                                                                           "void main()\n"
13066                                                                           "{\n"
13067                                                                           "    vec4 result = tcs_tes[0];\n"
13068                                                                           "\n"
13069                                                                           "VARIABLE_USE"
13070                                                                           "\n"
13071                                                                           "    tes_gs += result;\n"
13072                                                                           "}\n"
13073                                                                           "\n";
13074         static const GLchar* vs = "#version 430 core\n"
13075                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13076                                                           "\n"
13077                                                           "in  vec4 in_vs;\n"
13078                                                           "out vec4 vs_tcs;\n"
13079                                                           "\n"
13080                                                           "void main()\n"
13081                                                           "{\n"
13082                                                           "    vs_tcs = in_vs;\n"
13083                                                           "}\n"
13084                                                           "\n";
13085         static const GLchar* vs_tested = "#version 430 core\n"
13086                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13087                                                                          "\n"
13088                                                                          "STRUCT_DEFINITION"
13089                                                                          "\n"
13090                                                                          "VARIABLE_DEFINITION"
13091                                                                          "\n"
13092                                                                          "in  vec4 in_vs;\n"
13093                                                                          "out vec4 vs_tcs;\n"
13094                                                                          "\n"
13095                                                                          "void main()\n"
13096                                                                          "{\n"
13097                                                                          "    vec4 result = in_vs;\n"
13098                                                                          "\n"
13099                                                                          "VARIABLE_USE"
13100                                                                          "\n"
13101                                                                          "    vs_tcs += result;\n"
13102                                                                          "}\n"
13103                                                                          "\n";
13104
13105         std::string   source;
13106         testCase&        test_case               = m_test_cases[test_case_index];
13107         const GLchar* var_definition = 0;
13108         const GLchar* var_use            = 0;
13109
13110         if (true == test_case.m_is_input)
13111         {
13112                 var_definition = input_var;
13113                 var_use            = input_use;
13114         }
13115         else
13116         {
13117                 var_definition = output_var;
13118                 var_use            = output_use;
13119         }
13120
13121         if (test_case.m_stage == stage)
13122         {
13123                 size_t position = 0;
13124
13125                 switch (stage)
13126                 {
13127                 case Utils::Shader::FRAGMENT:
13128                         source = fs_tested;
13129                         break;
13130                 case Utils::Shader::GEOMETRY:
13131                         source = gs_tested;
13132                         break;
13133                 case Utils::Shader::TESS_CTRL:
13134                         source = tcs_tested;
13135                         break;
13136                 case Utils::Shader::TESS_EVAL:
13137                         source = tes_tested;
13138                         break;
13139                 case Utils::Shader::VERTEX:
13140                         source = vs_tested;
13141                         break;
13142                 default:
13143                         TCU_FAIL("Invalid enum");
13144                 }
13145
13146                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13147                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13148                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13149         }
13150         else
13151         {
13152                 switch (stage)
13153                 {
13154                 case Utils::Shader::FRAGMENT:
13155                         source = fs;
13156                         break;
13157                 case Utils::Shader::GEOMETRY:
13158                         source = gs;
13159                         break;
13160                 case Utils::Shader::TESS_CTRL:
13161                         source = tcs;
13162                         break;
13163                 case Utils::Shader::TESS_EVAL:
13164                         source = tes;
13165                         break;
13166                 case Utils::Shader::VERTEX:
13167                         source = vs;
13168                         break;
13169                 default:
13170                         TCU_FAIL("Invalid enum");
13171                 }
13172         }
13173
13174         return source;
13175 }
13176
13177 /** Get description of test case
13178  *
13179  * @param test_case_index Index of test case
13180  *
13181  * @return Test case description
13182  **/
13183 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13184 {
13185         std::stringstream stream;
13186         testCase&                 test_case = m_test_cases[test_case_index];
13187
13188         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13189
13190         if (true == test_case.m_is_input)
13191         {
13192                 stream << "input";
13193         }
13194         else
13195         {
13196                 stream << "output";
13197         }
13198
13199         return stream.str();
13200 }
13201
13202 /** Get number of test cases
13203  *
13204  * @return Number of test cases
13205  **/
13206 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13207 {
13208         return static_cast<GLuint>(m_test_cases.size());
13209 }
13210
13211 /** Selects if "compute" stage is relevant for test
13212  *
13213  * @param ignored
13214  *
13215  * @return false
13216  **/
13217 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13218 {
13219         return false;
13220 }
13221
13222 /** Prepare all test cases
13223  *
13224  **/
13225 void VaryingStructureMemberLocationTest::testInit()
13226 {
13227         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13228         {
13229                 if (Utils::Shader::COMPUTE == stage)
13230                 {
13231                         continue;
13232                 }
13233
13234                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13235                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13236
13237                 m_test_cases.push_back(test_case_in);
13238
13239                 if (Utils::Shader::FRAGMENT != stage)
13240                 {
13241                         m_test_cases.push_back(test_case_out);
13242                 }
13243         }
13244 }
13245
13246 /** Constructor
13247  *
13248  * @param context Test framework context
13249  **/
13250 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13251         : TextureTestBase(context, "varying_block_locations",
13252                                           "Test verifies that locations are respected when blocks are used as in and out ")
13253 {
13254 }
13255
13256 /** Prepare code snippet that will pass in variables to out variables
13257  *
13258  * @param ignored
13259  * @param varying_passthrough Collection of connections between in and out variables
13260  * @param stage               Shader stage
13261  *
13262  * @return Code that pass in variables to next stage
13263  **/
13264 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13265                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13266                                                                                                           Utils::Shader::STAGES          stage)
13267 {
13268         std::string result;
13269
13270         if (Utils::Shader::VERTEX != stage)
13271         {
13272                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13273         }
13274         else
13275         {
13276                 result = "vs_tcs_block.third  = vs_in_third;\n"
13277                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13278                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13279         }
13280
13281         return result;
13282 }
13283
13284 /** Get interface of program
13285  *
13286  * @param ignored
13287  * @param program_interface   Interface of program
13288  * @param varying_passthrough Collection of connections between in and out variables
13289  **/
13290 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13291                                                                                                         Utils::ProgramInterface&   program_interface,
13292                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13293 {
13294         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13295         const Utils::Type               vec4 = Utils::Type::vec4;
13296
13297         /* Prepare data */
13298         m_third_data  = vec4.GenerateData();
13299         m_fourth_data = vec4.GenerateData();
13300         m_fifth_data  = vec4.GenerateData();
13301
13302         /* Memory layout is different from location layout */
13303         const GLuint fifth_offset  = 0u;
13304         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13305         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13306
13307         m_data.resize(fourth_offset + m_fourth_data.size());
13308         GLubyte* ptr = (GLubyte*)&m_data[0];
13309         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13310         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13311         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13312
13313         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13314
13315         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13316                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13317
13318         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13319                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13320
13321         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13322                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13323
13324         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13325                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13326                           m_data.size() /* data_size */);
13327
13328         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13329                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13330                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13331
13332         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13333                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13334                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13335
13336         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13337                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13338                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13339
13340         program_interface.CloneVertexInterface(varying_passthrough);
13341 }
13342
13343 /** Selects if "compute" stage is relevant for test
13344  *
13345  * @param ignored
13346  *
13347  * @return false
13348  **/
13349 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13350 {
13351         return false;
13352 }
13353
13354 /** This test should be run with separable programs
13355  *
13356  * @param ignored
13357  *
13358  * @return true
13359  **/
13360 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13361 {
13362         return false;
13363 }
13364
13365 /** Constructor
13366  *
13367  * @param context Test framework context
13368  **/
13369 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13370         : NegativeTestBase(
13371                   context, "varying_block_member_locations",
13372                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13373 {
13374 }
13375
13376 /** Source for given test case and stage
13377  *
13378  * @param test_case_index Index of test case
13379  * @param stage           Shader stage
13380  *
13381  * @return Shader source
13382  **/
13383 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13384 {
13385         static const GLchar* block_definition_all = "Goku {\n"
13386                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13387                                                                                                 "    layout (location = 4) vec4 goten;\n"
13388                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13389                                                                                                 "} gokuARRAY;\n";
13390         static const GLchar* block_definition_default = "Goku {\n"
13391                                                                                                         "    vec4 gohan;\n"
13392                                                                                                         "    vec4 goten;\n"
13393                                                                                                         "    vec4 chichi;\n"
13394                                                                                                         "} gokuARRAY;\n";
13395         static const GLchar* block_definition_one = "Goku {\n"
13396                                                                                                 "    vec4 gohan;\n"
13397                                                                                                 "    layout (location = 4) vec4 goten;\n"
13398                                                                                                 "    vec4 chichi;\n"
13399                                                                                                 "} gokuARRAY;\n";
13400         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13401         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13402                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13403                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13404         static const GLchar* fs = "#version 430 core\n"
13405                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13406                                                           "\n"
13407                                                           "in  vec4 gs_fs;\n"
13408                                                           "out vec4 fs_out;\n"
13409                                                           "\n"
13410                                                           "void main()\n"
13411                                                           "{\n"
13412                                                           "    fs_out = gs_fs;\n"
13413                                                           "}\n"
13414                                                           "\n";
13415         static const GLchar* fs_tested = "#version 430 core\n"
13416                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13417                                                                          "\n"
13418                                                                          "DIRECTION BLOCK_DEFINITION"
13419                                                                          "\n"
13420                                                                          "in  vec4 gs_fs;\n"
13421                                                                          "out vec4 fs_out;\n"
13422                                                                          "\n"
13423                                                                          "void main()\n"
13424                                                                          "{\n"
13425                                                                          "    vec4 result = gs_fs;\n"
13426                                                                          "\n"
13427                                                                          "VARIABLE_USE"
13428                                                                          "\n"
13429                                                                          "    fs_out = result;\n"
13430                                                                          "}\n"
13431                                                                          "\n";
13432         static const GLchar* gs = "#version 430 core\n"
13433                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13434                                                           "\n"
13435                                                           "layout(points)                           in;\n"
13436                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13437                                                           "\n"
13438                                                           "in  vec4 tes_gs[];\n"
13439                                                           "out vec4 gs_fs;\n"
13440                                                           "\n"
13441                                                           "void main()\n"
13442                                                           "{\n"
13443                                                           "    gs_fs = tes_gs[0];\n"
13444                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13445                                                           "    EmitVertex();\n"
13446                                                           "    gs_fs = tes_gs[0];\n"
13447                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13448                                                           "    EmitVertex();\n"
13449                                                           "    gs_fs = tes_gs[0];\n"
13450                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13451                                                           "    EmitVertex();\n"
13452                                                           "    gs_fs = tes_gs[0];\n"
13453                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13454                                                           "    EmitVertex();\n"
13455                                                           "}\n"
13456                                                           "\n";
13457         static const GLchar* gs_tested = "#version 430 core\n"
13458                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13459                                                                          "\n"
13460                                                                          "layout(points)                           in;\n"
13461                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13462                                                                          "\n"
13463                                                                          "DIRECTION BLOCK_DEFINITION"
13464                                                                          "\n"
13465                                                                          "in  vec4 tes_gs[];\n"
13466                                                                          "out vec4 gs_fs;\n"
13467                                                                          "\n"
13468                                                                          "void main()\n"
13469                                                                          "{\n"
13470                                                                          "    vec4 result = tes_gs[0];\n"
13471                                                                          "\n"
13472                                                                          "VARIABLE_USE"
13473                                                                          "\n"
13474                                                                          "    gs_fs = result;\n"
13475                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13476                                                                          "    EmitVertex();\n"
13477                                                                          "    gs_fs = result;\n"
13478                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13479                                                                          "    EmitVertex();\n"
13480                                                                          "    gs_fs = result;\n"
13481                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13482                                                                          "    EmitVertex();\n"
13483                                                                          "    gs_fs = result;\n"
13484                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13485                                                                          "    EmitVertex();\n"
13486                                                                          "}\n"
13487                                                                          "\n";
13488         static const GLchar* tcs = "#version 430 core\n"
13489                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13490                                                            "\n"
13491                                                            "layout(vertices = 1) out;\n"
13492                                                            "\n"
13493                                                            "in  vec4 vs_tcs[];\n"
13494                                                            "out vec4 tcs_tes[];\n"
13495                                                            "\n"
13496                                                            "void main()\n"
13497                                                            "{\n"
13498                                                            "\n"
13499                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13500                                                            "\n"
13501                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13502                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13503                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13504                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13505                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13506                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13507                                                            "}\n"
13508                                                            "\n";
13509         static const GLchar* tcs_tested = "#version 430 core\n"
13510                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13511                                                                           "\n"
13512                                                                           "layout(vertices = 1) out;\n"
13513                                                                           "\n"
13514                                                                           "DIRECTION BLOCK_DEFINITION"
13515                                                                           "\n"
13516                                                                           "in  vec4 vs_tcs[];\n"
13517                                                                           "out vec4 tcs_tes[];\n"
13518                                                                           "\n"
13519                                                                           "void main()\n"
13520                                                                           "{\n"
13521                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13522                                                                           "\n"
13523                                                                           "VARIABLE_USE"
13524                                                                           "\n"
13525                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13526                                                                           "\n"
13527                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13528                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13529                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13530                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13531                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13532                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13533                                                                           "}\n"
13534                                                                           "\n";
13535         static const GLchar* tes = "#version 430 core\n"
13536                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13537                                                            "\n"
13538                                                            "layout(isolines, point_mode) in;\n"
13539                                                            "\n"
13540                                                            "in  vec4 tcs_tes[];\n"
13541                                                            "out vec4 tes_gs;\n"
13542                                                            "\n"
13543                                                            "void main()\n"
13544                                                            "{\n"
13545                                                            "    tes_gs = tcs_tes[0];\n"
13546                                                            "}\n"
13547                                                            "\n";
13548         static const GLchar* tes_tested = "#version 430 core\n"
13549                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13550                                                                           "\n"
13551                                                                           "layout(isolines, point_mode) in;\n"
13552                                                                           "\n"
13553                                                                           "DIRECTION BLOCK_DEFINITION"
13554                                                                           "\n"
13555                                                                           "in  vec4 tcs_tes[];\n"
13556                                                                           "out vec4 tes_gs;\n"
13557                                                                           "\n"
13558                                                                           "void main()\n"
13559                                                                           "{\n"
13560                                                                           "    vec4 result = tcs_tes[0];\n"
13561                                                                           "\n"
13562                                                                           "VARIABLE_USE"
13563                                                                           "\n"
13564                                                                           "    tes_gs = result;\n"
13565                                                                           "}\n"
13566                                                                           "\n";
13567         static const GLchar* vs = "#version 430 core\n"
13568                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13569                                                           "\n"
13570                                                           "in  vec4 in_vs;\n"
13571                                                           "out vec4 vs_tcs;\n"
13572                                                           "\n"
13573                                                           "void main()\n"
13574                                                           "{\n"
13575                                                           "    vs_tcs = in_vs;\n"
13576                                                           "}\n"
13577                                                           "\n";
13578         static const GLchar* vs_tested = "#version 430 core\n"
13579                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13580                                                                          "\n"
13581                                                                          "DIRECTION BLOCK_DEFINITION"
13582                                                                          "\n"
13583                                                                          "in  vec4 in_vs;\n"
13584                                                                          "out vec4 vs_tcs;\n"
13585                                                                          "\n"
13586                                                                          "void main()\n"
13587                                                                          "{\n"
13588                                                                          "    vec4 result = in_vs;\n"
13589                                                                          "\n"
13590                                                                          "VARIABLE_USE"
13591                                                                          "\n"
13592                                                                          "    vs_tcs = result;\n"
13593                                                                          "}\n"
13594                                                                          "\n";
13595
13596         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13597                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13598                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13599                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13600                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13601                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13602
13603         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13604                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13605                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13606                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13607                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13608                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13609
13610         static const bool require_modifications_in[6][6] = {
13611                 /* cs  */ { false, false, false, false, false, false },
13612                 /* vs  */ { false, true, false, false, false, false },
13613                 /* tcs */ { false, true, true, false, false, false },
13614                 /* tes */ { false, false, true, true, false, false },
13615                 /* gs  */ { false, false, false, true, true, false },
13616                 /* fs  */ { false, false, false, false, true, true }
13617         };
13618
13619         static const bool require_modifications_out[6][6] = {
13620                 /* cs  */ { false, false, false, false, false, false },
13621                 /* vs  */ { false, true, true, false, false, false },
13622                 /* tcs */ { false, false, true, true, false, false },
13623                 /* tes */ { false, false, false, true, true, false },
13624                 /* gs  */ { false, false, false, false, true, true },
13625                 /* fs  */ { false, false, false, false, false, false }
13626         };
13627
13628         const GLchar* array                                     = "";
13629         const GLchar* definition                        = block_definition_default;
13630         const GLchar* direction                         = "out";
13631         const GLchar* index                                     = "";
13632         bool              require_modifications = false;
13633         std::string   source;
13634         testCase&        test_case = m_test_cases[test_case_index];
13635         const GLchar* var_use   = output_use;
13636
13637         if (true == test_case.m_is_input)
13638         {
13639                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13640                 source                            = shaders_in[test_case.m_stage][stage];
13641
13642                 if (test_case.m_stage == stage)
13643                 {
13644                         direction = "in";
13645                         var_use   = input_use;
13646                 }
13647         }
13648         else
13649         {
13650                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13651                 source                            = shaders_out[test_case.m_stage][stage];
13652
13653                 if (test_case.m_stage != stage)
13654                 {
13655                         direction = "in";
13656                         var_use   = input_use;
13657                 }
13658         }
13659
13660         if (test_case.m_stage == stage)
13661         {
13662                 if (true == test_case.m_qualify_all)
13663                 {
13664                         definition = block_definition_all;
13665                 }
13666                 else
13667                 {
13668                         definition = block_definition_one;
13669                 }
13670         }
13671
13672         switch (stage)
13673         {
13674         case Utils::Shader::FRAGMENT:
13675                 break;
13676         case Utils::Shader::GEOMETRY:
13677                 array = "[]";
13678                 index = "[0]";
13679                 break;
13680         case Utils::Shader::TESS_CTRL:
13681                 array = "[]";
13682                 index = "[gl_InvocationID]";
13683                 break;
13684         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13685         // the GS input block is an array, so the DS output can't be declared as an array
13686         case Utils::Shader::TESS_EVAL:
13687         {
13688                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13689                 {
13690                         array = "[]";
13691                         index = "[0]";
13692                 }
13693                 else // match DS output and GS input
13694                 {
13695                         array = "";
13696                         index = "";
13697                 }
13698         }
13699         break;
13700         case Utils::Shader::VERTEX:
13701                 break;
13702         default:
13703                 TCU_FAIL("Invalid enum");
13704         }
13705
13706         if (true == require_modifications)
13707         {
13708                 size_t position = 0;
13709                 size_t temp;
13710
13711                 Utils::replaceToken("DIRECTION", position, direction, source);
13712                 temp = position;
13713                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13714                 position = temp;
13715                 Utils::replaceToken("ARRAY", position, array, source);
13716                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13717
13718                 Utils::replaceAllTokens("INDEX", index, source);
13719         }
13720         else
13721         {
13722                 switch (stage)
13723                 {
13724                 case Utils::Shader::FRAGMENT:
13725                         source = fs;
13726                         break;
13727                 case Utils::Shader::GEOMETRY:
13728                         source = gs;
13729                         break;
13730                 case Utils::Shader::TESS_CTRL:
13731                         source = tcs;
13732                         break;
13733                 case Utils::Shader::TESS_EVAL:
13734                         source = tes;
13735                         break;
13736                 case Utils::Shader::VERTEX:
13737                         source = vs;
13738                         break;
13739                 default:
13740                         TCU_FAIL("Invalid enum");
13741                 }
13742         }
13743
13744         return source;
13745 }
13746
13747 /** Get description of test case
13748  *
13749  * @param test_case_index Index of test case
13750  *
13751  * @return Test case description
13752  **/
13753 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13754 {
13755         std::stringstream stream;
13756         testCase&                 test_case = m_test_cases[test_case_index];
13757
13758         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13759
13760         if (true == test_case.m_is_input)
13761         {
13762                 stream << "input";
13763         }
13764         else
13765         {
13766                 stream << "output";
13767         }
13768
13769         if (true == test_case.m_qualify_all)
13770         {
13771                 stream << ", all members qualified";
13772         }
13773         else
13774         {
13775                 stream << ", not all members qualified";
13776         }
13777
13778         return stream.str();
13779 }
13780
13781 /** Get number of test cases
13782  *
13783  * @return Number of test cases
13784  **/
13785 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13786 {
13787         return static_cast<GLuint>(m_test_cases.size());
13788 }
13789
13790 /** Selects if "compute" stage is relevant for test
13791  *
13792  * @param ignored
13793  *
13794  * @return false
13795  **/
13796 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13797 {
13798         return false;
13799 }
13800
13801 /** Selects if compilation failure is expected result
13802  *
13803  * @param test_case_index Index of test case
13804  *
13805  * @return false when all members are qualified, true otherwise
13806  **/
13807 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13808 {
13809         return (true != m_test_cases[test_case_index].m_qualify_all);
13810 }
13811
13812 /** Prepare all test cases
13813  *
13814  **/
13815 void VaryingBlockMemberLocationsTest::testInit()
13816 {
13817         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13818         {
13819                 if (Utils::Shader::COMPUTE == stage)
13820                 {
13821                         continue;
13822                 }
13823
13824                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13825                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13826                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13827                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13828
13829                 if (Utils::Shader::VERTEX != stage)
13830                 {
13831                         m_test_cases.push_back(test_case_in_all);
13832                         m_test_cases.push_back(test_case_in_one);
13833                 }
13834
13835                 if (Utils::Shader::FRAGMENT != stage)
13836                 {
13837                         m_test_cases.push_back(test_case_out_all);
13838                         m_test_cases.push_back(test_case_out_one);
13839                 }
13840         }
13841 }
13842
13843 /** Constructor
13844  *
13845  * @param context Test framework context
13846  **/
13847 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13848         : NegativeTestBase(
13849                   context, "varying_block_automatic_member_locations",
13850                   "Test verifies that compiler assigns subsequent locations to block members, even if this casue error")
13851 {
13852 }
13853
13854 /** Source for given test case and stage
13855  *
13856  * @param test_case_index Index of test case
13857  * @param stage           Shader stage
13858  *
13859  * @return Shader source
13860  **/
13861 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13862                                                                                                                                           Utils::Shader::STAGES stage)
13863 {
13864         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13865                                                                                         "    vec4 goku;\n"
13866                                                                                         "    vec4 gohan[4];\n"
13867                                                                                         "    vec4 goten;\n"
13868                                                                                         "    layout (location = 1) vec4 chichi;\n"
13869                                                                                         "    vec4 pan;\n"
13870                                                                                         "} dbzARRAY;\n";
13871         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13872                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13873                                                                          "dbzINDEX.pan;\n";
13874         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13875                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13876                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13877                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13878                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13879                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13880                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13881                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13882                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13883         static const GLchar* fs = "#version 430 core\n"
13884                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13885                                                           "\n"
13886                                                           "in  vec4 gs_fs;\n"
13887                                                           "out vec4 fs_out;\n"
13888                                                           "\n"
13889                                                           "void main()\n"
13890                                                           "{\n"
13891                                                           "    fs_out = gs_fs;\n"
13892                                                           "}\n"
13893                                                           "\n";
13894         static const GLchar* fs_tested = "#version 430 core\n"
13895                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13896                                                                          "\n"
13897                                                                          "BLOCK_DEFINITION"
13898                                                                          "\n"
13899                                                                          "in  vec4 gs_fs;\n"
13900                                                                          "out vec4 fs_out;\n"
13901                                                                          "\n"
13902                                                                          "void main()\n"
13903                                                                          "{\n"
13904                                                                          "    vec4 result = gs_fs;\n"
13905                                                                          "\n"
13906                                                                          "VARIABLE_USE"
13907                                                                          "\n"
13908                                                                          "    fs_out += result;\n"
13909                                                                          "}\n"
13910                                                                          "\n";
13911         static const GLchar* gs = "#version 430 core\n"
13912                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13913                                                           "\n"
13914                                                           "layout(points)                           in;\n"
13915                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13916                                                           "\n"
13917                                                           "in  vec4 tes_gs[];\n"
13918                                                           "out vec4 gs_fs;\n"
13919                                                           "\n"
13920                                                           "void main()\n"
13921                                                           "{\n"
13922                                                           "    gs_fs = tes_gs[0];\n"
13923                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13924                                                           "    EmitVertex();\n"
13925                                                           "    gs_fs = tes_gs[0];\n"
13926                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13927                                                           "    EmitVertex();\n"
13928                                                           "    gs_fs = tes_gs[0];\n"
13929                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13930                                                           "    EmitVertex();\n"
13931                                                           "    gs_fs = tes_gs[0];\n"
13932                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13933                                                           "    EmitVertex();\n"
13934                                                           "}\n"
13935                                                           "\n";
13936         static const GLchar* gs_tested = "#version 430 core\n"
13937                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13938                                                                          "\n"
13939                                                                          "layout(points)                           in;\n"
13940                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13941                                                                          "\n"
13942                                                                          "BLOCK_DEFINITION"
13943                                                                          "\n"
13944                                                                          "in  vec4 tes_gs[];\n"
13945                                                                          "out vec4 gs_fs;\n"
13946                                                                          "\n"
13947                                                                          "void main()\n"
13948                                                                          "{\n"
13949                                                                          "    vec4 result = tes_gs[0];\n"
13950                                                                          "\n"
13951                                                                          "VARIABLE_USE"
13952                                                                          "\n"
13953                                                                          "    gs_fs = result;\n"
13954                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13955                                                                          "    EmitVertex();\n"
13956                                                                          "    gs_fs = result;\n"
13957                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13958                                                                          "    EmitVertex();\n"
13959                                                                          "    gs_fs = result;\n"
13960                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13961                                                                          "    EmitVertex();\n"
13962                                                                          "    gs_fs = result;\n"
13963                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13964                                                                          "    EmitVertex();\n"
13965                                                                          "}\n"
13966                                                                          "\n";
13967         static const GLchar* tcs = "#version 430 core\n"
13968                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13969                                                            "\n"
13970                                                            "layout(vertices = 1) out;\n"
13971                                                            "\n"
13972                                                            "in  vec4 vs_tcs[];\n"
13973                                                            "out vec4 tcs_tes[];\n"
13974                                                            "\n"
13975                                                            "void main()\n"
13976                                                            "{\n"
13977                                                            "\n"
13978                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13979                                                            "\n"
13980                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13981                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13982                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13983                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13984                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13985                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13986                                                            "}\n"
13987                                                            "\n";
13988         static const GLchar* tcs_tested = "#version 430 core\n"
13989                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13990                                                                           "\n"
13991                                                                           "layout(vertices = 1) out;\n"
13992                                                                           "\n"
13993                                                                           "BLOCK_DEFINITION"
13994                                                                           "\n"
13995                                                                           "in  vec4 vs_tcs[];\n"
13996                                                                           "out vec4 tcs_tes[];\n"
13997                                                                           "\n"
13998                                                                           "void main()\n"
13999                                                                           "{\n"
14000                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14001                                                                           "\n"
14002                                                                           "VARIABLE_USE"
14003                                                                           "\n"
14004                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14005                                                                           "\n"
14006                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14007                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14008                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14009                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14010                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14011                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14012                                                                           "}\n"
14013                                                                           "\n";
14014         static const GLchar* tes = "#version 430 core\n"
14015                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14016                                                            "\n"
14017                                                            "layout(isolines, point_mode) in;\n"
14018                                                            "\n"
14019                                                            "in  vec4 tcs_tes[];\n"
14020                                                            "out vec4 tes_gs;\n"
14021                                                            "\n"
14022                                                            "void main()\n"
14023                                                            "{\n"
14024                                                            "    tes_gs = tcs_tes[0];\n"
14025                                                            "}\n"
14026                                                            "\n";
14027         static const GLchar* tes_tested = "#version 430 core\n"
14028                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14029                                                                           "\n"
14030                                                                           "layout(isolines, point_mode) in;\n"
14031                                                                           "\n"
14032                                                                           "BLOCK_DEFINITION"
14033                                                                           "\n"
14034                                                                           "in  vec4 tcs_tes[];\n"
14035                                                                           "out vec4 tes_gs;\n"
14036                                                                           "\n"
14037                                                                           "void main()\n"
14038                                                                           "{\n"
14039                                                                           "    vec4 result = tcs_tes[0];\n"
14040                                                                           "\n"
14041                                                                           "VARIABLE_USE"
14042                                                                           "\n"
14043                                                                           "    tes_gs += result;\n"
14044                                                                           "}\n"
14045                                                                           "\n";
14046         static const GLchar* vs = "#version 430 core\n"
14047                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14048                                                           "\n"
14049                                                           "in  vec4 in_vs;\n"
14050                                                           "out vec4 vs_tcs;\n"
14051                                                           "\n"
14052                                                           "void main()\n"
14053                                                           "{\n"
14054                                                           "    vs_tcs = in_vs;\n"
14055                                                           "}\n"
14056                                                           "\n";
14057         static const GLchar* vs_tested = "#version 430 core\n"
14058                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14059                                                                          "\n"
14060                                                                          "BLOCK_DEFINITION"
14061                                                                          "\n"
14062                                                                          "in  vec4 in_vs;\n"
14063                                                                          "out vec4 vs_tcs;\n"
14064                                                                          "\n"
14065                                                                          "void main()\n"
14066                                                                          "{\n"
14067                                                                          "    vec4 result = in_vs;\n"
14068                                                                          "\n"
14069                                                                          "VARIABLE_USE"
14070                                                                          "\n"
14071                                                                          "    vs_tcs += result;\n"
14072                                                                          "}\n"
14073                                                                          "\n";
14074
14075         const GLchar* array             = "";
14076         const GLchar* direction = "out";
14077         const GLchar* index             = "";
14078         std::string   source;
14079         testCase&        test_case = m_test_cases[test_case_index];
14080         const GLchar* var_use   = output_use;
14081
14082         if (true == test_case.m_is_input)
14083         {
14084                 direction = "in ";
14085                 var_use   = input_use;
14086         }
14087
14088         if (test_case.m_stage == stage)
14089         {
14090                 size_t position = 0;
14091                 size_t temp;
14092
14093                 switch (stage)
14094                 {
14095                 case Utils::Shader::FRAGMENT:
14096                         source = fs_tested;
14097                         break;
14098                 case Utils::Shader::GEOMETRY:
14099                         source = gs_tested;
14100                         array  = "[]";
14101                         index  = "[0]";
14102                         break;
14103                 case Utils::Shader::TESS_CTRL:
14104                         source = tcs_tested;
14105                         array  = "[]";
14106                         index  = "[gl_InvocationID]";
14107                         break;
14108                 case Utils::Shader::TESS_EVAL:
14109                         source = tes_tested;
14110                         array  = "[]";
14111                         index  = "[0]";
14112                         break;
14113                 case Utils::Shader::VERTEX:
14114                         source = vs_tested;
14115                         break;
14116                 default:
14117                         TCU_FAIL("Invalid enum");
14118                 }
14119
14120                 temp = position;
14121                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14122                 position = temp;
14123                 Utils::replaceToken("DIRECTION", position, direction, source);
14124                 Utils::replaceToken("ARRAY", position, array, source);
14125                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14126
14127                 Utils::replaceAllTokens("INDEX", index, source);
14128         }
14129         else
14130         {
14131                 switch (stage)
14132                 {
14133                 case Utils::Shader::FRAGMENT:
14134                         source = fs;
14135                         break;
14136                 case Utils::Shader::GEOMETRY:
14137                         source = gs;
14138                         break;
14139                 case Utils::Shader::TESS_CTRL:
14140                         source = tcs;
14141                         break;
14142                 case Utils::Shader::TESS_EVAL:
14143                         source = tes;
14144                         break;
14145                 case Utils::Shader::VERTEX:
14146                         source = vs;
14147                         break;
14148                 default:
14149                         TCU_FAIL("Invalid enum");
14150                 }
14151         }
14152
14153         return source;
14154 }
14155
14156 /** Get description of test case
14157  *
14158  * @param test_case_index Index of test case
14159  *
14160  * @return Test case description
14161  **/
14162 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14163 {
14164         std::stringstream stream;
14165         testCase&                 test_case = m_test_cases[test_case_index];
14166
14167         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14168
14169         if (true == test_case.m_is_input)
14170         {
14171                 stream << "input";
14172         }
14173         else
14174         {
14175                 stream << "output";
14176         }
14177
14178         return stream.str();
14179 }
14180
14181 /** Get number of test cases
14182  *
14183  * @return Number of test cases
14184  **/
14185 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14186 {
14187         return static_cast<GLuint>(m_test_cases.size());
14188 }
14189
14190 /** Selects if "compute" stage is relevant for test
14191  *
14192  * @param ignored
14193  *
14194  * @return false
14195  **/
14196 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14197 {
14198         return false;
14199 }
14200
14201 /** Prepare all test cases
14202  *
14203  **/
14204 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14205 {
14206         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14207         {
14208                 if (Utils::Shader::COMPUTE == stage)
14209                 {
14210                         continue;
14211                 }
14212
14213                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14214                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14215
14216                 if (Utils::Shader::VERTEX != stage)
14217                 {
14218                         m_test_cases.push_back(test_case_in);
14219                 }
14220
14221                 if (Utils::Shader::FRAGMENT != stage)
14222                 {
14223                         m_test_cases.push_back(test_case_out);
14224                 }
14225         }
14226 }
14227
14228 /** Constructor
14229  *
14230  * @param context Test framework context
14231  **/
14232 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14233         : NegativeTestBase(context, "varying_location_limit",
14234                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14235 {
14236 }
14237
14238 /** Source for given test case and stage
14239  *
14240  * @param test_case_index Index of test case
14241  * @param stage           Shader stage
14242  *
14243  * @return Shader source
14244  **/
14245 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14246 {
14247         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14248         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14249                                                                          "    {\n"
14250                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14251                                                                          "    }\n";
14252         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14253                                                                           "    if (vec4(0) == result)\n"
14254                                                                           "    {\n"
14255                                                                           "        gokuINDEX = TYPE(1);\n"
14256                                                                           "    }\n";
14257         static const GLchar* fs = "#version 430 core\n"
14258                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14259                                                           "\n"
14260                                                           "in  vec4 gs_fs;\n"
14261                                                           "out vec4 fs_out;\n"
14262                                                           "\n"
14263                                                           "void main()\n"
14264                                                           "{\n"
14265                                                           "    fs_out = gs_fs;\n"
14266                                                           "}\n"
14267                                                           "\n";
14268         static const GLchar* fs_tested = "#version 430 core\n"
14269                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14270                                                                          "\n"
14271                                                                          "VAR_DEFINITION"
14272                                                                          "\n"
14273                                                                          "in  vec4 gs_fs;\n"
14274                                                                          "out vec4 fs_out;\n"
14275                                                                          "\n"
14276                                                                          "void main()\n"
14277                                                                          "{\n"
14278                                                                          "    vec4 result = gs_fs;\n"
14279                                                                          "\n"
14280                                                                          "VARIABLE_USE"
14281                                                                          "\n"
14282                                                                          "    fs_out += result;\n"
14283                                                                          "}\n"
14284                                                                          "\n";
14285         static const GLchar* gs = "#version 430 core\n"
14286                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14287                                                           "\n"
14288                                                           "layout(points)                           in;\n"
14289                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14290                                                           "\n"
14291                                                           "in  vec4 tes_gs[];\n"
14292                                                           "out vec4 gs_fs;\n"
14293                                                           "\n"
14294                                                           "void main()\n"
14295                                                           "{\n"
14296                                                           "    gs_fs = tes_gs[0];\n"
14297                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14298                                                           "    EmitVertex();\n"
14299                                                           "    gs_fs = tes_gs[0];\n"
14300                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14301                                                           "    EmitVertex();\n"
14302                                                           "    gs_fs = tes_gs[0];\n"
14303                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14304                                                           "    EmitVertex();\n"
14305                                                           "    gs_fs = tes_gs[0];\n"
14306                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14307                                                           "    EmitVertex();\n"
14308                                                           "}\n"
14309                                                           "\n";
14310         static const GLchar* gs_tested = "#version 430 core\n"
14311                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14312                                                                          "\n"
14313                                                                          "layout(points)                           in;\n"
14314                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14315                                                                          "\n"
14316                                                                          "VAR_DEFINITION"
14317                                                                          "\n"
14318                                                                          "in  vec4 tes_gs[];\n"
14319                                                                          "out vec4 gs_fs;\n"
14320                                                                          "\n"
14321                                                                          "void main()\n"
14322                                                                          "{\n"
14323                                                                          "    vec4 result = tes_gs[0];\n"
14324                                                                          "\n"
14325                                                                          "VARIABLE_USE"
14326                                                                          "\n"
14327                                                                          "    gs_fs = result;\n"
14328                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14329                                                                          "    EmitVertex();\n"
14330                                                                          "    gs_fs = result;\n"
14331                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14332                                                                          "    EmitVertex();\n"
14333                                                                          "    gs_fs = result;\n"
14334                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14335                                                                          "    EmitVertex();\n"
14336                                                                          "    gs_fs = result;\n"
14337                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14338                                                                          "    EmitVertex();\n"
14339                                                                          "}\n"
14340                                                                          "\n";
14341         static const GLchar* tcs = "#version 430 core\n"
14342                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14343                                                            "\n"
14344                                                            "layout(vertices = 1) out;\n"
14345                                                            "\n"
14346                                                            "in  vec4 vs_tcs[];\n"
14347                                                            "out vec4 tcs_tes[];\n"
14348                                                            "\n"
14349                                                            "void main()\n"
14350                                                            "{\n"
14351                                                            "\n"
14352                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14353                                                            "\n"
14354                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14355                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14356                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14357                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14358                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14359                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14360                                                            "}\n"
14361                                                            "\n";
14362         static const GLchar* tcs_tested = "#version 430 core\n"
14363                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14364                                                                           "\n"
14365                                                                           "layout(vertices = 1) out;\n"
14366                                                                           "\n"
14367                                                                           "VAR_DEFINITION"
14368                                                                           "\n"
14369                                                                           "in  vec4 vs_tcs[];\n"
14370                                                                           "out vec4 tcs_tes[];\n"
14371                                                                           "\n"
14372                                                                           "void main()\n"
14373                                                                           "{\n"
14374                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14375                                                                           "\n"
14376                                                                           "VARIABLE_USE"
14377                                                                           "\n"
14378                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14379                                                                           "\n"
14380                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14381                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14382                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14383                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14384                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14385                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14386                                                                           "}\n"
14387                                                                           "\n";
14388         static const GLchar* tes = "#version 430 core\n"
14389                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14390                                                            "\n"
14391                                                            "layout(isolines, point_mode) in;\n"
14392                                                            "\n"
14393                                                            "in  vec4 tcs_tes[];\n"
14394                                                            "out vec4 tes_gs;\n"
14395                                                            "\n"
14396                                                            "void main()\n"
14397                                                            "{\n"
14398                                                            "    tes_gs = tcs_tes[0];\n"
14399                                                            "}\n"
14400                                                            "\n";
14401         static const GLchar* tes_tested = "#version 430 core\n"
14402                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14403                                                                           "\n"
14404                                                                           "layout(isolines, point_mode) in;\n"
14405                                                                           "\n"
14406                                                                           "VAR_DEFINITION"
14407                                                                           "\n"
14408                                                                           "in  vec4 tcs_tes[];\n"
14409                                                                           "out vec4 tes_gs;\n"
14410                                                                           "\n"
14411                                                                           "void main()\n"
14412                                                                           "{\n"
14413                                                                           "    vec4 result = tcs_tes[0];\n"
14414                                                                           "\n"
14415                                                                           "VARIABLE_USE"
14416                                                                           "\n"
14417                                                                           "    tes_gs += result;\n"
14418                                                                           "}\n"
14419                                                                           "\n";
14420         static const GLchar* vs = "#version 430 core\n"
14421                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14422                                                           "\n"
14423                                                           "in  vec4 in_vs;\n"
14424                                                           "out vec4 vs_tcs;\n"
14425                                                           "\n"
14426                                                           "void main()\n"
14427                                                           "{\n"
14428                                                           "    vs_tcs = in_vs;\n"
14429                                                           "}\n"
14430                                                           "\n";
14431         static const GLchar* vs_tested = "#version 430 core\n"
14432                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14433                                                                          "\n"
14434                                                                          "VAR_DEFINITION"
14435                                                                          "\n"
14436                                                                          "in  vec4 in_vs;\n"
14437                                                                          "out vec4 vs_tcs;\n"
14438                                                                          "\n"
14439                                                                          "void main()\n"
14440                                                                          "{\n"
14441                                                                          "    vec4 result = in_vs;\n"
14442                                                                          "\n"
14443                                                                          "VARIABLE_USE"
14444                                                                          "\n"
14445                                                                          "    vs_tcs += result;\n"
14446                                                                          "}\n"
14447                                                                          "\n";
14448
14449         std::string source;
14450         testCase&   test_case = m_test_cases[test_case_index];
14451
14452         if (test_case.m_stage == stage)
14453         {
14454                 const GLchar*                    array = "";
14455                 GLchar                                   buffer[16];
14456                 const GLchar*                    direction = "in ";
14457                 const GLchar*                    flat     = "";
14458                 const GLchar*                    index   = "";
14459                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14460                 size_t                                   position  = 0;
14461                 size_t                                   temp;
14462                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14463                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14464                 const GLchar*                    var_use   = input_use;
14465
14466                 if (false == test_case.m_is_input)
14467                 {
14468                         direction = "out";
14469                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14470                         storage   = Utils::Variable::VARYING_OUTPUT;
14471                         var_use   = output_use;
14472                 }
14473
14474                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14475                 {
14476                         flat = "flat";
14477                 }
14478
14479                 sprintf(buffer, "%d", last);
14480
14481                 switch (stage)
14482                 {
14483                 case Utils::Shader::FRAGMENT:
14484                         source = fs_tested;
14485                         break;
14486                 case Utils::Shader::GEOMETRY:
14487                         source = gs_tested;
14488                         array  = "[]";
14489                         index  = "[0]";
14490                         break;
14491                 case Utils::Shader::TESS_CTRL:
14492                         source = tcs_tested;
14493                         array  = "[]";
14494                         index  = "[gl_InvocationID]";
14495                         break;
14496                 case Utils::Shader::TESS_EVAL:
14497                         source = tes_tested;
14498                         array  = "[]";
14499                         index  = "[0]";
14500                         break;
14501                 case Utils::Shader::VERTEX:
14502                         source = vs_tested;
14503                         break;
14504                 default:
14505                         TCU_FAIL("Invalid enum");
14506                 }
14507
14508                 temp = position;
14509                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14510                 position = temp;
14511                 Utils::replaceToken("LAST", position, buffer, source);
14512                 Utils::replaceToken("FLAT", position, flat, source);
14513                 Utils::replaceToken("DIRECTION", position, direction, source);
14514                 Utils::replaceToken("ARRAY", position, array, source);
14515                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14516
14517                 Utils::replaceAllTokens("TYPE", type_name, source);
14518                 Utils::replaceAllTokens("INDEX", index, source);
14519         }
14520         else
14521         {
14522                 switch (stage)
14523                 {
14524                 case Utils::Shader::FRAGMENT:
14525                         source = fs;
14526                         break;
14527                 case Utils::Shader::GEOMETRY:
14528                         source = gs;
14529                         break;
14530                 case Utils::Shader::TESS_CTRL:
14531                         source = tcs;
14532                         break;
14533                 case Utils::Shader::TESS_EVAL:
14534                         source = tes;
14535                         break;
14536                 case Utils::Shader::VERTEX:
14537                         source = vs;
14538                         break;
14539                 default:
14540                         TCU_FAIL("Invalid enum");
14541                 }
14542         }
14543
14544         return source;
14545 }
14546
14547 /** Get description of test case
14548  *
14549  * @param test_case_index Index of test case
14550  *
14551  * @return Test case description
14552  **/
14553 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14554 {
14555         std::stringstream stream;
14556         testCase&                 test_case = m_test_cases[test_case_index];
14557
14558         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14559                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14560
14561         if (true == test_case.m_is_input)
14562         {
14563                 stream << "input";
14564         }
14565         else
14566         {
14567                 stream << "output";
14568         }
14569
14570         return stream.str();
14571 }
14572
14573 /** Get number of test cases
14574  *
14575  * @return Number of test cases
14576  **/
14577 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14578 {
14579         return static_cast<GLuint>(m_test_cases.size());
14580 }
14581
14582 /** Selects if "compute" stage is relevant for test
14583  *
14584  * @param ignored
14585  *
14586  * @return false
14587  **/
14588 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14589 {
14590         return false;
14591 }
14592
14593 /** Prepare all test cases
14594  *
14595  **/
14596 void VaryingLocationLimitTest::testInit()
14597 {
14598         const GLuint n_types = getTypesNumber();
14599
14600         for (GLuint i = 0; i < n_types; ++i)
14601         {
14602                 const Utils::Type& type = getType(i);
14603
14604                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14605                 {
14606                         if (Utils::Shader::COMPUTE == stage)
14607                         {
14608                                 continue;
14609                         }
14610
14611                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14612                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14613
14614                         m_test_cases.push_back(test_case_in);
14615
14616                         if (Utils::Shader::FRAGMENT != stage)
14617                         {
14618                                 m_test_cases.push_back(test_case_out);
14619                         }
14620                 }
14621         }
14622 }
14623
14624 /** Constructor
14625  *
14626  * @param context Test framework context
14627  **/
14628 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14629         : VaryingLocationsTest(context, "varying_components",
14630                                                    "Test verifies that input and output components are respected")
14631 {
14632 }
14633
14634 /** Constructor
14635  *
14636  * @param context          Test framework context
14637  * @param test_name        Name of test
14638  * @param test_description Description of test
14639  **/
14640 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14641                                                                                          const glw::GLchar* test_description)
14642         : VaryingLocationsTest(context, test_name, test_description)
14643 {
14644 }
14645
14646 /** Get interface of program
14647  *
14648  * @param test_case_index     Test case
14649  * @param program_interface   Interface of program
14650  * @param varying_passthrough Collection of connections between in and out variables
14651  **/
14652 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14653                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14654 {
14655         GLuint                             array_length = getArrayLength();
14656         const testCase&            test_case    = m_test_cases[test_case_index];
14657         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14658         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14659
14660         /* Zero means no array, however we still need at least 1 slot of data */
14661         if (0 == array_length)
14662         {
14663                 array_length += 1;
14664         }
14665
14666         /* Generate data */
14667         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14668         const size_t                            data_size = data.size();
14669
14670         /* Prepare data for variables */
14671         m_data.resize(array_length * data_size);
14672
14673         GLubyte*           dst = &m_data[0];
14674         const GLubyte* src = &data[0];
14675
14676         for (GLuint i = 0; i < array_length; ++i)
14677         {
14678                 memcpy(dst + data_size * i, src, data_size);
14679         }
14680
14681         /* Prepare interface for each stage */
14682         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14683         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14684         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14685         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14686         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14687 }
14688
14689 /** Get type name
14690  *
14691  * @param test_case_index Index of test case
14692  *
14693  * @return Name of type test in test_case_index
14694  **/
14695 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14696 {
14697         std::string name;
14698
14699         const testCase& test_case = m_test_cases[test_case_index];
14700
14701         name = "Type: ";
14702
14703         switch (test_case.m_type)
14704         {
14705         case Utils::Type::Double:
14706                 name.append(Utils::Type::_double.GetGLSLTypeName());
14707                 break;
14708         case Utils::Type::Float:
14709                 name.append(Utils::Type::_float.GetGLSLTypeName());
14710                 break;
14711         case Utils::Type::Int:
14712                 name.append(Utils::Type::_int.GetGLSLTypeName());
14713                 break;
14714         case Utils::Type::Uint:
14715                 name.append(Utils::Type::uint.GetGLSLTypeName());
14716                 break;
14717         }
14718
14719         name.append(", layout: ");
14720
14721         switch (test_case.m_layout)
14722         {
14723         case GVEC4:
14724                 name.append("GVEC4");
14725                 break;
14726         case SCALAR_GVEC3:
14727                 name.append("SCALAR_GVEC3");
14728                 break;
14729         case GVEC3_SCALAR:
14730                 name.append("GVEC3_SCALAR");
14731                 break;
14732         case GVEC2_GVEC2:
14733                 name.append("GVEC2_GVEC2");
14734                 break;
14735         case GVEC2_SCALAR_SCALAR:
14736                 name.append("GVEC2_SCALAR_SCALAR");
14737                 break;
14738         case SCALAR_GVEC2_SCALAR:
14739                 name.append("SCALAR_GVEC2_SCALAR");
14740                 break;
14741         case SCALAR_SCALAR_GVEC2:
14742                 name.append("SCALAR_SCALAR_GVEC2");
14743                 break;
14744         case SCALAR_SCALAR_SCALAR_SCALAR:
14745                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14746                 break;
14747         }
14748
14749         return name;
14750 }
14751
14752 /** Returns number of types to test
14753  *
14754  * @return Number of types, 34
14755  **/
14756 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14757 {
14758         return static_cast<GLuint>(m_test_cases.size());
14759 }
14760
14761 /* Prepare test cases */
14762 void VaryingComponentsTest::testInit()
14763 {
14764         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Double));
14765         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Double));
14766         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Double));
14767         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Double));
14768         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Double));
14769         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Double));
14770         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Double));
14771         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Double));
14772
14773         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14774         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14775         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14776         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14777         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14778         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14779         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14780         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14781
14782         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14783         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14784         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14785         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14786         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14787         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14788         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14789         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14790
14791         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14792         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14793         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14794         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14795         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14796         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14797         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14798         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14799 }
14800
14801 /** Inform that test use components
14802  *
14803  * @param ignored
14804  *
14805  * @return true
14806  **/
14807 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14808 {
14809         return true;
14810 }
14811
14812 /** Get length of arrays that should be used during test
14813  *
14814  * @return 0u - no array at all
14815  **/
14816 GLuint VaryingComponentsTest::getArrayLength()
14817 {
14818         return 0;
14819 }
14820
14821 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14822 {
14823         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14824
14825         globals.append("const uint comp_x = 0u;\n"
14826                                    "const uint comp_y = 1u;\n"
14827                                    "const uint comp_z = 2u;\n"
14828                                    "const uint comp_w = 3u;\n");
14829
14830         return globals;
14831 }
14832
14833 /**
14834  *
14835  **/
14836 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14837                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14838 {
14839         GLchar            buffer[16];
14840         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14841         size_t            position = 0;
14842         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14843
14844         Utils::replaceToken("PREFIX", position, prefix, result);
14845         Utils::replaceToken("NAME", position, name, result);
14846
14847         sprintf(buffer, "%d", location);
14848         Utils::replaceToken("LOCATION", position, buffer, result);
14849
14850         sprintf(buffer, "%d", component);
14851         Utils::replaceToken("COMPONENT", position, buffer, result);
14852
14853         return result;
14854 }
14855
14856 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14857                                                                                                          const glw::GLchar* interpolation)
14858 {
14859         size_t          position   = 0;
14860         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14861
14862         Utils::replaceToken("LOCATION", position, location, qualifiers);
14863         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14864         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14865
14866         return qualifiers;
14867 }
14868
14869 /**
14870  *
14871  **/
14872 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14873                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14874                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14875 {
14876         const GLuint                    array_length = getArrayLength();
14877         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14878         descriptor                              desc_in[8];
14879         descriptor                              desc_out[8];
14880         const GLuint                    first_in_loc  = 0;
14881         const GLuint                    first_out_loc = 0;
14882         const GLchar*                   interpolation = "";
14883         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14884         GLuint                                  last_out_loc  = 0;
14885         GLuint                                  n_desc            = 0;
14886         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14887
14888         /* Select interpolation */
14889         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14890         {
14891                 interpolation = " flat";
14892         }
14893
14894         if (Utils::Shader::FRAGMENT != stage)
14895         {
14896                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14897         }
14898
14899         switch (test_case.m_layout)
14900         {
14901         case GVEC4:
14902                 n_desc = 2;
14903                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14904                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14905
14906                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14907                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14908                 break;
14909         case SCALAR_GVEC3:
14910                 n_desc = 4;
14911                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14912                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14913                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14914                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14915
14916                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14917                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14918                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14919                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14920                 break;
14921         case GVEC3_SCALAR:
14922                 n_desc = 4;
14923                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14924                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14925                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14926                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14927
14928                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14929                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14930                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14931                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14932                 break;
14933         case GVEC2_GVEC2:
14934                 n_desc = 4;
14935                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14936                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14937                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14938                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14939
14940                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14941                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14942                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14943                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14944                 break;
14945         case GVEC2_SCALAR_SCALAR:
14946                 n_desc = 6;
14947                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14948                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14949                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
14950                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14951                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14952                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14953
14954                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14955                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14956                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
14957                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
14958                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14959                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14960                 break;
14961         case SCALAR_GVEC2_SCALAR:
14962                 n_desc = 6;
14963                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14964                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14965                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
14966                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
14967                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14968                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14969
14970                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14971                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14972                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
14973                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
14974                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14975                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14976                 break;
14977         case SCALAR_SCALAR_GVEC2:
14978                 n_desc = 6;
14979                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14980                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14981                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
14982                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
14983                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14984                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14985
14986                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14987                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14988                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
14989                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
14990                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14991                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14992                 break;
14993         case SCALAR_SCALAR_SCALAR_SCALAR:
14994                 n_desc = 8;
14995                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14996                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14997                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
14998                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
14999                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15000                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15001                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15002                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15003
15004                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15005                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15006                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15007                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15008                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15009                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15010                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15011                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15012                 break;
15013         }
15014
15015         for (GLuint i = 0; i < n_desc; ++i)
15016         {
15017                 const descriptor& in_desc = desc_in[i];
15018
15019                 Utils::Variable* in =
15020                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15021
15022                 if (Utils::Shader::FRAGMENT != stage)
15023                 {
15024                         const descriptor& out_desc = desc_out[i];
15025
15026                         Utils::Variable* out =
15027                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15028
15029                         varying_passthrough.Add(stage, in, out);
15030                 }
15031         }
15032
15033         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15034 }
15035
15036 /**
15037  *
15038  **/
15039 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15040                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15041                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15042 {
15043         const GLuint       array_length   = getArrayLength();
15044         const GLuint       component_size = basic_type.GetSize();
15045         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15046         const GLuint       offset                 = desc.m_component * component_size;
15047         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15048         const GLuint       size                   = desc.m_n_rows * component_size;
15049         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15050         Utils::Variable*   var                    = 0;
15051
15052         if (Utils::Variable::VARYING_INPUT == storage)
15053         {
15054                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15055                                            desc.m_location /* expected_location */, type, /* built_in_type */
15056                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15057                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15058         }
15059         else
15060         {
15061                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15062                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15063                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15064                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15065         }
15066
15067         return var;
15068 }
15069
15070 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15071                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15072                                                                                            const glw::GLchar* name)
15073 {
15074         m_component             = component;
15075         m_component_str = component_str;
15076         m_location              = location;
15077         m_location_str  = location_str;
15078         m_n_rows                = n_rows;
15079         m_name                  = name;
15080 }
15081
15082 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15083         : m_layout(layout), m_type(type)
15084 {
15085 }
15086
15087 /** Constructor
15088  *
15089  * @param context Test framework context
15090  **/
15091 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15092         : VaryingComponentsTest(context, "varying_array_components",
15093                                                         "Test verifies that input and output components are respected for arrays")
15094 {
15095 }
15096
15097 /** Get length of arrays that should be used during test
15098  *
15099  * @return 4u
15100  **/
15101 GLuint VaryingArrayComponentsTest::getArrayLength()
15102 {
15103         return 4u;
15104 }
15105
15106 /** Constructor
15107  *
15108  * @param context Test framework context
15109  **/
15110 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15111         : NegativeTestBase(context, "varying_exceeding_components",
15112                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15113 {
15114 }
15115
15116 /** Source for given test case and stage
15117  *
15118  * @param test_case_index Index of test case
15119  * @param stage           Shader stage
15120  *
15121  * @return Shader source
15122  **/
15123 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15124 {
15125         static const GLchar* var_definition_arr =
15126                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15127         static const GLchar* var_definition_one =
15128                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15129         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15130                                                                                  "    {\n"
15131                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15132                                                                                  "    }\n";
15133         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15134                                                                                  "    {\n"
15135                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15136                                                                                  "    }\n";
15137         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15138                                                                                   "    if (vec4(0) == result)\n"
15139                                                                                   "    {\n"
15140                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15141                                                                                   "    }\n";
15142         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15143                                                                                   "    if (vec4(0) == result)\n"
15144                                                                                   "    {\n"
15145                                                                                   "        gokuINDEX = TYPE(1);\n"
15146                                                                                   "    }\n";
15147         static const GLchar* fs = "#version 430 core\n"
15148                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15149                                                           "\n"
15150                                                           "in  vec4 gs_fs;\n"
15151                                                           "out vec4 fs_out;\n"
15152                                                           "\n"
15153                                                           "void main()\n"
15154                                                           "{\n"
15155                                                           "    fs_out = gs_fs;\n"
15156                                                           "}\n"
15157                                                           "\n";
15158         static const GLchar* fs_tested = "#version 430 core\n"
15159                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15160                                                                          "\n"
15161                                                                          "VAR_DEFINITION"
15162                                                                          "\n"
15163                                                                          "in  vec4 gs_fs;\n"
15164                                                                          "out vec4 fs_out;\n"
15165                                                                          "\n"
15166                                                                          "void main()\n"
15167                                                                          "{\n"
15168                                                                          "    vec4 result = gs_fs;\n"
15169                                                                          "\n"
15170                                                                          "VARIABLE_USE"
15171                                                                          "\n"
15172                                                                          "    fs_out += result;\n"
15173                                                                          "}\n"
15174                                                                          "\n";
15175         static const GLchar* gs = "#version 430 core\n"
15176                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15177                                                           "\n"
15178                                                           "layout(points)                           in;\n"
15179                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15180                                                           "\n"
15181                                                           "in  vec4 tes_gs[];\n"
15182                                                           "out vec4 gs_fs;\n"
15183                                                           "\n"
15184                                                           "void main()\n"
15185                                                           "{\n"
15186                                                           "    gs_fs = tes_gs[0];\n"
15187                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15188                                                           "    EmitVertex();\n"
15189                                                           "    gs_fs = tes_gs[0];\n"
15190                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15191                                                           "    EmitVertex();\n"
15192                                                           "    gs_fs = tes_gs[0];\n"
15193                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15194                                                           "    EmitVertex();\n"
15195                                                           "    gs_fs = tes_gs[0];\n"
15196                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15197                                                           "    EmitVertex();\n"
15198                                                           "}\n"
15199                                                           "\n";
15200         static const GLchar* gs_tested = "#version 430 core\n"
15201                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15202                                                                          "\n"
15203                                                                          "layout(points)                           in;\n"
15204                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15205                                                                          "\n"
15206                                                                          "VAR_DEFINITION"
15207                                                                          "\n"
15208                                                                          "in  vec4 tes_gs[];\n"
15209                                                                          "out vec4 gs_fs;\n"
15210                                                                          "\n"
15211                                                                          "void main()\n"
15212                                                                          "{\n"
15213                                                                          "    vec4 result = tes_gs[0];\n"
15214                                                                          "\n"
15215                                                                          "VARIABLE_USE"
15216                                                                          "\n"
15217                                                                          "    gs_fs = result;\n"
15218                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15219                                                                          "    EmitVertex();\n"
15220                                                                          "    gs_fs = result;\n"
15221                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15222                                                                          "    EmitVertex();\n"
15223                                                                          "    gs_fs = result;\n"
15224                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15225                                                                          "    EmitVertex();\n"
15226                                                                          "    gs_fs = result;\n"
15227                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15228                                                                          "    EmitVertex();\n"
15229                                                                          "}\n"
15230                                                                          "\n";
15231         static const GLchar* tcs = "#version 430 core\n"
15232                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15233                                                            "\n"
15234                                                            "layout(vertices = 1) out;\n"
15235                                                            "\n"
15236                                                            "in  vec4 vs_tcs[];\n"
15237                                                            "out vec4 tcs_tes[];\n"
15238                                                            "\n"
15239                                                            "void main()\n"
15240                                                            "{\n"
15241                                                            "\n"
15242                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15243                                                            "\n"
15244                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15245                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15246                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15247                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15248                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15249                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15250                                                            "}\n"
15251                                                            "\n";
15252         static const GLchar* tcs_tested = "#version 430 core\n"
15253                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15254                                                                           "\n"
15255                                                                           "layout(vertices = 1) out;\n"
15256                                                                           "\n"
15257                                                                           "VAR_DEFINITION"
15258                                                                           "\n"
15259                                                                           "in  vec4 vs_tcs[];\n"
15260                                                                           "out vec4 tcs_tes[];\n"
15261                                                                           "\n"
15262                                                                           "void main()\n"
15263                                                                           "{\n"
15264                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15265                                                                           "\n"
15266                                                                           "VARIABLE_USE"
15267                                                                           "\n"
15268                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15269                                                                           "\n"
15270                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15271                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15272                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15273                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15274                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15275                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15276                                                                           "}\n"
15277                                                                           "\n";
15278         static const GLchar* tes = "#version 430 core\n"
15279                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15280                                                            "\n"
15281                                                            "layout(isolines, point_mode) in;\n"
15282                                                            "\n"
15283                                                            "in  vec4 tcs_tes[];\n"
15284                                                            "out vec4 tes_gs;\n"
15285                                                            "\n"
15286                                                            "void main()\n"
15287                                                            "{\n"
15288                                                            "    tes_gs = tcs_tes[0];\n"
15289                                                            "}\n"
15290                                                            "\n";
15291         static const GLchar* tes_tested = "#version 430 core\n"
15292                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15293                                                                           "\n"
15294                                                                           "layout(isolines, point_mode) in;\n"
15295                                                                           "\n"
15296                                                                           "VAR_DEFINITION"
15297                                                                           "\n"
15298                                                                           "in  vec4 tcs_tes[];\n"
15299                                                                           "out vec4 tes_gs;\n"
15300                                                                           "\n"
15301                                                                           "void main()\n"
15302                                                                           "{\n"
15303                                                                           "    vec4 result = tcs_tes[0];\n"
15304                                                                           "\n"
15305                                                                           "VARIABLE_USE"
15306                                                                           "\n"
15307                                                                           "    tes_gs += result;\n"
15308                                                                           "}\n"
15309                                                                           "\n";
15310         static const GLchar* vs = "#version 430 core\n"
15311                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15312                                                           "\n"
15313                                                           "in  vec4 in_vs;\n"
15314                                                           "out vec4 vs_tcs;\n"
15315                                                           "\n"
15316                                                           "void main()\n"
15317                                                           "{\n"
15318                                                           "    vs_tcs = in_vs;\n"
15319                                                           "}\n"
15320                                                           "\n";
15321         static const GLchar* vs_tested = "#version 430 core\n"
15322                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15323                                                                          "\n"
15324                                                                          "VAR_DEFINITION"
15325                                                                          "\n"
15326                                                                          "in  vec4 in_vs;\n"
15327                                                                          "out vec4 vs_tcs;\n"
15328                                                                          "\n"
15329                                                                          "void main()\n"
15330                                                                          "{\n"
15331                                                                          "    vec4 result = in_vs;\n"
15332                                                                          "\n"
15333                                                                          "VARIABLE_USE"
15334                                                                          "\n"
15335                                                                          "    vs_tcs += result;\n"
15336                                                                          "}\n"
15337                                                                          "\n";
15338
15339         std::string source;
15340         testCase&   test_case = m_test_cases[test_case_index];
15341
15342         if (test_case.m_stage == stage)
15343         {
15344                 const GLchar* array = "";
15345                 GLchar            buffer[16];
15346                 const GLchar* var_definition = 0;
15347                 const GLchar* direction          = "in ";
15348                 const GLchar* index                      = "";
15349                 size_t            position               = 0;
15350                 size_t            temp;
15351                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15352                 const GLchar* var_use   = 0;
15353
15354                 if (false == test_case.m_is_input)
15355                 {
15356                         direction = "out";
15357
15358                         if (false == test_case.m_is_array)
15359                         {
15360                                 var_definition = var_definition_one;
15361                                 var_use            = output_use_one;
15362                         }
15363                         else
15364                         {
15365                                 var_definition = var_definition_arr;
15366                                 var_use            = output_use_arr;
15367                         }
15368                 }
15369                 else
15370                 {
15371                         if (false == test_case.m_is_array)
15372                         {
15373                                 var_definition = var_definition_one;
15374                                 var_use            = input_use_one;
15375                         }
15376                         else
15377                         {
15378                                 var_definition = var_definition_arr;
15379                                 var_use            = input_use_arr;
15380                         }
15381                 }
15382
15383                 sprintf(buffer, "%d", test_case.m_component);
15384
15385                 switch (stage)
15386                 {
15387                 case Utils::Shader::FRAGMENT:
15388                         source = fs_tested;
15389                         break;
15390                 case Utils::Shader::GEOMETRY:
15391                         source = gs_tested;
15392                         array  = "[]";
15393                         index  = "[0]";
15394                         break;
15395                 case Utils::Shader::TESS_CTRL:
15396                         source = tcs_tested;
15397                         array  = "[]";
15398                         index  = "[gl_InvocationID]";
15399                         break;
15400                 case Utils::Shader::TESS_EVAL:
15401                         source = tes_tested;
15402                         array  = "[]";
15403                         index  = "[0]";
15404                         break;
15405                 case Utils::Shader::VERTEX:
15406                         source = vs_tested;
15407                         break;
15408                 default:
15409                         TCU_FAIL("Invalid enum");
15410                 }
15411
15412                 temp = position;
15413                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15414                 position = temp;
15415                 Utils::replaceToken("COMPONENT", position, buffer, source);
15416                 Utils::replaceToken("DIRECTION", position, direction, source);
15417                 Utils::replaceToken("ARRAY", position, array, source);
15418                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15419
15420                 Utils::replaceAllTokens("TYPE", type_name, source);
15421                 Utils::replaceAllTokens("INDEX", index, source);
15422         }
15423         else
15424         {
15425                 switch (stage)
15426                 {
15427                 case Utils::Shader::FRAGMENT:
15428                         source = fs;
15429                         break;
15430                 case Utils::Shader::GEOMETRY:
15431                         source = gs;
15432                         break;
15433                 case Utils::Shader::TESS_CTRL:
15434                         source = tcs;
15435                         break;
15436                 case Utils::Shader::TESS_EVAL:
15437                         source = tes;
15438                         break;
15439                 case Utils::Shader::VERTEX:
15440                         source = vs;
15441                         break;
15442                 default:
15443                         TCU_FAIL("Invalid enum");
15444                 }
15445         }
15446
15447         return source;
15448 }
15449
15450 /** Get description of test case
15451  *
15452  * @param test_case_index Index of test case
15453  *
15454  * @return Test case description
15455  **/
15456 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15457 {
15458         std::stringstream stream;
15459         testCase&                 test_case = m_test_cases[test_case_index];
15460
15461         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15462                    << " type: " << test_case.m_type.GetGLSLTypeName();
15463
15464         if (true == test_case.m_is_array)
15465         {
15466                 stream << "[1]";
15467         }
15468
15469         stream << ", direction: ";
15470
15471         if (true == test_case.m_is_input)
15472         {
15473                 stream << "input";
15474         }
15475         else
15476         {
15477                 stream << "output";
15478         }
15479
15480         stream << ", component: " << test_case.m_component;
15481
15482         return stream.str();
15483 }
15484
15485 /** Get number of test cases
15486  *
15487  * @return Number of test cases
15488  **/
15489 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15490 {
15491         return static_cast<GLuint>(m_test_cases.size());
15492 }
15493
15494 /** Selects if "compute" stage is relevant for test
15495  *
15496  * @param ignored
15497  *
15498  * @return false
15499  **/
15500 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15501 {
15502         return false;
15503 }
15504
15505 /** Prepare all test cases
15506  *
15507  **/
15508 void VaryingExceedingComponentsTest::testInit()
15509 {
15510         static const GLuint n_components_per_location = 4;
15511         const GLuint            n_types                                   = getTypesNumber();
15512
15513         for (GLuint i = 0; i < n_types; ++i)
15514         {
15515                 const Utils::Type& type                          = getType(i);
15516                 const GLuint       n_req_components  = type.m_n_rows;
15517                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15518                 const GLuint       invalid_component = valid_component + 1;
15519
15520                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15521                 {
15522                         if (Utils::Shader::COMPUTE == stage)
15523                         {
15524                                 continue;
15525                         }
15526
15527                         /* Component cannot be used for matrices */
15528                         if (1 != type.m_n_columns)
15529                         {
15530                                 continue;
15531                         }
15532
15533                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15534                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15535                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15536                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15537
15538                         m_test_cases.push_back(test_case_in_arr);
15539                         m_test_cases.push_back(test_case_in_one);
15540
15541                         if (Utils::Shader::FRAGMENT != stage)
15542                         {
15543                                 m_test_cases.push_back(test_case_out_arr);
15544                                 m_test_cases.push_back(test_case_out_one);
15545                         }
15546                 }
15547         }
15548 }
15549
15550 /** Constructor
15551  *
15552  * @param context Test framework context
15553  **/
15554 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15555         : NegativeTestBase(context, "varying_component_without_location",
15556                                            "Test verifies that compiler reports error when component qualifier is used without location")
15557 {
15558 }
15559
15560 /** Source for given test case and stage
15561  *
15562  * @param test_case_index Index of test case
15563  * @param stage           Shader stage
15564  *
15565  * @return Shader source
15566  **/
15567 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15568 {
15569         static const GLchar* var_definition = "layout (component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15570         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15571                                                                          "    {\n"
15572                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15573                                                                          "    }\n";
15574         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15575                                                                           "    if (vec4(0) == result)\n"
15576                                                                           "    {\n"
15577                                                                           "        gokuINDEX = TYPE(1);\n"
15578                                                                           "    }\n";
15579         static const GLchar* fs = "#version 430 core\n"
15580                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15581                                                           "\n"
15582                                                           "in  vec4 gs_fs;\n"
15583                                                           "out vec4 fs_out;\n"
15584                                                           "\n"
15585                                                           "void main()\n"
15586                                                           "{\n"
15587                                                           "    fs_out = gs_fs;\n"
15588                                                           "}\n"
15589                                                           "\n";
15590         static const GLchar* fs_tested = "#version 430 core\n"
15591                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15592                                                                          "\n"
15593                                                                          "VAR_DEFINITION"
15594                                                                          "\n"
15595                                                                          "in  vec4 gs_fs;\n"
15596                                                                          "out vec4 fs_out;\n"
15597                                                                          "\n"
15598                                                                          "void main()\n"
15599                                                                          "{\n"
15600                                                                          "    vec4 result = gs_fs;\n"
15601                                                                          "\n"
15602                                                                          "VARIABLE_USE"
15603                                                                          "\n"
15604                                                                          "    fs_out += result;\n"
15605                                                                          "}\n"
15606                                                                          "\n";
15607         static const GLchar* gs = "#version 430 core\n"
15608                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15609                                                           "\n"
15610                                                           "layout(points)                           in;\n"
15611                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15612                                                           "\n"
15613                                                           "in  vec4 tes_gs[];\n"
15614                                                           "out vec4 gs_fs;\n"
15615                                                           "\n"
15616                                                           "void main()\n"
15617                                                           "{\n"
15618                                                           "    gs_fs = tes_gs[0];\n"
15619                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15620                                                           "    EmitVertex();\n"
15621                                                           "    gs_fs = tes_gs[0];\n"
15622                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15623                                                           "    EmitVertex();\n"
15624                                                           "    gs_fs = tes_gs[0];\n"
15625                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15626                                                           "    EmitVertex();\n"
15627                                                           "    gs_fs = tes_gs[0];\n"
15628                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15629                                                           "    EmitVertex();\n"
15630                                                           "}\n"
15631                                                           "\n";
15632         static const GLchar* gs_tested = "#version 430 core\n"
15633                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15634                                                                          "\n"
15635                                                                          "layout(points)                           in;\n"
15636                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15637                                                                          "\n"
15638                                                                          "VAR_DEFINITION"
15639                                                                          "\n"
15640                                                                          "in  vec4 tes_gs[];\n"
15641                                                                          "out vec4 gs_fs;\n"
15642                                                                          "\n"
15643                                                                          "void main()\n"
15644                                                                          "{\n"
15645                                                                          "    vec4 result = tes_gs[0];\n"
15646                                                                          "\n"
15647                                                                          "VARIABLE_USE"
15648                                                                          "\n"
15649                                                                          "    gs_fs = result;\n"
15650                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15651                                                                          "    EmitVertex();\n"
15652                                                                          "    gs_fs = result;\n"
15653                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15654                                                                          "    EmitVertex();\n"
15655                                                                          "    gs_fs = result;\n"
15656                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15657                                                                          "    EmitVertex();\n"
15658                                                                          "    gs_fs = result;\n"
15659                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15660                                                                          "    EmitVertex();\n"
15661                                                                          "}\n"
15662                                                                          "\n";
15663         static const GLchar* tcs = "#version 430 core\n"
15664                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15665                                                            "\n"
15666                                                            "layout(vertices = 1) out;\n"
15667                                                            "\n"
15668                                                            "in  vec4 vs_tcs[];\n"
15669                                                            "out vec4 tcs_tes[];\n"
15670                                                            "\n"
15671                                                            "void main()\n"
15672                                                            "{\n"
15673                                                            "\n"
15674                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15675                                                            "\n"
15676                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15677                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15678                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15679                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15680                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15681                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15682                                                            "}\n"
15683                                                            "\n";
15684         static const GLchar* tcs_tested = "#version 430 core\n"
15685                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15686                                                                           "\n"
15687                                                                           "layout(vertices = 1) out;\n"
15688                                                                           "\n"
15689                                                                           "VAR_DEFINITION"
15690                                                                           "\n"
15691                                                                           "in  vec4 vs_tcs[];\n"
15692                                                                           "out vec4 tcs_tes[];\n"
15693                                                                           "\n"
15694                                                                           "void main()\n"
15695                                                                           "{\n"
15696                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15697                                                                           "\n"
15698                                                                           "VARIABLE_USE"
15699                                                                           "\n"
15700                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15701                                                                           "\n"
15702                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15703                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15704                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15705                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15706                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15707                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15708                                                                           "}\n"
15709                                                                           "\n";
15710         static const GLchar* tes = "#version 430 core\n"
15711                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15712                                                            "\n"
15713                                                            "layout(isolines, point_mode) in;\n"
15714                                                            "\n"
15715                                                            "in  vec4 tcs_tes[];\n"
15716                                                            "out vec4 tes_gs;\n"
15717                                                            "\n"
15718                                                            "void main()\n"
15719                                                            "{\n"
15720                                                            "    tes_gs = tcs_tes[0];\n"
15721                                                            "}\n"
15722                                                            "\n";
15723         static const GLchar* tes_tested = "#version 430 core\n"
15724                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15725                                                                           "\n"
15726                                                                           "layout(isolines, point_mode) in;\n"
15727                                                                           "\n"
15728                                                                           "VAR_DEFINITION"
15729                                                                           "\n"
15730                                                                           "in  vec4 tcs_tes[];\n"
15731                                                                           "out vec4 tes_gs;\n"
15732                                                                           "\n"
15733                                                                           "void main()\n"
15734                                                                           "{\n"
15735                                                                           "    vec4 result = tcs_tes[0];\n"
15736                                                                           "\n"
15737                                                                           "VARIABLE_USE"
15738                                                                           "\n"
15739                                                                           "    tes_gs += result;\n"
15740                                                                           "}\n"
15741                                                                           "\n";
15742         static const GLchar* vs = "#version 430 core\n"
15743                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15744                                                           "\n"
15745                                                           "in  vec4 in_vs;\n"
15746                                                           "out vec4 vs_tcs;\n"
15747                                                           "\n"
15748                                                           "void main()\n"
15749                                                           "{\n"
15750                                                           "    vs_tcs = in_vs;\n"
15751                                                           "}\n"
15752                                                           "\n";
15753         static const GLchar* vs_tested = "#version 430 core\n"
15754                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15755                                                                          "\n"
15756                                                                          "VAR_DEFINITION"
15757                                                                          "\n"
15758                                                                          "in  vec4 in_vs;\n"
15759                                                                          "out vec4 vs_tcs;\n"
15760                                                                          "\n"
15761                                                                          "void main()\n"
15762                                                                          "{\n"
15763                                                                          "    vec4 result = in_vs;\n"
15764                                                                          "\n"
15765                                                                          "VARIABLE_USE"
15766                                                                          "\n"
15767                                                                          "    vs_tcs += result;\n"
15768                                                                          "}\n"
15769                                                                          "\n";
15770
15771         std::string source;
15772         testCase&   test_case = m_test_cases[test_case_index];
15773
15774         if (test_case.m_stage == stage)
15775         {
15776                 const GLchar* array = "";
15777                 GLchar            buffer[16];
15778                 const GLchar* direction = "in ";
15779                 const GLchar* index             = "";
15780                 size_t            position  = 0;
15781                 size_t            temp;
15782                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15783                 const GLchar* var_use   = input_use;
15784
15785                 if (false == test_case.m_is_input)
15786                 {
15787                         direction = "out";
15788                         var_use   = output_use;
15789                 }
15790
15791                 sprintf(buffer, "%d", test_case.m_component);
15792
15793                 switch (stage)
15794                 {
15795                 case Utils::Shader::FRAGMENT:
15796                         source = fs_tested;
15797                         break;
15798                 case Utils::Shader::GEOMETRY:
15799                         source = gs_tested;
15800                         array  = "[]";
15801                         index  = "[0]";
15802                         break;
15803                 case Utils::Shader::TESS_CTRL:
15804                         source = tcs_tested;
15805                         array  = "[]";
15806                         index  = "[gl_InvocationID]";
15807                         break;
15808                 case Utils::Shader::TESS_EVAL:
15809                         source = tes_tested;
15810                         array  = "[]";
15811                         index  = "[0]";
15812                         break;
15813                 case Utils::Shader::VERTEX:
15814                         source = vs_tested;
15815                         break;
15816                 default:
15817                         TCU_FAIL("Invalid enum");
15818                 }
15819
15820                 temp = position;
15821                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15822                 position = temp;
15823                 Utils::replaceToken("COMPONENT", position, buffer, source);
15824                 Utils::replaceToken("DIRECTION", position, direction, source);
15825                 Utils::replaceToken("ARRAY", position, array, source);
15826                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15827
15828                 Utils::replaceAllTokens("TYPE", type_name, source);
15829                 Utils::replaceAllTokens("INDEX", index, source);
15830         }
15831         else
15832         {
15833                 switch (stage)
15834                 {
15835                 case Utils::Shader::FRAGMENT:
15836                         source = fs;
15837                         break;
15838                 case Utils::Shader::GEOMETRY:
15839                         source = gs;
15840                         break;
15841                 case Utils::Shader::TESS_CTRL:
15842                         source = tcs;
15843                         break;
15844                 case Utils::Shader::TESS_EVAL:
15845                         source = tes;
15846                         break;
15847                 case Utils::Shader::VERTEX:
15848                         source = vs;
15849                         break;
15850                 default:
15851                         TCU_FAIL("Invalid enum");
15852                 }
15853         }
15854
15855         return source;
15856 }
15857
15858 /** Get description of test case
15859  *
15860  * @param test_case_index Index of test case
15861  *
15862  * @return Test case description
15863  **/
15864 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15865 {
15866         std::stringstream stream;
15867         testCase&                 test_case = m_test_cases[test_case_index];
15868
15869         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15870                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15871
15872         if (true == test_case.m_is_input)
15873         {
15874                 stream << "input";
15875         }
15876         else
15877         {
15878                 stream << "output";
15879         }
15880
15881         stream << ", component: " << test_case.m_component;
15882
15883         return stream.str();
15884 }
15885
15886 /** Get number of test cases
15887  *
15888  * @return Number of test cases
15889  **/
15890 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15891 {
15892         return static_cast<GLuint>(m_test_cases.size());
15893 }
15894
15895 /** Selects if "compute" stage is relevant for test
15896  *
15897  * @param ignored
15898  *
15899  * @return false
15900  **/
15901 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15902 {
15903         return false;
15904 }
15905
15906 /** Prepare all test cases
15907  *
15908  **/
15909 void VaryingComponentWithoutLocationTest::testInit()
15910 {
15911         static const GLuint n_components_per_location = 4;
15912         const GLuint            n_types                                   = getTypesNumber();
15913
15914         for (GLuint i = 0; i < n_types; ++i)
15915         {
15916                 const Utils::Type& type                         = getType(i);
15917                 const GLuint       n_req_components = type.m_n_rows;
15918                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15919
15920                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15921                 {
15922                         if (Utils::Shader::COMPUTE == stage)
15923                         {
15924                                 continue;
15925                         }
15926
15927                         /* Component cannot be used for matrices */
15928                         if (1 != type.m_n_columns)
15929                         {
15930                                 continue;
15931                         }
15932
15933                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
15934                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
15935
15936                         m_test_cases.push_back(test_case_in);
15937
15938                         if (Utils::Shader::FRAGMENT != stage)
15939                         {
15940                                 m_test_cases.push_back(test_case_out);
15941                         }
15942                 }
15943         }
15944 }
15945
15946 /** Constructor
15947  *
15948  * @param context Test framework context
15949  **/
15950 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
15951         : NegativeTestBase(context, "varying_component_of_invalid_type",
15952                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
15953 {
15954 }
15955
15956 /** Source for given test case and stage
15957  *
15958  * @param test_case_index Index of test case
15959  * @param stage           Shader stage
15960  *
15961  * @return Shader source
15962  **/
15963 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15964 {
15965         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15966                                                                                                 "    TYPE member;\n"
15967                                                                                                 "} gokuARRAY[1];\n";
15968         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15969                                                                                                 "    TYPE member;\n"
15970                                                                                                 "} gokuARRAY;\n";
15971         static const GLchar* matrix_definition_arr =
15972                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15973         static const GLchar* matrix_definition_one =
15974                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15975         static const GLchar* struct_definition_arr =
15976                 "struct Goku {\n"
15977                 "    TYPE member;\n"
15978                 "};\n"
15979                 "\n"
15980                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
15981         static const GLchar* struct_definition_one =
15982                 "struct Goku {\n"
15983                 "    TYPE member;\n"
15984                 "};\n"
15985                 "\n"
15986                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
15987         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15988                                                                                                 "    {\n"
15989                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15990                                                                                                 "    }\n";
15991         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15992                                                                                                 "    {\n"
15993                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15994                                                                                                 "    }\n";
15995         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15996                                                                                                  "    if (vec4(0) == result)\n"
15997                                                                                                  "    {\n"
15998                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
15999                                                                                                  "    }\n";
16000         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16001                                                                                                  "    if (vec4(0) == result)\n"
16002                                                                                                  "    {\n"
16003                                                                                                  "        gokuINDEX = TYPE(1);\n"
16004                                                                                                  "    }\n";
16005         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16006                                                                                                 "    {\n"
16007                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16008                                                                                                 "    }\n";
16009         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16010                                                                                                 "    {\n"
16011                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16012                                                                                                 "    }\n";
16013         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16014                                                                                                  "    if (vec4(0) == result)\n"
16015                                                                                                  "    {\n"
16016                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16017                                                                                                  "    }\n";
16018         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16019                                                                                                  "    if (vec4(0) == result)\n"
16020                                                                                                  "    {\n"
16021                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16022                                                                                                  "    }\n";
16023         static const GLchar* fs = "#version 430 core\n"
16024                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16025                                                           "\n"
16026                                                           "in  vec4 gs_fs;\n"
16027                                                           "out vec4 fs_out;\n"
16028                                                           "\n"
16029                                                           "void main()\n"
16030                                                           "{\n"
16031                                                           "    fs_out = gs_fs;\n"
16032                                                           "}\n"
16033                                                           "\n";
16034         static const GLchar* fs_tested = "#version 430 core\n"
16035                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16036                                                                          "\n"
16037                                                                          "VAR_DEFINITION"
16038                                                                          "\n"
16039                                                                          "in  vec4 gs_fs;\n"
16040                                                                          "out vec4 fs_out;\n"
16041                                                                          "\n"
16042                                                                          "void main()\n"
16043                                                                          "{\n"
16044                                                                          "    vec4 result = gs_fs;\n"
16045                                                                          "\n"
16046                                                                          "VARIABLE_USE"
16047                                                                          "\n"
16048                                                                          "    fs_out += result;\n"
16049                                                                          "}\n"
16050                                                                          "\n";
16051         static const GLchar* gs = "#version 430 core\n"
16052                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16053                                                           "\n"
16054                                                           "layout(points)                           in;\n"
16055                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16056                                                           "\n"
16057                                                           "in  vec4 tes_gs[];\n"
16058                                                           "out vec4 gs_fs;\n"
16059                                                           "\n"
16060                                                           "void main()\n"
16061                                                           "{\n"
16062                                                           "    gs_fs = tes_gs[0];\n"
16063                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16064                                                           "    EmitVertex();\n"
16065                                                           "    gs_fs = tes_gs[0];\n"
16066                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16067                                                           "    EmitVertex();\n"
16068                                                           "    gs_fs = tes_gs[0];\n"
16069                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16070                                                           "    EmitVertex();\n"
16071                                                           "    gs_fs = tes_gs[0];\n"
16072                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16073                                                           "    EmitVertex();\n"
16074                                                           "}\n"
16075                                                           "\n";
16076         static const GLchar* gs_tested = "#version 430 core\n"
16077                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16078                                                                          "\n"
16079                                                                          "layout(points)                           in;\n"
16080                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16081                                                                          "\n"
16082                                                                          "VAR_DEFINITION"
16083                                                                          "\n"
16084                                                                          "in  vec4 tes_gs[];\n"
16085                                                                          "out vec4 gs_fs;\n"
16086                                                                          "\n"
16087                                                                          "void main()\n"
16088                                                                          "{\n"
16089                                                                          "    vec4 result = tes_gs[0];\n"
16090                                                                          "\n"
16091                                                                          "VARIABLE_USE"
16092                                                                          "\n"
16093                                                                          "    gs_fs = result;\n"
16094                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16095                                                                          "    EmitVertex();\n"
16096                                                                          "    gs_fs = result;\n"
16097                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16098                                                                          "    EmitVertex();\n"
16099                                                                          "    gs_fs = result;\n"
16100                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16101                                                                          "    EmitVertex();\n"
16102                                                                          "    gs_fs = result;\n"
16103                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16104                                                                          "    EmitVertex();\n"
16105                                                                          "}\n"
16106                                                                          "\n";
16107         static const GLchar* tcs = "#version 430 core\n"
16108                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16109                                                            "\n"
16110                                                            "layout(vertices = 1) out;\n"
16111                                                            "\n"
16112                                                            "in  vec4 vs_tcs[];\n"
16113                                                            "out vec4 tcs_tes[];\n"
16114                                                            "\n"
16115                                                            "void main()\n"
16116                                                            "{\n"
16117                                                            "\n"
16118                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16119                                                            "\n"
16120                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16121                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16122                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16123                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16124                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16125                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16126                                                            "}\n"
16127                                                            "\n";
16128         static const GLchar* tcs_tested = "#version 430 core\n"
16129                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16130                                                                           "\n"
16131                                                                           "layout(vertices = 1) out;\n"
16132                                                                           "\n"
16133                                                                           "VAR_DEFINITION"
16134                                                                           "\n"
16135                                                                           "in  vec4 vs_tcs[];\n"
16136                                                                           "out vec4 tcs_tes[];\n"
16137                                                                           "\n"
16138                                                                           "void main()\n"
16139                                                                           "{\n"
16140                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16141                                                                           "\n"
16142                                                                           "VARIABLE_USE"
16143                                                                           "\n"
16144                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16145                                                                           "\n"
16146                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16147                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16148                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16149                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16150                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16151                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16152                                                                           "}\n"
16153                                                                           "\n";
16154         static const GLchar* tes = "#version 430 core\n"
16155                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16156                                                            "\n"
16157                                                            "layout(isolines, point_mode) in;\n"
16158                                                            "\n"
16159                                                            "in  vec4 tcs_tes[];\n"
16160                                                            "out vec4 tes_gs;\n"
16161                                                            "\n"
16162                                                            "void main()\n"
16163                                                            "{\n"
16164                                                            "    tes_gs = tcs_tes[0];\n"
16165                                                            "}\n"
16166                                                            "\n";
16167         static const GLchar* tes_tested = "#version 430 core\n"
16168                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16169                                                                           "\n"
16170                                                                           "layout(isolines, point_mode) in;\n"
16171                                                                           "\n"
16172                                                                           "VAR_DEFINITION"
16173                                                                           "\n"
16174                                                                           "in  vec4 tcs_tes[];\n"
16175                                                                           "out vec4 tes_gs;\n"
16176                                                                           "\n"
16177                                                                           "void main()\n"
16178                                                                           "{\n"
16179                                                                           "    vec4 result = tcs_tes[0];\n"
16180                                                                           "\n"
16181                                                                           "VARIABLE_USE"
16182                                                                           "\n"
16183                                                                           "    tes_gs += result;\n"
16184                                                                           "}\n"
16185                                                                           "\n";
16186         static const GLchar* vs = "#version 430 core\n"
16187                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16188                                                           "\n"
16189                                                           "in  vec4 in_vs;\n"
16190                                                           "out vec4 vs_tcs;\n"
16191                                                           "\n"
16192                                                           "void main()\n"
16193                                                           "{\n"
16194                                                           "    vs_tcs = in_vs;\n"
16195                                                           "}\n"
16196                                                           "\n";
16197         static const GLchar* vs_tested = "#version 430 core\n"
16198                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16199                                                                          "\n"
16200                                                                          "VAR_DEFINITION"
16201                                                                          "\n"
16202                                                                          "in  vec4 in_vs;\n"
16203                                                                          "out vec4 vs_tcs;\n"
16204                                                                          "\n"
16205                                                                          "void main()\n"
16206                                                                          "{\n"
16207                                                                          "    vec4 result = in_vs;\n"
16208                                                                          "\n"
16209                                                                          "VARIABLE_USE"
16210                                                                          "\n"
16211                                                                          "    vs_tcs += result;\n"
16212                                                                          "}\n"
16213                                                                          "\n";
16214
16215         std::string source;
16216         testCase&   test_case = m_test_cases[test_case_index];
16217
16218         if (test_case.m_stage == stage)
16219         {
16220                 const GLchar* array = "";
16221                 GLchar            buffer[16];
16222                 const GLchar* var_definition = 0;
16223                 const GLchar* direction          = "in ";
16224                 const GLchar* index                      = "";
16225                 size_t            position               = 0;
16226                 size_t            temp;
16227                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16228                 const GLchar* var_use   = 0;
16229
16230                 if (false == test_case.m_is_input)
16231                 {
16232                         direction = "out";
16233
16234                         if (false == test_case.m_is_array)
16235                         {
16236                                 switch (test_case.m_case)
16237                                 {
16238                                 case BLOCK:
16239                                         var_definition = block_definition_one;
16240                                         var_use            = member_output_use_one;
16241                                         break;
16242                                 case MATRIX:
16243                                         var_definition = matrix_definition_one;
16244                                         var_use            = matrix_output_use_one;
16245                                         break;
16246                                 case STRUCT:
16247                                         var_definition = struct_definition_one;
16248                                         var_use            = member_output_use_one;
16249                                         break;
16250                                 default:
16251                                         TCU_FAIL("Invalid enum");
16252                                 }
16253                         }
16254                         else
16255                         {
16256                                 switch (test_case.m_case)
16257                                 {
16258                                 case BLOCK:
16259                                         var_definition = block_definition_arr;
16260                                         var_use            = member_output_use_arr;
16261                                         break;
16262                                 case MATRIX:
16263                                         var_definition = matrix_definition_arr;
16264                                         var_use            = matrix_output_use_arr;
16265                                         break;
16266                                 case STRUCT:
16267                                         var_definition = struct_definition_arr;
16268                                         var_use            = member_output_use_arr;
16269                                         break;
16270                                 default:
16271                                         TCU_FAIL("Invalid enum");
16272                                 }
16273                         }
16274                 }
16275                 else
16276                 {
16277                         if (false == test_case.m_is_array)
16278                         {
16279                                 switch (test_case.m_case)
16280                                 {
16281                                 case BLOCK:
16282                                         var_definition = block_definition_one;
16283                                         var_use            = member_input_use_one;
16284                                         break;
16285                                 case MATRIX:
16286                                         var_definition = matrix_definition_one;
16287                                         var_use            = matrix_input_use_one;
16288                                         break;
16289                                 case STRUCT:
16290                                         var_definition = struct_definition_one;
16291                                         var_use            = member_input_use_one;
16292                                         break;
16293                                 default:
16294                                         TCU_FAIL("Invalid enum");
16295                                 }
16296                         }
16297                         else
16298                         {
16299                                 switch (test_case.m_case)
16300                                 {
16301                                 case BLOCK:
16302                                         var_definition = block_definition_arr;
16303                                         var_use            = member_input_use_arr;
16304                                         break;
16305                                 case MATRIX:
16306                                         var_definition = matrix_definition_arr;
16307                                         var_use            = matrix_input_use_arr;
16308                                         break;
16309                                 case STRUCT:
16310                                         var_definition = struct_definition_arr;
16311                                         var_use            = member_input_use_arr;
16312                                         break;
16313                                 default:
16314                                         TCU_FAIL("Invalid enum");
16315                                 }
16316                         }
16317                 }
16318
16319                 sprintf(buffer, "%d", test_case.m_component);
16320
16321                 switch (stage)
16322                 {
16323                 case Utils::Shader::FRAGMENT:
16324                         source = fs_tested;
16325                         break;
16326                 case Utils::Shader::GEOMETRY:
16327                         source = gs_tested;
16328                         array  = "[]";
16329                         index  = "[0]";
16330                         break;
16331                 case Utils::Shader::TESS_CTRL:
16332                         source = tcs_tested;
16333                         array  = "[]";
16334                         index  = "[gl_InvocationID]";
16335                         break;
16336                 case Utils::Shader::TESS_EVAL:
16337                         source = tes_tested;
16338                         array  = "[]";
16339                         index  = "[0]";
16340                         break;
16341                 case Utils::Shader::VERTEX:
16342                         source = vs_tested;
16343                         break;
16344                 default:
16345                         TCU_FAIL("Invalid enum");
16346                 }
16347
16348                 temp = position;
16349                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16350                 position = temp;
16351                 Utils::replaceToken("COMPONENT", position, buffer, source);
16352                 Utils::replaceToken("DIRECTION", position, direction, source);
16353                 Utils::replaceToken("ARRAY", position, array, source);
16354                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16355
16356                 Utils::replaceAllTokens("TYPE", type_name, source);
16357                 Utils::replaceAllTokens("INDEX", index, source);
16358         }
16359         else
16360         {
16361                 switch (stage)
16362                 {
16363                 case Utils::Shader::FRAGMENT:
16364                         source = fs;
16365                         break;
16366                 case Utils::Shader::GEOMETRY:
16367                         source = gs;
16368                         break;
16369                 case Utils::Shader::TESS_CTRL:
16370                         source = tcs;
16371                         break;
16372                 case Utils::Shader::TESS_EVAL:
16373                         source = tes;
16374                         break;
16375                 case Utils::Shader::VERTEX:
16376                         source = vs;
16377                         break;
16378                 default:
16379                         TCU_FAIL("Invalid enum");
16380                 }
16381         }
16382
16383         return source;
16384 }
16385
16386 /** Get description of test case
16387  *
16388  * @param test_case_index Index of test case
16389  *
16390  * @return Test case description
16391  **/
16392 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16393 {
16394         std::stringstream stream;
16395         testCase&                 test_case = m_test_cases[test_case_index];
16396
16397         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16398                    << " type: " << test_case.m_type.GetGLSLTypeName();
16399
16400         if (true == test_case.m_is_array)
16401         {
16402                 stream << "[1]";
16403         }
16404
16405         stream << ", direction: ";
16406
16407         if (true == test_case.m_is_input)
16408         {
16409                 stream << "input";
16410         }
16411         else
16412         {
16413                 stream << "output";
16414         }
16415
16416         stream << ", component: " << test_case.m_component;
16417
16418         return stream.str();
16419 }
16420
16421 /** Get number of test cases
16422  *
16423  * @return Number of test cases
16424  **/
16425 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16426 {
16427         return static_cast<GLuint>(m_test_cases.size());
16428 }
16429
16430 /** Selects if "compute" stage is relevant for test
16431  *
16432  * @param ignored
16433  *
16434  * @return false
16435  **/
16436 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16437 {
16438         return false;
16439 }
16440
16441 /** Prepare all test cases
16442  *
16443  **/
16444 void VaryingComponentOfInvalidTypeTest::testInit()
16445 {
16446         static const GLuint n_components_per_location = 4;
16447         const GLuint            n_types                                   = getTypesNumber();
16448
16449         for (GLuint i = 0; i < n_types; ++i)
16450         {
16451                 const Utils::Type& type                         = getType(i);
16452                 const GLuint       n_req_components = type.m_n_rows;
16453                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16454
16455                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16456                 {
16457                         if (Utils::Shader::COMPUTE == stage)
16458                         {
16459                                 continue;
16460                         }
16461
16462                         /* Use different CASE for matrices */
16463                         if (1 != type.m_n_columns)
16464                         {
16465                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16466                                 testCase test_case_in_one = {
16467                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16468                                 };
16469                                 testCase test_case_out_arr = {
16470                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16471                                 };
16472                                 testCase test_case_out_one = {
16473                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16474                                 };
16475
16476                                 m_test_cases.push_back(test_case_in_arr);
16477                                 m_test_cases.push_back(test_case_in_one);
16478
16479                                 if (Utils::Shader::FRAGMENT != stage)
16480                                 {
16481                                         m_test_cases.push_back(test_case_out_arr);
16482                                         m_test_cases.push_back(test_case_out_one);
16483                                 }
16484                         }
16485                         else
16486                         {
16487                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16488                                 {
16489                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16490                                                                                                   type };
16491                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16492                                                                                                   type };
16493                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16494                                                                                                    type };
16495                                         testCase test_case_out_one = {
16496                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16497                                         };
16498
16499                                         if (Utils::Shader::VERTEX != stage)
16500                                         {
16501                                                 m_test_cases.push_back(test_case_in_arr);
16502                                                 m_test_cases.push_back(test_case_in_one);
16503                                         }
16504
16505                                         if (Utils::Shader::FRAGMENT != stage)
16506                                         {
16507                                                 m_test_cases.push_back(test_case_out_arr);
16508                                                 m_test_cases.push_back(test_case_out_one);
16509                                         }
16510                                 }
16511                         }
16512                 }
16513         }
16514 }
16515
16516 /** Constructor
16517  *
16518  * @param context Test framework context
16519  **/
16520 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16521         : NegativeTestBase(context, "input_component_aliasing",
16522                                            "Test verifies that compiler reports component aliasing as error")
16523 {
16524 }
16525
16526 /** Source for given test case and stage
16527  *
16528  * @param test_case_index Index of test case
16529  * @param stage           Shader stage
16530  *
16531  * @return Shader source
16532  **/
16533 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16534 {
16535         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16536                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16537         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16538                                                                         "    {\n"
16539                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16540                                                                         "    }\n";
16541         static const GLchar* test_both = "    if (TYPE(0) == gohanINDEX)\n"
16542                                                                          "    {\n"
16543                                                                          "        result = vec4(goten.xxxx);\n"
16544                                                                          "    }\n";
16545         static const GLchar* fs = "#version 430 core\n"
16546                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16547                                                           "\n"
16548                                                           "in  vec4 gs_fs;\n"
16549                                                           "out vec4 fs_out;\n"
16550                                                           "\n"
16551                                                           "void main()\n"
16552                                                           "{\n"
16553                                                           "    fs_out = gs_fs;\n"
16554                                                           "}\n"
16555                                                           "\n";
16556         static const GLchar* fs_tested = "#version 430 core\n"
16557                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16558                                                                          "\n"
16559                                                                          "VAR_DEFINITION"
16560                                                                          "\n"
16561                                                                          "in  vec4 gs_fs;\n"
16562                                                                          "out vec4 fs_out;\n"
16563                                                                          "\n"
16564                                                                          "void main()\n"
16565                                                                          "{\n"
16566                                                                          "    vec4 result = gs_fs;\n"
16567                                                                          "\n"
16568                                                                          "VARIABLE_USE"
16569                                                                          "\n"
16570                                                                          "    fs_out += result;\n"
16571                                                                          "}\n"
16572                                                                          "\n";
16573         static const GLchar* gs = "#version 430 core\n"
16574                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16575                                                           "\n"
16576                                                           "layout(points)                           in;\n"
16577                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16578                                                           "\n"
16579                                                           "in  vec4 tes_gs[];\n"
16580                                                           "out vec4 gs_fs;\n"
16581                                                           "\n"
16582                                                           "void main()\n"
16583                                                           "{\n"
16584                                                           "    gs_fs = tes_gs[0];\n"
16585                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16586                                                           "    EmitVertex();\n"
16587                                                           "    gs_fs = tes_gs[0];\n"
16588                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16589                                                           "    EmitVertex();\n"
16590                                                           "    gs_fs = tes_gs[0];\n"
16591                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16592                                                           "    EmitVertex();\n"
16593                                                           "    gs_fs = tes_gs[0];\n"
16594                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16595                                                           "    EmitVertex();\n"
16596                                                           "}\n"
16597                                                           "\n";
16598         static const GLchar* gs_tested = "#version 430 core\n"
16599                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16600                                                                          "\n"
16601                                                                          "layout(points)                           in;\n"
16602                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16603                                                                          "\n"
16604                                                                          "VAR_DEFINITION"
16605                                                                          "\n"
16606                                                                          "in  vec4 tes_gs[];\n"
16607                                                                          "out vec4 gs_fs;\n"
16608                                                                          "\n"
16609                                                                          "void main()\n"
16610                                                                          "{\n"
16611                                                                          "    vec4 result = tes_gs[0];\n"
16612                                                                          "\n"
16613                                                                          "VARIABLE_USE"
16614                                                                          "\n"
16615                                                                          "    gs_fs = result;\n"
16616                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16617                                                                          "    EmitVertex();\n"
16618                                                                          "    gs_fs = result;\n"
16619                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16620                                                                          "    EmitVertex();\n"
16621                                                                          "    gs_fs = result;\n"
16622                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16623                                                                          "    EmitVertex();\n"
16624                                                                          "    gs_fs = result;\n"
16625                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16626                                                                          "    EmitVertex();\n"
16627                                                                          "}\n"
16628                                                                          "\n";
16629         static const GLchar* tcs = "#version 430 core\n"
16630                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16631                                                            "\n"
16632                                                            "layout(vertices = 1) out;\n"
16633                                                            "\n"
16634                                                            "in  vec4 vs_tcs[];\n"
16635                                                            "out vec4 tcs_tes[];\n"
16636                                                            "\n"
16637                                                            "void main()\n"
16638                                                            "{\n"
16639                                                            "\n"
16640                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16641                                                            "\n"
16642                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16643                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16644                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16645                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16646                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16647                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16648                                                            "}\n"
16649                                                            "\n";
16650         static const GLchar* tcs_tested = "#version 430 core\n"
16651                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16652                                                                           "\n"
16653                                                                           "layout(vertices = 1) out;\n"
16654                                                                           "\n"
16655                                                                           "VAR_DEFINITION"
16656                                                                           "\n"
16657                                                                           "in  vec4 vs_tcs[];\n"
16658                                                                           "out vec4 tcs_tes[];\n"
16659                                                                           "\n"
16660                                                                           "void main()\n"
16661                                                                           "{\n"
16662                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16663                                                                           "\n"
16664                                                                           "VARIABLE_USE"
16665                                                                           "\n"
16666                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16667                                                                           "\n"
16668                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16669                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16670                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16671                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16672                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16673                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16674                                                                           "}\n"
16675                                                                           "\n";
16676         static const GLchar* tes = "#version 430 core\n"
16677                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16678                                                            "\n"
16679                                                            "layout(isolines, point_mode) in;\n"
16680                                                            "\n"
16681                                                            "in  vec4 tcs_tes[];\n"
16682                                                            "out vec4 tes_gs;\n"
16683                                                            "\n"
16684                                                            "void main()\n"
16685                                                            "{\n"
16686                                                            "    tes_gs = tcs_tes[0];\n"
16687                                                            "}\n"
16688                                                            "\n";
16689         static const GLchar* tes_tested = "#version 430 core\n"
16690                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16691                                                                           "\n"
16692                                                                           "layout(isolines, point_mode) in;\n"
16693                                                                           "\n"
16694                                                                           "VAR_DEFINITION"
16695                                                                           "\n"
16696                                                                           "in  vec4 tcs_tes[];\n"
16697                                                                           "out vec4 tes_gs;\n"
16698                                                                           "\n"
16699                                                                           "void main()\n"
16700                                                                           "{\n"
16701                                                                           "    vec4 result = tcs_tes[0];\n"
16702                                                                           "\n"
16703                                                                           "VARIABLE_USE"
16704                                                                           "\n"
16705                                                                           "    tes_gs += result;\n"
16706                                                                           "}\n"
16707                                                                           "\n";
16708         static const GLchar* vs = "#version 430 core\n"
16709                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16710                                                           "\n"
16711                                                           "in  vec4 in_vs;\n"
16712                                                           "out vec4 vs_tcs;\n"
16713                                                           "\n"
16714                                                           "void main()\n"
16715                                                           "{\n"
16716                                                           "    vs_tcs = in_vs;\n"
16717                                                           "}\n"
16718                                                           "\n";
16719         static const GLchar* vs_tested = "#version 430 core\n"
16720                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16721                                                                          "\n"
16722                                                                          "VAR_DEFINITION"
16723                                                                          "\n"
16724                                                                          "in  vec4 in_vs;\n"
16725                                                                          "out vec4 vs_tcs;\n"
16726                                                                          "\n"
16727                                                                          "void main()\n"
16728                                                                          "{\n"
16729                                                                          "    vec4 result = in_vs;\n"
16730                                                                          "\n"
16731                                                                          "VARIABLE_USE"
16732                                                                          "\n"
16733                                                                          "    vs_tcs += result;\n"
16734                                                                          "}\n"
16735                                                                          "\n";
16736
16737         std::string source;
16738         testCase&   test_case = m_test_cases[test_case_index];
16739
16740         if (test_case.m_stage == stage)
16741         {
16742                 const GLchar* array = "";
16743                 GLchar            buffer_gohan[16];
16744                 GLchar            buffer_goten[16];
16745                 const GLchar* flat                = "";
16746                 const GLchar* index               = "";
16747                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16748                 size_t            position      = 0;
16749                 size_t            temp;
16750                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16751                 const GLchar* var_use   = test_one;
16752
16753                 if (true == test_case.m_use_both)
16754                 {
16755                         var_use = test_both;
16756                 }
16757
16758                 if (true == is_flat_req)
16759                 {
16760                         flat = "flat";
16761                 }
16762
16763                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16764                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16765
16766                 switch (stage)
16767                 {
16768                 case Utils::Shader::FRAGMENT:
16769                         source = fs_tested;
16770                         break;
16771                 case Utils::Shader::GEOMETRY:
16772                         source = gs_tested;
16773                         array  = "[]";
16774                         index  = "[0]";
16775                         break;
16776                 case Utils::Shader::TESS_CTRL:
16777                         source = tcs_tested;
16778                         array  = "[]";
16779                         index  = "[gl_InvocationID]";
16780                         break;
16781                 case Utils::Shader::TESS_EVAL:
16782                         source = tes_tested;
16783                         array  = "[]";
16784                         index  = "[0]";
16785                         break;
16786                 case Utils::Shader::VERTEX:
16787                         source = vs_tested;
16788                         break;
16789                 default:
16790                         TCU_FAIL("Invalid enum");
16791                 }
16792
16793                 temp = position;
16794                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16795                 position = temp;
16796                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16797                 Utils::replaceToken("ARRAY", position, array, source);
16798                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16799                 Utils::replaceToken("ARRAY", position, array, source);
16800                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16801
16802                 Utils::replaceAllTokens("FLAT", flat, source);
16803                 Utils::replaceAllTokens("TYPE", type_name, source);
16804                 Utils::replaceAllTokens("INDEX", index, source);
16805         }
16806         else
16807         {
16808                 switch (stage)
16809                 {
16810                 case Utils::Shader::FRAGMENT:
16811                         source = fs;
16812                         break;
16813                 case Utils::Shader::GEOMETRY:
16814                         source = gs;
16815                         break;
16816                 case Utils::Shader::TESS_CTRL:
16817                         source = tcs;
16818                         break;
16819                 case Utils::Shader::TESS_EVAL:
16820                         source = tes;
16821                         break;
16822                 case Utils::Shader::VERTEX:
16823                         source = vs;
16824                         break;
16825                 default:
16826                         TCU_FAIL("Invalid enum");
16827                 }
16828         }
16829
16830         return source;
16831 }
16832
16833 /** Get description of test case
16834  *
16835  * @param test_case_index Index of test case
16836  *
16837  * @return Test case description
16838  **/
16839 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16840 {
16841         std::stringstream stream;
16842         testCase&                 test_case = m_test_cases[test_case_index];
16843
16844         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16845                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16846                    << " & " << test_case.m_component_goten;
16847
16848         return stream.str();
16849 }
16850
16851 /** Get number of test cases
16852  *
16853  * @return Number of test cases
16854  **/
16855 GLuint InputComponentAliasingTest::getTestCaseNumber()
16856 {
16857         return static_cast<GLuint>(m_test_cases.size());
16858 }
16859
16860 /** Selects if "compute" stage is relevant for test
16861  *
16862  * @param ignored
16863  *
16864  * @return false
16865  **/
16866 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16867 {
16868         return false;
16869 }
16870
16871 /** Selects if compilation failure is expected result
16872  *
16873  * @param test_case_index Index of test case
16874  *
16875  * @return false for VS that use only single variable, true otherwise
16876  **/
16877 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16878 {
16879         testCase& test_case = m_test_cases[test_case_index];
16880
16881         return !((Utils::Shader::VERTEX == test_case.m_stage) && (false == test_case.m_use_both));
16882 }
16883
16884 /** Prepare all test cases
16885  *
16886  **/
16887 void InputComponentAliasingTest::testInit()
16888 {
16889         static const GLuint n_components_per_location = 4;
16890         const GLuint            n_types                                   = getTypesNumber();
16891
16892         for (GLuint i = 0; i < n_types; ++i)
16893         {
16894                 const Utils::Type& type                         = getType(i);
16895                 const GLuint       n_req_components = type.m_n_rows;
16896                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16897
16898                 /* Skip matrices */
16899                 if (1 != type.m_n_columns)
16900                 {
16901                         continue;
16902                 }
16903
16904                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16905                 {
16906                         if (Utils::Shader::COMPUTE == stage)
16907                         {
16908                                 continue;
16909                         }
16910
16911                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
16912                         {
16913                                 const GLint first_aliasing = gohan - n_req_components + 1;
16914                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16915
16916                                 const GLuint goten_start = std::max(0, first_aliasing);
16917                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
16918
16919                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16920                                 {
16921                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type, false };
16922
16923                                         m_test_cases.push_back(test_case);
16924
16925                                         if (Utils::Shader::VERTEX == test_case.m_stage)
16926                                         {
16927                                                 test_case.m_use_both = true;
16928
16929                                                 m_test_cases.push_back(test_case);
16930                                         }
16931                                 }
16932                         }
16933                 }
16934         }
16935 }
16936
16937 /** Constructor
16938  *
16939  * @param context Test framework context
16940  **/
16941 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
16942         : NegativeTestBase(context, "output_component_aliasing",
16943                                            "Test verifies that compiler reports component aliasing as error")
16944 {
16945 }
16946
16947 /** Source for given test case and stage
16948  *
16949  * @param test_case_index Index of test case
16950  * @param stage           Shader stage
16951  *
16952  * @return Shader source
16953  **/
16954 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16955 {
16956         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
16957                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
16958         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
16959                                                                   "    gotenINDEX = TYPE(0);\n";
16960         static const GLchar* fs = "#version 430 core\n"
16961                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16962                                                           "\n"
16963                                                           "in  vec4 gs_fs;\n"
16964                                                           "out vec4 fs_out;\n"
16965                                                           "\n"
16966                                                           "void main()\n"
16967                                                           "{\n"
16968                                                           "    fs_out = gs_fs;\n"
16969                                                           "}\n"
16970                                                           "\n";
16971         static const GLchar* fs_tested = "#version 430 core\n"
16972                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16973                                                                          "\n"
16974                                                                          "VAR_DEFINITION"
16975                                                                          "\n"
16976                                                                          "in  vec4 gs_fs;\n"
16977                                                                          "out vec4 fs_out;\n"
16978                                                                          "\n"
16979                                                                          "void main()\n"
16980                                                                          "{\n"
16981                                                                          "    vec4 result = gs_fs;\n"
16982                                                                          "\n"
16983                                                                          "VARIABLE_USE"
16984                                                                          "\n"
16985                                                                          "    fs_out += result;\n"
16986                                                                          "}\n"
16987                                                                          "\n";
16988         static const GLchar* gs = "#version 430 core\n"
16989                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16990                                                           "\n"
16991                                                           "layout(points)                           in;\n"
16992                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16993                                                           "\n"
16994                                                           "in  vec4 tes_gs[];\n"
16995                                                           "out vec4 gs_fs;\n"
16996                                                           "\n"
16997                                                           "void main()\n"
16998                                                           "{\n"
16999                                                           "    gs_fs = tes_gs[0];\n"
17000                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17001                                                           "    EmitVertex();\n"
17002                                                           "    gs_fs = tes_gs[0];\n"
17003                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17004                                                           "    EmitVertex();\n"
17005                                                           "    gs_fs = tes_gs[0];\n"
17006                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17007                                                           "    EmitVertex();\n"
17008                                                           "    gs_fs = tes_gs[0];\n"
17009                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17010                                                           "    EmitVertex();\n"
17011                                                           "}\n"
17012                                                           "\n";
17013         static const GLchar* gs_tested = "#version 430 core\n"
17014                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17015                                                                          "\n"
17016                                                                          "layout(points)                           in;\n"
17017                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17018                                                                          "\n"
17019                                                                          "VAR_DEFINITION"
17020                                                                          "\n"
17021                                                                          "in  vec4 tes_gs[];\n"
17022                                                                          "out vec4 gs_fs;\n"
17023                                                                          "\n"
17024                                                                          "void main()\n"
17025                                                                          "{\n"
17026                                                                          "    vec4 result = tes_gs[0];\n"
17027                                                                          "\n"
17028                                                                          "VARIABLE_USE"
17029                                                                          "\n"
17030                                                                          "    gs_fs = result;\n"
17031                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17032                                                                          "    EmitVertex();\n"
17033                                                                          "    gs_fs = result;\n"
17034                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17035                                                                          "    EmitVertex();\n"
17036                                                                          "    gs_fs = result;\n"
17037                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17038                                                                          "    EmitVertex();\n"
17039                                                                          "    gs_fs = result;\n"
17040                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17041                                                                          "    EmitVertex();\n"
17042                                                                          "}\n"
17043                                                                          "\n";
17044         static const GLchar* tcs = "#version 430 core\n"
17045                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17046                                                            "\n"
17047                                                            "layout(vertices = 1) out;\n"
17048                                                            "\n"
17049                                                            "in  vec4 vs_tcs[];\n"
17050                                                            "out vec4 tcs_tes[];\n"
17051                                                            "\n"
17052                                                            "void main()\n"
17053                                                            "{\n"
17054                                                            "\n"
17055                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17056                                                            "\n"
17057                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17058                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17059                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17060                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17061                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17062                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17063                                                            "}\n"
17064                                                            "\n";
17065         static const GLchar* tcs_tested = "#version 430 core\n"
17066                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17067                                                                           "\n"
17068                                                                           "layout(vertices = 1) out;\n"
17069                                                                           "\n"
17070                                                                           "VAR_DEFINITION"
17071                                                                           "\n"
17072                                                                           "in  vec4 vs_tcs[];\n"
17073                                                                           "out vec4 tcs_tes[];\n"
17074                                                                           "\n"
17075                                                                           "void main()\n"
17076                                                                           "{\n"
17077                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17078                                                                           "\n"
17079                                                                           "VARIABLE_USE"
17080                                                                           "\n"
17081                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17082                                                                           "\n"
17083                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17084                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17085                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17086                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17087                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17088                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17089                                                                           "}\n"
17090                                                                           "\n";
17091         static const GLchar* tes = "#version 430 core\n"
17092                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17093                                                            "\n"
17094                                                            "layout(isolines, point_mode) in;\n"
17095                                                            "\n"
17096                                                            "in  vec4 tcs_tes[];\n"
17097                                                            "out vec4 tes_gs;\n"
17098                                                            "\n"
17099                                                            "void main()\n"
17100                                                            "{\n"
17101                                                            "    tes_gs = tcs_tes[0];\n"
17102                                                            "}\n"
17103                                                            "\n";
17104         static const GLchar* tes_tested = "#version 430 core\n"
17105                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17106                                                                           "\n"
17107                                                                           "layout(isolines, point_mode) in;\n"
17108                                                                           "\n"
17109                                                                           "VAR_DEFINITION"
17110                                                                           "\n"
17111                                                                           "in  vec4 tcs_tes[];\n"
17112                                                                           "out vec4 tes_gs;\n"
17113                                                                           "\n"
17114                                                                           "void main()\n"
17115                                                                           "{\n"
17116                                                                           "    vec4 result = tcs_tes[0];\n"
17117                                                                           "\n"
17118                                                                           "VARIABLE_USE"
17119                                                                           "\n"
17120                                                                           "    tes_gs += result;\n"
17121                                                                           "}\n"
17122                                                                           "\n";
17123         static const GLchar* vs = "#version 430 core\n"
17124                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17125                                                           "\n"
17126                                                           "in  vec4 in_vs;\n"
17127                                                           "out vec4 vs_tcs;\n"
17128                                                           "\n"
17129                                                           "void main()\n"
17130                                                           "{\n"
17131                                                           "    vs_tcs = in_vs;\n"
17132                                                           "}\n"
17133                                                           "\n";
17134         static const GLchar* vs_tested = "#version 430 core\n"
17135                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17136                                                                          "\n"
17137                                                                          "VAR_DEFINITION"
17138                                                                          "\n"
17139                                                                          "in  vec4 in_vs;\n"
17140                                                                          "out vec4 vs_tcs;\n"
17141                                                                          "\n"
17142                                                                          "void main()\n"
17143                                                                          "{\n"
17144                                                                          "    vec4 result = in_vs;\n"
17145                                                                          "\n"
17146                                                                          "VARIABLE_USE"
17147                                                                          "\n"
17148                                                                          "    vs_tcs += result;\n"
17149                                                                          "}\n"
17150                                                                          "\n";
17151
17152         std::string source;
17153         testCase&   test_case = m_test_cases[test_case_index];
17154
17155         if (test_case.m_stage == stage)
17156         {
17157                 const GLchar* array = "";
17158                 GLchar            buffer_gohan[16];
17159                 GLchar            buffer_goten[16];
17160                 const GLchar* index     = "";
17161                 size_t            position = 0;
17162                 size_t            temp;
17163                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17164
17165                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17166                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17167
17168                 switch (stage)
17169                 {
17170                 case Utils::Shader::FRAGMENT:
17171                         source = fs_tested;
17172                         break;
17173                 case Utils::Shader::GEOMETRY:
17174                         source = gs_tested;
17175                         array  = "[]";
17176                         index  = "[0]";
17177                         break;
17178                 case Utils::Shader::TESS_CTRL:
17179                         source = tcs_tested;
17180                         array  = "[]";
17181                         index  = "[gl_InvocationID]";
17182                         break;
17183                 case Utils::Shader::TESS_EVAL:
17184                         source = tes_tested;
17185                         array  = "[]";
17186                         index  = "[0]";
17187                         break;
17188                 case Utils::Shader::VERTEX:
17189                         source = vs_tested;
17190                         break;
17191                 default:
17192                         TCU_FAIL("Invalid enum");
17193                 }
17194
17195                 temp = position;
17196                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17197                 position = temp;
17198                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17199                 Utils::replaceToken("ARRAY", position, array, source);
17200                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17201                 Utils::replaceToken("ARRAY", position, array, source);
17202                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17203
17204                 Utils::replaceAllTokens("TYPE", type_name, source);
17205                 Utils::replaceAllTokens("INDEX", index, source);
17206         }
17207         else
17208         {
17209                 switch (stage)
17210                 {
17211                 case Utils::Shader::FRAGMENT:
17212                         source = fs;
17213                         break;
17214                 case Utils::Shader::GEOMETRY:
17215                         source = gs;
17216                         break;
17217                 case Utils::Shader::TESS_CTRL:
17218                         source = tcs;
17219                         break;
17220                 case Utils::Shader::TESS_EVAL:
17221                         source = tes;
17222                         break;
17223                 case Utils::Shader::VERTEX:
17224                         source = vs;
17225                         break;
17226                 default:
17227                         TCU_FAIL("Invalid enum");
17228                 }
17229         }
17230
17231         return source;
17232 }
17233
17234 /** Get description of test case
17235  *
17236  * @param test_case_index Index of test case
17237  *
17238  * @return Test case description
17239  **/
17240 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17241 {
17242         std::stringstream stream;
17243         testCase&                 test_case = m_test_cases[test_case_index];
17244
17245         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17246                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17247                    << " & " << test_case.m_component_goten;
17248
17249         return stream.str();
17250 }
17251
17252 /** Get number of test cases
17253  *
17254  * @return Number of test cases
17255  **/
17256 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17257 {
17258         return static_cast<GLuint>(m_test_cases.size());
17259 }
17260
17261 /** Selects if "compute" stage is relevant for test
17262  *
17263  * @param ignored
17264  *
17265  * @return false
17266  **/
17267 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17268 {
17269         return false;
17270 }
17271
17272 /** Prepare all test cases
17273  *
17274  **/
17275 void OutputComponentAliasingTest::testInit()
17276 {
17277         static const GLuint n_components_per_location = 4;
17278         const GLuint            n_types                                   = getTypesNumber();
17279
17280         for (GLuint i = 0; i < n_types; ++i)
17281         {
17282                 const Utils::Type& type                         = getType(i);
17283                 const GLuint       n_req_components = type.m_n_rows;
17284                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17285
17286                 /* Skip matrices */
17287                 if (1 != type.m_n_columns)
17288                 {
17289                         continue;
17290                 }
17291
17292                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17293                 {
17294                         if (Utils::Shader::COMPUTE == stage)
17295                         {
17296                                 continue;
17297                         }
17298
17299                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17300                         {
17301                                 continue;
17302                         }
17303
17304                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17305                         {
17306                                 const GLint first_aliasing = gohan - n_req_components + 1;
17307                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17308
17309                                 const GLuint goten_start = std::max(0, first_aliasing);
17310                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17311
17312                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17313                                 {
17314                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17315
17316                                         m_test_cases.push_back(test_case);
17317                                 }
17318                         }
17319                 }
17320         }
17321 }
17322
17323 /** Constructor
17324  *
17325  * @param context Test framework context
17326  **/
17327 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17328         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17329                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17330 {
17331 }
17332
17333 /** Source for given test case and stage
17334  *
17335  * @param test_case_index Index of test case
17336  * @param stage           Shader stage
17337  *
17338  * @return Shader source
17339  **/
17340 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17341                                                                                                                                            Utils::Shader::STAGES stage)
17342 {
17343         static const GLchar* var_definition =
17344                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17345                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17346         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17347                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17348                                                                          "    {\n"
17349                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17350                                                                          "    }\n";
17351         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17352                                                                           "    gotenINDEX = TYPE(1);\n"
17353                                                                           "    if (vec4(0) == result)\n"
17354                                                                           "    {\n"
17355                                                                           "        gohanINDEX = TYPE(1);\n"
17356                                                                           "        gotenINDEX = TYPE(0);\n"
17357                                                                           "    }\n";
17358         static const GLchar* fs = "#version 430 core\n"
17359                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17360                                                           "\n"
17361                                                           "in  vec4 gs_fs;\n"
17362                                                           "out vec4 fs_out;\n"
17363                                                           "\n"
17364                                                           "void main()\n"
17365                                                           "{\n"
17366                                                           "    fs_out = gs_fs;\n"
17367                                                           "}\n"
17368                                                           "\n";
17369         static const GLchar* fs_tested = "#version 430 core\n"
17370                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17371                                                                          "\n"
17372                                                                          "VAR_DEFINITION"
17373                                                                          "\n"
17374                                                                          "in  vec4 gs_fs;\n"
17375                                                                          "out vec4 fs_out;\n"
17376                                                                          "\n"
17377                                                                          "void main()\n"
17378                                                                          "{\n"
17379                                                                          "    vec4 result = gs_fs;\n"
17380                                                                          "\n"
17381                                                                          "VARIABLE_USE"
17382                                                                          "\n"
17383                                                                          "    fs_out += result;\n"
17384                                                                          "}\n"
17385                                                                          "\n";
17386         static const GLchar* gs = "#version 430 core\n"
17387                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17388                                                           "\n"
17389                                                           "layout(points)                           in;\n"
17390                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17391                                                           "\n"
17392                                                           "in  vec4 tes_gs[];\n"
17393                                                           "out vec4 gs_fs;\n"
17394                                                           "\n"
17395                                                           "void main()\n"
17396                                                           "{\n"
17397                                                           "    gs_fs = tes_gs[0];\n"
17398                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17399                                                           "    EmitVertex();\n"
17400                                                           "    gs_fs = tes_gs[0];\n"
17401                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17402                                                           "    EmitVertex();\n"
17403                                                           "    gs_fs = tes_gs[0];\n"
17404                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17405                                                           "    EmitVertex();\n"
17406                                                           "    gs_fs = tes_gs[0];\n"
17407                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17408                                                           "    EmitVertex();\n"
17409                                                           "}\n"
17410                                                           "\n";
17411         static const GLchar* gs_tested = "#version 430 core\n"
17412                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17413                                                                          "\n"
17414                                                                          "layout(points)                           in;\n"
17415                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17416                                                                          "\n"
17417                                                                          "VAR_DEFINITION"
17418                                                                          "\n"
17419                                                                          "in  vec4 tes_gs[];\n"
17420                                                                          "out vec4 gs_fs;\n"
17421                                                                          "\n"
17422                                                                          "void main()\n"
17423                                                                          "{\n"
17424                                                                          "    vec4 result = tes_gs[0];\n"
17425                                                                          "\n"
17426                                                                          "VARIABLE_USE"
17427                                                                          "\n"
17428                                                                          "    gs_fs = result;\n"
17429                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17430                                                                          "    EmitVertex();\n"
17431                                                                          "    gs_fs = result;\n"
17432                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17433                                                                          "    EmitVertex();\n"
17434                                                                          "    gs_fs = result;\n"
17435                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17436                                                                          "    EmitVertex();\n"
17437                                                                          "    gs_fs = result;\n"
17438                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17439                                                                          "    EmitVertex();\n"
17440                                                                          "}\n"
17441                                                                          "\n";
17442         static const GLchar* tcs = "#version 430 core\n"
17443                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17444                                                            "\n"
17445                                                            "layout(vertices = 1) out;\n"
17446                                                            "\n"
17447                                                            "in  vec4 vs_tcs[];\n"
17448                                                            "out vec4 tcs_tes[];\n"
17449                                                            "\n"
17450                                                            "void main()\n"
17451                                                            "{\n"
17452                                                            "\n"
17453                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17454                                                            "\n"
17455                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17456                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17457                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17458                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17459                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17460                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17461                                                            "}\n"
17462                                                            "\n";
17463         static const GLchar* tcs_tested = "#version 430 core\n"
17464                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17465                                                                           "\n"
17466                                                                           "layout(vertices = 1) out;\n"
17467                                                                           "\n"
17468                                                                           "VAR_DEFINITION"
17469                                                                           "\n"
17470                                                                           "in  vec4 vs_tcs[];\n"
17471                                                                           "out vec4 tcs_tes[];\n"
17472                                                                           "\n"
17473                                                                           "void main()\n"
17474                                                                           "{\n"
17475                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17476                                                                           "\n"
17477                                                                           "VARIABLE_USE"
17478                                                                           "\n"
17479                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17480                                                                           "\n"
17481                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17482                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17483                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17484                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17485                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17486                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17487                                                                           "}\n"
17488                                                                           "\n";
17489         static const GLchar* tes = "#version 430 core\n"
17490                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17491                                                            "\n"
17492                                                            "layout(isolines, point_mode) in;\n"
17493                                                            "\n"
17494                                                            "in  vec4 tcs_tes[];\n"
17495                                                            "out vec4 tes_gs;\n"
17496                                                            "\n"
17497                                                            "void main()\n"
17498                                                            "{\n"
17499                                                            "    tes_gs = tcs_tes[0];\n"
17500                                                            "}\n"
17501                                                            "\n";
17502         static const GLchar* tes_tested = "#version 430 core\n"
17503                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17504                                                                           "\n"
17505                                                                           "layout(isolines, point_mode) in;\n"
17506                                                                           "\n"
17507                                                                           "VAR_DEFINITION"
17508                                                                           "\n"
17509                                                                           "in  vec4 tcs_tes[];\n"
17510                                                                           "out vec4 tes_gs;\n"
17511                                                                           "\n"
17512                                                                           "void main()\n"
17513                                                                           "{\n"
17514                                                                           "    vec4 result = tcs_tes[0];\n"
17515                                                                           "\n"
17516                                                                           "VARIABLE_USE"
17517                                                                           "\n"
17518                                                                           "    tes_gs += result;\n"
17519                                                                           "}\n"
17520                                                                           "\n";
17521         static const GLchar* vs = "#version 430 core\n"
17522                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17523                                                           "\n"
17524                                                           "in  vec4 in_vs;\n"
17525                                                           "out vec4 vs_tcs;\n"
17526                                                           "\n"
17527                                                           "void main()\n"
17528                                                           "{\n"
17529                                                           "    vs_tcs = in_vs;\n"
17530                                                           "}\n"
17531                                                           "\n";
17532         static const GLchar* vs_tested = "#version 430 core\n"
17533                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17534                                                                          "\n"
17535                                                                          "VAR_DEFINITION"
17536                                                                          "\n"
17537                                                                          "in  vec4 in_vs;\n"
17538                                                                          "out vec4 vs_tcs;\n"
17539                                                                          "\n"
17540                                                                          "void main()\n"
17541                                                                          "{\n"
17542                                                                          "    vec4 result = in_vs;\n"
17543                                                                          "\n"
17544                                                                          "VARIABLE_USE"
17545                                                                          "\n"
17546                                                                          "    vs_tcs += result;\n"
17547                                                                          "}\n"
17548                                                                          "\n";
17549
17550         std::string source;
17551         testCase&   test_case = m_test_cases[test_case_index];
17552
17553         if (test_case.m_stage == stage)
17554         {
17555                 const GLchar*                    array = "";
17556                 GLchar                                   buffer_gohan[16];
17557                 GLchar                                   buffer_goten[16];
17558                 const GLchar*                    direction  = "in ";
17559                 const GLchar*                    flat_gohan = "";
17560                 const GLchar*                    flat_goten = "";
17561                 const GLchar*                    index          = "";
17562                 size_t                                   position   = 0;
17563                 size_t                                   temp;
17564                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17565                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17566                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17567                 const GLchar*                    var_use                 = input_use;
17568
17569                 if (false == test_case.m_is_input)
17570                 {
17571                         direction = "out";
17572                         storage   = Utils::Variable::VARYING_OUTPUT;
17573                         var_use   = output_use;
17574                 }
17575
17576                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17577                 {
17578                         flat_gohan = "flat";
17579                 }
17580
17581                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17582                 {
17583                         flat_goten = "flat";
17584                 }
17585
17586                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17587                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17588
17589                 switch (stage)
17590                 {
17591                 case Utils::Shader::FRAGMENT:
17592                         source = fs_tested;
17593                         break;
17594                 case Utils::Shader::GEOMETRY:
17595                         source = gs_tested;
17596                         array  = "[]";
17597                         index  = "[0]";
17598                         break;
17599                 case Utils::Shader::TESS_CTRL:
17600                         source = tcs_tested;
17601                         array  = "[]";
17602                         index  = "[gl_InvocationID]";
17603                         break;
17604                 case Utils::Shader::TESS_EVAL:
17605                         source = tes_tested;
17606                         array  = "[]";
17607                         index  = "[0]";
17608                         break;
17609                 case Utils::Shader::VERTEX:
17610                         source = vs_tested;
17611                         break;
17612                 default:
17613                         TCU_FAIL("Invalid enum");
17614                 }
17615
17616                 temp = position;
17617                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17618                 position = temp;
17619                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17620                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17621                 Utils::replaceToken("DIRECTION", position, direction, source);
17622                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17623                 Utils::replaceToken("ARRAY", position, array, source);
17624                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17625                 Utils::replaceToken("FLAT", position, flat_goten, source);
17626                 Utils::replaceToken("DIRECTION", position, direction, source);
17627                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17628                 Utils::replaceToken("ARRAY", position, array, source);
17629
17630                 temp = position;
17631                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17632                 position = temp;
17633                 if (true == test_case.m_is_input)
17634                 {
17635                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17636                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17637                 }
17638                 else
17639                 {
17640                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17641                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17642                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17643                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17644                 }
17645
17646                 Utils::replaceAllTokens("INDEX", index, source);
17647         }
17648         else
17649         {
17650                 switch (stage)
17651                 {
17652                 case Utils::Shader::FRAGMENT:
17653                         source = fs;
17654                         break;
17655                 case Utils::Shader::GEOMETRY:
17656                         source = gs;
17657                         break;
17658                 case Utils::Shader::TESS_CTRL:
17659                         source = tcs;
17660                         break;
17661                 case Utils::Shader::TESS_EVAL:
17662                         source = tes;
17663                         break;
17664                 case Utils::Shader::VERTEX:
17665                         source = vs;
17666                         break;
17667                 default:
17668                         TCU_FAIL("Invalid enum");
17669                 }
17670         }
17671
17672         return source;
17673 }
17674
17675 /** Get description of test case
17676  *
17677  * @param test_case_index Index of test case
17678  *
17679  * @return Test case description
17680  **/
17681 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17682 {
17683         std::stringstream stream;
17684         testCase&                 test_case = m_test_cases[test_case_index];
17685
17686         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17687                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17688                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17689
17690         if (true == test_case.m_is_input)
17691         {
17692                 stream << "input";
17693         }
17694         else
17695         {
17696                 stream << "output";
17697         }
17698
17699         return stream.str();
17700 }
17701
17702 /** Get number of test cases
17703  *
17704  * @return Number of test cases
17705  **/
17706 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17707 {
17708         return static_cast<GLuint>(m_test_cases.size());
17709 }
17710
17711 /** Selects if "compute" stage is relevant for test
17712  *
17713  * @param ignored
17714  *
17715  * @return false
17716  **/
17717 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17718 {
17719         return false;
17720 }
17721
17722 /** Prepare all test cases
17723  *
17724  **/
17725 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17726 {
17727         static const GLuint n_components_per_location = 4;
17728         const GLuint            n_types                                   = getTypesNumber();
17729
17730         for (GLuint i = 0; i < n_types; ++i)
17731         {
17732                 const Utils::Type& type_gohan              = getType(i);
17733                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17734
17735                 /* Skip matrices */
17736                 if (1 != type_gohan.m_n_columns)
17737                 {
17738                         continue;
17739                 }
17740
17741                 for (GLuint j = 0; j < n_types; ++j)
17742                 {
17743                         const Utils::Type& type_goten              = getType(j);
17744                         const bool                 is_float_type_goten = isFloatType(type_goten);
17745
17746                         /* Skip matrices */
17747                         if (1 != type_goten.m_n_columns)
17748                         {
17749                                 continue;
17750                         }
17751
17752                         /* Skip valid combinations */
17753                         if (is_float_type_gohan == is_float_type_goten)
17754                         {
17755                                 continue;
17756                         }
17757
17758                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17759                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17760                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17761                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17762
17763                         /* Skip pairs that cannot fit into one location */
17764                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17765                         {
17766                                 continue;
17767                         }
17768
17769                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17770                         {
17771                                 /* Skip compute shader */
17772                                 if (Utils::Shader::COMPUTE == stage)
17773                                 {
17774                                         continue;
17775                                 }
17776
17777                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17778                                 {
17779                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17780                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17781
17782                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17783                                         const GLuint goten_upper_limit = last_aliasing + 1;
17784
17785                                         /* Compoennets before gohan */
17786                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17787                                         {
17788                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17789                                                                                                   type_gohan, type_goten };
17790                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17791                                                                                                    type_gohan, type_goten };
17792
17793                                                 m_test_cases.push_back(test_case_in);
17794
17795                                                 /* Skip double outputs in fragment shader */
17796                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17797                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17798                                                 {
17799                                                         m_test_cases.push_back(test_case_out);
17800                                                 }
17801                                         }
17802
17803                                         /* Components after gohan */
17804                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17805                                         {
17806                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17807                                                                                                   type_gohan, type_goten };
17808                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17809                                                                                                    type_gohan, type_goten };
17810
17811                                                 m_test_cases.push_back(test_case_in);
17812
17813                                                 /* Skip double outputs in fragment shader */
17814                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17815                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17816                                                 {
17817                                                         m_test_cases.push_back(test_case_out);
17818                                                 }
17819                                         }
17820                                 }
17821                         }
17822                 }
17823         }
17824 }
17825
17826 /** Check if given type is float
17827  *
17828  * @param type Type in question
17829  *
17830  * @return true if tpye is float, false otherwise
17831  **/
17832 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17833 {
17834         bool is_float = false;
17835
17836         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17837         {
17838                 is_float = true;
17839         }
17840
17841         return is_float;
17842 }
17843
17844 /** Constructor
17845  *
17846  * @param context Test framework context
17847  **/
17848 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17849         deqp::Context& context)
17850         : NegativeTestBase(
17851                   context, "varying_location_aliasing_with_mixed_interpolation",
17852                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17853 {
17854 }
17855
17856 /** Source for given test case and stage
17857  *
17858  * @param test_case_index Index of test case
17859  * @param stage           Shader stage
17860  *
17861  * @return Shader source
17862  **/
17863 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17864                                                                                                                                                            Utils::Shader::STAGES stage)
17865 {
17866         static const GLchar* var_definition =
17867                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17868                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17869         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17870                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17871                                                                          "    {\n"
17872                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17873                                                                          "    }\n";
17874         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17875                                                                           "    gotenINDEX = TYPE(1);\n"
17876                                                                           "    if (vec4(0) == result)\n"
17877                                                                           "    {\n"
17878                                                                           "        gohanINDEX = TYPE(1);\n"
17879                                                                           "        gotenINDEX = TYPE(0);\n"
17880                                                                           "    }\n";
17881         static const GLchar* fs = "#version 430 core\n"
17882                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17883                                                           "\n"
17884                                                           "in  vec4 gs_fs;\n"
17885                                                           "out vec4 fs_out;\n"
17886                                                           "\n"
17887                                                           "void main()\n"
17888                                                           "{\n"
17889                                                           "    fs_out = gs_fs;\n"
17890                                                           "}\n"
17891                                                           "\n";
17892         static const GLchar* fs_tested = "#version 430 core\n"
17893                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17894                                                                          "\n"
17895                                                                          "VAR_DEFINITION"
17896                                                                          "\n"
17897                                                                          "in  vec4 gs_fs;\n"
17898                                                                          "out vec4 fs_out;\n"
17899                                                                          "\n"
17900                                                                          "void main()\n"
17901                                                                          "{\n"
17902                                                                          "    vec4 result = gs_fs;\n"
17903                                                                          "\n"
17904                                                                          "VARIABLE_USE"
17905                                                                          "\n"
17906                                                                          "    fs_out = result;\n"
17907                                                                          "}\n"
17908                                                                          "\n";
17909         static const GLchar* gs = "#version 430 core\n"
17910                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17911                                                           "\n"
17912                                                           "layout(points)                           in;\n"
17913                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17914                                                           "\n"
17915                                                           "in  vec4 tes_gs[];\n"
17916                                                           "out vec4 gs_fs;\n"
17917                                                           "\n"
17918                                                           "void main()\n"
17919                                                           "{\n"
17920                                                           "    gs_fs = tes_gs[0];\n"
17921                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17922                                                           "    EmitVertex();\n"
17923                                                           "    gs_fs = tes_gs[0];\n"
17924                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17925                                                           "    EmitVertex();\n"
17926                                                           "    gs_fs = tes_gs[0];\n"
17927                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17928                                                           "    EmitVertex();\n"
17929                                                           "    gs_fs = tes_gs[0];\n"
17930                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17931                                                           "    EmitVertex();\n"
17932                                                           "}\n"
17933                                                           "\n";
17934         static const GLchar* gs_tested = "#version 430 core\n"
17935                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17936                                                                          "\n"
17937                                                                          "layout(points)                           in;\n"
17938                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17939                                                                          "\n"
17940                                                                          "VAR_DEFINITION"
17941                                                                          "\n"
17942                                                                          "in  vec4 tes_gs[];\n"
17943                                                                          "out vec4 gs_fs;\n"
17944                                                                          "\n"
17945                                                                          "void main()\n"
17946                                                                          "{\n"
17947                                                                          "    vec4 result = tes_gs[0];\n"
17948                                                                          "\n"
17949                                                                          "VARIABLE_USE"
17950                                                                          "\n"
17951                                                                          "    gs_fs = result;\n"
17952                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17953                                                                          "    EmitVertex();\n"
17954                                                                          "    gs_fs = result;\n"
17955                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17956                                                                          "    EmitVertex();\n"
17957                                                                          "    gs_fs = result;\n"
17958                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17959                                                                          "    EmitVertex();\n"
17960                                                                          "    gs_fs = result;\n"
17961                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17962                                                                          "    EmitVertex();\n"
17963                                                                          "}\n"
17964                                                                          "\n";
17965         static const GLchar* tcs = "#version 430 core\n"
17966                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17967                                                            "\n"
17968                                                            "layout(vertices = 1) out;\n"
17969                                                            "\n"
17970                                                            "in  vec4 vs_tcs[];\n"
17971                                                            "out vec4 tcs_tes[];\n"
17972                                                            "\n"
17973                                                            "void main()\n"
17974                                                            "{\n"
17975                                                            "\n"
17976                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17977                                                            "\n"
17978                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17979                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17980                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17981                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17982                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17983                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17984                                                            "}\n"
17985                                                            "\n";
17986         static const GLchar* tcs_tested = "#version 430 core\n"
17987                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17988                                                                           "\n"
17989                                                                           "layout(vertices = 1) out;\n"
17990                                                                           "\n"
17991                                                                           "VAR_DEFINITION"
17992                                                                           "\n"
17993                                                                           "in  vec4 vs_tcs[];\n"
17994                                                                           "out vec4 tcs_tes[];\n"
17995                                                                           "\n"
17996                                                                           "void main()\n"
17997                                                                           "{\n"
17998                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17999                                                                           "\n"
18000                                                                           "VARIABLE_USE"
18001                                                                           "\n"
18002                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18003                                                                           "\n"
18004                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18005                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18006                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18007                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18008                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18009                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18010                                                                           "}\n"
18011                                                                           "\n";
18012         static const GLchar* tes = "#version 430 core\n"
18013                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18014                                                            "\n"
18015                                                            "layout(isolines, point_mode) in;\n"
18016                                                            "\n"
18017                                                            "in  vec4 tcs_tes[];\n"
18018                                                            "out vec4 tes_gs;\n"
18019                                                            "\n"
18020                                                            "void main()\n"
18021                                                            "{\n"
18022                                                            "    tes_gs = tcs_tes[0];\n"
18023                                                            "}\n"
18024                                                            "\n";
18025         static const GLchar* tes_tested = "#version 430 core\n"
18026                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18027                                                                           "\n"
18028                                                                           "layout(isolines, point_mode) in;\n"
18029                                                                           "\n"
18030                                                                           "VAR_DEFINITION"
18031                                                                           "\n"
18032                                                                           "in  vec4 tcs_tes[];\n"
18033                                                                           "out vec4 tes_gs;\n"
18034                                                                           "\n"
18035                                                                           "void main()\n"
18036                                                                           "{\n"
18037                                                                           "    vec4 result = tcs_tes[0];\n"
18038                                                                           "\n"
18039                                                                           "VARIABLE_USE"
18040                                                                           "\n"
18041                                                                           "    tes_gs += result;\n"
18042                                                                           "}\n"
18043                                                                           "\n";
18044         static const GLchar* vs = "#version 430 core\n"
18045                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18046                                                           "\n"
18047                                                           "in  vec4 in_vs;\n"
18048                                                           "out vec4 vs_tcs;\n"
18049                                                           "\n"
18050                                                           "void main()\n"
18051                                                           "{\n"
18052                                                           "    vs_tcs = in_vs;\n"
18053                                                           "}\n"
18054                                                           "\n";
18055         static const GLchar* vs_tested = "#version 430 core\n"
18056                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18057                                                                          "\n"
18058                                                                          "VAR_DEFINITION"
18059                                                                          "\n"
18060                                                                          "in  vec4 in_vs;\n"
18061                                                                          "out vec4 vs_tcs;\n"
18062                                                                          "\n"
18063                                                                          "void main()\n"
18064                                                                          "{\n"
18065                                                                          "    vec4 result = in_vs;\n"
18066                                                                          "\n"
18067                                                                          "VARIABLE_USE"
18068                                                                          "\n"
18069                                                                          "    vs_tcs += result;\n"
18070                                                                          "}\n"
18071                                                                          "\n";
18072
18073         std::string source;
18074         testCase&   test_case = m_test_cases[test_case_index];
18075
18076         if (test_case.m_stage == stage)
18077         {
18078                 const GLchar* array = "";
18079                 GLchar            buffer_gohan[16];
18080                 GLchar            buffer_goten[16];
18081                 const GLchar* direction = "in ";
18082                 const GLchar* index             = "";
18083                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18084                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18085                 size_t            position  = 0;
18086                 size_t            temp;
18087                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18088                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18089                 const GLchar* var_use             = input_use;
18090
18091                 if (false == test_case.m_is_input)
18092                 {
18093                         direction = "out";
18094
18095                         var_use = output_use;
18096                 }
18097
18098                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18099                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18100
18101                 switch (stage)
18102                 {
18103                 case Utils::Shader::FRAGMENT:
18104                         source = fs_tested;
18105                         break;
18106                 case Utils::Shader::GEOMETRY:
18107                         source = gs_tested;
18108                         array  = "[]";
18109                         index  = "[0]";
18110                         break;
18111                 case Utils::Shader::TESS_CTRL:
18112                         source = tcs_tested;
18113                         array  = "[]";
18114                         index  = "[gl_InvocationID]";
18115                         break;
18116                 case Utils::Shader::TESS_EVAL:
18117                         source = tes_tested;
18118                         array  = "[]";
18119                         index  = "[0]";
18120                         break;
18121                 case Utils::Shader::VERTEX:
18122                         source = vs_tested;
18123                         break;
18124                 default:
18125                         TCU_FAIL("Invalid enum");
18126                 }
18127
18128                 temp = position;
18129                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18130                 position = temp;
18131                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18132                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18133                 Utils::replaceToken("DIRECTION", position, direction, source);
18134                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18135                 Utils::replaceToken("ARRAY", position, array, source);
18136                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18137                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18138                 Utils::replaceToken("DIRECTION", position, direction, source);
18139                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18140                 Utils::replaceToken("ARRAY", position, array, source);
18141
18142                 temp = position;
18143                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18144                 position = temp;
18145                 if (true == test_case.m_is_input)
18146                 {
18147                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18148                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18149                 }
18150                 else
18151                 {
18152                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18153                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18154                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18155                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18156                 }
18157
18158                 Utils::replaceAllTokens("INDEX", index, source);
18159         }
18160         else
18161         {
18162                 switch (stage)
18163                 {
18164                 case Utils::Shader::FRAGMENT:
18165                         source = fs;
18166                         break;
18167                 case Utils::Shader::GEOMETRY:
18168                         source = gs;
18169                         break;
18170                 case Utils::Shader::TESS_CTRL:
18171                         source = tcs;
18172                         break;
18173                 case Utils::Shader::TESS_EVAL:
18174                         source = tes;
18175                         break;
18176                 case Utils::Shader::VERTEX:
18177                         source = vs;
18178                         break;
18179                 default:
18180                         TCU_FAIL("Invalid enum");
18181                 }
18182         }
18183
18184         return source;
18185 }
18186
18187 /** Get description of test case
18188  *
18189  * @param test_case_index Index of test case
18190  *
18191  * @return Test case description
18192  **/
18193 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18194 {
18195         std::stringstream stream;
18196         testCase&                 test_case = m_test_cases[test_case_index];
18197
18198         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18199                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18200                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18201                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18202                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18203
18204         if (true == test_case.m_is_input)
18205         {
18206                 stream << "input";
18207         }
18208         else
18209         {
18210                 stream << "output";
18211         }
18212
18213         return stream.str();
18214 }
18215
18216 /** Get number of test cases
18217  *
18218  * @return Number of test cases
18219  **/
18220 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18221 {
18222         return static_cast<GLuint>(m_test_cases.size());
18223 }
18224
18225 /** Selects if "compute" stage is relevant for test
18226  *
18227  * @param ignored
18228  *
18229  * @return false
18230  **/
18231 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18232 {
18233         return false;
18234 }
18235
18236 /** Prepare all test cases
18237  *
18238  **/
18239 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18240 {
18241         static const GLuint n_components_per_location = 4;
18242         const GLuint            n_types                                   = getTypesNumber();
18243
18244         for (GLuint i = 0; i < n_types; ++i)
18245         {
18246                 const Utils::Type& type_gohan              = getType(i);
18247                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18248
18249                 /* Skip matrices */
18250                 if (1 != type_gohan.m_n_columns)
18251                 {
18252                         continue;
18253                 }
18254
18255                 for (GLuint j = 0; j < n_types; ++j)
18256                 {
18257                         const Utils::Type& type_goten              = getType(j);
18258                         const bool                 is_float_type_goten = isFloatType(type_goten);
18259
18260                         /* Skip matrices */
18261                         if (1 != type_goten.m_n_columns)
18262                         {
18263                                 continue;
18264                         }
18265
18266                         /* Skip invalid combinations */
18267                         if (is_float_type_gohan != is_float_type_goten)
18268                         {
18269                                 continue;
18270                         }
18271
18272                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18273                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18274
18275                         /* Skip pairs that cannot fit into one location */
18276                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18277                         {
18278                                 continue;
18279                         }
18280
18281                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18282                         {
18283                                 /* Skip compute shader */
18284                                 if (Utils::Shader::COMPUTE == stage)
18285                                 {
18286                                         continue;
18287                                 }
18288
18289                                 const GLuint gohan = 0;
18290                                 const GLuint goten = gohan + n_req_components_gohan;
18291
18292                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18293                                 {
18294                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18295                                         {
18296                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18297                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18298                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18299                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18300                                                 const bool is_gohan_accepted_as_fs_in =
18301                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18302                                                 const bool is_goten_accepted_as_fs_in =
18303                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18304                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18305
18306                                                 /* Skip when both are the same */
18307                                                 if (int_gohan == int_goten)
18308                                                 {
18309                                                         continue;
18310                                                 }
18311
18312                                                 testCase test_case_in = { gohan,
18313                                                                                                   goten,
18314                                                                                                   (INTERPOLATIONS)int_gohan,
18315                                                                                                   (INTERPOLATIONS)int_goten,
18316                                                                                                   true,
18317                                                                                                   (Utils::Shader::STAGES)stage,
18318                                                                                                   type_gohan,
18319                                                                                                   type_goten };
18320
18321                                                 testCase test_case_out = { gohan,
18322                                                                                                    goten,
18323                                                                                                    (INTERPOLATIONS)int_gohan,
18324                                                                                                    (INTERPOLATIONS)int_goten,
18325                                                                                                    false,
18326                                                                                                    (Utils::Shader::STAGES)stage,
18327                                                                                                    type_gohan,
18328                                                                                                    type_goten };
18329
18330                                                 /* Skip inputs in:
18331                                                  * vertex shader,
18332                                                  * fragment shader when not flat double is used
18333                                                  */
18334                                                 if ((Utils::Shader::VERTEX != stage) &&
18335                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18336                                                 {
18337                                                         m_test_cases.push_back(test_case_in);
18338                                                 }
18339
18340                                                 /* Skip outputs in fragment shader */
18341                                                 if (Utils::Shader::FRAGMENT != stage)
18342                                                 {
18343                                                         m_test_cases.push_back(test_case_out);
18344                                                 }
18345                                         }
18346                                 }
18347                         }
18348                 }
18349         }
18350 }
18351
18352 /** Get interpolation qualifier
18353  *
18354  * @param interpolation Enumeration
18355  *
18356  * @return GLSL qualifier
18357  **/
18358 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18359 {
18360         const GLchar* result = 0;
18361
18362         switch (interpolation)
18363         {
18364         case SMOOTH:
18365                 result = "smooth";
18366                 break;
18367         case FLAT:
18368                 result = "flat";
18369                 break;
18370         case NO_PERSPECTIVE:
18371                 result = "noperspective";
18372                 break;
18373         default:
18374                 TCU_FAIL("Invalid enum");
18375         }
18376
18377         return result;
18378 }
18379
18380 /** Check if given type is float
18381  *
18382  * @param type Type in question
18383  *
18384  * @return true if tpye is float, false otherwise
18385  **/
18386 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18387 {
18388         bool is_float = false;
18389
18390         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18391         {
18392                 is_float = true;
18393         }
18394
18395         return is_float;
18396 }
18397
18398 /** Constructor
18399  *
18400  * @param context Test framework context
18401  **/
18402 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18403         deqp::Context& context)
18404         : NegativeTestBase(
18405                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18406                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18407 {
18408 }
18409
18410 /** Source for given test case and stage
18411  *
18412  * @param test_case_index Index of test case
18413  * @param stage           Shader stage
18414  *
18415  * @return Shader source
18416  **/
18417 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18418                                                                                                                                                                   Utils::Shader::STAGES stage)
18419 {
18420         static const GLchar* var_definition =
18421                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18422                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18423         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18424                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18425                                                                          "    {\n"
18426                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18427                                                                          "    }\n";
18428         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18429                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18430                                                                           "    if (vec4(0) == result)\n"
18431                                                                           "    {\n"
18432                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18433                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18434                                                                           "    }\n";
18435         static const GLchar* fs = "#version 430 core\n"
18436                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18437                                                           "\n"
18438                                                           "in  vec4 gs_fs;\n"
18439                                                           "out vec4 fs_out;\n"
18440                                                           "\n"
18441                                                           "void main()\n"
18442                                                           "{\n"
18443                                                           "    fs_out = gs_fs;\n"
18444                                                           "}\n"
18445                                                           "\n";
18446         static const GLchar* fs_tested = "#version 430 core\n"
18447                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18448                                                                          "\n"
18449                                                                          "VAR_DEFINITION"
18450                                                                          "\n"
18451                                                                          "in  vec4 gs_fs;\n"
18452                                                                          "out vec4 fs_out;\n"
18453                                                                          "\n"
18454                                                                          "void main()\n"
18455                                                                          "{\n"
18456                                                                          "    vec4 result = gs_fs;\n"
18457                                                                          "\n"
18458                                                                          "VARIABLE_USE"
18459                                                                          "\n"
18460                                                                          "    fs_out = result;\n"
18461                                                                          "}\n"
18462                                                                          "\n";
18463         static const GLchar* gs = "#version 430 core\n"
18464                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18465                                                           "\n"
18466                                                           "layout(points)                           in;\n"
18467                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18468                                                           "\n"
18469                                                           "in  vec4 tes_gs[];\n"
18470                                                           "out vec4 gs_fs;\n"
18471                                                           "\n"
18472                                                           "void main()\n"
18473                                                           "{\n"
18474                                                           "    gs_fs = tes_gs[0];\n"
18475                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18476                                                           "    EmitVertex();\n"
18477                                                           "    gs_fs = tes_gs[0];\n"
18478                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18479                                                           "    EmitVertex();\n"
18480                                                           "    gs_fs = tes_gs[0];\n"
18481                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18482                                                           "    EmitVertex();\n"
18483                                                           "    gs_fs = tes_gs[0];\n"
18484                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18485                                                           "    EmitVertex();\n"
18486                                                           "}\n"
18487                                                           "\n";
18488         static const GLchar* gs_tested = "#version 430 core\n"
18489                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18490                                                                          "\n"
18491                                                                          "layout(points)                           in;\n"
18492                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18493                                                                          "\n"
18494                                                                          "VAR_DEFINITION"
18495                                                                          "\n"
18496                                                                          "in  vec4 tes_gs[];\n"
18497                                                                          "out vec4 gs_fs;\n"
18498                                                                          "\n"
18499                                                                          "void main()\n"
18500                                                                          "{\n"
18501                                                                          "    vec4 result = tes_gs[0];\n"
18502                                                                          "\n"
18503                                                                          "VARIABLE_USE"
18504                                                                          "\n"
18505                                                                          "    gs_fs = result;\n"
18506                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18507                                                                          "    EmitVertex();\n"
18508                                                                          "    gs_fs = result;\n"
18509                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18510                                                                          "    EmitVertex();\n"
18511                                                                          "    gs_fs = result;\n"
18512                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18513                                                                          "    EmitVertex();\n"
18514                                                                          "    gs_fs = result;\n"
18515                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18516                                                                          "    EmitVertex();\n"
18517                                                                          "}\n"
18518                                                                          "\n";
18519         static const GLchar* tcs = "#version 430 core\n"
18520                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18521                                                            "\n"
18522                                                            "layout(vertices = 1) out;\n"
18523                                                            "\n"
18524                                                            "in  vec4 vs_tcs[];\n"
18525                                                            "out vec4 tcs_tes[];\n"
18526                                                            "\n"
18527                                                            "void main()\n"
18528                                                            "{\n"
18529                                                            "\n"
18530                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18531                                                            "\n"
18532                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18533                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18534                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18535                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18536                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18537                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18538                                                            "}\n"
18539                                                            "\n";
18540         static const GLchar* tcs_tested = "#version 430 core\n"
18541                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18542                                                                           "\n"
18543                                                                           "layout(vertices = 1) out;\n"
18544                                                                           "\n"
18545                                                                           "VAR_DEFINITION"
18546                                                                           "\n"
18547                                                                           "in  vec4 vs_tcs[];\n"
18548                                                                           "out vec4 tcs_tes[];\n"
18549                                                                           "\n"
18550                                                                           "void main()\n"
18551                                                                           "{\n"
18552                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18553                                                                           "\n"
18554                                                                           "VARIABLE_USE"
18555                                                                           "\n"
18556                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18557                                                                           "\n"
18558                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18559                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18560                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18561                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18562                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18563                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18564                                                                           "}\n"
18565                                                                           "\n";
18566         static const GLchar* tes = "#version 430 core\n"
18567                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18568                                                            "\n"
18569                                                            "layout(isolines, point_mode) in;\n"
18570                                                            "\n"
18571                                                            "in  vec4 tcs_tes[];\n"
18572                                                            "out vec4 tes_gs;\n"
18573                                                            "\n"
18574                                                            "void main()\n"
18575                                                            "{\n"
18576                                                            "    tes_gs = tcs_tes[0];\n"
18577                                                            "}\n"
18578                                                            "\n";
18579         static const GLchar* tes_tested = "#version 430 core\n"
18580                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18581                                                                           "\n"
18582                                                                           "layout(isolines, point_mode) in;\n"
18583                                                                           "\n"
18584                                                                           "VAR_DEFINITION"
18585                                                                           "\n"
18586                                                                           "in  vec4 tcs_tes[];\n"
18587                                                                           "out vec4 tes_gs;\n"
18588                                                                           "\n"
18589                                                                           "void main()\n"
18590                                                                           "{\n"
18591                                                                           "    vec4 result = tcs_tes[0];\n"
18592                                                                           "\n"
18593                                                                           "VARIABLE_USE"
18594                                                                           "\n"
18595                                                                           "    tes_gs += result;\n"
18596                                                                           "}\n"
18597                                                                           "\n";
18598         static const GLchar* vs = "#version 430 core\n"
18599                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18600                                                           "\n"
18601                                                           "in  vec4 in_vs;\n"
18602                                                           "out vec4 vs_tcs;\n"
18603                                                           "\n"
18604                                                           "void main()\n"
18605                                                           "{\n"
18606                                                           "    vs_tcs = in_vs;\n"
18607                                                           "}\n"
18608                                                           "\n";
18609         static const GLchar* vs_tested = "#version 430 core\n"
18610                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18611                                                                          "\n"
18612                                                                          "VAR_DEFINITION"
18613                                                                          "\n"
18614                                                                          "in  vec4 in_vs;\n"
18615                                                                          "out vec4 vs_tcs;\n"
18616                                                                          "\n"
18617                                                                          "void main()\n"
18618                                                                          "{\n"
18619                                                                          "    vec4 result = in_vs;\n"
18620                                                                          "\n"
18621                                                                          "VARIABLE_USE"
18622                                                                          "\n"
18623                                                                          "    vs_tcs += result;\n"
18624                                                                          "}\n"
18625                                                                          "\n";
18626
18627         std::string source;
18628         testCase&   test_case = m_test_cases[test_case_index];
18629
18630         if (test_case.m_stage == stage)
18631         {
18632                 const GLchar* array_gohan = "";
18633                 const GLchar* array_goten = "";
18634                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18635                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18636                 GLchar            buffer_gohan[16];
18637                 GLchar            buffer_goten[16];
18638                 const GLchar* direction   = "in ";
18639                 const GLchar* index_gohan = "";
18640                 const GLchar* index_goten = "";
18641                 const GLchar* int_gohan   = test_case.m_int_gohan;
18642                 const GLchar* int_goten   = test_case.m_int_goten;
18643                 size_t            position      = 0;
18644                 size_t            temp;
18645                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18646                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18647                 const GLchar* var_use             = input_use;
18648
18649                 if (false == test_case.m_is_input)
18650                 {
18651                         direction = "out";
18652
18653                         var_use = output_use;
18654                 }
18655
18656                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18657                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18658
18659                 switch (stage)
18660                 {
18661                 case Utils::Shader::FRAGMENT:
18662                         source = fs_tested;
18663                         break;
18664                 case Utils::Shader::GEOMETRY:
18665                         source          = gs_tested;
18666                         array_gohan = "[]";
18667                         index_gohan = "[0]";
18668                         array_goten = "[]";
18669                         index_goten = "[0]";
18670                         break;
18671                 case Utils::Shader::TESS_CTRL:
18672                         source = tcs_tested;
18673                         if (PATCH != test_case.m_aux_gohan)
18674                         {
18675                                 array_gohan = "[]";
18676                                 index_gohan = "[gl_InvocationID]";
18677                         }
18678                         if (PATCH != test_case.m_aux_goten)
18679                         {
18680                                 array_goten = "[]";
18681                                 index_goten = "[gl_InvocationID]";
18682                         }
18683                         break;
18684                 case Utils::Shader::TESS_EVAL:
18685                         source          = tes_tested;
18686                         array_gohan = "[]";
18687                         index_gohan = "[0]";
18688                         array_goten = "[]";
18689                         index_goten = "[0]";
18690                         break;
18691                 case Utils::Shader::VERTEX:
18692                         source = vs_tested;
18693                         break;
18694                 default:
18695                         TCU_FAIL("Invalid enum");
18696                 }
18697
18698                 temp = position;
18699                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18700                 position = temp;
18701                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18702                 Utils::replaceToken("AUX", position, aux_gohan, source);
18703                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18704                 Utils::replaceToken("DIRECTION", position, direction, source);
18705                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18706                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18707                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18708                 Utils::replaceToken("AUX", position, aux_goten, source);
18709                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18710                 Utils::replaceToken("DIRECTION", position, direction, source);
18711                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18712                 Utils::replaceToken("ARRAY", position, array_goten, source);
18713
18714                 temp = position;
18715                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18716                 position = temp;
18717                 if (true == test_case.m_is_input)
18718                 {
18719                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18720                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18721                 }
18722                 else
18723                 {
18724                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18725                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18726                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18727                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18728                 }
18729
18730                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18731                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18732         }
18733         else
18734         {
18735                 switch (stage)
18736                 {
18737                 case Utils::Shader::FRAGMENT:
18738                         source = fs;
18739                         break;
18740                 case Utils::Shader::GEOMETRY:
18741                         source = gs;
18742                         break;
18743                 case Utils::Shader::TESS_CTRL:
18744                         source = tcs;
18745                         break;
18746                 case Utils::Shader::TESS_EVAL:
18747                         source = tes;
18748                         break;
18749                 case Utils::Shader::VERTEX:
18750                         source = vs;
18751                         break;
18752                 default:
18753                         TCU_FAIL("Invalid enum");
18754                 }
18755         }
18756
18757         return source;
18758 }
18759
18760 /** Get description of test case
18761  *
18762  * @param test_case_index Index of test case
18763  *
18764  * @return Test case description
18765  **/
18766 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18767 {
18768         std::stringstream stream;
18769         testCase&                 test_case = m_test_cases[test_case_index];
18770
18771         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18772                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18773                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18774                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18775
18776         if (true == test_case.m_is_input)
18777         {
18778                 stream << "input";
18779         }
18780         else
18781         {
18782                 stream << "output";
18783         }
18784
18785         return stream.str();
18786 }
18787
18788 /** Get number of test cases
18789  *
18790  * @return Number of test cases
18791  **/
18792 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18793 {
18794         return static_cast<GLuint>(m_test_cases.size());
18795 }
18796
18797 /** Selects if "compute" stage is relevant for test
18798  *
18799  * @param ignored
18800  *
18801  * @return false
18802  **/
18803 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18804 {
18805         return false;
18806 }
18807
18808 /** Prepare all test cases
18809  *
18810  **/
18811 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18812 {
18813         static const GLuint n_components_per_location = 4;
18814         const GLuint            n_types                                   = getTypesNumber();
18815
18816         for (GLuint i = 0; i < n_types; ++i)
18817         {
18818                 const Utils::Type& type_gohan              = getType(i);
18819                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18820
18821                 /* Skip matrices */
18822                 if (1 != type_gohan.m_n_columns)
18823                 {
18824                         continue;
18825                 }
18826
18827                 for (GLuint j = 0; j < n_types; ++j)
18828                 {
18829                         const Utils::Type& type_goten              = getType(j);
18830                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18831                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18832                         const bool                 is_float_type_goten = isFloatType(type_goten);
18833
18834                         /* Skip matrices */
18835                         if (1 != type_goten.m_n_columns)
18836                         {
18837                                 continue;
18838                         }
18839
18840                         /* Skip invalid combinations */
18841                         if (is_float_type_gohan != is_float_type_goten)
18842                         {
18843                                 continue;
18844                         }
18845
18846                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18847                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18848
18849                         /* Skip pairs that cannot fit into one location */
18850                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18851                         {
18852                                 continue;
18853                         }
18854
18855                         const GLuint gohan = 0;
18856                         const GLuint goten = gohan + n_req_components_gohan;
18857
18858                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18859                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18860
18861                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18862                                                                                   type_gohan, type_goten };
18863
18864                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18865                                                                                   type_gohan, type_goten };
18866
18867                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18868                                                                                   type_gohan, type_goten };
18869
18870                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18871                                                                                   type_gohan, type_goten };
18872
18873                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18874                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18875                                                                                  type_gohan,   type_goten };
18876
18877                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18878                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18879                                                                                  type_gohan,   type_goten };
18880
18881                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18882                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18883                                                                                  type_gohan,   type_goten };
18884
18885                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18886                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18887                                                                                  type_gohan,   type_goten };
18888
18889                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18890                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18891                                                                                  type_gohan,   type_goten };
18892
18893                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18894                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18895                                                                                  type_gohan,   type_goten };
18896
18897                         m_test_cases.push_back(test_case_tcs_np);
18898                         m_test_cases.push_back(test_case_tcs_pn);
18899                         m_test_cases.push_back(test_case_tes_np);
18900                         m_test_cases.push_back(test_case_tes_pn);
18901                         m_test_cases.push_back(test_case_fs_nc);
18902                         m_test_cases.push_back(test_case_fs_cn);
18903                         m_test_cases.push_back(test_case_fs_ns);
18904                         m_test_cases.push_back(test_case_fs_sn);
18905                         m_test_cases.push_back(test_case_fs_cs);
18906                         m_test_cases.push_back(test_case_fs_sc);
18907                 }
18908         }
18909 }
18910
18911 /** Get auxiliary storage qualifier
18912  *
18913  * @param aux Enumeration
18914  *
18915  * @return GLSL qualifier
18916  **/
18917 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18918 {
18919         const GLchar* result = 0;
18920
18921         switch (aux)
18922         {
18923         case NONE:
18924                 result = "";
18925                 break;
18926         case PATCH:
18927                 result = "patch";
18928                 break;
18929         case CENTROID:
18930                 result = "centroid";
18931                 break;
18932         case SAMPLE:
18933                 result = "sample";
18934                 break;
18935         default:
18936                 TCU_FAIL("Invalid enum");
18937         }
18938
18939         return result;
18940 }
18941
18942 /** Check if given type is float
18943  *
18944  * @param type Type in question
18945  *
18946  * @return true if tpye is float, false otherwise
18947  **/
18948 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
18949 {
18950         bool is_float = false;
18951
18952         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18953         {
18954                 is_float = true;
18955         }
18956
18957         return is_float;
18958 }
18959
18960 /* Constants used by VertexAttribLocationAPITest */
18961 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
18962
18963 /** Constructor
18964  *
18965  * @param context Test framework context
18966  **/
18967 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
18968         : TextureTestBase(context, "vertex_attrib_location_api",
18969                                           "Test verifies that attribute locations API works as expected")
18970 {
18971 }
18972
18973 /** Does BindAttribLocation for "goten" and relink program
18974  *
18975  * @param program           Program object
18976  * @param program_interface Interface of program
18977  **/
18978 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
18979                                                                                                                 Utils::ProgramInterface& program_interface)
18980 {
18981         const Functions& gl = m_context.getRenderContext().getFunctions();
18982
18983         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
18984         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
18985
18986         program.Link(gl, program.m_id);
18987
18988         /* We still need to get locations for gohan and chichi */
18989         TextureTestBase::prepareAttribLocation(program, program_interface);
18990 }
18991
18992 /** Get interface of program
18993  *
18994  * @param ignored
18995  * @param program_interface   Interface of program
18996  * @param ignored
18997  **/
18998 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
18999                                                                                                           Utils::ProgramInterface& program_interface,
19000                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19001 {
19002         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19003         const Utils::Type&              type      = Utils::Type::vec4;
19004         const GLuint                    type_size = type.GetSize();
19005
19006         /* Offsets */
19007         const GLuint chichi_offset = 0;
19008         const GLuint goten_offset  = chichi_offset + type_size;
19009         const GLuint gohan_offset  = goten_offset + type_size;
19010         const GLuint goku_offset   = gohan_offset + type_size;
19011
19012         /* Locations */
19013         const GLuint goku_location  = 2;
19014         const GLuint goten_location = m_goten_location;
19015
19016         /* Generate data */
19017         m_goku_data   = type.GenerateDataPacked();
19018         m_gohan_data  = type.GenerateDataPacked();
19019         m_goten_data  = type.GenerateDataPacked();
19020         m_chichi_data = type.GenerateDataPacked();
19021
19022         /* Globals */
19023         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19024
19025         /* Attributes */
19026         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19027                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19028                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19029                          m_goku_data.size() /* data_size */);
19030
19031         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19032                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19033                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19034                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19035
19036         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19037                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19038                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19039                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19040
19041         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19042                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19043                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19044                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19045 }
19046
19047 /** Selects if "compute" stage is relevant for test
19048  *
19049  * @param ignored
19050  *
19051  * @return false
19052  **/
19053 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19054 {
19055         return false;
19056 }
19057
19058 /* Constants used by FragmentDataLocationAPITest */
19059 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19060
19061 /** Constructor
19062  *
19063  * @param context Test framework context
19064  **/
19065 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19066         : TextureTestBase(context, "fragment_data_location_api",
19067                                           "Test verifies that fragment data locations API works as expected")
19068         , m_goku(context)
19069         , m_gohan(context)
19070         , m_goten(context)
19071         , m_chichi(context)
19072 {
19073 }
19074
19075 /** Verifies contents of drawn images
19076  *
19077  * @param ignored
19078  * @param ignored
19079  *
19080  * @return true if images are filled with expected values, false otherwise
19081  **/
19082 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19083 {
19084         static const GLuint size                        = m_width * m_height;
19085         static const GLuint expected_goku   = 0xff000000;
19086         static const GLuint expected_gohan  = 0xff0000ff;
19087         static const GLuint expected_goten  = 0xff00ff00;
19088         static const GLuint expected_chichi = 0xffff0000;
19089
19090         std::vector<GLuint> data;
19091         data.resize(size);
19092
19093         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19094
19095         for (GLuint i = 0; i < size; ++i)
19096         {
19097                 const GLuint color = data[i];
19098
19099                 if (expected_goku != color)
19100                 {
19101                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19102                                                                                                 << tcu::TestLog::EndMessage;
19103                         return false;
19104                 }
19105         }
19106
19107         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19108
19109         for (GLuint i = 0; i < size; ++i)
19110         {
19111                 const GLuint color = data[i];
19112
19113                 if (expected_gohan != color)
19114                 {
19115                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19116                                                                                                 << tcu::TestLog::EndMessage;
19117                         return false;
19118                 }
19119         }
19120
19121         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19122
19123         for (GLuint i = 0; i < size; ++i)
19124         {
19125                 const GLuint color = data[i];
19126
19127                 if (expected_goten != color)
19128                 {
19129                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19130                                                                                                 << tcu::TestLog::EndMessage;
19131                         return false;
19132                 }
19133         }
19134
19135         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19136
19137         for (GLuint i = 0; i < size; ++i)
19138         {
19139                 const GLuint color = data[i];
19140
19141                 if (expected_chichi != color)
19142                 {
19143                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19144                                                                                                 << tcu::TestLog::EndMessage;
19145                         return false;
19146                 }
19147         }
19148
19149         return true;
19150 }
19151
19152 /** Prepare code snippet that will set out variables
19153  *
19154  * @param ignored
19155  * @param ignored
19156  * @param stage               Shader stage
19157  *
19158  * @return Code that pass in variables to next stage
19159  **/
19160 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19161                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19162                                                                                                                 Utils::Shader::STAGES stage)
19163 {
19164         std::string result;
19165
19166         /* Skip for compute shader */
19167         if (Utils::Shader::FRAGMENT != stage)
19168         {
19169                 result = "";
19170         }
19171         else
19172         {
19173                 result = "chichi = vec4(0, 0, 1, 1);\n"
19174                                  "    goku   = vec4(0, 0, 0, 1);\n"
19175                                  "    goten  = vec4(0, 1, 0, 1);\n"
19176                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19177         }
19178
19179         return result;
19180 }
19181
19182 /** Get interface of program
19183  *
19184  * @param ignored
19185  * @param program_interface Interface of program
19186  * @param ignored
19187  **/
19188 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19189                                                                                                           Utils::ProgramInterface& program_interface,
19190                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19191 {
19192         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19193         const Utils::Type&              type = Utils::Type::vec4;
19194
19195         /* Locations */
19196         m_goku_location = 2;
19197
19198         /* Globals */
19199         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19200
19201         /* Attributes */
19202         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19203                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19204                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19205
19206         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19207                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19208                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19209
19210         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19211                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19212                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19213
19214         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19215                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19216                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19217 }
19218
19219 /** Selects if "compute" stage is relevant for test
19220  *
19221  * @param ignored
19222  *
19223  * @return false
19224  **/
19225 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19226 {
19227         return false;
19228 }
19229
19230 /** Get locations for all outputs with automatic_location
19231  *
19232  * @param program           Program object
19233  * @param program_interface Interface of program
19234  **/
19235 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19236                                                                                                                  Utils::ProgramInterface& program_interface)
19237 {
19238         /* Bind location of goten */
19239         const Functions& gl = m_context.getRenderContext().getFunctions();
19240
19241         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19242         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19243
19244         program.Link(gl, program.m_id);
19245
19246         /* Prepare locations for gohan and chichi */
19247         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19248
19249         /* Get all locations */
19250         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19251
19252         Utils::Variable::PtrVector& outputs = si.m_outputs;
19253
19254         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19255         {
19256                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19257
19258                 if (0 == desc.m_name.compare("gohan"))
19259                 {
19260                         m_gohan_location = desc.m_expected_location;
19261                 }
19262                 else if (0 == desc.m_name.compare("chichi"))
19263                 {
19264                         m_chichi_location = desc.m_expected_location;
19265                 }
19266
19267                 /* Locations of goku and goten are fixed */
19268         }
19269 }
19270
19271 /** Prepare framebuffer with single texture as color attachment
19272  *
19273  * @param framebuffer     Framebuffer
19274  * @param color_0_texture Texture that will used as color attachment
19275  **/
19276 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19277 {
19278         /* Let parent prepare its stuff */
19279         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19280
19281         /* Prepare data */
19282         std::vector<GLuint> texture_data;
19283         texture_data.resize(m_width * m_height);
19284
19285         for (GLuint i = 0; i < texture_data.size(); ++i)
19286         {
19287                 texture_data[i] = 0x20406080;
19288         }
19289
19290         /* Prepare textures */
19291         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19292
19293         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19294
19295         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19296
19297         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19298
19299         /* Attach textures to framebuffer */
19300         framebuffer.Bind();
19301         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19302         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19303         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19304         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19305
19306         /* Set up drawbuffers */
19307         const Functions& gl = m_context.getRenderContext().getFunctions();
19308         //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
19309         //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
19310         //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
19311         //  we needt to change the above code of glDrawBuffers() as :
19312         GLint  buffers_size = 4;
19313         GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
19314                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
19315                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
19316                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
19317         gl.drawBuffers(buffers_size, buffers);
19318         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19319 }
19320
19321 /** Constructor
19322  *
19323  * @param context Test framework context
19324  **/
19325 XFBInputTest::XFBInputTest(deqp::Context& context)
19326         : NegativeTestBase(context, "xfb_input",
19327                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19328 {
19329 }
19330
19331 /** Source for given test case and stage
19332  *
19333  * @param test_case_index Index of test case
19334  * @param stage           Shader stage
19335  *
19336  * @return Shader source
19337  **/
19338 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19339 {
19340         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19341         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19342         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19343         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19344         static const GLchar* fs                                    = "#version 430 core\n"
19345                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19346                                                           "\n"
19347                                                           "in  vec4 gs_fs;\n"
19348                                                           "out vec4 fs_out;\n"
19349                                                           "\n"
19350                                                           "void main()\n"
19351                                                           "{\n"
19352                                                           "    fs_out = gs_fs;\n"
19353                                                           "}\n"
19354                                                           "\n";
19355         static const GLchar* fs_tested = "#version 430 core\n"
19356                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19357                                                                          "\n"
19358                                                                          "VAR_DEFINITION"
19359                                                                          "\n"
19360                                                                          "in  vec4 gs_fs;\n"
19361                                                                          "out vec4 fs_out;\n"
19362                                                                          "\n"
19363                                                                          "void main()\n"
19364                                                                          "{\n"
19365                                                                          "    vec4 result = gs_fs;\n"
19366                                                                          "\n"
19367                                                                          "VARIABLE_USE"
19368                                                                          "\n"
19369                                                                          "    fs_out = result;\n"
19370                                                                          "}\n"
19371                                                                          "\n";
19372         static const GLchar* gs = "#version 430 core\n"
19373                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19374                                                           "\n"
19375                                                           "layout(points)                           in;\n"
19376                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19377                                                           "\n"
19378                                                           "in  vec4 tes_gs[];\n"
19379                                                           "out vec4 gs_fs;\n"
19380                                                           "\n"
19381                                                           "void main()\n"
19382                                                           "{\n"
19383                                                           "    gs_fs = tes_gs[0];\n"
19384                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19385                                                           "    EmitVertex();\n"
19386                                                           "    gs_fs = tes_gs[0];\n"
19387                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19388                                                           "    EmitVertex();\n"
19389                                                           "    gs_fs = tes_gs[0];\n"
19390                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19391                                                           "    EmitVertex();\n"
19392                                                           "    gs_fs = tes_gs[0];\n"
19393                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19394                                                           "    EmitVertex();\n"
19395                                                           "}\n"
19396                                                           "\n";
19397         static const GLchar* gs_tested = "#version 430 core\n"
19398                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19399                                                                          "\n"
19400                                                                          "layout(points)                           in;\n"
19401                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19402                                                                          "\n"
19403                                                                          "VAR_DEFINITION"
19404                                                                          "\n"
19405                                                                          "in  vec4 tes_gs[];\n"
19406                                                                          "out vec4 gs_fs;\n"
19407                                                                          "\n"
19408                                                                          "void main()\n"
19409                                                                          "{\n"
19410                                                                          "    vec4 result = tes_gs[0];\n"
19411                                                                          "\n"
19412                                                                          "VARIABLE_USE"
19413                                                                          "\n"
19414                                                                          "    gs_fs = result;\n"
19415                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19416                                                                          "    EmitVertex();\n"
19417                                                                          "    gs_fs = result;\n"
19418                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19419                                                                          "    EmitVertex();\n"
19420                                                                          "    gs_fs = result;\n"
19421                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19422                                                                          "    EmitVertex();\n"
19423                                                                          "    gs_fs = result;\n"
19424                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19425                                                                          "    EmitVertex();\n"
19426                                                                          "}\n"
19427                                                                          "\n";
19428         static const GLchar* tcs = "#version 430 core\n"
19429                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19430                                                            "\n"
19431                                                            "layout(vertices = 1) out;\n"
19432                                                            "\n"
19433                                                            "in  vec4 vs_tcs[];\n"
19434                                                            "out vec4 tcs_tes[];\n"
19435                                                            "\n"
19436                                                            "void main()\n"
19437                                                            "{\n"
19438                                                            "\n"
19439                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19440                                                            "\n"
19441                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19442                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19443                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19444                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19445                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19446                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19447                                                            "}\n"
19448                                                            "\n";
19449         static const GLchar* tcs_tested = "#version 430 core\n"
19450                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19451                                                                           "\n"
19452                                                                           "layout(vertices = 1) out;\n"
19453                                                                           "\n"
19454                                                                           "VAR_DEFINITION"
19455                                                                           "\n"
19456                                                                           "in  vec4 vs_tcs[];\n"
19457                                                                           "out vec4 tcs_tes[];\n"
19458                                                                           "\n"
19459                                                                           "void main()\n"
19460                                                                           "{\n"
19461                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19462                                                                           "\n"
19463                                                                           "VARIABLE_USE"
19464                                                                           "\n"
19465                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19466                                                                           "\n"
19467                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19468                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19469                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19470                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19471                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19472                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19473                                                                           "}\n"
19474                                                                           "\n";
19475         static const GLchar* tes = "#version 430 core\n"
19476                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19477                                                            "\n"
19478                                                            "layout(isolines, point_mode) in;\n"
19479                                                            "\n"
19480                                                            "in  vec4 tcs_tes[];\n"
19481                                                            "out vec4 tes_gs;\n"
19482                                                            "\n"
19483                                                            "void main()\n"
19484                                                            "{\n"
19485                                                            "    tes_gs = tcs_tes[0];\n"
19486                                                            "}\n"
19487                                                            "\n";
19488         static const GLchar* tes_tested = "#version 430 core\n"
19489                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19490                                                                           "\n"
19491                                                                           "layout(isolines, point_mode) in;\n"
19492                                                                           "\n"
19493                                                                           "VAR_DEFINITION"
19494                                                                           "\n"
19495                                                                           "in  vec4 tcs_tes[];\n"
19496                                                                           "out vec4 tes_gs;\n"
19497                                                                           "\n"
19498                                                                           "void main()\n"
19499                                                                           "{\n"
19500                                                                           "    vec4 result = tcs_tes[0];\n"
19501                                                                           "\n"
19502                                                                           "VARIABLE_USE"
19503                                                                           "\n"
19504                                                                           "    tes_gs += result;\n"
19505                                                                           "}\n"
19506                                                                           "\n";
19507         static const GLchar* vs = "#version 430 core\n"
19508                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19509                                                           "\n"
19510                                                           "in  vec4 in_vs;\n"
19511                                                           "out vec4 vs_tcs;\n"
19512                                                           "\n"
19513                                                           "void main()\n"
19514                                                           "{\n"
19515                                                           "    vs_tcs = in_vs;\n"
19516                                                           "}\n"
19517                                                           "\n";
19518         static const GLchar* vs_tested = "#version 430 core\n"
19519                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19520                                                                          "\n"
19521                                                                          "VAR_DEFINITION"
19522                                                                          "\n"
19523                                                                          "in  vec4 in_vs;\n"
19524                                                                          "out vec4 vs_tcs;\n"
19525                                                                          "\n"
19526                                                                          "void main()\n"
19527                                                                          "{\n"
19528                                                                          "    vec4 result = in_vs;\n"
19529                                                                          "\n"
19530                                                                          "VARIABLE_USE"
19531                                                                          "\n"
19532                                                                          "    vs_tcs += result;\n"
19533                                                                          "}\n"
19534                                                                          "\n";
19535
19536         std::string source;
19537         testCase&   test_case = m_test_cases[test_case_index];
19538
19539         if (test_case.m_stage == stage)
19540         {
19541                 const GLchar* array     = "";
19542                 const GLchar* index     = "";
19543                 size_t            position = 0;
19544                 size_t            temp;
19545                 const GLchar* var_definition = 0;
19546                 const GLchar* var_use            = input_use;
19547
19548                 switch (test_case.m_qualifier)
19549                 {
19550                 case BUFFER:
19551                         var_definition = buffer_var_definition;
19552                         break;
19553                 case OFFSET:
19554                         var_definition = offset_var_definition;
19555                         break;
19556                 case STRIDE:
19557                         var_definition = stride_var_definition;
19558                         break;
19559                 default:
19560                         TCU_FAIL("Invalid enum");
19561                 }
19562
19563                 switch (stage)
19564                 {
19565                 case Utils::Shader::FRAGMENT:
19566                         source = fs_tested;
19567                         break;
19568                 case Utils::Shader::GEOMETRY:
19569                         source = gs_tested;
19570                         array  = "[]";
19571                         index  = "[0]";
19572                         break;
19573                 case Utils::Shader::TESS_CTRL:
19574                         source = tcs_tested;
19575                         array  = "[]";
19576                         index  = "[gl_InvocationID]";
19577                         break;
19578                 case Utils::Shader::TESS_EVAL:
19579                         source = tes_tested;
19580                         array  = "[]";
19581                         index  = "[0]";
19582                         break;
19583                 case Utils::Shader::VERTEX:
19584                         source = vs_tested;
19585                         break;
19586                 default:
19587                         TCU_FAIL("Invalid enum");
19588                 }
19589
19590                 temp = position;
19591                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19592                 position = temp;
19593                 Utils::replaceToken("ARRAY", position, array, source);
19594                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19595
19596                 Utils::replaceAllTokens("INDEX", index, source);
19597         }
19598         else
19599         {
19600                 switch (stage)
19601                 {
19602                 case Utils::Shader::FRAGMENT:
19603                         source = fs;
19604                         break;
19605                 case Utils::Shader::GEOMETRY:
19606                         source = gs;
19607                         break;
19608                 case Utils::Shader::TESS_CTRL:
19609                         source = tcs;
19610                         break;
19611                 case Utils::Shader::TESS_EVAL:
19612                         source = tes;
19613                         break;
19614                 case Utils::Shader::VERTEX:
19615                         source = vs;
19616                         break;
19617                 default:
19618                         TCU_FAIL("Invalid enum");
19619                 }
19620         }
19621
19622         return source;
19623 }
19624
19625 /** Get description of test case
19626  *
19627  * @param test_case_index Index of test case
19628  *
19629  * @return Test case description
19630  **/
19631 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19632 {
19633         std::stringstream stream;
19634         testCase&                 test_case = m_test_cases[test_case_index];
19635
19636         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19637
19638         switch (test_case.m_qualifier)
19639         {
19640         case BUFFER:
19641                 stream << "xfb_buffer";
19642                 break;
19643         case OFFSET:
19644                 stream << "xfb_offset";
19645                 break;
19646         case STRIDE:
19647                 stream << "xfb_stride";
19648                 break;
19649         default:
19650                 TCU_FAIL("Invalid enum");
19651         }
19652
19653         return stream.str();
19654 }
19655
19656 /** Get number of test cases
19657  *
19658  * @return Number of test cases
19659  **/
19660 GLuint XFBInputTest::getTestCaseNumber()
19661 {
19662         return static_cast<GLuint>(m_test_cases.size());
19663 }
19664
19665 /** Selects if "compute" stage is relevant for test
19666  *
19667  * @param ignored
19668  *
19669  * @return false
19670  **/
19671 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19672 {
19673         return false;
19674 }
19675
19676 /** Prepare all test cases
19677  *
19678  **/
19679 void XFBInputTest::testInit()
19680 {
19681         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19682         {
19683                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19684                 {
19685                         if (Utils::Shader::COMPUTE == stage)
19686                         {
19687                                 continue;
19688                         }
19689
19690                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19691
19692                         m_test_cases.push_back(test_case);
19693                 }
19694         }
19695 }
19696
19697 /* Constants used by XFBAllStagesTest */
19698 const GLuint XFBAllStagesTest::m_gs_index = 3;
19699
19700 /** Constructor
19701  *
19702  * @param context Test context
19703  **/
19704 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19705         : BufferTestBase(context, "xfb_all_stages",
19706                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19707 {
19708         /* Nothing to be done here */
19709 }
19710
19711 /** Get descriptors of buffers necessary for test
19712  *
19713  * @param ignored
19714  * @param out_descriptors Descriptors of buffers used by test
19715  **/
19716 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19717                                                                                         bufferDescriptor::Vector& out_descriptors)
19718 {
19719         static const GLuint n_stages = 4;
19720         const Utils::Type&  vec4         = Utils::Type::vec4;
19721
19722         /* Data */
19723         tcu::Vec4 sum;
19724
19725         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19726         out_descriptors.resize(n_stages * 2 + 1);
19727
19728         /* */
19729         for (GLuint i = 0; i < n_stages; ++i)
19730         {
19731                 /* Get references */
19732                 bufferDescriptor& uniform = out_descriptors[i + 0];
19733                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19734
19735                 /* Index */
19736                 uniform.m_index = i;
19737                 xfb.m_index             = i;
19738
19739                 /* Target */
19740                 uniform.m_target = Utils::Buffer::Uniform;
19741                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19742
19743                 /* Data */
19744                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19745
19746                 sum += var;
19747
19748                 uniform.m_initial_data.resize(vec4.GetSize());
19749                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19750
19751                 xfb.m_initial_data = vec4.GenerateDataPacked();
19752
19753                 if (m_gs_index != i)
19754                 {
19755                         xfb.m_expected_data = xfb.m_initial_data;
19756                 }
19757                 else
19758                 {
19759                         xfb.m_expected_data.resize(vec4.GetSize());
19760                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19761                 }
19762         }
19763
19764         /* FS */
19765         {
19766                 /* Get reference */
19767                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19768
19769                 /* Index */
19770                 uniform.m_index = n_stages;
19771
19772                 /* Target */
19773                 uniform.m_target = Utils::Buffer::Uniform;
19774
19775                 /* Data */
19776                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19777
19778                 uniform.m_initial_data.resize(vec4.GetSize());
19779                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19780         }
19781 }
19782
19783 /** Get body of main function for given shader stage
19784  *
19785  * @param ignored
19786  * @param stage            Shader stage
19787  * @param out_assignments  Set to empty
19788  * @param out_calculations Set to empty
19789  **/
19790 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19791                                                                          std::string& out_assignments, std::string& out_calculations)
19792 {
19793         out_calculations = "";
19794
19795         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19796         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19797         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19798         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19799         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19800
19801         const GLchar* assignments = 0;
19802         switch (stage)
19803         {
19804         case Utils::Shader::FRAGMENT:
19805                 assignments = fs;
19806                 break;
19807         case Utils::Shader::GEOMETRY:
19808                 assignments = gs;
19809                 break;
19810         case Utils::Shader::TESS_CTRL:
19811                 assignments = tcs;
19812                 break;
19813         case Utils::Shader::TESS_EVAL:
19814                 assignments = tes;
19815                 break;
19816         case Utils::Shader::VERTEX:
19817                 assignments = vs;
19818                 break;
19819         default:
19820                 TCU_FAIL("Invalid enum");
19821         }
19822
19823         out_assignments = assignments;
19824 }
19825
19826 /** Get interface of shader
19827  *
19828  * @param ignored
19829  * @param stage         Shader stage
19830  * @param out_interface Set to ""
19831  **/
19832 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19833                                                                                   std::string& out_interface)
19834 {
19835         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19836                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19837                                                           "    vec4 uni_vs;\n"
19838                                                           "};\n";
19839         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19840                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19841                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19842                                                            "    vec4 uni_tcs;\n"
19843                                                            "};\n";
19844         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19845                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19846                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19847                                                            "    vec4 uni_tes;\n"
19848                                                            "};\n";
19849         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19850                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19851                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19852                                                           "    vec4 uni_gs;\n"
19853                                                           "};\n";
19854         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19855                                                           "                       out     vec4 fs_out;\n"
19856                                                           "layout(binding    = 4) uniform fs_block {\n"
19857                                                           "    vec4 uni_fs;\n"
19858                                                           "};\n";
19859
19860         const GLchar* interface = 0;
19861         switch (stage)
19862         {
19863         case Utils::Shader::FRAGMENT:
19864                 interface = fs;
19865                 break;
19866         case Utils::Shader::GEOMETRY:
19867                 interface = gs;
19868                 break;
19869         case Utils::Shader::TESS_CTRL:
19870                 interface = tcs;
19871                 break;
19872         case Utils::Shader::TESS_EVAL:
19873                 interface = tes;
19874                 break;
19875         case Utils::Shader::VERTEX:
19876                 interface = vs;
19877                 break;
19878         default:
19879                 TCU_FAIL("Invalid enum");
19880         }
19881
19882         out_interface = interface;
19883 }
19884
19885 /* Constants used by XFBStrideOfEmptyListTest */
19886 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19887
19888 /** Constructor
19889  *
19890  * @param context Test context
19891  **/
19892 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19893         : BufferTestBase(context, "xfb_stride_of_empty_list",
19894                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19895 {
19896         /* Nothing to be done here */
19897 }
19898
19899 /** Execute drawArrays for single vertex
19900  *
19901  * @param test_case_index Index of test case
19902  *
19903  * @return true if proper error is reported
19904  **/
19905 bool XFBStrideOfEmptyListTest::executeDrawCall(GLuint test_case_index)
19906 {
19907         const Functions& gl             = m_context.getRenderContext().getFunctions();
19908         bool                     result = true;
19909
19910         /* Draw */
19911         gl.disable(GL_RASTERIZER_DISCARD);
19912         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19913
19914         gl.beginTransformFeedback(GL_POINTS);
19915         GLenum error = gl.getError();
19916         switch (test_case_index)
19917         {
19918         case VALID:
19919                 if (GL_NO_ERROR != error)
19920                 {
19921                         gl.endTransformFeedback();
19922                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19923                 }
19924
19925                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19926                 error = gl.getError();
19927
19928                 gl.endTransformFeedback();
19929                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19930                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19931
19932                 break;
19933
19934         case FIRST_MISSING:
19935                 if (GL_NO_ERROR == error)
19936                 {
19937                         gl.endTransformFeedback();
19938                 }
19939
19940                 if (GL_INVALID_OPERATION != error)
19941                 {
19942                         m_context.getTestContext().getLog()
19943                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
19944                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19945                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19946
19947                         result = false;
19948                 }
19949
19950                 break;
19951
19952         case SECOND_MISSING:
19953                 if (GL_NO_ERROR == error)
19954                 {
19955                         gl.endTransformFeedback();
19956                 }
19957
19958                 if (GL_INVALID_OPERATION != error)
19959                 {
19960                         m_context.getTestContext().getLog()
19961                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
19962                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19963                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19964
19965                         result = false;
19966                 }
19967
19968                 break;
19969         }
19970
19971         /* Done */
19972         return result;
19973 }
19974
19975 /** Get descriptors of buffers necessary for test
19976  *
19977  * @param test_case_index Index of test case
19978  * @param out_descriptors Descriptors of buffers used by test
19979  **/
19980 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
19981                                                                                                         bufferDescriptor::Vector& out_descriptors)
19982 {
19983         switch (test_case_index)
19984         {
19985         case VALID:
19986         {
19987                 /* Test needs single uniform and two xfbs */
19988                 out_descriptors.resize(3);
19989
19990                 /* Get references */
19991                 bufferDescriptor& uniform = out_descriptors[0];
19992                 bufferDescriptor& xfb_0   = out_descriptors[1];
19993                 bufferDescriptor& xfb_1   = out_descriptors[2];
19994
19995                 /* Index */
19996                 uniform.m_index = 0;
19997                 xfb_0.m_index   = 0;
19998                 xfb_1.m_index   = 1;
19999
20000                 /* Target */
20001                 uniform.m_target = Utils::Buffer::Uniform;
20002                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20003                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20004
20005                 /* Data */
20006                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20007
20008                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20009                 xfb_0.m_expected_data = uniform.m_initial_data;
20010
20011                 /* Data, contents are the same as no modification is expected */
20012                 xfb_1.m_initial_data.resize(m_stride);
20013                 xfb_1.m_expected_data.resize(m_stride);
20014
20015                 for (GLuint i = 0; i < m_stride; ++i)
20016                 {
20017                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20018                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20019                 }
20020         }
20021
20022         break;
20023
20024         case FIRST_MISSING:
20025         {
20026                 /* Test needs single uniform and two xfbs */
20027                 out_descriptors.resize(2);
20028
20029                 /* Get references */
20030                 bufferDescriptor& uniform = out_descriptors[0];
20031                 bufferDescriptor& xfb_1   = out_descriptors[1];
20032
20033                 /* Index */
20034                 uniform.m_index = 0;
20035                 xfb_1.m_index   = 1;
20036
20037                 /* Target */
20038                 uniform.m_target = Utils::Buffer::Uniform;
20039                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20040
20041                 /* Data */
20042                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20043
20044                 /* Draw call will not be executed, contents does not matter */
20045                 xfb_1.m_initial_data.resize(m_stride);
20046         }
20047
20048         break;
20049
20050         case SECOND_MISSING:
20051         {
20052                 /* Test needs single uniform and two xfbs */
20053                 out_descriptors.resize(2);
20054
20055                 /* Get references */
20056                 bufferDescriptor& uniform = out_descriptors[0];
20057                 bufferDescriptor& xfb_0   = out_descriptors[1];
20058
20059                 /* Index */
20060                 uniform.m_index = 0;
20061                 xfb_0.m_index   = 0;
20062
20063                 /* Target */
20064                 uniform.m_target = Utils::Buffer::Uniform;
20065                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20066
20067                 /* Data */
20068                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20069
20070                 /* Draw call will not be executed, contents does not matter */
20071                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20072         }
20073
20074         break;
20075         }
20076 }
20077
20078 /** Get body of main function for given shader stage
20079  *
20080  * @param ignored
20081  * @param stage            Shader stage
20082  * @param out_assignments  Set to empty
20083  * @param out_calculations Set to empty
20084  **/
20085 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20086                                                                                          std::string& out_assignments, std::string& out_calculations)
20087 {
20088         out_calculations = "";
20089
20090         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20091         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20092
20093         const GLchar* assignments = "";
20094         switch (stage)
20095         {
20096         case Utils::Shader::FRAGMENT:
20097                 assignments = fs;
20098                 break;
20099         case Utils::Shader::GEOMETRY:
20100                 assignments = gs;
20101                 break;
20102         default:
20103                 break;
20104         }
20105
20106         out_assignments = assignments;
20107 }
20108
20109 /** Get interface of shader
20110  *
20111  * @param ignored
20112  * @param stage            Shader stage
20113  * @param out_interface    Set to ""
20114  **/
20115 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20116                                                                                                   std::string& out_interface)
20117 {
20118         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20119                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20120                                                           "\n"
20121                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20122                                                           "    vec4 uni_gs;\n"
20123                                                           "};\n";
20124         static const GLchar* fs = "in  vec4 gs_fs;\n"
20125                                                           "out vec4 fs_out;\n";
20126
20127         switch (stage)
20128         {
20129         case Utils::Shader::FRAGMENT:
20130                 out_interface = fs;
20131                 break;
20132         case Utils::Shader::GEOMETRY:
20133                 out_interface = gs;
20134                 break;
20135         default:
20136                 out_interface = "";
20137                 return;
20138         }
20139 }
20140
20141 /** Returns buffer details in human readable form.
20142  *
20143  * @param test_case_index Index of test case
20144  *
20145  * @return Case description
20146  **/
20147 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20148 {
20149         std::string result;
20150
20151         switch (test_case_index)
20152         {
20153         case VALID:
20154                 result = "Valid case";
20155                 break;
20156         case FIRST_MISSING:
20157                 result = "Missing xfb at index 0";
20158                 break;
20159         case SECOND_MISSING:
20160                 result = "Missing xfb at index 1";
20161                 break;
20162         default:
20163                 TCU_FAIL("Invalid enum");
20164         }
20165
20166         return result;
20167 }
20168
20169 /** Get number of test cases
20170  *
20171  * @return 3
20172  **/
20173 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20174 {
20175         return 3;
20176 }
20177
20178 /* Constants used by XFBStrideOfEmptyListTest */
20179 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20180
20181 /** Constructor
20182  *
20183  * @param context Test context
20184  **/
20185 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20186         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20187                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20188 {
20189         /* Nothing to be done here */
20190 }
20191
20192 /** Execute drawArrays for single vertex
20193  *
20194  * @param test_case_index Index of test case
20195  *
20196  * @return true if proper error is reported
20197  **/
20198 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(GLuint test_case_index)
20199 {
20200         const Functions& gl             = m_context.getRenderContext().getFunctions();
20201         bool                     result = true;
20202
20203         /* Draw */
20204         gl.disable(GL_RASTERIZER_DISCARD);
20205         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20206
20207         gl.beginTransformFeedback(GL_POINTS);
20208         GLenum error = gl.getError();
20209         switch (test_case_index)
20210         {
20211         case VALID:
20212                 if (GL_NO_ERROR != error)
20213                 {
20214                         gl.endTransformFeedback();
20215                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20216                 }
20217
20218                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20219                 error = gl.getError();
20220
20221                 gl.endTransformFeedback();
20222                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20223                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20224
20225                 break;
20226
20227         case FIRST_MISSING:
20228                 if (GL_NO_ERROR == error)
20229                 {
20230                         gl.endTransformFeedback();
20231                 }
20232
20233                 if (GL_INVALID_OPERATION != error)
20234                 {
20235                         m_context.getTestContext().getLog()
20236                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20237                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20238                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20239
20240                         result = false;
20241                 }
20242
20243                 break;
20244
20245         case SECOND_MISSING:
20246                 if (GL_NO_ERROR == error)
20247                 {
20248                         gl.endTransformFeedback();
20249                 }
20250
20251                 if (GL_INVALID_OPERATION != error)
20252                 {
20253                         m_context.getTestContext().getLog()
20254                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20255                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20256                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20257
20258                         result = false;
20259                 }
20260
20261                 break;
20262         }
20263
20264         /* Done */
20265         return result;
20266 }
20267
20268 /** Get descriptors of buffers necessary for test
20269  *
20270  * @param test_case_index Index of test case
20271  * @param out_descriptors Descriptors of buffers used by test
20272  **/
20273 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20274                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20275 {
20276         switch (test_case_index)
20277         {
20278         case VALID:
20279         {
20280                 /* Test needs single uniform and two xfbs */
20281                 out_descriptors.resize(3);
20282
20283                 /* Get references */
20284                 bufferDescriptor& uniform = out_descriptors[0];
20285                 bufferDescriptor& xfb_0   = out_descriptors[1];
20286                 bufferDescriptor& xfb_1   = out_descriptors[2];
20287
20288                 /* Index */
20289                 uniform.m_index = 0;
20290                 xfb_0.m_index   = 0;
20291                 xfb_1.m_index   = 1;
20292
20293                 /* Target */
20294                 uniform.m_target = Utils::Buffer::Uniform;
20295                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20296                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20297
20298                 /* Data */
20299                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20300
20301                 /* Data, contents are the same as no modification is expected */
20302                 xfb_0.m_initial_data.resize(m_stride);
20303                 xfb_0.m_expected_data.resize(m_stride);
20304
20305                 for (GLuint i = 0; i < m_stride; ++i)
20306                 {
20307                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20308                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20309                 }
20310
20311                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20312                 xfb_1.m_expected_data = uniform.m_initial_data;
20313         }
20314
20315         break;
20316
20317         case FIRST_MISSING:
20318         {
20319                 /* Test needs single uniform and two xfbs */
20320                 out_descriptors.resize(2);
20321
20322                 /* Get references */
20323                 bufferDescriptor& uniform = out_descriptors[0];
20324                 bufferDescriptor& xfb_1   = out_descriptors[1];
20325
20326                 /* Index */
20327                 uniform.m_index = 0;
20328                 xfb_1.m_index   = 1;
20329
20330                 /* Target */
20331                 uniform.m_target = Utils::Buffer::Uniform;
20332                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20333
20334                 /* Data */
20335                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20336
20337                 /* Draw call will not be executed, contents does not matter */
20338                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20339         }
20340
20341         break;
20342
20343         case SECOND_MISSING:
20344         {
20345                 /* Test needs single uniform and two xfbs */
20346                 out_descriptors.resize(2);
20347
20348                 /* Get references */
20349                 bufferDescriptor& uniform = out_descriptors[0];
20350                 bufferDescriptor& xfb_0   = out_descriptors[1];
20351
20352                 /* Index */
20353                 uniform.m_index = 0;
20354                 xfb_0.m_index   = 0;
20355
20356                 /* Target */
20357                 uniform.m_target = Utils::Buffer::Uniform;
20358                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20359
20360                 /* Data */
20361                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20362
20363                 /* Draw call will not be executed, contents does not matter */
20364                 xfb_0.m_initial_data.resize(m_stride);
20365         }
20366
20367         break;
20368         }
20369 }
20370
20371 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20372  *
20373  * @param ignored
20374  * @param captured_varyings Vector of varying names to be captured
20375  **/
20376 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20377                                                                                                                  Utils::Program::NameVector& captured_varyings)
20378 {
20379         captured_varyings.push_back("gs_fs");
20380 }
20381
20382 /** Get body of main function for given shader stage
20383  *
20384  * @param ignored
20385  * @param stage            Shader stage
20386  * @param out_assignments  Set to empty
20387  * @param out_calculations Set to empty
20388  **/
20389 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20390                                                                                                    std::string& out_assignments, std::string& out_calculations)
20391 {
20392         out_calculations = "";
20393
20394         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20395         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20396
20397         const GLchar* assignments = "";
20398         switch (stage)
20399         {
20400         case Utils::Shader::FRAGMENT:
20401                 assignments = fs;
20402                 break;
20403         case Utils::Shader::GEOMETRY:
20404                 assignments = gs;
20405                 break;
20406         default:
20407                 break;
20408         }
20409
20410         out_assignments = assignments;
20411 }
20412
20413 /** Get interface of shader
20414  *
20415  * @param ignored
20416  * @param stage            Shader stage
20417  * @param out_interface    Set to ""
20418  **/
20419 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20420                                                                                                                 std::string& out_interface)
20421 {
20422         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20423                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20424                                                           "\n"
20425                                                           "layout(binding    = 0) uniform gs_block {\n"
20426                                                           "    vec4 uni_gs;\n"
20427                                                           "};\n";
20428         static const GLchar* fs = "in  vec4 gs_fs;\n"
20429                                                           "out vec4 fs_out;\n";
20430
20431         switch (stage)
20432         {
20433         case Utils::Shader::FRAGMENT:
20434                 out_interface = fs;
20435                 break;
20436         case Utils::Shader::GEOMETRY:
20437                 out_interface = gs;
20438                 break;
20439         default:
20440                 out_interface = "";
20441                 return;
20442         }
20443 }
20444
20445 /** Returns buffer details in human readable form.
20446  *
20447  * @param test_case_index Index of test case
20448  *
20449  * @return Case description
20450  **/
20451 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20452 {
20453         std::string result;
20454
20455         switch (test_case_index)
20456         {
20457         case VALID:
20458                 result = "Valid case";
20459                 break;
20460         case FIRST_MISSING:
20461                 result = "Missing xfb at index 0";
20462                 break;
20463         case SECOND_MISSING:
20464                 result = "Missing xfb at index 1";
20465                 break;
20466         default:
20467                 TCU_FAIL("Invalid enum");
20468         }
20469
20470         return result;
20471 }
20472
20473 /** Get number of test cases
20474  *
20475  * @return 2
20476  **/
20477 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20478 {
20479         return 3;
20480 }
20481
20482 /** Constructor
20483  *
20484  * @param context Test framework context
20485  **/
20486 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20487         : NegativeTestBase(context, "xfb_too_small_stride",
20488                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20489 {
20490 }
20491
20492 /** Source for given test case and stage
20493  *
20494  * @param test_case_index Index of test case
20495  * @param stage           Shader stage
20496  *
20497  * @return Shader source
20498  **/
20499 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20500 {
20501         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20502                                                                                                 "\n"
20503                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20504         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20505                                                                                                 "\n"
20506                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20507                                                                                                 "    vec4 gohan;\n"
20508                                                                                                 "    vec4 goten;\n"
20509                                                                                                 "    vec4 chichi;\n"
20510                                                                                                 "} gokuARRAY;\n";
20511         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20512                                                                                                  "\n"
20513                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20514         // The test considers gohan overflows the buffer 0, but according to spec, it is valid to declare the variable with qualifier "layout (xfb_offset = 16, xfb_stride = 32) out vec4 gohan;"
20515         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20516         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20517                                                                                                  "\n"
20518                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20519         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20520                                                                          "    gohanINDEX[1] = result / 4;\n"
20521                                                                          "    gohanINDEX[2] = result / 6;\n"
20522                                                                          "    gohanINDEX[3] = result / 8;\n";
20523         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20524                                                                          "    gokuINDEX.goten  = result / 4;\n"
20525                                                                          "    gokuINDEX.chichi = result / 6;\n";
20526         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20527         static const GLchar* fs                 = "#version 430 core\n"
20528                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20529                                                           "\n"
20530                                                           "in  vec4 gs_fs;\n"
20531                                                           "out vec4 fs_out;\n"
20532                                                           "\n"
20533                                                           "void main()\n"
20534                                                           "{\n"
20535                                                           "    fs_out = gs_fs;\n"
20536                                                           "}\n"
20537                                                           "\n";
20538         static const GLchar* gs_tested = "#version 430 core\n"
20539                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20540                                                                          "\n"
20541                                                                          "layout(points)                           in;\n"
20542                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20543                                                                          "\n"
20544                                                                          "VAR_DEFINITION"
20545                                                                          "\n"
20546                                                                          "in  vec4 tes_gs[];\n"
20547                                                                          "out vec4 gs_fs;\n"
20548                                                                          "\n"
20549                                                                          "void main()\n"
20550                                                                          "{\n"
20551                                                                          "    vec4 result = tes_gs[0];\n"
20552                                                                          "\n"
20553                                                                          "VARIABLE_USE"
20554                                                                          "\n"
20555                                                                          "    gs_fs = result;\n"
20556                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20557                                                                          "    EmitVertex();\n"
20558                                                                          "    gs_fs = result;\n"
20559                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20560                                                                          "    EmitVertex();\n"
20561                                                                          "    gs_fs = result;\n"
20562                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20563                                                                          "    EmitVertex();\n"
20564                                                                          "    gs_fs = result;\n"
20565                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20566                                                                          "    EmitVertex();\n"
20567                                                                          "}\n"
20568                                                                          "\n";
20569         static const GLchar* tcs = "#version 430 core\n"
20570                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20571                                                            "\n"
20572                                                            "layout(vertices = 1) out;\n"
20573                                                            "\n"
20574                                                            "in  vec4 vs_tcs[];\n"
20575                                                            "out vec4 tcs_tes[];\n"
20576                                                            "\n"
20577                                                            "void main()\n"
20578                                                            "{\n"
20579                                                            "\n"
20580                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20581                                                            "\n"
20582                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20583                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20584                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20585                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20586                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20587                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20588                                                            "}\n"
20589                                                            "\n";
20590         static const GLchar* tcs_tested = "#version 430 core\n"
20591                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20592                                                                           "\n"
20593                                                                           "layout(vertices = 1) out;\n"
20594                                                                           "\n"
20595                                                                           "VAR_DEFINITION"
20596                                                                           "\n"
20597                                                                           "in  vec4 vs_tcs[];\n"
20598                                                                           "out vec4 tcs_tes[];\n"
20599                                                                           "\n"
20600                                                                           "void main()\n"
20601                                                                           "{\n"
20602                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20603                                                                           "\n"
20604                                                                           "VARIABLE_USE"
20605                                                                           "\n"
20606                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20607                                                                           "\n"
20608                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20609                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20610                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20611                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20612                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20613                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20614                                                                           "}\n"
20615                                                                           "\n";
20616         static const GLchar* tes_tested = "#version 430 core\n"
20617                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20618                                                                           "\n"
20619                                                                           "layout(isolines, point_mode) in;\n"
20620                                                                           "\n"
20621                                                                           "VAR_DEFINITION"
20622                                                                           "\n"
20623                                                                           "in  vec4 tcs_tes[];\n"
20624                                                                           "out vec4 tes_gs;\n"
20625                                                                           "\n"
20626                                                                           "void main()\n"
20627                                                                           "{\n"
20628                                                                           "    vec4 result = tcs_tes[0];\n"
20629                                                                           "\n"
20630                                                                           "VARIABLE_USE"
20631                                                                           "\n"
20632                                                                           "    tes_gs += result;\n"
20633                                                                           "}\n"
20634                                                                           "\n";
20635         static const GLchar* vs = "#version 430 core\n"
20636                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20637                                                           "\n"
20638                                                           "in  vec4 in_vs;\n"
20639                                                           "out vec4 vs_tcs;\n"
20640                                                           "\n"
20641                                                           "void main()\n"
20642                                                           "{\n"
20643                                                           "    vs_tcs = in_vs;\n"
20644                                                           "}\n"
20645                                                           "\n";
20646         static const GLchar* vs_tested = "#version 430 core\n"
20647                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20648                                                                          "\n"
20649                                                                          "VAR_DEFINITION"
20650                                                                          "\n"
20651                                                                          "in  vec4 in_vs;\n"
20652                                                                          "out vec4 vs_tcs;\n"
20653                                                                          "\n"
20654                                                                          "void main()\n"
20655                                                                          "{\n"
20656                                                                          "    vec4 result = in_vs;\n"
20657                                                                          "\n"
20658                                                                          "VARIABLE_USE"
20659                                                                          "\n"
20660                                                                          "    vs_tcs += result;\n"
20661                                                                          "}\n"
20662                                                                          "\n";
20663
20664         std::string source;
20665         testCase&   test_case = m_test_cases[test_case_index];
20666
20667         if (test_case.m_stage == stage)
20668         {
20669                 const GLchar* array     = "";
20670                 const GLchar* index     = "";
20671                 size_t            position = 0;
20672                 size_t            temp;
20673                 const GLchar* var_definition = 0;
20674                 const GLchar* var_use            = 0;
20675
20676                 switch (test_case.m_case)
20677                 {
20678                 case OFFSET:
20679                         var_definition = offset_var_definition;
20680                         var_use            = output_use;
20681                         break;
20682                 case STRIDE:
20683                         var_definition = stride_var_definition;
20684                         var_use            = output_use;
20685                         break;
20686                 case BLOCK:
20687                         var_definition = block_var_definition;
20688                         var_use            = block_use;
20689                         break;
20690                 case ARRAY:
20691                         var_definition = array_var_definition;
20692                         var_use            = array_use;
20693                         break;
20694                 default:
20695                         TCU_FAIL("Invalid enum");
20696                 }
20697
20698                 switch (stage)
20699                 {
20700                 case Utils::Shader::GEOMETRY:
20701                         source = gs_tested;
20702                         array  = "[]";
20703                         index  = "[0]";
20704                         break;
20705                 case Utils::Shader::TESS_CTRL:
20706                         source = tcs_tested;
20707                         array  = "[]";
20708                         index  = "[gl_InvocationID]";
20709                         break;
20710                 case Utils::Shader::TESS_EVAL:
20711                         source = tes_tested;
20712                         array  = "[]";
20713                         index  = "[0]";
20714                         break;
20715                 case Utils::Shader::VERTEX:
20716                         source = vs_tested;
20717                         break;
20718                 default:
20719                         TCU_FAIL("Invalid enum");
20720                 }
20721
20722                 temp = position;
20723                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20724                 position = temp;
20725                 Utils::replaceToken("ARRAY", position, array, source);
20726                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20727
20728                 Utils::replaceAllTokens("INDEX", index, source);
20729         }
20730         else
20731         {
20732                 switch (test_case.m_stage)
20733                 {
20734                 case Utils::Shader::GEOMETRY:
20735                         switch (stage)
20736                         {
20737                         case Utils::Shader::FRAGMENT:
20738                                 source = fs;
20739                                 break;
20740                         case Utils::Shader::VERTEX:
20741                                 source = vs;
20742                                 break;
20743                         default:
20744                                 source = "";
20745                         }
20746                         break;
20747                 case Utils::Shader::TESS_CTRL:
20748                         switch (stage)
20749                         {
20750                         case Utils::Shader::FRAGMENT:
20751                                 source = fs;
20752                                 break;
20753                         case Utils::Shader::VERTEX:
20754                                 source = vs;
20755                                 break;
20756                         default:
20757                                 source = "";
20758                         }
20759                         break;
20760                 case Utils::Shader::TESS_EVAL:
20761                         switch (stage)
20762                         {
20763                         case Utils::Shader::FRAGMENT:
20764                                 source = fs;
20765                                 break;
20766                         case Utils::Shader::TESS_CTRL:
20767                                 source = tcs;
20768                                 break;
20769                         case Utils::Shader::VERTEX:
20770                                 source = vs;
20771                                 break;
20772                         default:
20773                                 source = "";
20774                         }
20775                         break;
20776                 case Utils::Shader::VERTEX:
20777                         switch (stage)
20778                         {
20779                         case Utils::Shader::FRAGMENT:
20780                                 source = fs;
20781                                 break;
20782                         default:
20783                                 source = "";
20784                         }
20785                         break;
20786                 default:
20787                         TCU_FAIL("Invalid enum");
20788                         break;
20789                 }
20790         }
20791
20792         return source;
20793 }
20794
20795 /** Get description of test case
20796  *
20797  * @param test_case_index Index of test case
20798  *
20799  * @return Test case description
20800  **/
20801 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20802 {
20803         std::stringstream stream;
20804         testCase&                 test_case = m_test_cases[test_case_index];
20805
20806         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20807
20808         switch (test_case.m_case)
20809         {
20810         case OFFSET:
20811                 stream << "buffer stride: 40, vec4 offset: 32";
20812                 break;
20813         case STRIDE:
20814                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20815                 break;
20816         case BLOCK:
20817                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20818                 break;
20819         case ARRAY:
20820                 stream << "buffer stride: 32, vec4[4] offset 16";
20821                 break;
20822         default:
20823                 TCU_FAIL("Invalid enum");
20824         }
20825
20826         return stream.str();
20827 }
20828
20829 /** Get number of test cases
20830  *
20831  * @return Number of test cases
20832  **/
20833 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20834 {
20835         return static_cast<GLuint>(m_test_cases.size());
20836 }
20837
20838 /** Selects if "compute" stage is relevant for test
20839  *
20840  * @param ignored
20841  *
20842  * @return false
20843  **/
20844 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20845 {
20846         return false;
20847 }
20848
20849 /** Prepare all test cases
20850  *
20851  **/
20852 void XFBTooSmallStrideTest::testInit()
20853 {
20854         for (GLuint c = 0; c < CASE_MAX; ++c)
20855         {
20856                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20857                 {
20858                         /*
20859                          It is invalid to define transform feedback output in TCS, according to spec:
20860                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20861                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20862                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20863                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20864                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20865                          each primitive processed by the vertex shader.
20866                          */
20867                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20868                                 (Utils::Shader::FRAGMENT == stage))
20869                         {
20870                                 continue;
20871                         }
20872
20873                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20874
20875                         m_test_cases.push_back(test_case);
20876                 }
20877         }
20878 }
20879
20880 /** Constructor
20881  *
20882  * @param context Test framework context
20883  **/
20884 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20885         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20886 {
20887 }
20888
20889 /** Source for given test case and stage
20890  *
20891  * @param test_case_index Index of test case
20892  * @param stage           Shader stage
20893  *
20894  * @return Shader source
20895  **/
20896 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20897 {
20898         static const GLchar* invalid_var_definition =
20899                 "const uint type_size = SIZE;\n"
20900                 "\n"
20901                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20902                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20903         static const GLchar* valid_var_definition =
20904                 "const uint type_size = SIZE;\n"
20905                 "\n"
20906                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20907         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20908                                                                            "    vegetaINDEX = TYPE(0);\n"
20909                                                                            "    if (vec4(0) == result)\n"
20910                                                                            "    {\n"
20911                                                                            "        gokuINDEX   = TYPE(0);\n"
20912                                                                            "        vegetaINDEX = TYPE(1);\n"
20913                                                                            "    }\n";
20914         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20915                                                                          "    if (vec4(0) == result)\n"
20916                                                                          "    {\n"
20917                                                                          "        gokuINDEX   = TYPE(0);\n"
20918                                                                          "    }\n";
20919         static const GLchar* fs = "#version 430 core\n"
20920                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20921                                                           "\n"
20922                                                           "in  vec4 any_fs;\n"
20923                                                           "out vec4 fs_out;\n"
20924                                                           "\n"
20925                                                           "void main()\n"
20926                                                           "{\n"
20927                                                           "    fs_out = any_fs;\n"
20928                                                           "}\n"
20929                                                           "\n";
20930         static const GLchar* gs_tested = "#version 430 core\n"
20931                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20932                                                                          "\n"
20933                                                                          "layout(points)                           in;\n"
20934                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20935                                                                          "\n"
20936                                                                          "VAR_DEFINITION"
20937                                                                          "\n"
20938                                                                          "in  vec4 vs_any[];\n"
20939                                                                          "out vec4 any_fs;\n"
20940                                                                          "\n"
20941                                                                          "void main()\n"
20942                                                                          "{\n"
20943                                                                          "    vec4 result = vs_any[0];\n"
20944                                                                          "\n"
20945                                                                          "VARIABLE_USE"
20946                                                                          "\n"
20947                                                                          "    any_fs = result;\n"
20948                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20949                                                                          "    EmitVertex();\n"
20950                                                                          "    any_fs = result;\n"
20951                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20952                                                                          "    EmitVertex();\n"
20953                                                                          "    any_fs = result;\n"
20954                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20955                                                                          "    EmitVertex();\n"
20956                                                                          "    any_fs = result;\n"
20957                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20958                                                                          "    EmitVertex();\n"
20959                                                                          "}\n"
20960                                                                          "\n";
20961         static const GLchar* tcs = "#version 430 core\n"
20962                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20963                                                            "\n"
20964                                                            "layout(vertices = 1) out;\n"
20965                                                            "\n"
20966                                                            "in  vec4 vs_any[];\n"
20967                                                            "out vec4 tcs_tes[];\n"
20968                                                            "\n"
20969                                                            "void main()\n"
20970                                                            "{\n"
20971                                                            "\n"
20972                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
20973                                                            "\n"
20974                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20975                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20976                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20977                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20978                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20979                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20980                                                            "}\n"
20981                                                            "\n";
20982         static const GLchar* tcs_tested = "#version 430 core\n"
20983                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20984                                                                           "\n"
20985                                                                           "layout(vertices = 1) out;\n"
20986                                                                           "\n"
20987                                                                           "VAR_DEFINITION"
20988                                                                           "\n"
20989                                                                           "in  vec4 vs_any[];\n"
20990                                                                           "out vec4 any_fs[];\n"
20991                                                                           "\n"
20992                                                                           "void main()\n"
20993                                                                           "{\n"
20994                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
20995                                                                           "\n"
20996                                                                           "VARIABLE_USE"
20997                                                                           "\n"
20998                                                                           "    any_fs[gl_InvocationID] = result;\n"
20999                                                                           "\n"
21000                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21001                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21002                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21003                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21004                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21005                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21006                                                                           "}\n"
21007                                                                           "\n";
21008         static const GLchar* tes_tested = "#version 430 core\n"
21009                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21010                                                                           "\n"
21011                                                                           "layout(isolines, point_mode) in;\n"
21012                                                                           "\n"
21013                                                                           "VAR_DEFINITION"
21014                                                                           "\n"
21015                                                                           "in  vec4 tcs_tes[];\n"
21016                                                                           "out vec4 any_fs;\n"
21017                                                                           "\n"
21018                                                                           "void main()\n"
21019                                                                           "{\n"
21020                                                                           "    vec4 result = tcs_tes[0];\n"
21021                                                                           "\n"
21022                                                                           "VARIABLE_USE"
21023                                                                           "\n"
21024                                                                           "    any_fs = result;\n"
21025                                                                           "}\n"
21026                                                                           "\n";
21027         static const GLchar* vs = "#version 430 core\n"
21028                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21029                                                           "\n"
21030                                                           "in  vec4 in_vs;\n"
21031                                                           "out vec4 vs_any;\n"
21032                                                           "\n"
21033                                                           "void main()\n"
21034                                                           "{\n"
21035                                                           "    vs_any = in_vs;\n"
21036                                                           "}\n"
21037                                                           "\n";
21038         static const GLchar* vs_tested = "#version 430 core\n"
21039                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21040                                                                          "\n"
21041                                                                          "VAR_DEFINITION"
21042                                                                          "\n"
21043                                                                          "in  vec4 in_vs;\n"
21044                                                                          "out vec4 any_fs;\n"
21045                                                                          "\n"
21046                                                                          "void main()\n"
21047                                                                          "{\n"
21048                                                                          "    vec4 result = in_vs;\n"
21049                                                                          "\n"
21050                                                                          "VARIABLE_USE"
21051                                                                          "\n"
21052                                                                          "    any_fs = result;\n"
21053                                                                          "}\n"
21054                                                                          "\n";
21055
21056         std::string source;
21057         testCase&   test_case = m_test_cases[test_case_index];
21058
21059         if (test_case.m_stage == stage)
21060         {
21061                 const GLchar* array = "";
21062                 GLchar            buffer[16];
21063                 const GLchar* index     = "";
21064                 size_t            position = 0;
21065                 size_t            temp;
21066                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21067                 const GLchar* var_definition = 0;
21068                 const GLchar* var_use            = 0;
21069
21070                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21071
21072                 switch (test_case.m_case)
21073                 {
21074                 case VALID:
21075                         var_definition = valid_var_definition;
21076                         var_use            = valid_use;
21077                         break;
21078                 case INVALID:
21079                         var_definition = invalid_var_definition;
21080                         var_use            = invalid_use;
21081                         break;
21082                 default:
21083                         TCU_FAIL("Invalid enum");
21084                 }
21085
21086                 switch (stage)
21087                 {
21088                 case Utils::Shader::GEOMETRY:
21089                         source = gs_tested;
21090                         array  = "[1]";
21091                         index  = "[0]";
21092                         break;
21093                 case Utils::Shader::TESS_CTRL:
21094                         source = tcs_tested;
21095                         array  = "[1]";
21096                         index  = "[gl_InvocationID]";
21097                         break;
21098                 case Utils::Shader::TESS_EVAL:
21099                         source = tes_tested;
21100                         array  = "[1]";
21101                         index  = "[0]";
21102                         break;
21103                 case Utils::Shader::VERTEX:
21104                         source = vs_tested;
21105                         break;
21106                 default:
21107                         TCU_FAIL("Invalid enum");
21108                 }
21109
21110                 temp = position;
21111                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21112                 position = temp;
21113                 Utils::replaceToken("SIZE", position, buffer, source);
21114                 Utils::replaceToken("ARRAY", position, array, source);
21115                 if (INVALID == test_case.m_case)
21116                 {
21117                         Utils::replaceToken("ARRAY", position, array, source);
21118                 }
21119                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21120
21121                 Utils::replaceAllTokens("TYPE", type_name, source);
21122                 Utils::replaceAllTokens("INDEX", index, source);
21123         }
21124         else
21125         {
21126                 switch (test_case.m_stage)
21127                 {
21128                 case Utils::Shader::GEOMETRY:
21129                         switch (stage)
21130                         {
21131                         case Utils::Shader::FRAGMENT:
21132                                 source = fs;
21133                                 break;
21134                         case Utils::Shader::VERTEX:
21135                                 source = vs;
21136                                 break;
21137                         default:
21138                                 source = "";
21139                         }
21140                         break;
21141                 case Utils::Shader::TESS_CTRL:
21142                         switch (stage)
21143                         {
21144                         case Utils::Shader::FRAGMENT:
21145                                 source = fs;
21146                                 break;
21147                         case Utils::Shader::VERTEX:
21148                                 source = vs;
21149                                 break;
21150                         default:
21151                                 source = "";
21152                         }
21153                         break;
21154                 case Utils::Shader::TESS_EVAL:
21155                         switch (stage)
21156                         {
21157                         case Utils::Shader::FRAGMENT:
21158                                 source = fs;
21159                                 break;
21160                         case Utils::Shader::TESS_CTRL:
21161                                 source = tcs;
21162                                 break;
21163                         case Utils::Shader::VERTEX:
21164                                 source = vs;
21165                                 break;
21166                         default:
21167                                 source = "";
21168                         }
21169                         break;
21170                 case Utils::Shader::VERTEX:
21171                         switch (stage)
21172                         {
21173                         case Utils::Shader::FRAGMENT:
21174                                 source = fs;
21175                                 break;
21176                         default:
21177                                 source = "";
21178                         }
21179                         break;
21180                 default:
21181                         TCU_FAIL("Invalid enum");
21182                         break;
21183                 }
21184         }
21185
21186         return source;
21187 }
21188
21189 /** Get description of test case
21190  *
21191  * @param test_case_index Index of test case
21192  *
21193  * @return Test case description
21194  **/
21195 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21196 {
21197         std::stringstream stream;
21198         testCase&                 test_case = m_test_cases[test_case_index];
21199
21200         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21201                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21202
21203         switch (test_case.m_case)
21204         {
21205         case VALID:
21206                 stream << "valid";
21207                 break;
21208         case INVALID:
21209                 stream << "invalid";
21210                 break;
21211         default:
21212                 TCU_FAIL("Invalid enum");
21213         }
21214
21215         return stream.str();
21216 }
21217
21218 /** Get number of test cases
21219  *
21220  * @return Number of test cases
21221  **/
21222 GLuint XFBVariableStrideTest::getTestCaseNumber()
21223 {
21224         return static_cast<GLuint>(m_test_cases.size());
21225 }
21226
21227 /** Selects if "compute" stage is relevant for test
21228  *
21229  * @param ignored
21230  *
21231  * @return false
21232  **/
21233 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21234 {
21235         return false;
21236 }
21237
21238 /** Selects if compilation failure is expected result
21239  *
21240  * @param test_case_index Index of test case
21241  *
21242  * @return true
21243  **/
21244 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21245 {
21246         testCase& test_case = m_test_cases[test_case_index];
21247
21248         return (INVALID == test_case.m_case);
21249 }
21250
21251 /** Prepare all test cases
21252  *
21253  **/
21254 void XFBVariableStrideTest::testInit()
21255 {
21256         const GLuint n_types = getTypesNumber();
21257
21258         for (GLuint i = 0; i < n_types; ++i)
21259         {
21260                 const Utils::Type& type = getType(i);
21261
21262                 /*
21263                  Some of the cases are declared as following are considered as invalid,
21264                  but accoring to spec, the following declaration is valid: shaders in the
21265                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21266                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21267                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21268                  the stride.
21269
21270                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21271                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21272                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21273                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21274
21275                  int type_size = 8;
21276                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21277                  layout (xfb_offset = type_size)                     out double vegeta;
21278                  */
21279                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21280                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21281                 {
21282                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21283                         {
21284                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21285                                         (Utils::Shader::FRAGMENT == stage))
21286                                 {
21287                                         continue;
21288                                 }
21289
21290                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21291
21292                                 m_test_cases.push_back(test_case);
21293                         }
21294                 }
21295         }
21296 }
21297
21298 /** Constructor
21299  *
21300  * @param context Test framework context
21301  **/
21302 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21303         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21304 {
21305 }
21306
21307 /** Source for given test case and stage
21308  *
21309  * @param test_case_index Index of test case
21310  * @param stage           Shader stage
21311  *
21312  * @return Shader source
21313  **/
21314 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21315 {
21316         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21317                                                                                   "    vec4 gohan;\n"
21318                                                                                   "    vec4 goten;\n"
21319                                                                                   "    vec4 chichi;\n"
21320                                                                                   "} gokuARRAY;\n";
21321         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21322                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21323                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21324                                                                    "    if (vec4(0) == result)\n"
21325                                                                    "    {\n"
21326                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21327                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21328                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21329                                                                    "    }\n";
21330         static const GLchar* gs_tested =
21331                 "#version 430 core\n"
21332                 "#extension GL_ARB_enhanced_layouts : require\n"
21333                 "\n"
21334                 "layout(points)                           in;\n"
21335                 "layout(triangle_strip, max_vertices = 4) out;\n"
21336                 "\n"
21337                 "VAR_DEFINITION"
21338                 "\n"
21339                 "out gl_PerVertex \n"
21340                 "{ \n"
21341                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21342                 "}; \n"
21343                 "in  vec4 tes_gs[];\n"
21344                 "out vec4 gs_fs;\n"
21345                 "\n"
21346                 "void main()\n"
21347                 "{\n"
21348                 "    vec4 result = tes_gs[0];\n"
21349                 "\n"
21350                 "VARIABLE_USE"
21351                 "\n"
21352                 "    gs_fs = result;\n"
21353                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21354                 "    EmitVertex();\n"
21355                 "    gs_fs = result;\n"
21356                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21357                 "    EmitVertex();\n"
21358                 "    gs_fs = result;\n"
21359                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21360                 "    EmitVertex();\n"
21361                 "    gs_fs = result;\n"
21362                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21363                 "    EmitVertex();\n"
21364                 "}\n"
21365                 "\n";
21366         static const GLchar* tcs = "#version 430 core\n"
21367                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21368                                                            "\n"
21369                                                            "layout(vertices = 1) out;\n"
21370                                                            "\n"
21371                                                            "in  vec4 vs_tcs[];\n"
21372                                                            "out vec4 tcs_tes[];\n"
21373                                                            "\n"
21374                                                            "void main()\n"
21375                                                            "{\n"
21376                                                            "\n"
21377                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21378                                                            "\n"
21379                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21380                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21381                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21382                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21383                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21384                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21385                                                            "}\n"
21386                                                            "\n";
21387 #if 0
21388         static const GLchar* tcs_tested =
21389                 "#version 430 core\n"
21390                 "#extension GL_ARB_enhanced_layouts : require\n"
21391                 "\n"
21392                 "layout(vertices = 1) out;\n"
21393                 "\n"
21394                 "VAR_DEFINITION"
21395                 "\n"
21396                 "in  vec4 vs_tcs[];\n"
21397                 "out vec4 tcs_tes[];\n"
21398                 "\n"
21399                 "void main()\n"
21400                 "{\n"
21401                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21402                 "\n"
21403                 "VARIABLE_USE"
21404                 "\n"
21405                 "    tcs_tes[gl_InvocationID] = result;\n"
21406                 "\n"
21407                 "    gl_TessLevelOuter[0] = 1.0;\n"
21408                 "    gl_TessLevelOuter[1] = 1.0;\n"
21409                 "    gl_TessLevelOuter[2] = 1.0;\n"
21410                 "    gl_TessLevelOuter[3] = 1.0;\n"
21411                 "    gl_TessLevelInner[0] = 1.0;\n"
21412                 "    gl_TessLevelInner[1] = 1.0;\n"
21413                 "}\n"
21414                 "\n";
21415 #endif
21416         static const GLchar* tes_tested = "#version 430 core\n"
21417                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21418                                                                           "\n"
21419                                                                           "layout(isolines, point_mode) in;\n"
21420                                                                           "\n"
21421                                                                           "VAR_DEFINITION"
21422                                                                           "\n"
21423                                                                           "in  vec4 tcs_tes[];\n"
21424                                                                           "out vec4 tes_gs;\n"
21425                                                                           "\n"
21426                                                                           "void main()\n"
21427                                                                           "{\n"
21428                                                                           "    vec4 result = tcs_tes[0];\n"
21429                                                                           "\n"
21430                                                                           "VARIABLE_USE"
21431                                                                           "\n"
21432                                                                           "    tes_gs += result;\n"
21433                                                                           "}\n"
21434                                                                           "\n";
21435         static const GLchar* vs = "#version 430 core\n"
21436                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21437                                                           "\n"
21438                                                           "in  vec4 in_vs;\n"
21439                                                           "out vec4 vs_tcs;\n"
21440                                                           "\n"
21441                                                           "void main()\n"
21442                                                           "{\n"
21443                                                           "    vs_tcs = in_vs;\n"
21444                                                           "}\n"
21445                                                           "\n";
21446         static const GLchar* vs_tested = "#version 430 core\n"
21447                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21448                                                                          "\n"
21449                                                                          "VAR_DEFINITION"
21450                                                                          "\n"
21451                                                                          "in  vec4 in_vs;\n"
21452                                                                          "out vec4 vs_tcs;\n"
21453                                                                          "\n"
21454                                                                          "void main()\n"
21455                                                                          "{\n"
21456                                                                          "    vec4 result = in_vs;\n"
21457                                                                          "\n"
21458                                                                          "VARIABLE_USE"
21459                                                                          "\n"
21460                                                                          "    vs_tcs += result;\n"
21461                                                                          "}\n"
21462                                                                          "\n";
21463
21464         std::string                       source;
21465         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21466
21467         if (test_case == stage)
21468         {
21469                 const GLchar* array     = "";
21470                 const GLchar* index     = "";
21471                 size_t            position = 0;
21472                 size_t            temp;
21473                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21474                 // change array = "[]" to "[1]"
21475                 switch (stage)
21476                 {
21477                 case Utils::Shader::GEOMETRY:
21478                         source = gs_tested;
21479                         array  = "[1]";
21480                         index  = "[0]";
21481                         break;
21482 /*
21483                          It is invalid to define transform feedback output in HS
21484                          */
21485 #if 0
21486                         case Utils::Shader::TESS_CTRL:
21487                         source = tcs_tested;
21488                         array = "[]";
21489                         index = "[gl_InvocationID]";
21490                         break;
21491 #endif
21492                 case Utils::Shader::TESS_EVAL:
21493                         source = tes_tested;
21494                         array  = "[1]";
21495                         index  = "[0]";
21496                         break;
21497                 case Utils::Shader::VERTEX:
21498                         source = vs_tested;
21499                         break;
21500                 default:
21501                         TCU_FAIL("Invalid enum");
21502                 }
21503
21504                 temp = position;
21505                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21506                 position = temp;
21507                 Utils::replaceToken("ARRAY", position, array, source);
21508                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21509
21510                 Utils::replaceAllTokens("INDEX", index, source);
21511         }
21512         else
21513         {
21514                 switch (test_case)
21515                 {
21516                 case Utils::Shader::GEOMETRY:
21517                         switch (stage)
21518                         {
21519                         case Utils::Shader::VERTEX:
21520                                 source = vs;
21521                                 break;
21522                         default:
21523                                 source = "";
21524                         }
21525                         break;
21526                 case Utils::Shader::TESS_CTRL:
21527                         switch (stage)
21528                         {
21529                         case Utils::Shader::VERTEX:
21530                                 source = vs;
21531                                 break;
21532                         default:
21533                                 source = "";
21534                         }
21535                         break;
21536                 case Utils::Shader::TESS_EVAL:
21537                         switch (stage)
21538                         {
21539                         case Utils::Shader::TESS_CTRL:
21540                                 source = tcs;
21541                                 break;
21542                         case Utils::Shader::VERTEX:
21543                                 source = vs;
21544                                 break;
21545                         default:
21546                                 source = "";
21547                         }
21548                         break;
21549                 case Utils::Shader::VERTEX:
21550                         source = "";
21551                         break;
21552                 default:
21553                         TCU_FAIL("Invalid enum");
21554                         break;
21555                 }
21556         }
21557
21558         return source;
21559 }
21560
21561 /** Get description of test case
21562  *
21563  * @param test_case_index Index of test case
21564  *
21565  * @return Test case description
21566  **/
21567 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21568 {
21569         std::stringstream stream;
21570
21571         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21572
21573         return stream.str();
21574 }
21575
21576 /** Get number of test cases
21577  *
21578  * @return Number of test cases
21579  **/
21580 GLuint XFBBlockStrideTest::getTestCaseNumber()
21581 {
21582         return static_cast<GLuint>(m_test_cases.size());
21583 }
21584
21585 /** Inspects program for xfb stride
21586  *
21587  * @param program Program to query
21588  *
21589  * @return true if query results match expected values, false otherwise
21590  **/
21591 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21592 {
21593         GLint stride = 0;
21594
21595         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21596                                                 1 /* buf_size */, &stride);
21597
21598         return (128 == stride);
21599 }
21600
21601 /** Runs test case
21602  *
21603  * @param test_case_index Id of test case
21604  *
21605  * @return true if test case pass, false otherwise
21606  **/
21607 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21608 {
21609         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21610         Utils::Program   program(m_context);
21611         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21612         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21613         bool                       test_case_result = true;
21614         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21615
21616         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21617
21618         test_case_result = inspectProgram(program);
21619
21620         return test_case_result;
21621 }
21622
21623 /** Prepare all test cases
21624  *
21625  **/
21626 void XFBBlockStrideTest::testInit()
21627 {
21628         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21629         {
21630                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21631                         (Utils::Shader::FRAGMENT == stage))
21632                 {
21633                         continue;
21634                 }
21635
21636                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21637         }
21638 }
21639
21640 /** Constructor
21641  *
21642  * @param context Test context
21643  **/
21644 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21645         : BufferTestBase(context, "xfb_block_member_stride",
21646                                          "Test verifies that xfb_stride qualifier is respected for block member")
21647 {
21648         /* Nothing to be done here */
21649 }
21650
21651 /** Get descriptors of buffers necessary for test
21652  *
21653  * @param ignored
21654  * @param out_descriptors Descriptors of buffers used by test
21655  **/
21656 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21657                                                                                                         bufferDescriptor::Vector& out_descriptors)
21658 {
21659         const Utils::Type& vec4 = Utils::Type::vec4;
21660
21661         /* Test needs single uniform and xfb */
21662         out_descriptors.resize(2);
21663
21664         /* Get references */
21665         bufferDescriptor& uniform = out_descriptors[0];
21666         bufferDescriptor& xfb    = out_descriptors[1];
21667
21668         /* Index */
21669         uniform.m_index = 0;
21670         xfb.m_index             = 0;
21671
21672         /* Target */
21673         uniform.m_target = Utils::Buffer::Uniform;
21674         xfb.m_target     = Utils::Buffer::Transform_feedback;
21675
21676         /* Data */
21677         static const GLuint                     vec4_size   = 16;
21678         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21679         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21680         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21681
21682         /* Uniform data */
21683         uniform.m_initial_data.resize(3 * vec4_size);
21684         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21685         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21686         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21687
21688         /* XFB data */
21689         xfb.m_initial_data.resize(4 * vec4_size);
21690         xfb.m_expected_data.resize(4 * vec4_size);
21691
21692         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21693         {
21694                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21695                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21696         }
21697
21698         // the xfb_offset of "chichi" should be 32
21699         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21700         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21701         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21702 }
21703
21704 /** Get body of main function for given shader stage
21705  *
21706  * @param ignored
21707  * @param stage            Shader stage
21708  * @param out_assignments  Set to empty
21709  * @param out_calculations Set to empty
21710  **/
21711 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21712                                                                                          std::string& out_assignments, std::string& out_calculations)
21713 {
21714         out_calculations = "";
21715
21716         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21717                                                           "    goten  = uni_goten;\n"
21718                                                           "    chichi = uni_chichi;\n";
21719         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21720
21721         const GLchar* assignments = "";
21722         switch (stage)
21723         {
21724         case Utils::Shader::FRAGMENT:
21725                 assignments = fs;
21726                 break;
21727         case Utils::Shader::GEOMETRY:
21728                 assignments = gs;
21729                 break;
21730         default:
21731                 break;
21732         }
21733
21734         out_assignments = assignments;
21735 }
21736
21737 /** Get interface of shader
21738  *
21739  * @param ignored
21740  * @param stage            Shader stage
21741  * @param out_interface    Set to ""
21742  **/
21743 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21744                                                                                                   std::string& out_interface)
21745 {
21746         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21747                                                           "                             vec4 gohan;\n"
21748                                                           "    layout (xfb_stride = 32) vec4 goten;\n"
21749                                                           "                             vec4 chichi;\n"
21750                                                           "};\n"
21751                                                           "layout(binding = 0) uniform gs_block {\n"
21752                                                           "    vec4 uni_gohan;\n"
21753                                                           "    vec4 uni_goten;\n"
21754                                                           "    vec4 uni_chichi;\n"
21755                                                           "};\n";
21756         static const GLchar* fs = "in Goku {\n"
21757                                                           "    vec4 gohan;\n"
21758                                                           "    vec4 goten;\n"
21759                                                           "    vec4 chichi;\n"
21760                                                           "};\n"
21761                                                           "out vec4 fs_out;\n";
21762
21763         switch (stage)
21764         {
21765         case Utils::Shader::FRAGMENT:
21766                 out_interface = fs;
21767                 break;
21768         case Utils::Shader::GEOMETRY:
21769                 out_interface = gs;
21770                 break;
21771         default:
21772                 out_interface = "";
21773                 return;
21774         }
21775 }
21776
21777 /** Inspects program to check if all resources are as expected
21778  *
21779  * @param ignored
21780  * @param program    Program instance
21781  * @param out_stream Error message
21782  *
21783  * @return true if everything is ok, false otherwise
21784  **/
21785 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21786                                                                                           std::stringstream& out_stream)
21787 {
21788         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21789         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21790         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21791
21792         GLint gohan_offset  = 0;
21793         GLint goten_offset  = 0;
21794         GLint chichi_offset = 0;
21795
21796         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21797         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21798         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21799
21800         // the xfb_offset of "chichi" should be 32
21801         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21802         {
21803                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21804                                    << "] expected: [0, 16, 48]";
21805                 return false;
21806         }
21807
21808         return true;
21809 }
21810
21811 /** Constructor
21812  *
21813  * @param context Test framework context
21814  **/
21815 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21816         : NegativeTestBase(context, "xfb_duplicated_stride",
21817                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21818 {
21819 }
21820
21821 /** Source for given test case and stage
21822  *
21823  * @param test_case_index Index of test case
21824  * @param stage           Shader stage
21825  *
21826  * @return Shader source
21827  **/
21828 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21829 {
21830         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21831                                                                                                   "const uint conflicting_stride = 128;\n"
21832                                                                                                   "\n"
21833                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21834                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21835         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21836                                                                                                 "\n"
21837                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21838                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21839         static const GLchar* fs = "#version 430 core\n"
21840                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21841                                                           "\n"
21842                                                           "in  vec4 any_fs;\n"
21843                                                           "out vec4 fs_out;\n"
21844                                                           "\n"
21845                                                           "void main()\n"
21846                                                           "{\n"
21847                                                           "    fs_out = any_fs;\n"
21848                                                           "}\n"
21849                                                           "\n";
21850         static const GLchar* gs_tested = "#version 430 core\n"
21851                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21852                                                                          "\n"
21853                                                                          "layout(points)                           in;\n"
21854                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21855                                                                          "\n"
21856                                                                          "VAR_DEFINITION"
21857                                                                          "\n"
21858                                                                          "in  vec4 vs_any[];\n"
21859                                                                          "out vec4 any_fs;\n"
21860                                                                          "\n"
21861                                                                          "void main()\n"
21862                                                                          "{\n"
21863                                                                          "    vec4 result = vs_any[0];\n"
21864                                                                          "\n"
21865                                                                          "VARIABLE_USE"
21866                                                                          "\n"
21867                                                                          "    any_fs = result;\n"
21868                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21869                                                                          "    EmitVertex();\n"
21870                                                                          "    any_fs = result;\n"
21871                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21872                                                                          "    EmitVertex();\n"
21873                                                                          "    any_fs = result;\n"
21874                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21875                                                                          "    EmitVertex();\n"
21876                                                                          "    any_fs = result;\n"
21877                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21878                                                                          "    EmitVertex();\n"
21879                                                                          "}\n"
21880                                                                          "\n";
21881         static const GLchar* tcs = "#version 430 core\n"
21882                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21883                                                            "\n"
21884                                                            "layout(vertices = 1) out;\n"
21885                                                            "\n"
21886                                                            "in  vec4 vs_any[];\n"
21887                                                            "out vec4 tcs_tes[];\n"
21888                                                            "\n"
21889                                                            "void main()\n"
21890                                                            "{\n"
21891                                                            "\n"
21892                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21893                                                            "\n"
21894                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21895                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21896                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21897                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21898                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21899                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21900                                                            "}\n"
21901                                                            "\n";
21902         static const GLchar* tcs_tested = "#version 430 core\n"
21903                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21904                                                                           "\n"
21905                                                                           "layout(vertices = 1) out;\n"
21906                                                                           "\n"
21907                                                                           "VAR_DEFINITION"
21908                                                                           "\n"
21909                                                                           "in  vec4 vs_any[];\n"
21910                                                                           "out vec4 any_fs[];\n"
21911                                                                           "\n"
21912                                                                           "void main()\n"
21913                                                                           "{\n"
21914                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21915                                                                           "\n"
21916                                                                           "VARIABLE_USE"
21917                                                                           "\n"
21918                                                                           "    any_fs[gl_InvocationID] = result;\n"
21919                                                                           "\n"
21920                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21921                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21922                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21923                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21924                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21925                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21926                                                                           "}\n"
21927                                                                           "\n";
21928         static const GLchar* tes_tested = "#version 430 core\n"
21929                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21930                                                                           "\n"
21931                                                                           "layout(isolines, point_mode) in;\n"
21932                                                                           "\n"
21933                                                                           "VAR_DEFINITION"
21934                                                                           "\n"
21935                                                                           "in  vec4 tcs_tes[];\n"
21936                                                                           "out vec4 any_fs;\n"
21937                                                                           "\n"
21938                                                                           "void main()\n"
21939                                                                           "{\n"
21940                                                                           "    vec4 result = tcs_tes[0];\n"
21941                                                                           "\n"
21942                                                                           "VARIABLE_USE"
21943                                                                           "\n"
21944                                                                           "    any_fs = result;\n"
21945                                                                           "}\n"
21946                                                                           "\n";
21947         static const GLchar* vs = "#version 430 core\n"
21948                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21949                                                           "\n"
21950                                                           "in  vec4 in_vs;\n"
21951                                                           "out vec4 vs_any;\n"
21952                                                           "\n"
21953                                                           "void main()\n"
21954                                                           "{\n"
21955                                                           "    vs_any = in_vs;\n"
21956                                                           "}\n"
21957                                                           "\n";
21958         static const GLchar* vs_tested = "#version 430 core\n"
21959                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21960                                                                          "\n"
21961                                                                          "VAR_DEFINITION"
21962                                                                          "\n"
21963                                                                          "in  vec4 in_vs;\n"
21964                                                                          "out vec4 any_fs;\n"
21965                                                                          "\n"
21966                                                                          "void main()\n"
21967                                                                          "{\n"
21968                                                                          "    vec4 result = in_vs;\n"
21969                                                                          "\n"
21970                                                                          "VARIABLE_USE"
21971                                                                          "\n"
21972                                                                          "    any_fs += result;\n"
21973                                                                          "}\n"
21974                                                                          "\n";
21975
21976         std::string source;
21977         testCase&   test_case = m_test_cases[test_case_index];
21978
21979         if (test_case.m_stage == stage)
21980         {
21981                 size_t            position               = 0;
21982                 const GLchar* var_definition = 0;
21983                 const GLchar* var_use            = "";
21984
21985                 switch (test_case.m_case)
21986                 {
21987                 case VALID:
21988                         var_definition = valid_var_definition;
21989                         break;
21990                 case INVALID:
21991                         var_definition = invalid_var_definition;
21992                         break;
21993                 default:
21994                         TCU_FAIL("Invalid enum");
21995                 }
21996
21997                 switch (stage)
21998                 {
21999                 case Utils::Shader::GEOMETRY:
22000                         source = gs_tested;
22001                         break;
22002                 case Utils::Shader::TESS_CTRL:
22003                         source = tcs_tested;
22004                         break;
22005                 case Utils::Shader::TESS_EVAL:
22006                         source = tes_tested;
22007                         break;
22008                 case Utils::Shader::VERTEX:
22009                         source = vs_tested;
22010                         break;
22011                 default:
22012                         TCU_FAIL("Invalid enum");
22013                 }
22014
22015                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22016                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22017         }
22018         else
22019         {
22020                 switch (test_case.m_stage)
22021                 {
22022                 case Utils::Shader::GEOMETRY:
22023                         switch (stage)
22024                         {
22025                         case Utils::Shader::FRAGMENT:
22026                                 source = fs;
22027                                 break;
22028                         case Utils::Shader::VERTEX:
22029                                 source = vs;
22030                                 break;
22031                         default:
22032                                 source = "";
22033                         }
22034                         break;
22035                 case Utils::Shader::TESS_CTRL:
22036                         switch (stage)
22037                         {
22038                         case Utils::Shader::FRAGMENT:
22039                                 source = fs;
22040                                 break;
22041                         case Utils::Shader::VERTEX:
22042                                 source = vs;
22043                                 break;
22044                         default:
22045                                 source = "";
22046                         }
22047                         break;
22048                 case Utils::Shader::TESS_EVAL:
22049                         switch (stage)
22050                         {
22051                         case Utils::Shader::FRAGMENT:
22052                                 source = fs;
22053                                 break;
22054                         case Utils::Shader::TESS_CTRL:
22055                                 source = tcs;
22056                                 break;
22057                         case Utils::Shader::VERTEX:
22058                                 source = vs;
22059                                 break;
22060                         default:
22061                                 source = "";
22062                         }
22063                         break;
22064                 case Utils::Shader::VERTEX:
22065                         switch (stage)
22066                         {
22067                         case Utils::Shader::FRAGMENT:
22068                                 source = fs;
22069                                 break;
22070                         default:
22071                                 source = "";
22072                         }
22073                         break;
22074                 default:
22075                         TCU_FAIL("Invalid enum");
22076                         break;
22077                 }
22078         }
22079
22080         return source;
22081 }
22082
22083 /** Get description of test case
22084  *
22085  * @param test_case_index Index of test case
22086  *
22087  * @return Test case description
22088  **/
22089 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22090 {
22091         std::stringstream stream;
22092         testCase&                 test_case = m_test_cases[test_case_index];
22093
22094         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22095
22096         switch (test_case.m_case)
22097         {
22098         case VALID:
22099                 stream << "valid";
22100                 break;
22101         case INVALID:
22102                 stream << "invalid";
22103                 break;
22104         default:
22105                 TCU_FAIL("Invalid enum");
22106         }
22107
22108         return stream.str();
22109 }
22110
22111 /** Get number of test cases
22112  *
22113  * @return Number of test cases
22114  **/
22115 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22116 {
22117         return static_cast<GLuint>(m_test_cases.size());
22118 }
22119
22120 /** Selects if "compute" stage is relevant for test
22121  *
22122  * @param ignored
22123  *
22124  * @return false
22125  **/
22126 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22127 {
22128         return false;
22129 }
22130
22131 /** Selects if compilation failure is expected result
22132  *
22133  * @param test_case_index Index of test case
22134  *
22135  * @return true
22136  **/
22137 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22138 {
22139         testCase& test_case = m_test_cases[test_case_index];
22140
22141         return (INVALID == test_case.m_case);
22142 }
22143
22144 /** Prepare all test cases
22145  *
22146  **/
22147 void XFBDuplicatedStrideTest::testInit()
22148 {
22149         for (GLuint c = 0; c < CASE_MAX; ++c)
22150         {
22151                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22152                 {
22153                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22154                                 (Utils::Shader::FRAGMENT == stage))
22155                         {
22156                                 continue;
22157                         }
22158
22159                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22160
22161                         m_test_cases.push_back(test_case);
22162                 }
22163         }
22164 }
22165
22166 /** Constructor
22167  *
22168  * @param context Test framework context
22169  **/
22170 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22171         : TestBase(context, "xfb_get_program_resource_api",
22172                            "Test verifies that get program resource reports correct results for XFB")
22173 {
22174 }
22175
22176 /** Source for given test case and stage
22177  *
22178  * @param test_case_index Index of test case
22179  * @param stage           Shader stage
22180  *
22181  * @return Shader source
22182  **/
22183 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22184 {
22185         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22186                                                                                           "out TYPE b1_v1ARRAY;\n"
22187                                                                                           "out TYPE b0_v3ARRAY;\n"
22188                                                                                           "out TYPE b0_v0ARRAY;\n";
22189         static const GLchar* xfb_var_definition =
22190                 "const uint type_size = SIZE;\n"
22191                 "\n"
22192                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22193                 "\n"
22194                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22195                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22196                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22197                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22198         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22199                                                                    "    b1_v1INDEX = TYPE(1);\n"
22200                                                                    "    b0_v3INDEX = TYPE(0);\n"
22201                                                                    "    b0_v0INDEX = TYPE(1);\n"
22202                                                                    "    if (vec4(0) == result)\n"
22203                                                                    "    {\n"
22204                                                                    "        b0_v1INDEX = TYPE(1);\n"
22205                                                                    "        b1_v1INDEX = TYPE(0);\n"
22206                                                                    "        b0_v3INDEX = TYPE(1);\n"
22207                                                                    "        b0_v0INDEX = TYPE(0);\n"
22208                                                                    "    }\n";
22209         static const GLchar* gs_tested =
22210                 "#version 430 core\n"
22211                 "#extension GL_ARB_enhanced_layouts : require\n"
22212                 "\n"
22213                 "layout(points)                           in;\n"
22214                 "layout(triangle_strip, max_vertices = 4) out;\n"
22215                 "\n"
22216                 "VAR_DEFINITION"
22217                 "\n"
22218                 "out gl_PerVertex \n"
22219                 "{ \n"
22220                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22221                 "}; \n"
22222                 "in  vec4 tes_gs[];\n"
22223                 "out vec4 gs_fs;\n"
22224                 "\n"
22225                 "void main()\n"
22226                 "{\n"
22227                 "    vec4 result = tes_gs[0];\n"
22228                 "\n"
22229                 "VARIABLE_USE"
22230                 "\n"
22231                 "    gs_fs = result;\n"
22232                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22233                 "    EmitVertex();\n"
22234                 "    gs_fs = result;\n"
22235                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22236                 "    EmitVertex();\n"
22237                 "    gs_fs = result;\n"
22238                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22239                 "    EmitVertex();\n"
22240                 "    gs_fs = result;\n"
22241                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22242                 "    EmitVertex();\n"
22243                 "}\n"
22244                 "\n";
22245 #if 0
22246         static const GLchar* tcs_tested =
22247                 "#version 430 core\n"
22248                 "#extension GL_ARB_enhanced_layouts : require\n"
22249                 "\n"
22250                 "layout(vertices = 1) out;\n"
22251                 "\n"
22252                 "VAR_DEFINITION"
22253                 "\n"
22254                 "in  vec4 vs_tcs[];\n"
22255                 "out vec4 tcs_tes[];\n"
22256                 "\n"
22257                 "void main()\n"
22258                 "{\n"
22259                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22260                 "\n"
22261                 "VARIABLE_USE"
22262                 "\n"
22263                 "    tcs_tes[gl_InvocationID] = result;\n"
22264                 "\n"
22265                 "    gl_TessLevelOuter[0] = 1.0;\n"
22266                 "    gl_TessLevelOuter[1] = 1.0;\n"
22267                 "    gl_TessLevelOuter[2] = 1.0;\n"
22268                 "    gl_TessLevelOuter[3] = 1.0;\n"
22269                 "    gl_TessLevelInner[0] = 1.0;\n"
22270                 "    gl_TessLevelInner[1] = 1.0;\n"
22271                 "}\n"
22272                 "\n";
22273 #endif
22274         static const GLchar* tes_tested = "#version 430 core\n"
22275                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22276                                                                           "\n"
22277                                                                           "layout(isolines, point_mode) in;\n"
22278                                                                           "\n"
22279                                                                           "VAR_DEFINITION"
22280                                                                           "\n"
22281                                                                           "in  vec4 tcs_tes[];\n"
22282                                                                           "out vec4 tes_gs;\n"
22283                                                                           "\n"
22284                                                                           "void main()\n"
22285                                                                           "{\n"
22286                                                                           "    vec4 result = tcs_tes[0];\n"
22287                                                                           "\n"
22288                                                                           "VARIABLE_USE"
22289                                                                           "\n"
22290                                                                           "    tes_gs = result;\n"
22291                                                                           "}\n"
22292                                                                           "\n";
22293         static const GLchar* vs_tested = "#version 430 core\n"
22294                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22295                                                                          "\n"
22296                                                                          "VAR_DEFINITION"
22297                                                                          "\n"
22298                                                                          "in  vec4 in_vs;\n"
22299                                                                          "out vec4 vs_tcs;\n"
22300                                                                          "\n"
22301                                                                          "void main()\n"
22302                                                                          "{\n"
22303                                                                          "    vec4 result = in_vs;\n"
22304                                                                          "\n"
22305                                                                          "VARIABLE_USE"
22306                                                                          "\n"
22307                                                                          "    vs_tcs = result;\n"
22308                                                                          "}\n"
22309                                                                          "\n";
22310
22311         std::string              source;
22312         const test_Case& test_case = m_test_cases[test_case_index];
22313
22314         if (test_case.m_stage == stage)
22315         {
22316                 const GLchar* array = "";
22317                 GLchar            buffer[16];
22318                 const GLchar* index     = "";
22319                 size_t            position = 0;
22320                 size_t            temp;
22321                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22322                 const GLchar* var_definition = 0;
22323
22324                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22325
22326                 if (XFB == test_case.m_case)
22327                 {
22328                         var_definition = xfb_var_definition;
22329                 }
22330                 else
22331                 {
22332                         var_definition = api_var_definition;
22333                 }
22334
22335                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22336                 // change array = "[]" to "[1]"
22337                 switch (stage)
22338                 {
22339                 case Utils::Shader::GEOMETRY:
22340                         source = gs_tested;
22341                         array  = "[1]";
22342                         index  = "[0]";
22343                         break;
22344 // It is invalid to output transform feedback varyings in tessellation control shader
22345 #if 0
22346                 case Utils::Shader::TESS_CTRL:
22347                         source = tcs_tested;
22348                         array = "[]";
22349                         index = "[gl_InvocationID]";
22350                         break;
22351 #endif
22352                 case Utils::Shader::TESS_EVAL:
22353                         source = tes_tested;
22354                         array  = "[1]";
22355                         index  = "[0]";
22356                         break;
22357                 case Utils::Shader::VERTEX:
22358                         source = vs_tested;
22359                         break;
22360                 default:
22361                         TCU_FAIL("Invalid enum");
22362                 }
22363
22364                 temp = position;
22365                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22366                 if (XFB == test_case.m_case)
22367                 {
22368                         position = temp;
22369                         Utils::replaceToken("SIZE", position, buffer, source);
22370                 }
22371                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22372
22373                 Utils::replaceAllTokens("ARRAY", array, source);
22374                 Utils::replaceAllTokens("INDEX", index, source);
22375                 Utils::replaceAllTokens("TYPE", type_name, source);
22376         }
22377         else
22378         {
22379                 source = "";
22380         }
22381
22382         return source;
22383 }
22384
22385 /** Get description of test case
22386  *
22387  * @param test_case_index Index of test case
22388  *
22389  * @return Test case description
22390  **/
22391 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22392 {
22393         std::stringstream stream;
22394         const test_Case&  test_case = m_test_cases[test_case_index];
22395
22396         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22397                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22398
22399         switch (test_case.m_case)
22400         {
22401         case INTERLEAVED:
22402                 stream << "interleaved";
22403                 break;
22404         case SEPARATED:
22405                 stream << "separated";
22406                 break;
22407         case XFB:
22408                 stream << "xfb";
22409                 break;
22410         default:
22411                 TCU_FAIL("Invalid enum");
22412         }
22413
22414         return stream.str();
22415 }
22416
22417 /** Get number of test cases
22418  *
22419  * @return Number of test cases
22420  **/
22421 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22422 {
22423         return static_cast<GLuint>(m_test_cases.size());
22424 }
22425
22426 /** Inspects program for offset, buffer index, buffer stride and type
22427  *
22428  * @param test_case_index Index of test case
22429  * @param program         Program to query
22430  *
22431  * @return true if query results match expected values, false otherwise
22432  **/
22433 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22434 {
22435         GLint                    b0_stride      = 0;
22436         GLint                    b1_stride      = 0;
22437         GLint                    b0_v0_buf      = 0;
22438         GLint                    b0_v0_offset = 0;
22439         GLint                    b0_v0_type   = 0;
22440         GLint                    b0_v1_buf      = 0;
22441         GLint                    b0_v1_offset = 0;
22442         GLint                    b0_v1_type   = 0;
22443         GLint                    b0_v3_buf      = 0;
22444         GLint                    b0_v3_offset = 0;
22445         GLint                    b0_v3_type   = 0;
22446         GLint                    b1_v1_buf      = 0;
22447         GLint                    b1_v1_offset = 0;
22448         GLint                    b1_v1_type   = 0;
22449         const test_Case& test_case      = m_test_cases[test_case_index];
22450         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22451         const GLint              type_size      = test_case.m_type.GetSize();
22452
22453         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22454         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22455         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22456         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22457
22458         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22459         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22460         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22461         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22462
22463         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22464         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22465         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22466         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22467
22468         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22469                                                 1 /* buf_size */, &b0_v0_buf);
22470         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22471                                                 1 /* buf_size */, &b0_v1_buf);
22472         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22473                                                 1 /* buf_size */, &b0_v3_buf);
22474         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22475                                                 1 /* buf_size */, &b1_v1_buf);
22476
22477         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22478                                                 &b0_stride);
22479         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22480                                                 &b1_stride);
22481
22482         if (SEPARATED != test_case.m_case)
22483         {
22484                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22485                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22486                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22487                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22488                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22489                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22490                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22491         }
22492         else
22493         {
22494                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22495                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22496                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22497                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22498                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22499         }
22500 }
22501
22502 /** Insert gl_SkipComponents
22503  *
22504  * @param num_components How many gl_SkipComponents1 need to be inserted
22505  * @param varyings The transform feedback varyings string vector
22506  *
22507  **/
22508 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22509 {
22510         int num_component_4 = num_components / 4;
22511         int num_component_1 = num_components % 4;
22512         for (int i = 0; i < num_component_4; i++)
22513         {
22514                 varyings.push_back("gl_SkipComponents4");
22515         }
22516         switch (num_component_1)
22517         {
22518         case 1:
22519                 varyings.push_back("gl_SkipComponents1");
22520                 break;
22521         case 2:
22522                 varyings.push_back("gl_SkipComponents2");
22523                 break;
22524         case 3:
22525                 varyings.push_back("gl_SkipComponents3");
22526                 break;
22527         default:
22528                 break;
22529         }
22530 }
22531
22532 /** Runs test case
22533  *
22534  * @param test_case_index Id of test case
22535  *
22536  * @return true if test case pass, false otherwise
22537  **/
22538 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22539 {
22540         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22541         Utils::Program   program(m_context);
22542         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22543         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22544         const test_Case&   test_case            = m_test_cases[test_case_index];
22545         bool                       test_case_result = true;
22546         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22547
22548         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22549         // No data will be recorded for such strings, but the offset assigned to the next variable in varyings and the stride of the assigned bingding point will be affected.
22550
22551         if (INTERLEAVED == test_case.m_case)
22552         {
22553                 /*
22554                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22555                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22556                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22557                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22558
22559                  Note: the type can be float, double, mat2, mat3x2, dmat2, dmat3x2..., so to make the each variable of "captured_varyings" has the same xfb_offset with the above shaders,
22560                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22561                  */
22562                 Utils::Program::NameVector captured_varyings;
22563                 captured_varyings.push_back("b0_v0");
22564                 captured_varyings.push_back("b0_v1");
22565                 // Compute how many gl_SkipComponents to be inserted
22566                 int numComponents = test_case.m_type.GetSize() / 4;
22567                 insertSkipComponents(numComponents, captured_varyings);
22568                 captured_varyings.push_back("b0_v3");
22569                 captured_varyings.push_back("gl_NextBuffer");
22570                 insertSkipComponents(numComponents, captured_varyings);
22571                 captured_varyings.push_back("b1_v1");
22572                 insertSkipComponents(numComponents * 2, captured_varyings);
22573
22574                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22575                                          true /* separable */);
22576         }
22577         else if (SEPARATED == test_case.m_case)
22578         {
22579                 Utils::Program::NameVector captured_varyings;
22580
22581                 captured_varyings.push_back("b0_v0");
22582                 captured_varyings.push_back("b0_v1");
22583                 captured_varyings.push_back("b0_v3");
22584                 captured_varyings.push_back("b1_v1");
22585
22586                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22587                                          true /* separable */);
22588         }
22589         else
22590         {
22591
22592                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22593         }
22594
22595         test_case_result = inspectProgram(test_case_index, program);
22596
22597         return test_case_result;
22598 }
22599
22600 /** Prepare all test cases
22601  *
22602  **/
22603 void XFBGetProgramResourceAPITest::testInit()
22604 {
22605         const Functions& gl              = m_context.getRenderContext().getFunctions();
22606         const GLuint     n_types = getTypesNumber();
22607         GLint                    max_xfb_int;
22608         GLint                    max_xfb_sep;
22609
22610         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22611         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22612
22613         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22614         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22615
22616         GLint max_varyings;
22617         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22618
22619         for (GLuint i = 0; i < n_types; ++i)
22620         {
22621                 // When i == 7, the type is dmat4, i == 9 the type is dmat4x3, the number of output components exceeds the maximum value that AMD's driver supported,
22622                 // the MAX_VARYING_COMPONENTS is 32 in our driver, but when the variable type is dmat4 or dmat4x3, the number of output component is 33, to make the
22623                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22624                 // to guarantee the number of varying not exceeded.
22625                 /*
22626                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22627                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22628                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22629                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22630                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22631                  in  vec4 in_vs;
22632                  out vec4 vs_tcs;
22633                  */
22634                 if (i == 7 || i == 9)
22635                         continue;
22636                 const Utils::Type& type = getType(i);
22637                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22638                 {
22639                         continue;
22640                 }
22641                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22642                 {
22643                         /*
22644                          It is invalid to define transform feedback output in HS
22645                          */
22646                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22647                                 (Utils::Shader::FRAGMENT == stage))
22648                         {
22649                                 continue;
22650                         }
22651
22652                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22653                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22654                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22655
22656                         if ((int)type.GetSize() <= max_xfb_int)
22657                         {
22658                                 m_test_cases.push_back(test_case_xfb);
22659                                 m_test_cases.push_back(test_case_int);
22660                         }
22661
22662                         if ((int)type.GetSize() <= max_xfb_sep)
22663                         {
22664                                 m_test_cases.push_back(test_case_sep);
22665                         }
22666                 }
22667         }
22668 }
22669
22670 /** Constructor
22671  *
22672  * @param context Test context
22673  **/
22674 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22675         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22676                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22677 {
22678         /* Nothing to be done here */
22679 }
22680
22681 /** Get descriptors of buffers necessary for test
22682  *
22683  * @param test_case_index Index of test case
22684  * @param out_descriptors Descriptors of buffers used by test
22685  **/
22686 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22687                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22688 {
22689         const Utils::Type& type = getType(test_case_index);
22690
22691         /* Test needs single uniform and xfb */
22692         out_descriptors.resize(2);
22693
22694         /* Get references */
22695         bufferDescriptor& uniform = out_descriptors[0];
22696         bufferDescriptor& xfb    = out_descriptors[1];
22697
22698         /* Index */
22699         uniform.m_index = 0;
22700         xfb.m_index             = 0;
22701
22702         /* Target */
22703         uniform.m_target = Utils::Buffer::Uniform;
22704         xfb.m_target     = Utils::Buffer::Transform_feedback;
22705
22706         /* Data */
22707         const GLuint                            gen_start   = Utils::s_rand;
22708         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22709         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22710         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22711         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22712
22713         Utils::s_rand                                                           = gen_start;
22714         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22715         /*
22716          The xfb varying goku is -0.375, it is expected to equal to xfb.m_expected_data[0], xfb.m_expected_data[0] is assigned from goku_data_pck(-0.5)
22717          how can make them equal ? is it as designed?  Add the following statement,  which can make sure goku_data_pck equals to goku_data
22718          */
22719         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22720
22721         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22722         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22723
22724         /* Uniform data */
22725         uniform.m_initial_data.resize(4 * type_size);
22726         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22727         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22728         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22729         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &gohan_data[0], type_size);
22730
22731         /* XFB data */
22732         xfb.m_initial_data.resize(4 * type_size_pck);
22733         xfb.m_expected_data.resize(4 * type_size_pck);
22734
22735         for (GLuint i = 0; i < 4 * type_size_pck; ++i)
22736         {
22737                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22738                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22739         }
22740
22741         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22742         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22743 }
22744
22745 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22746  *
22747  * @param ignored
22748  * @param captured_varyings List of names
22749  **/
22750 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22751                                                                                                                    Utils::Program::NameVector& captured_varyings)
22752 {
22753         captured_varyings.resize(2);
22754
22755         captured_varyings[0] = "trunks";
22756         captured_varyings[1] = "gohan";
22757 }
22758
22759 /** Get body of main function for given shader stage
22760  *
22761  * @param test_case_index  Index of test case
22762  * @param stage            Shader stage
22763  * @param out_assignments  Set to empty
22764  * @param out_calculations Set to empty
22765  **/
22766 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22767                                                                                                          std::string& out_assignments, std::string& out_calculations)
22768 {
22769         out_calculations = "";
22770
22771         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22772                                                           "    trunks = uni_trunks;\n"
22773                                                           "    goku   = uni_goku;\n"
22774                                                           "    gohan  = uni_gohan;\n";
22775         static const GLchar* fs = "    fs_out = vec4(0);\n"
22776                                                           "    if (TYPE(1) == gohan + goku + trunks + vegeta)\n"
22777                                                           "    {\n"
22778                                                           "        fs_out = vec4(1);\n"
22779                                                           "    }\n";
22780
22781         const GLchar* assignments = "";
22782         switch (stage)
22783         {
22784         case Utils::Shader::FRAGMENT:
22785                 assignments = fs;
22786                 break;
22787         case Utils::Shader::GEOMETRY:
22788                 assignments = gs;
22789                 break;
22790         default:
22791                 break;
22792         }
22793
22794         out_assignments = assignments;
22795
22796         if (Utils::Shader::FRAGMENT == stage)
22797         {
22798                 const Utils::Type& type = getType(test_case_index);
22799
22800                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22801         }
22802 }
22803
22804 /** Get interface of shader
22805  *
22806  * @param test_case_index  Index of test case
22807  * @param stage            Shader stage
22808  * @param out_interface    Set to ""
22809  **/
22810 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22811                                                                                                                   std::string& out_interface)
22812 {
22813         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22814                                                           "\n"
22815                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22816                                                           "                                      flat out TYPE trunks;\n"
22817                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22818                                                           "                                      flat out TYPE gohan;\n"
22819                                                           "\n"
22820                                                           /*
22821                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22822                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22823                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22824                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22825                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22826                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22827                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22828                  */
22829                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22830                                                           "    TYPE uni_vegeta;\n"
22831                                                           "    TYPE uni_trunks;\n"
22832                                                           "    TYPE uni_goku;\n"
22833                                                           "    TYPE uni_gohan;\n"
22834                                                           "};\n";
22835         static const GLchar* fs = "flat in TYPE vegeta;\n"
22836                                                           "flat in TYPE trunks;\n"
22837                                                           "flat in TYPE goku;\n"
22838                                                           "flat in TYPE gohan;\n"
22839                                                           "\n"
22840                                                           "out vec4 fs_out;\n";
22841
22842         const Utils::Type& type = getType(test_case_index);
22843
22844         switch (stage)
22845         {
22846         case Utils::Shader::FRAGMENT:
22847                 out_interface = fs;
22848                 break;
22849         case Utils::Shader::GEOMETRY:
22850                 out_interface = gs;
22851                 break;
22852         default:
22853                 out_interface = "";
22854                 return;
22855         }
22856
22857         if (Utils::Shader::GEOMETRY == stage)
22858         {
22859                 GLchar           buffer[16];
22860                 size_t           position  = 0;
22861                 const GLuint type_size = type.GetSize();
22862
22863                 sprintf(buffer, "%d", type_size);
22864
22865                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22866         }
22867
22868         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22869 }
22870
22871 /** Get type name
22872  *
22873  * @param test_case_index Index of test case
22874  *
22875  * @return Name of type test in test_case_index
22876  **/
22877 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22878 {
22879         return getTypeName(test_case_index);
22880 }
22881
22882 /** Returns number of types to test
22883  *
22884  * @return Number of types, 34
22885  **/
22886 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22887 {
22888         return getTypesNumber();
22889 }
22890
22891 /** Inspects program to check if all resources are as expected
22892  *
22893  * @param test_case_index Index of test case
22894  * @param program         Program instance
22895  * @param out_stream      Error message
22896  *
22897  * @return true if everything is ok, false otherwise
22898  **/
22899 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22900                                                                                                           std::stringstream& out_stream)
22901 {
22902         GLint                      stride       = 0;
22903         const Utils::Type& type          = getType(test_case_index);
22904         const GLuint       type_size = type.GetSize();
22905
22906         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22907                                                 1 /* buf_size */, &stride);
22908
22909         if ((GLint)(3 * type_size) != stride)
22910         {
22911                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22912
22913                 return false;
22914         }
22915
22916         return true;
22917 }
22918
22919 /** Constructor
22920  *
22921  * @param context Test context
22922  **/
22923 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22924         : BufferTestBase(context, "xfb_vertex_streams",
22925                                          "Test verifies that xfb qualifier works with multiple output streams")
22926 {
22927         /* Nothing to be done here */
22928 }
22929
22930 /** Get descriptors of buffers necessary for test
22931  *
22932  * @param ignored
22933  * @param out_descriptors Descriptors of buffers used by test
22934  **/
22935 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22936                                                                                                 bufferDescriptor::Vector& out_descriptors)
22937 {
22938         const Utils::Type& type = Utils::Type::vec4;
22939
22940         /* Test needs single uniform and three xfbs */
22941         out_descriptors.resize(4);
22942
22943         /* Get references */
22944         bufferDescriptor& uniform = out_descriptors[0];
22945         bufferDescriptor& xfb_1   = out_descriptors[1];
22946         bufferDescriptor& xfb_2   = out_descriptors[2];
22947         bufferDescriptor& xfb_3   = out_descriptors[3];
22948
22949         /* Index */
22950         uniform.m_index = 0;
22951         xfb_1.m_index   = 1;
22952         xfb_2.m_index   = 2;
22953         xfb_3.m_index   = 3;
22954
22955         /* Target */
22956         uniform.m_target = Utils::Buffer::Uniform;
22957         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
22958         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
22959         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
22960
22961         /* Data */
22962         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22963         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22964         const std::vector<GLubyte>& goten_data  = type.GenerateData();
22965         const std::vector<GLubyte>& picolo_data = type.GenerateData();
22966         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22967         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
22968
22969         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
22970
22971         /* Uniform data */
22972         uniform.m_initial_data.resize(6 * type_size);
22973         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
22974         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
22975         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
22976         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
22977         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
22978         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
22979
22980         /* XFB data */
22981         static const GLuint xfb_stride = 64;
22982         xfb_1.m_initial_data.resize(xfb_stride);
22983         xfb_1.m_expected_data.resize(xfb_stride);
22984         xfb_2.m_initial_data.resize(xfb_stride);
22985         xfb_2.m_expected_data.resize(xfb_stride);
22986         xfb_3.m_initial_data.resize(xfb_stride);
22987         xfb_3.m_expected_data.resize(xfb_stride);
22988
22989         for (GLuint i = 0; i < xfb_stride; ++i)
22990         {
22991                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
22992                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
22993                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
22994                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
22995                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
22996                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
22997         }
22998
22999         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23000         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23001         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23002         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23003         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23004         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23005 }
23006
23007 /** Get body of main function for given shader stage
23008  *
23009  * @param ignored
23010  * @param stage            Shader stage
23011  * @param out_assignments  Set to empty
23012  * @param out_calculations Set to empty
23013  **/
23014 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23015                                                                                  std::string& out_assignments, std::string& out_calculations)
23016 {
23017         out_calculations = "";
23018
23019         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23020         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23021         // by the GS is assigned to specific stream.
23022         static const GLchar* gs = "    goku   = uni_goku;\n"
23023                                                           "    gohan  = uni_gohan;\n"
23024                                                           "    goten  = uni_goten;\n"
23025                                                           "    EmitStreamVertex(0);\n"
23026                                                           "    EndStreamPrimitive(0);\n"
23027                                                           "    picolo = uni_picolo;\n"
23028                                                           "    vegeta = uni_vegeta;\n"
23029                                                           "    EmitStreamVertex(1);\n"
23030                                                           "    EndStreamPrimitive(1);\n"
23031                                                           "    bulma  = uni_bulma;\n"
23032                                                           "    EmitStreamVertex(2);\n"
23033                                                           "    EndStreamPrimitive(2);\n";
23034
23035         static const GLchar* fs = "    fs_out = gohan + goku + goten + picolo + vegeta + bulma;\n";
23036
23037         const GLchar* assignments = "";
23038         switch (stage)
23039         {
23040         case Utils::Shader::FRAGMENT:
23041                 assignments = fs;
23042                 break;
23043         case Utils::Shader::GEOMETRY:
23044                 assignments = gs;
23045                 break;
23046         default:
23047                 break;
23048         }
23049
23050         out_assignments = assignments;
23051 }
23052
23053 /** Get interface of shader
23054  *
23055  * @param ignored
23056  * @param stage            Shader stage
23057  * @param out_interface    Set to ""
23058  **/
23059 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23060                                                                                           std::string& out_interface)
23061 {
23062         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23063                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23064                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23065                                                           "\n"
23066                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23067                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23068                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23069                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23070                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23071                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23072                                                           "\n"
23073                                                           "layout(binding = 0) uniform gs_block {\n"
23074                                                           "    vec4 uni_goku;\n"
23075                                                           "    vec4 uni_gohan;\n"
23076                                                           "    vec4 uni_goten;\n"
23077                                                           "    vec4 uni_picolo;\n"
23078                                                           "    vec4 uni_vegeta;\n"
23079                                                           "    vec4 uni_bulma;\n"
23080                                                           "};\n";
23081         /*
23082          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23083          */
23084         static const GLchar* fs = "in vec4 goku;\n"
23085                                                           "in vec4 gohan;\n"
23086                                                           "in vec4 goten;\n"
23087                                                           "in vec4 picolo;\n"
23088                                                           "in vec4 vegeta;\n"
23089                                                           "in vec4 bulma;\n"
23090                                                           "\n"
23091                                                           "out vec4 fs_out;\n";
23092
23093         switch (stage)
23094         {
23095         case Utils::Shader::FRAGMENT:
23096                 out_interface = fs;
23097                 break;
23098         case Utils::Shader::GEOMETRY:
23099                 out_interface = gs;
23100                 break;
23101         default:
23102                 out_interface = "";
23103                 return;
23104         }
23105 }
23106
23107 /** Constructor
23108  *
23109  * @param context Test framework context
23110  **/
23111 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23112         : NegativeTestBase(
23113                   context, "xfb_multiple_vertex_streams",
23114                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23115 {
23116 }
23117
23118 /** Source for given test case and stage
23119  *
23120  * @param ignored
23121  * @param stage           Shader stage
23122  *
23123  * @return Shader source
23124  **/
23125 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23126 {
23127         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23128                                                                                   "\n"
23129                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23130                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23131                                                                                   "\n"
23132                                                                                   "\n"
23133                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23134                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23135                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23136         static const GLchar* var_use = "    goku  = result / 2;\n"
23137                                                                    "    gohan = result / 4;\n"
23138                                                                    "    goten = result / 6;\n";
23139         static const GLchar* fs = "#version 430 core\n"
23140                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23141                                                           "\n"
23142                                                           "in  vec4 gs_fs;\n"
23143                                                           "in  vec4 goku;\n"
23144                                                           "out vec4 fs_out;\n"
23145                                                           "\n"
23146                                                           "void main()\n"
23147                                                           "{\n"
23148                                                           "    fs_out = gs_fs + goku;\n"
23149                                                           "}\n"
23150                                                           "\n";
23151         static const GLchar* gs = "#version 430 core\n"
23152                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23153                                                           "\n"
23154                                                           "layout(points)                           in;\n"
23155                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23156                                                           "\n"
23157                                                           "VAR_DEFINITION"
23158                                                           "\n"
23159                                                           "in  vec4 tes_gs[];\n"
23160                                                           "out vec4 gs_fs;\n"
23161                                                           "\n"
23162                                                           "void main()\n"
23163                                                           "{\n"
23164                                                           "    vec4 result = tes_gs[0];\n"
23165                                                           "\n"
23166                                                           "VARIABLE_USE"
23167                                                           "\n"
23168                                                           "    gs_fs = result;\n"
23169                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23170                                                           "    EmitVertex();\n"
23171                                                           "    gs_fs = result;\n"
23172                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23173                                                           "    EmitVertex();\n"
23174                                                           "    gs_fs = result;\n"
23175                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23176                                                           "    EmitVertex();\n"
23177                                                           "    gs_fs = result;\n"
23178                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23179                                                           "    EmitVertex();\n"
23180                                                           "}\n"
23181                                                           "\n";
23182         static const GLchar* vs = "#version 430 core\n"
23183                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23184                                                           "\n"
23185                                                           "in  vec4 in_vs;\n"
23186                                                           "out vec4 vs_tcs;\n"
23187                                                           "\n"
23188                                                           "void main()\n"
23189                                                           "{\n"
23190                                                           "    vs_tcs = in_vs;\n"
23191                                                           "}\n"
23192                                                           "\n";
23193
23194         std::string source;
23195
23196         if (Utils::Shader::GEOMETRY == stage)
23197         {
23198                 size_t position = 0;
23199
23200                 source = gs;
23201
23202                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23203                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23204         }
23205         else
23206         {
23207                 switch (stage)
23208                 {
23209                 case Utils::Shader::FRAGMENT:
23210                         source = fs;
23211                         break;
23212                 case Utils::Shader::VERTEX:
23213                         source = vs;
23214                         break;
23215                 default:
23216                         source = "";
23217                 }
23218         }
23219
23220         return source;
23221 }
23222
23223 /** Selects if "compute" stage is relevant for test
23224  *
23225  * @param ignored
23226  *
23227  * @return false
23228  **/
23229 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23230 {
23231         return false;
23232 }
23233
23234 /** Constructor
23235  *
23236  * @param context Test framework context
23237  **/
23238 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23239         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23240                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23241 {
23242 }
23243
23244 /** Source for given test case and stage
23245  *
23246  * @param test_case_index Index of test case
23247  * @param stage           Shader stage
23248  *
23249  * @return Shader source
23250  **/
23251 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23252 {
23253         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23254                                                                                                 "\n"
23255                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23256                                                                                                 "    vec4 member;\n"
23257                                                                                                 "} gokuARRAY;\n";
23258         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23259                                                                                                  "\n"
23260                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23261         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23262                                                                                                  "\n"
23263                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23264         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23265         static const GLchar* global_use = "";
23266         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23267         static const GLchar* fs                 = "#version 430 core\n"
23268                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23269                                                           "\n"
23270                                                           "in  vec4 gs_fs;\n"
23271                                                           "out vec4 fs_out;\n"
23272                                                           "\n"
23273                                                           "void main()\n"
23274                                                           "{\n"
23275                                                           "    fs_out = gs_fs;\n"
23276                                                           "}\n"
23277                                                           "\n";
23278         static const GLchar* gs_tested = "#version 430 core\n"
23279                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23280                                                                          "\n"
23281                                                                          "layout(points)                           in;\n"
23282                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23283                                                                          "\n"
23284                                                                          "VAR_DEFINITION"
23285                                                                          "\n"
23286                                                                          "in  vec4 tes_gs[];\n"
23287                                                                          "out vec4 gs_fs;\n"
23288                                                                          "\n"
23289                                                                          "void main()\n"
23290                                                                          "{\n"
23291                                                                          "    vec4 result = tes_gs[0];\n"
23292                                                                          "\n"
23293                                                                          "VARIABLE_USE"
23294                                                                          "\n"
23295                                                                          "    gs_fs = result;\n"
23296                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23297                                                                          "    EmitVertex();\n"
23298                                                                          "    gs_fs = result;\n"
23299                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23300                                                                          "    EmitVertex();\n"
23301                                                                          "    gs_fs = result;\n"
23302                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23303                                                                          "    EmitVertex();\n"
23304                                                                          "    gs_fs = result;\n"
23305                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23306                                                                          "    EmitVertex();\n"
23307                                                                          "}\n"
23308                                                                          "\n";
23309         static const GLchar* tcs = "#version 430 core\n"
23310                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23311                                                            "\n"
23312                                                            "layout(vertices = 1) out;\n"
23313                                                            "\n"
23314                                                            "in  vec4 vs_tcs[];\n"
23315                                                            "out vec4 tcs_tes[];\n"
23316                                                            "\n"
23317                                                            "void main()\n"
23318                                                            "{\n"
23319                                                            "\n"
23320                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23321                                                            "\n"
23322                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23323                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23324                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23325                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23326                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23327                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23328                                                            "}\n"
23329                                                            "\n";
23330         static const GLchar* tcs_tested = "#version 430 core\n"
23331                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23332                                                                           "\n"
23333                                                                           "layout(vertices = 1) out;\n"
23334                                                                           "\n"
23335                                                                           "VAR_DEFINITION"
23336                                                                           "\n"
23337                                                                           "in  vec4 vs_tcs[];\n"
23338                                                                           "out vec4 tcs_tes[];\n"
23339                                                                           "\n"
23340                                                                           "void main()\n"
23341                                                                           "{\n"
23342                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23343                                                                           "\n"
23344                                                                           "VARIABLE_USE"
23345                                                                           "\n"
23346                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23347                                                                           "\n"
23348                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23349                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23350                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23351                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23352                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23353                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23354                                                                           "}\n"
23355                                                                           "\n";
23356         static const GLchar* tes_tested = "#version 430 core\n"
23357                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23358                                                                           "\n"
23359                                                                           "layout(isolines, point_mode) in;\n"
23360                                                                           "\n"
23361                                                                           "VAR_DEFINITION"
23362                                                                           "\n"
23363                                                                           "in  vec4 tcs_tes[];\n"
23364                                                                           "out vec4 tes_gs;\n"
23365                                                                           "\n"
23366                                                                           "void main()\n"
23367                                                                           "{\n"
23368                                                                           "    vec4 result = tcs_tes[0];\n"
23369                                                                           "\n"
23370                                                                           "VARIABLE_USE"
23371                                                                           "\n"
23372                                                                           "    tes_gs += result;\n"
23373                                                                           "}\n"
23374                                                                           "\n";
23375         static const GLchar* vs = "#version 430 core\n"
23376                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23377                                                           "\n"
23378                                                           "in  vec4 in_vs;\n"
23379                                                           "out vec4 vs_tcs;\n"
23380                                                           "\n"
23381                                                           "void main()\n"
23382                                                           "{\n"
23383                                                           "    vs_tcs = in_vs;\n"
23384                                                           "}\n"
23385                                                           "\n";
23386         static const GLchar* vs_tested = "#version 430 core\n"
23387                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23388                                                                          "\n"
23389                                                                          "VAR_DEFINITION"
23390                                                                          "\n"
23391                                                                          "in  vec4 in_vs;\n"
23392                                                                          "out vec4 vs_tcs;\n"
23393                                                                          "\n"
23394                                                                          "void main()\n"
23395                                                                          "{\n"
23396                                                                          "    vec4 result = in_vs;\n"
23397                                                                          "\n"
23398                                                                          "VARIABLE_USE"
23399                                                                          "\n"
23400                                                                          "    vs_tcs = result;\n"
23401                                                                          "}\n"
23402                                                                          "\n";
23403
23404         std::string source;
23405         testCase&   test_case = m_test_cases[test_case_index];
23406
23407         if (test_case.m_stage == stage)
23408         {
23409                 const GLchar*   array = "";
23410                 GLchar                   buffer[16];
23411                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23412                 const GLchar*   index    = "";
23413                 GLint                    max_n_xfb = 0;
23414                 size_t                   position  = 0;
23415                 size_t                   temp;
23416                 const GLchar*   var_definition = 0;
23417                 const GLchar*   var_use         = 0;
23418
23419                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23420                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23421
23422                 sprintf(buffer, "%d", max_n_xfb);
23423
23424                 switch (test_case.m_case)
23425                 {
23426                 case BLOCK:
23427                         var_definition = block_var_definition;
23428                         var_use            = block_use;
23429                         break;
23430                 case GLOBAL:
23431                         var_definition = global_var_definition;
23432                         var_use            = global_use;
23433                         break;
23434                 case VECTOR:
23435                         var_definition = vector_var_definition;
23436                         var_use            = vector_use;
23437                         break;
23438                 default:
23439                         TCU_FAIL("Invalid enum");
23440                 }
23441
23442                 switch (stage)
23443                 {
23444                 case Utils::Shader::GEOMETRY:
23445                         source = gs_tested;
23446                         array  = "[]";
23447                         index  = "[0]";
23448                         break;
23449                 case Utils::Shader::TESS_CTRL:
23450                         source = tcs_tested;
23451                         array  = "[]";
23452                         index  = "[gl_InvocationID]";
23453                         break;
23454                 case Utils::Shader::TESS_EVAL:
23455                         source = tes_tested;
23456                         array  = "[]";
23457                         index  = "[0]";
23458                         break;
23459                 case Utils::Shader::VERTEX:
23460                         source = vs_tested;
23461                         break;
23462                 default:
23463                         TCU_FAIL("Invalid enum");
23464                 }
23465
23466                 temp = position;
23467                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23468                 position = temp;
23469                 Utils::replaceToken("BUFFER", position, buffer, source);
23470                 if (GLOBAL != test_case.m_case)
23471                 {
23472                         Utils::replaceToken("ARRAY", position, array, source);
23473                 }
23474                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23475
23476                 Utils::replaceAllTokens("INDEX", index, source);
23477         }
23478         else
23479         {
23480                 switch (test_case.m_stage)
23481                 {
23482                 case Utils::Shader::GEOMETRY:
23483                         switch (stage)
23484                         {
23485                         case Utils::Shader::FRAGMENT:
23486                                 source = fs;
23487                                 break;
23488                         case Utils::Shader::VERTEX:
23489                                 source = vs;
23490                                 break;
23491                         default:
23492                                 source = "";
23493                         }
23494                         break;
23495                 case Utils::Shader::TESS_CTRL:
23496                         switch (stage)
23497                         {
23498                         case Utils::Shader::FRAGMENT:
23499                                 source = fs;
23500                                 break;
23501                         case Utils::Shader::VERTEX:
23502                                 source = vs;
23503                                 break;
23504                         default:
23505                                 source = "";
23506                         }
23507                         break;
23508                 case Utils::Shader::TESS_EVAL:
23509                         switch (stage)
23510                         {
23511                         case Utils::Shader::FRAGMENT:
23512                                 source = fs;
23513                                 break;
23514                         case Utils::Shader::TESS_CTRL:
23515                                 source = tcs;
23516                                 break;
23517                         case Utils::Shader::VERTEX:
23518                                 source = vs;
23519                                 break;
23520                         default:
23521                                 source = "";
23522                         }
23523                         break;
23524                 case Utils::Shader::VERTEX:
23525                         switch (stage)
23526                         {
23527                         case Utils::Shader::FRAGMENT:
23528                                 source = fs;
23529                                 break;
23530                         default:
23531                                 source = "";
23532                         }
23533                         break;
23534                 default:
23535                         TCU_FAIL("Invalid enum");
23536                         break;
23537                 }
23538         }
23539
23540         return source;
23541 }
23542
23543 /** Get description of test case
23544  *
23545  * @param test_case_index Index of test case
23546  *
23547  * @return Test case description
23548  **/
23549 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23550 {
23551         std::stringstream stream;
23552         testCase&                 test_case = m_test_cases[test_case_index];
23553
23554         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23555
23556         switch (test_case.m_case)
23557         {
23558         case BLOCK:
23559                 stream << "BLOCK";
23560                 break;
23561         case GLOBAL:
23562                 stream << "GLOBAL";
23563                 break;
23564         case VECTOR:
23565                 stream << "VECTOR";
23566                 break;
23567         default:
23568                 TCU_FAIL("Invalid enum");
23569         }
23570
23571         return stream.str();
23572 }
23573
23574 /** Get number of test cases
23575  *
23576  * @return Number of test cases
23577  **/
23578 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23579 {
23580         return static_cast<GLuint>(m_test_cases.size());
23581 }
23582
23583 /** Selects if "compute" stage is relevant for test
23584  *
23585  * @param ignored
23586  *
23587  * @return false
23588  **/
23589 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23590 {
23591         return false;
23592 }
23593
23594 /** Prepare all test cases
23595  *
23596  **/
23597 void XFBExceedBufferLimitTest::testInit()
23598 {
23599         for (GLuint c = 0; c < CASE_MAX; ++c)
23600         {
23601                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23602                 {
23603                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23604                                 (Utils::Shader::FRAGMENT == stage))
23605                         {
23606                                 continue;
23607                         }
23608
23609                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23610
23611                         m_test_cases.push_back(test_case);
23612                 }
23613         }
23614 }
23615
23616 /** Constructor
23617  *
23618  * @param context Test framework context
23619  **/
23620 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23621         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23622                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23623 {
23624 }
23625
23626 /** Source for given test case and stage
23627  *
23628  * @param test_case_index Index of test case
23629  * @param stage           Shader stage
23630  *
23631  * @return Shader source
23632  **/
23633 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23634 {
23635         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23636                                                                                                 "\n"
23637                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23638                                                                                                 "    vec4 member;\n"
23639                                                                                                 "} gokuARRAY;\n";
23640         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23641                                                                                                  "\n"
23642                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23643         static const GLchar* vector_var_definition =
23644                 "const uint max_size = SIZE;\n"
23645                 "\n"
23646                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23647         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23648         static const GLchar* global_use = "";
23649         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23650         static const GLchar* fs                 = "#version 430 core\n"
23651                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23652                                                           "\n"
23653                                                           "in  vec4 gs_fs;\n"
23654                                                           "out vec4 fs_out;\n"
23655                                                           "\n"
23656                                                           "void main()\n"
23657                                                           "{\n"
23658                                                           "    fs_out = gs_fs;\n"
23659                                                           "}\n"
23660                                                           "\n";
23661         static const GLchar* gs_tested = "#version 430 core\n"
23662                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23663                                                                          "\n"
23664                                                                          "layout(points)                           in;\n"
23665                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23666                                                                          "\n"
23667                                                                          "VAR_DEFINITION"
23668                                                                          "\n"
23669                                                                          "in  vec4 tes_gs[];\n"
23670                                                                          "out vec4 gs_fs;\n"
23671                                                                          "\n"
23672                                                                          "void main()\n"
23673                                                                          "{\n"
23674                                                                          "    vec4 result = tes_gs[0];\n"
23675                                                                          "\n"
23676                                                                          "VARIABLE_USE"
23677                                                                          "\n"
23678                                                                          "    gs_fs = result;\n"
23679                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23680                                                                          "    EmitVertex();\n"
23681                                                                          "    gs_fs = result;\n"
23682                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23683                                                                          "    EmitVertex();\n"
23684                                                                          "    gs_fs = result;\n"
23685                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23686                                                                          "    EmitVertex();\n"
23687                                                                          "    gs_fs = result;\n"
23688                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23689                                                                          "    EmitVertex();\n"
23690                                                                          "}\n"
23691                                                                          "\n";
23692         static const GLchar* tcs = "#version 430 core\n"
23693                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23694                                                            "\n"
23695                                                            "layout(vertices = 1) out;\n"
23696                                                            "\n"
23697                                                            "in  vec4 vs_tcs[];\n"
23698                                                            "out vec4 tcs_tes[];\n"
23699                                                            "\n"
23700                                                            "void main()\n"
23701                                                            "{\n"
23702                                                            "\n"
23703                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23704                                                            "\n"
23705                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23706                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23707                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23708                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23709                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23710                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23711                                                            "}\n"
23712                                                            "\n";
23713         static const GLchar* tcs_tested = "#version 430 core\n"
23714                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23715                                                                           "\n"
23716                                                                           "layout(vertices = 1) out;\n"
23717                                                                           "\n"
23718                                                                           "VAR_DEFINITION"
23719                                                                           "\n"
23720                                                                           "in  vec4 vs_tcs[];\n"
23721                                                                           "out vec4 tcs_tes[];\n"
23722                                                                           "\n"
23723                                                                           "void main()\n"
23724                                                                           "{\n"
23725                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23726                                                                           "\n"
23727                                                                           "VARIABLE_USE"
23728                                                                           "\n"
23729                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23730                                                                           "\n"
23731                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23732                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23733                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23734                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23735                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23736                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23737                                                                           "}\n"
23738                                                                           "\n";
23739         static const GLchar* tes_tested = "#version 430 core\n"
23740                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23741                                                                           "\n"
23742                                                                           "layout(isolines, point_mode) in;\n"
23743                                                                           "\n"
23744                                                                           "VAR_DEFINITION"
23745                                                                           "\n"
23746                                                                           "in  vec4 tcs_tes[];\n"
23747                                                                           "out vec4 tes_gs;\n"
23748                                                                           "\n"
23749                                                                           "void main()\n"
23750                                                                           "{\n"
23751                                                                           "    vec4 result = tcs_tes[0];\n"
23752                                                                           "\n"
23753                                                                           "VARIABLE_USE"
23754                                                                           "\n"
23755                                                                           "    tes_gs += result;\n"
23756                                                                           "}\n"
23757                                                                           "\n";
23758         static const GLchar* vs = "#version 430 core\n"
23759                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23760                                                           "\n"
23761                                                           "in  vec4 in_vs;\n"
23762                                                           "out vec4 vs_tcs;\n"
23763                                                           "\n"
23764                                                           "void main()\n"
23765                                                           "{\n"
23766                                                           "    vs_tcs = in_vs;\n"
23767                                                           "}\n"
23768                                                           "\n";
23769         static const GLchar* vs_tested = "#version 430 core\n"
23770                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23771                                                                          "\n"
23772                                                                          "VAR_DEFINITION"
23773                                                                          "\n"
23774                                                                          "in  vec4 in_vs;\n"
23775                                                                          "out vec4 vs_tcs;\n"
23776                                                                          "\n"
23777                                                                          "void main()\n"
23778                                                                          "{\n"
23779                                                                          "    vec4 result = in_vs;\n"
23780                                                                          "\n"
23781                                                                          "VARIABLE_USE"
23782                                                                          "\n"
23783                                                                          "    vs_tcs = result;\n"
23784                                                                          "}\n"
23785                                                                          "\n";
23786
23787         std::string source;
23788         testCase&   test_case = m_test_cases[test_case_index];
23789
23790         if (test_case.m_stage == stage)
23791         {
23792                 const GLchar*   array = "";
23793                 GLchar                   buffer[16];
23794                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23795                 const GLchar*   index                    = "";
23796                 GLint                    max_n_xfb_comp  = 0;
23797                 GLint                    max_n_xfb_bytes = 0;
23798                 size_t                   position                = 0;
23799                 size_t                   temp;
23800                 const GLchar*   var_definition = 0;
23801                 const GLchar*   var_use         = 0;
23802
23803                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23804                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23805
23806                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23807
23808                 sprintf(buffer, "%d", max_n_xfb_bytes);
23809
23810                 switch (test_case.m_case)
23811                 {
23812                 case BLOCK:
23813                         var_definition = block_var_definition;
23814                         var_use            = block_use;
23815                         break;
23816                 case GLOBAL:
23817                         var_definition = global_var_definition;
23818                         var_use            = global_use;
23819                         break;
23820                 case VECTOR:
23821                         var_definition = vector_var_definition;
23822                         var_use            = vector_use;
23823                         break;
23824                 default:
23825                         TCU_FAIL("Invalid enum");
23826                 }
23827                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23828                 // change array = "[]" to "[1]"
23829                 switch (stage)
23830                 {
23831                 case Utils::Shader::GEOMETRY:
23832                         source = gs_tested;
23833                         array  = "[1]";
23834                         index  = "[0]";
23835                         break;
23836                 case Utils::Shader::TESS_CTRL:
23837                         source = tcs_tested;
23838                         array  = "[1]";
23839                         index  = "[gl_InvocationID]";
23840                         break;
23841                 case Utils::Shader::TESS_EVAL:
23842                         source = tes_tested;
23843                         array  = "[1]";
23844                         index  = "[0]";
23845                         break;
23846                 case Utils::Shader::VERTEX:
23847                         source = vs_tested;
23848                         break;
23849                 default:
23850                         TCU_FAIL("Invalid enum");
23851                 }
23852
23853                 temp = position;
23854                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23855                 position = temp;
23856                 Utils::replaceToken("SIZE", position, buffer, source);
23857                 if (GLOBAL != test_case.m_case)
23858                 {
23859                         Utils::replaceToken("ARRAY", position, array, source);
23860                 }
23861                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23862
23863                 Utils::replaceAllTokens("INDEX", index, source);
23864         }
23865         else
23866         {
23867                 switch (test_case.m_stage)
23868                 {
23869                 case Utils::Shader::GEOMETRY:
23870                         switch (stage)
23871                         {
23872                         case Utils::Shader::FRAGMENT:
23873                                 source = fs;
23874                                 break;
23875                         case Utils::Shader::VERTEX:
23876                                 source = vs;
23877                                 break;
23878                         default:
23879                                 source = "";
23880                         }
23881                         break;
23882                 case Utils::Shader::TESS_CTRL:
23883                         switch (stage)
23884                         {
23885                         case Utils::Shader::FRAGMENT:
23886                                 source = fs;
23887                                 break;
23888                         case Utils::Shader::VERTEX:
23889                                 source = vs;
23890                                 break;
23891                         default:
23892                                 source = "";
23893                         }
23894                         break;
23895                 case Utils::Shader::TESS_EVAL:
23896                         switch (stage)
23897                         {
23898                         case Utils::Shader::FRAGMENT:
23899                                 source = fs;
23900                                 break;
23901                         case Utils::Shader::TESS_CTRL:
23902                                 source = tcs;
23903                                 break;
23904                         case Utils::Shader::VERTEX:
23905                                 source = vs;
23906                                 break;
23907                         default:
23908                                 source = "";
23909                         }
23910                         break;
23911                 case Utils::Shader::VERTEX:
23912                         switch (stage)
23913                         {
23914                         case Utils::Shader::FRAGMENT:
23915                                 source = fs;
23916                                 break;
23917                         default:
23918                                 source = "";
23919                         }
23920                         break;
23921                 default:
23922                         TCU_FAIL("Invalid enum");
23923                         break;
23924                 }
23925         }
23926
23927         return source;
23928 }
23929
23930 /** Get description of test case
23931  *
23932  * @param test_case_index Index of test case
23933  *
23934  * @return Test case description
23935  **/
23936 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23937 {
23938         std::stringstream stream;
23939         testCase&                 test_case = m_test_cases[test_case_index];
23940
23941         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23942
23943         switch (test_case.m_case)
23944         {
23945         case BLOCK:
23946                 stream << "BLOCK";
23947                 break;
23948         case GLOBAL:
23949                 stream << "GLOBAL";
23950                 break;
23951         case VECTOR:
23952                 stream << "VECTOR";
23953                 break;
23954         default:
23955                 TCU_FAIL("Invalid enum");
23956         }
23957
23958         return stream.str();
23959 }
23960
23961 /** Get number of test cases
23962  *
23963  * @return Number of test cases
23964  **/
23965 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
23966 {
23967         return static_cast<GLuint>(m_test_cases.size());
23968 }
23969
23970 /** Selects if "compute" stage is relevant for test
23971  *
23972  * @param ignored
23973  *
23974  * @return false
23975  **/
23976 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23977 {
23978         return false;
23979 }
23980
23981 /** Prepare all test cases
23982  *
23983  **/
23984 void XFBExceedOffsetLimitTest::testInit()
23985 {
23986         for (GLuint c = 0; c < CASE_MAX; ++c)
23987         {
23988                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23989                 {
23990                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23991                                 (Utils::Shader::FRAGMENT == stage))
23992                         {
23993                                 continue;
23994                         }
23995
23996                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23997
23998                         m_test_cases.push_back(test_case);
23999                 }
24000         }
24001 }
24002
24003 /** Constructor
24004  *
24005  * @param context Test context
24006  **/
24007 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24008         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24009 {
24010         /* Nothing to be done here */
24011 }
24012
24013 /** Get descriptors of buffers necessary for test
24014  *
24015  * @param test_case_index Index of test case
24016  * @param out_descriptors Descriptors of buffers used by test
24017  **/
24018 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24019 {
24020         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24021         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24022
24023         /* Test needs single uniform and two xfbs */
24024         out_descriptors.resize(3);
24025
24026         /* Get references */
24027         bufferDescriptor& uniform = out_descriptors[0];
24028         bufferDescriptor& xfb_1   = out_descriptors[1];
24029         bufferDescriptor& xfb_3   = out_descriptors[2];
24030
24031         /* Index */
24032         uniform.m_index = 0;
24033         xfb_1.m_index   = 1;
24034         xfb_3.m_index   = 3;
24035
24036         /* Target */
24037         uniform.m_target = Utils::Buffer::Uniform;
24038         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24039         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24040
24041         /* Data */
24042         const GLuint                            gen_start   = Utils::s_rand;
24043         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24044         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24045         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24046         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24047         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24048         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24049
24050         Utils::s_rand                                                           = gen_start;
24051         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24052         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24053         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24054         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24055         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24056         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24057
24058         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24059         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24060
24061         /* Uniform data */
24062         uniform.m_initial_data.resize(6 * type_size);
24063         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24064         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24065         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24066         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24067         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24068         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24069
24070         /* XFB data */
24071         xfb_1.m_initial_data.resize(3 * type_size_pck);
24072         xfb_1.m_expected_data.resize(3 * type_size_pck);
24073         xfb_3.m_initial_data.resize(3 * type_size_pck);
24074         xfb_3.m_expected_data.resize(3 * type_size_pck);
24075
24076         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24077         {
24078                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24079                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24080                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24081                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24082         }
24083
24084         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24085         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24086         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24087         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24088         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24089         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24090 }
24091
24092 /** Source for given test case and stage
24093  *
24094  * @param test_case_index Index of test case
24095  * @param stage           Shader stage
24096  *
24097  * @return Shader source
24098  **/
24099 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24100 {
24101         static const GLchar* fs =
24102                 "#version 430 core\n"
24103                 "#extension GL_ARB_enhanced_layouts : require\n"
24104                 "\n"
24105                 "flat in TYPE chichi;\n"
24106                 "flat in TYPE bulma;\n"
24107                 "in Vegeta {\n"
24108                 "    TYPE trunk;\n"
24109                 "    TYPE bra;\n"
24110                 "} vegeta;\n"
24111                 "in Goku {\n"
24112                 "    TYPE gohan;\n"
24113                 "    TYPE goten;\n"
24114                 "} goku;\n"
24115                 "\n"
24116                 "out vec4 fs_out;\n"
24117                 "\n"
24118                 "void main()\n"
24119                 "{\n"
24120                 "    fs_out = vec4(1);\n"
24121                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24122                 "    {\n"
24123                 "        fs_out = vec4(0);\n"
24124                 "    }\n"
24125                 "}\n"
24126                 "\n";
24127
24128         static const GLchar* gs = "#version 430 core\n"
24129                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24130                                                           "\n"
24131                                                           "layout(points)                   in;\n"
24132                                                           "layout(points, max_vertices = 1) out;\n"
24133                                                           "\n"
24134                                                           "INTERFACE"
24135                                                           "\n"
24136                                                           "void main()\n"
24137                                                           "{\n"
24138                                                           "ASSIGNMENTS"
24139                                                           "    EmitVertex();\n"
24140                                                           "}\n"
24141                                                           "\n";
24142
24143         static const GLchar* tcs = "#version 430 core\n"
24144                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24145                                                            "\n"
24146                                                            "layout(vertices = 1) out;\n"
24147                                                            "\n"
24148                                                            "\n"
24149                                                            "void main()\n"
24150                                                            "{\n"
24151                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24152                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24153                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24154                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24155                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24156                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24157                                                            "}\n"
24158                                                            "\n";
24159
24160         static const GLchar* tes = "#version 430 core\n"
24161                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24162                                                            "\n"
24163                                                            "layout(isolines, point_mode) in;\n"
24164                                                            "\n"
24165                                                            "INTERFACE"
24166                                                            "\n"
24167                                                            "void main()\n"
24168                                                            "{\n"
24169                                                            "ASSIGNMENTS"
24170                                                            "}\n"
24171                                                            "\n";
24172
24173         static const GLchar* vs = "#version 430 core\n"
24174                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24175                                                           "\n"
24176                                                           "void main()\n"
24177                                                           "{\n"
24178                                                           "}\n"
24179                                                           "\n";
24180
24181         static const GLchar* vs_tested = "#version 430 core\n"
24182                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24183                                                                          "\n"
24184                                                                          "INTERFACE"
24185                                                                          "\n"
24186                                                                          "void main()\n"
24187                                                                          "{\n"
24188                                                                          "ASSIGNMENTS"
24189                                                                          "}\n"
24190                                                                          "\n";
24191
24192         std::string              source;
24193         const _testCase& test_case = m_test_cases[test_case_index];
24194         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24195
24196         if (test_case.m_stage == stage)
24197         {
24198                 std::string assignments = "    chichi       = uni_chichi;\n"
24199                                                                   "    bulma        = uni_bulma;\n"
24200                                                                   "    vegeta.trunk = uni_trunk;\n"
24201                                                                   "    vegeta.bra   = uni_bra;\n"
24202                                                                   "    goku.gohan   = uni_gohan;\n"
24203                                                                   "    goku.goten   = uni_goten;\n";
24204
24205                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24206                                                                 "\n"
24207                                                                 "const uint type_size = SIZE;\n"
24208                                                                 "\n"
24209                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24210                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24211                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24212                                                                 "    TYPE trunk;\n"
24213                                                                 "    TYPE bra;\n"
24214                                                                 "} vegeta;\n"
24215                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24216                                                                 "    TYPE gohan;\n"
24217                                                                 "    TYPE goten;\n"
24218                                                                 "} goku;\n"
24219                                                                 "\n"
24220                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24221                                                                 "layout(binding = 0, std140) uniform block {\n"
24222                                                                 "    TYPE uni_chichi;\n"
24223                                                                 "    TYPE uni_bulma;\n"
24224                                                                 "    TYPE uni_trunk;\n"
24225                                                                 "    TYPE uni_bra;\n"
24226                                                                 "    TYPE uni_gohan;\n"
24227                                                                 "    TYPE uni_goten;\n"
24228                                                                 "};\n";
24229
24230                 /* Prepare interface string */
24231                 {
24232                         GLchar           buffer[16];
24233                         size_t           position  = 0;
24234                         const GLuint type_size = test_case.m_type.GetSize();
24235
24236                         sprintf(buffer, "%d", type_size);
24237
24238                         Utils::replaceToken("SIZE", position, buffer, interface);
24239                         Utils::replaceAllTokens("TYPE", type_name, interface);
24240                 }
24241
24242                 switch (stage)
24243                 {
24244                 case Utils::Shader::GEOMETRY:
24245                         source = gs;
24246                         break;
24247                 case Utils::Shader::TESS_EVAL:
24248                         source = tes;
24249                         break;
24250                 case Utils::Shader::VERTEX:
24251                         source = vs_tested;
24252                         break;
24253                 default:
24254                         TCU_FAIL("Invalid enum");
24255                 }
24256
24257                 /* Replace tokens */
24258                 {
24259                         size_t position = 0;
24260
24261                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24262                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24263                 }
24264         }
24265         else
24266         {
24267                 switch (test_case.m_stage)
24268                 {
24269                 case Utils::Shader::GEOMETRY:
24270                         switch (stage)
24271                         {
24272                         case Utils::Shader::FRAGMENT:
24273                                 source = fs;
24274                                 Utils::replaceAllTokens("TYPE", type_name, source);
24275                                 break;
24276                         case Utils::Shader::VERTEX:
24277                                 source = vs;
24278                                 break;
24279                         default:
24280                                 source = "";
24281                         }
24282                         break;
24283                 case Utils::Shader::TESS_EVAL:
24284                         switch (stage)
24285                         {
24286                         case Utils::Shader::FRAGMENT:
24287                                 source = fs;
24288                                 Utils::replaceAllTokens("TYPE", type_name, source);
24289                                 break;
24290                         case Utils::Shader::TESS_CTRL:
24291                                 source = tcs;
24292                                 break;
24293                         case Utils::Shader::VERTEX:
24294                                 source = vs;
24295                                 break;
24296                         default:
24297                                 source = "";
24298                         }
24299                         break;
24300                 case Utils::Shader::VERTEX:
24301                         switch (stage)
24302                         {
24303                         case Utils::Shader::FRAGMENT:
24304                                 source = fs;
24305                                 Utils::replaceAllTokens("TYPE", type_name, source);
24306                                 break;
24307                         default:
24308                                 source = "";
24309                         }
24310                         break;
24311                 default:
24312                         TCU_FAIL("Invalid enum");
24313                         break;
24314                 }
24315         }
24316
24317         return source;
24318 }
24319
24320 /** Get name of test case
24321  *
24322  * @param test_case_index Index of test case
24323  *
24324  * @return Name of case
24325  **/
24326 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24327 {
24328         std::string              name;
24329         const _testCase& test_case = m_test_cases[test_case_index];
24330
24331         name = "Tested stage: ";
24332         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24333         name.append(". Tested type: ");
24334         name.append(test_case.m_type.GetGLSLTypeName());
24335
24336         return name;
24337 }
24338
24339 /** Get number of cases
24340  *
24341  * @return Number of test cases
24342  **/
24343 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24344 {
24345         return static_cast<GLuint>(m_test_cases.size());
24346 }
24347
24348 /** Prepare set of test cases
24349  *
24350  **/
24351 void XFBGlobalBufferTest::testInit()
24352 {
24353         GLuint n_types = getTypesNumber();
24354
24355         for (GLuint i = 0; i < n_types; ++i)
24356         {
24357                 const Utils::Type& type = getType(i);
24358                 /*
24359                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24360                  cause a link time error.
24361                  */
24362                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24363                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24364                 {
24365                         continue;
24366                 }
24367                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24368                                                                                  { Utils::Shader::GEOMETRY, type },
24369                                                                                  { Utils::Shader::TESS_EVAL, type } };
24370
24371                 m_test_cases.push_back(test_cases[0]);
24372                 m_test_cases.push_back(test_cases[1]);
24373                 m_test_cases.push_back(test_cases[2]);
24374         }
24375 }
24376
24377 /** Constructor
24378  *
24379  * @param context Test context
24380  **/
24381 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24382         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24383 {
24384         /* Nothing to be done here */
24385 }
24386
24387 /** Execute drawArrays for single vertex
24388  *
24389  * @param test_case_index
24390  *
24391  * @return true
24392  **/
24393 bool XFBStrideTest::executeDrawCall(GLuint test_case_index)
24394 {
24395         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24396         GLenum                   primitive_type = GL_PATCHES;
24397         const testCase&  test_case              = m_test_cases[test_case_index];
24398
24399         if (Utils::Shader::VERTEX == test_case.m_stage)
24400         {
24401                 primitive_type = GL_POINTS;
24402         }
24403
24404         gl.disable(GL_RASTERIZER_DISCARD);
24405         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24406
24407         gl.beginTransformFeedback(GL_POINTS);
24408         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24409
24410         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24411         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24412
24413         gl.endTransformFeedback();
24414         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24415
24416         return true;
24417 }
24418
24419 /** Get descriptors of buffers necessary for test
24420  *
24421  * @param test_case_index Index of test case
24422  * @param out_descriptors Descriptors of buffers used by test
24423  **/
24424 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24425 {
24426         const testCase& test_case = m_test_cases[test_case_index];
24427         const Utils::Type& type          = test_case.m_type;
24428
24429         /* Test needs single uniform and xfb */
24430         out_descriptors.resize(2);
24431
24432         /* Get references */
24433         bufferDescriptor& uniform = out_descriptors[0];
24434         bufferDescriptor& xfb    = out_descriptors[1];
24435
24436         /* Index */
24437         uniform.m_index = 0;
24438         xfb.m_index             = 0;
24439
24440         /* Target */
24441         uniform.m_target = Utils::Buffer::Uniform;
24442         xfb.m_target     = Utils::Buffer::Transform_feedback;
24443
24444         /* Data */
24445         const GLuint                            rand_start   = Utils::s_rand;
24446         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24447
24448         Utils::s_rand                                            = rand_start;
24449         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24450
24451         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24452         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24453         /*
24454          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24455          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24456          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24457          only one valid data should be initialized in xfb.m_expected_data
24458          */
24459         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24460         /* Uniform data */
24461         uniform.m_initial_data.resize(uni_type_size);
24462         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24463
24464         /* XFB data */
24465         xfb.m_initial_data.resize(xfb_data_size);
24466         xfb.m_expected_data.resize(xfb_data_size);
24467
24468         for (GLuint i = 0; i < xfb_data_size; ++i)
24469         {
24470                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24471                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24472         }
24473
24474         if (test_case.m_stage == Utils::Shader::VERTEX)
24475         {
24476                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24477         }
24478         else
24479         {
24480                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24481                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24482         }
24483 }
24484
24485 /** Get body of main function for given shader stage
24486  *
24487  * @param test_case_index  Index of test case
24488  * @param stage            Shader stage
24489  * @param out_assignments  Set to empty
24490  * @param out_calculations Set to empty
24491  **/
24492 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24493                                                                   std::string& out_calculations)
24494 {
24495         const testCase& test_case = m_test_cases[test_case_index];
24496
24497         out_calculations = "";
24498
24499         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24500         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24501                                                           "    if (TYPE(0) == goku)\n"
24502                                                           "    {\n"
24503                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24504                                                           "    }\n";
24505
24506         const GLchar* assignments = "";
24507
24508         if (test_case.m_stage == stage)
24509         {
24510                 switch (stage)
24511                 {
24512                 case Utils::Shader::GEOMETRY:
24513                         assignments = vs_tes_gs;
24514                         break;
24515                 case Utils::Shader::TESS_EVAL:
24516                         assignments = vs_tes_gs;
24517                         break;
24518                 case Utils::Shader::VERTEX:
24519                         assignments = vs_tes_gs;
24520                         break;
24521                 default:
24522                         TCU_FAIL("Invalid enum");
24523                 }
24524         }
24525         else
24526         {
24527                 switch (stage)
24528                 {
24529                 case Utils::Shader::FRAGMENT:
24530                         assignments = fs;
24531                         break;
24532                 case Utils::Shader::GEOMETRY:
24533                 case Utils::Shader::TESS_CTRL:
24534                 case Utils::Shader::TESS_EVAL:
24535                 case Utils::Shader::VERTEX:
24536                         break;
24537                 default:
24538                         TCU_FAIL("Invalid enum");
24539                 }
24540         }
24541
24542         out_assignments = assignments;
24543
24544         if (Utils::Shader::FRAGMENT == stage)
24545         {
24546                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24547         }
24548 }
24549
24550 /** Get interface of shader
24551  *
24552  * @param test_case_index  Index of test case
24553  * @param stage            Shader stage
24554  * @param out_interface    Set to ""
24555  **/
24556 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24557 {
24558         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24559                                                                          "\n"
24560                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24561                                                                          "    TYPE uni_goku;\n"
24562                                                                          "};\n";
24563         static const GLchar* fs = "FLAT in TYPE goku;\n"
24564                                                           "\n"
24565                                                           "out vec4 fs_out;\n";
24566
24567         const testCase& test_case = m_test_cases[test_case_index];
24568         const GLchar*   interface = "";
24569         const GLchar*   flat      = "";
24570
24571         if (test_case.m_stage == stage)
24572         {
24573                 switch (stage)
24574                 {
24575                 case Utils::Shader::GEOMETRY:
24576                         interface = vs_tes_gs;
24577                         break;
24578                 case Utils::Shader::TESS_EVAL:
24579                         interface = vs_tes_gs;
24580                         break;
24581                 case Utils::Shader::VERTEX:
24582                         interface = vs_tes_gs;
24583                         break;
24584                 default:
24585                         TCU_FAIL("Invalid enum");
24586                 }
24587         }
24588         else
24589         {
24590                 switch (stage)
24591                 {
24592                 case Utils::Shader::FRAGMENT:
24593                         interface = fs;
24594                         break;
24595                 case Utils::Shader::GEOMETRY:
24596                 case Utils::Shader::TESS_CTRL:
24597                 case Utils::Shader::TESS_EVAL:
24598                 case Utils::Shader::VERTEX:
24599                         break;
24600                 default:
24601                         TCU_FAIL("Invalid enum");
24602                 }
24603         }
24604
24605         out_interface = interface;
24606
24607         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24608         {
24609                 flat = "flat";
24610         }
24611
24612         Utils::replaceAllTokens("FLAT", flat, out_interface);
24613         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24614 }
24615
24616 /** Get source code of shader
24617  *
24618  * @param test_case_index Index of test case
24619  * @param stage           Shader stage
24620  *
24621  * @return Source
24622  **/
24623 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24624 {
24625         std::string             source;
24626         const testCase& test_case = m_test_cases[test_case_index];
24627
24628         switch (test_case.m_stage)
24629         {
24630         case Utils::Shader::VERTEX:
24631                 switch (stage)
24632                 {
24633                 case Utils::Shader::FRAGMENT:
24634                 case Utils::Shader::VERTEX:
24635                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24636                         break;
24637                 default:
24638                         break;
24639                 }
24640                 break;
24641
24642         case Utils::Shader::TESS_EVAL:
24643                 switch (stage)
24644                 {
24645                 case Utils::Shader::FRAGMENT:
24646                 case Utils::Shader::TESS_CTRL:
24647                 case Utils::Shader::TESS_EVAL:
24648                 case Utils::Shader::VERTEX:
24649                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24650                         break;
24651                 default:
24652                         break;
24653                 }
24654                 break;
24655
24656         case Utils::Shader::GEOMETRY:
24657                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24658                 break;
24659
24660         default:
24661                 TCU_FAIL("Invalid enum");
24662                 break;
24663         }
24664
24665         /* */
24666         return source;
24667 }
24668
24669 /** Get name of test case
24670  *
24671  * @param test_case_index Index of test case
24672  *
24673  * @return Name of tested stage
24674  **/
24675 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24676 {
24677         std::stringstream stream;
24678         const testCase&   test_case = m_test_cases[test_case_index];
24679
24680         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24681                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24682
24683         return stream.str();
24684 }
24685
24686 /** Returns number of test cases
24687  *
24688  * @return TEST_MAX
24689  **/
24690 glw::GLuint XFBStrideTest::getTestCaseNumber()
24691 {
24692         return static_cast<GLuint>(m_test_cases.size());
24693 }
24694
24695 /** Prepare all test cases
24696  *
24697  **/
24698 void XFBStrideTest::testInit()
24699 {
24700         const GLuint n_types = getTypesNumber();
24701
24702         for (GLuint i = 0; i < n_types; ++i)
24703         {
24704                 const Utils::Type& type = getType(i);
24705
24706                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24707                 {
24708                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24709                                 (Utils::Shader::TESS_CTRL == stage))
24710                         {
24711                                 continue;
24712                         }
24713
24714                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24715
24716                         m_test_cases.push_back(test_case);
24717                 }
24718         }
24719 }
24720
24721 /** Constructor
24722  *
24723  * @param context Test framework context
24724  **/
24725 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24726         : NegativeTestBase(
24727                   context, "xfb_block_member_buffer",
24728                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24729 {
24730 }
24731
24732 /** Source for given test case and stage
24733  *
24734  * @param test_case_index Index of test case
24735  * @param stage           Shader stage
24736  *
24737  * @return Shader source
24738  **/
24739 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24740 {
24741         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24742                                                                                   "                            vec4 gohan;\n"
24743                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24744                                                                                   "} gokuARRAY;\n";
24745         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24746                                                                    "    gokuINDEX.goten = result / 4;\n";
24747         static const GLchar* fs = "#version 430 core\n"
24748                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24749                                                           "\n"
24750                                                           "in  vec4 gs_fs;\n"
24751                                                           "out vec4 fs_out;\n"
24752                                                           "\n"
24753                                                           "void main()\n"
24754                                                           "{\n"
24755                                                           "    fs_out = gs_fs;\n"
24756                                                           "}\n"
24757                                                           "\n";
24758         static const GLchar* gs_tested = "#version 430 core\n"
24759                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24760                                                                          "\n"
24761                                                                          "layout(points)                           in;\n"
24762                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24763                                                                          "\n"
24764                                                                          "VAR_DEFINITION"
24765                                                                          "\n"
24766                                                                          "in  vec4 tes_gs[];\n"
24767                                                                          "out vec4 gs_fs;\n"
24768                                                                          "\n"
24769                                                                          "void main()\n"
24770                                                                          "{\n"
24771                                                                          "    vec4 result = tes_gs[0];\n"
24772                                                                          "\n"
24773                                                                          "VARIABLE_USE"
24774                                                                          "\n"
24775                                                                          "    gs_fs = result;\n"
24776                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24777                                                                          "    EmitVertex();\n"
24778                                                                          "    gs_fs = result;\n"
24779                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24780                                                                          "    EmitVertex();\n"
24781                                                                          "    gs_fs = result;\n"
24782                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24783                                                                          "    EmitVertex();\n"
24784                                                                          "    gs_fs = result;\n"
24785                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24786                                                                          "    EmitVertex();\n"
24787                                                                          "}\n"
24788                                                                          "\n";
24789         static const GLchar* tcs = "#version 430 core\n"
24790                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24791                                                            "\n"
24792                                                            "layout(vertices = 1) out;\n"
24793                                                            "\n"
24794                                                            "in  vec4 vs_tcs[];\n"
24795                                                            "out vec4 tcs_tes[];\n"
24796                                                            "\n"
24797                                                            "void main()\n"
24798                                                            "{\n"
24799                                                            "\n"
24800                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24801                                                            "\n"
24802                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24803                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24804                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24805                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24806                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24807                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24808                                                            "}\n"
24809                                                            "\n";
24810         static const GLchar* tcs_tested = "#version 430 core\n"
24811                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24812                                                                           "\n"
24813                                                                           "layout(vertices = 1) out;\n"
24814                                                                           "\n"
24815                                                                           "VAR_DEFINITION"
24816                                                                           "\n"
24817                                                                           "in  vec4 vs_tcs[];\n"
24818                                                                           "out vec4 tcs_tes[];\n"
24819                                                                           "\n"
24820                                                                           "void main()\n"
24821                                                                           "{\n"
24822                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24823                                                                           "\n"
24824                                                                           "VARIABLE_USE"
24825                                                                           "\n"
24826                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24827                                                                           "\n"
24828                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24829                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24830                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24831                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24832                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24833                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24834                                                                           "}\n"
24835                                                                           "\n";
24836         static const GLchar* tes_tested = "#version 430 core\n"
24837                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24838                                                                           "\n"
24839                                                                           "layout(isolines, point_mode) in;\n"
24840                                                                           "\n"
24841                                                                           "VAR_DEFINITION"
24842                                                                           "\n"
24843                                                                           "in  vec4 tcs_tes[];\n"
24844                                                                           "out vec4 tes_gs;\n"
24845                                                                           "\n"
24846                                                                           "void main()\n"
24847                                                                           "{\n"
24848                                                                           "    vec4 result = tcs_tes[0];\n"
24849                                                                           "\n"
24850                                                                           "VARIABLE_USE"
24851                                                                           "\n"
24852                                                                           "    tes_gs += result;\n"
24853                                                                           "}\n"
24854                                                                           "\n";
24855         static const GLchar* vs = "#version 430 core\n"
24856                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24857                                                           "\n"
24858                                                           "in  vec4 in_vs;\n"
24859                                                           "out vec4 vs_tcs;\n"
24860                                                           "\n"
24861                                                           "void main()\n"
24862                                                           "{\n"
24863                                                           "    vs_tcs = in_vs;\n"
24864                                                           "}\n"
24865                                                           "\n";
24866         static const GLchar* vs_tested = "#version 430 core\n"
24867                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24868                                                                          "\n"
24869                                                                          "VAR_DEFINITION"
24870                                                                          "\n"
24871                                                                          "in  vec4 in_vs;\n"
24872                                                                          "out vec4 vs_tcs;\n"
24873                                                                          "\n"
24874                                                                          "void main()\n"
24875                                                                          "{\n"
24876                                                                          "    vec4 result = in_vs;\n"
24877                                                                          "\n"
24878                                                                          "VARIABLE_USE"
24879                                                                          "\n"
24880                                                                          "    vs_tcs = result;\n"
24881                                                                          "}\n"
24882                                                                          "\n";
24883
24884         std::string source;
24885         testCase&   test_case = m_test_cases[test_case_index];
24886
24887         if (test_case.m_stage == stage)
24888         {
24889                 const GLchar* array     = "";
24890                 const GLchar* index     = "";
24891                 size_t            position = 0;
24892
24893                 switch (stage)
24894                 {
24895                 case Utils::Shader::GEOMETRY:
24896                         source = gs_tested;
24897                         array  = "[]";
24898                         index  = "[0]";
24899                         break;
24900                 case Utils::Shader::TESS_CTRL:
24901                         source = tcs_tested;
24902                         array  = "[]";
24903                         index  = "[gl_InvocationID]";
24904                         break;
24905                 case Utils::Shader::TESS_EVAL:
24906                         source = tes_tested;
24907                         array  = "[]";
24908                         index  = "[0]";
24909                         break;
24910                 case Utils::Shader::VERTEX:
24911                         source = vs_tested;
24912                         break;
24913                 default:
24914                         TCU_FAIL("Invalid enum");
24915                 }
24916
24917                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24918                 position = 0;
24919                 Utils::replaceToken("ARRAY", position, array, source);
24920                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24921
24922                 Utils::replaceAllTokens("INDEX", index, source);
24923         }
24924         else
24925         {
24926                 switch (test_case.m_stage)
24927                 {
24928                 case Utils::Shader::GEOMETRY:
24929                         switch (stage)
24930                         {
24931                         case Utils::Shader::FRAGMENT:
24932                                 source = fs;
24933                                 break;
24934                         case Utils::Shader::VERTEX:
24935                                 source = vs;
24936                                 break;
24937                         default:
24938                                 source = "";
24939                         }
24940                         break;
24941                 case Utils::Shader::TESS_CTRL:
24942                         switch (stage)
24943                         {
24944                         case Utils::Shader::FRAGMENT:
24945                                 source = fs;
24946                                 break;
24947                         case Utils::Shader::VERTEX:
24948                                 source = vs;
24949                                 break;
24950                         default:
24951                                 source = "";
24952                         }
24953                         break;
24954                 case Utils::Shader::TESS_EVAL:
24955                         switch (stage)
24956                         {
24957                         case Utils::Shader::FRAGMENT:
24958                                 source = fs;
24959                                 break;
24960                         case Utils::Shader::TESS_CTRL:
24961                                 source = tcs;
24962                                 break;
24963                         case Utils::Shader::VERTEX:
24964                                 source = vs;
24965                                 break;
24966                         default:
24967                                 source = "";
24968                         }
24969                         break;
24970                 case Utils::Shader::VERTEX:
24971                         switch (stage)
24972                         {
24973                         case Utils::Shader::FRAGMENT:
24974                                 source = fs;
24975                                 break;
24976                         default:
24977                                 source = "";
24978                         }
24979                         break;
24980                 default:
24981                         TCU_FAIL("Invalid enum");
24982                         break;
24983                 }
24984         }
24985
24986         return source;
24987 }
24988
24989 /** Get description of test case
24990  *
24991  * @param test_case_index Index of test case
24992  *
24993  * @return Test case description
24994  **/
24995 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
24996 {
24997         std::stringstream stream;
24998         testCase&                 test_case = m_test_cases[test_case_index];
24999
25000         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25001
25002         return stream.str();
25003 }
25004
25005 /** Get number of test cases
25006  *
25007  * @return Number of test cases
25008  **/
25009 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25010 {
25011         return static_cast<GLuint>(m_test_cases.size());
25012 }
25013
25014 /** Selects if "compute" stage is relevant for test
25015  *
25016  * @param ignored
25017  *
25018  * @return false
25019  **/
25020 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25021 {
25022         return false;
25023 }
25024
25025 /** Prepare all test cases
25026  *
25027  **/
25028 void XFBBlockMemberBufferTest::testInit()
25029 {
25030         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25031         {
25032                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25033                         (Utils::Shader::FRAGMENT == stage))
25034                 {
25035                         continue;
25036                 }
25037
25038                 testCase test_case = { (Utils::Shader::STAGES)stage };
25039
25040                 m_test_cases.push_back(test_case);
25041         }
25042 }
25043
25044 /** Constructor
25045  *
25046  * @param context Test framework context
25047  **/
25048 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25049         : NegativeTestBase(context, "xfb_output_overlapping",
25050                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25051 {
25052 }
25053
25054 /** Source for given test case and stage
25055  *
25056  * @param test_case_index Index of test case
25057  * @param stage           Shader stage
25058  *
25059  * @return Shader source
25060  **/
25061 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25062 {
25063         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25064                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25065         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25066                                                                    "    gotenINDEX = TYPE(1);\n"
25067                                                                    "    if (vec4(0) == result)\n"
25068                                                                    "    {\n"
25069                                                                    "        gohanINDEX = TYPE(1);\n"
25070                                                                    "        gotenINDEX = TYPE(0);\n"
25071                                                                    "    }\n";
25072         static const GLchar* fs = "#version 430 core\n"
25073                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25074                                                           "\n"
25075                                                           "in  vec4 gs_fs;\n"
25076                                                           "out vec4 fs_out;\n"
25077                                                           "\n"
25078                                                           "void main()\n"
25079                                                           "{\n"
25080                                                           "    fs_out = gs_fs;\n"
25081                                                           "}\n"
25082                                                           "\n";
25083         static const GLchar* gs_tested = "#version 430 core\n"
25084                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25085                                                                          "\n"
25086                                                                          "layout(points)                           in;\n"
25087                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25088                                                                          "\n"
25089                                                                          "VAR_DEFINITION"
25090                                                                          "\n"
25091                                                                          "in  vec4 tes_gs[];\n"
25092                                                                          "out vec4 gs_fs;\n"
25093                                                                          "\n"
25094                                                                          "void main()\n"
25095                                                                          "{\n"
25096                                                                          "    vec4 result = tes_gs[0];\n"
25097                                                                          "\n"
25098                                                                          "VARIABLE_USE"
25099                                                                          "\n"
25100                                                                          "    gs_fs = result;\n"
25101                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25102                                                                          "    EmitVertex();\n"
25103                                                                          "    gs_fs = result;\n"
25104                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25105                                                                          "    EmitVertex();\n"
25106                                                                          "    gs_fs = result;\n"
25107                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25108                                                                          "    EmitVertex();\n"
25109                                                                          "    gs_fs = result;\n"
25110                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25111                                                                          "    EmitVertex();\n"
25112                                                                          "}\n"
25113                                                                          "\n";
25114         static const GLchar* tcs = "#version 430 core\n"
25115                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25116                                                            "\n"
25117                                                            "layout(vertices = 1) out;\n"
25118                                                            "\n"
25119                                                            "in  vec4 vs_tcs[];\n"
25120                                                            "out vec4 tcs_tes[];\n"
25121                                                            "\n"
25122                                                            "void main()\n"
25123                                                            "{\n"
25124                                                            "\n"
25125                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25126                                                            "\n"
25127                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25128                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25129                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25130                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25131                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25132                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25133                                                            "}\n"
25134                                                            "\n";
25135         static const GLchar* tcs_tested = "#version 430 core\n"
25136                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25137                                                                           "\n"
25138                                                                           "layout(vertices = 1) out;\n"
25139                                                                           "\n"
25140                                                                           "VAR_DEFINITION"
25141                                                                           "\n"
25142                                                                           "in  vec4 vs_tcs[];\n"
25143                                                                           "out vec4 tcs_tes[];\n"
25144                                                                           "\n"
25145                                                                           "void main()\n"
25146                                                                           "{\n"
25147                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25148                                                                           "\n"
25149                                                                           "VARIABLE_USE"
25150                                                                           "\n"
25151                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25152                                                                           "\n"
25153                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25154                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25155                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25156                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25157                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25158                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25159                                                                           "}\n"
25160                                                                           "\n";
25161         static const GLchar* tes_tested = "#version 430 core\n"
25162                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25163                                                                           "\n"
25164                                                                           "layout(isolines, point_mode) in;\n"
25165                                                                           "\n"
25166                                                                           "VAR_DEFINITION"
25167                                                                           "\n"
25168                                                                           "in  vec4 tcs_tes[];\n"
25169                                                                           "out vec4 tes_gs;\n"
25170                                                                           "\n"
25171                                                                           "void main()\n"
25172                                                                           "{\n"
25173                                                                           "    vec4 result = tcs_tes[0];\n"
25174                                                                           "\n"
25175                                                                           "VARIABLE_USE"
25176                                                                           "\n"
25177                                                                           "    tes_gs += result;\n"
25178                                                                           "}\n"
25179                                                                           "\n";
25180         static const GLchar* vs = "#version 430 core\n"
25181                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25182                                                           "\n"
25183                                                           "in  vec4 in_vs;\n"
25184                                                           "out vec4 vs_tcs;\n"
25185                                                           "\n"
25186                                                           "void main()\n"
25187                                                           "{\n"
25188                                                           "    vs_tcs = in_vs;\n"
25189                                                           "}\n"
25190                                                           "\n";
25191         static const GLchar* vs_tested = "#version 430 core\n"
25192                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25193                                                                          "\n"
25194                                                                          "VAR_DEFINITION"
25195                                                                          "\n"
25196                                                                          "in  vec4 in_vs;\n"
25197                                                                          "out vec4 vs_tcs;\n"
25198                                                                          "\n"
25199                                                                          "void main()\n"
25200                                                                          "{\n"
25201                                                                          "    vec4 result = in_vs;\n"
25202                                                                          "\n"
25203                                                                          "VARIABLE_USE"
25204                                                                          "\n"
25205                                                                          "    vs_tcs = result;\n"
25206                                                                          "}\n"
25207                                                                          "\n";
25208
25209         std::string source;
25210         testCase&   test_case = m_test_cases[test_case_index];
25211
25212         if (test_case.m_stage == stage)
25213         {
25214                 const GLchar* array = "";
25215                 GLchar            buffer_gohan[16];
25216                 GLchar            buffer_goten[16];
25217                 const GLchar* index                      = "";
25218                 size_t            position               = 0;
25219                 size_t            position_start = 0;
25220                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25221
25222                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25223                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25224
25225                 switch (stage)
25226                 {
25227                 case Utils::Shader::GEOMETRY:
25228                         source = gs_tested;
25229                         array  = "[]";
25230                         index  = "[0]";
25231                         break;
25232                 case Utils::Shader::TESS_CTRL:
25233                         source = tcs_tested;
25234                         array  = "[]";
25235                         index  = "[gl_InvocationID]";
25236                         break;
25237                 case Utils::Shader::TESS_EVAL:
25238                         source = tes_tested;
25239                         array  = "[]";
25240                         index  = "[0]";
25241                         break;
25242                 case Utils::Shader::VERTEX:
25243                         source = vs_tested;
25244                         break;
25245                 default:
25246                         TCU_FAIL("Invalid enum");
25247                 }
25248
25249                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25250                 position = 0;
25251                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25252                 Utils::replaceToken("TYPE", position, type_name, source);
25253                 Utils::replaceToken("ARRAY", position, array, source);
25254                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25255                 Utils::replaceToken("TYPE", position, type_name, source);
25256                 Utils::replaceToken("ARRAY", position, array, source);
25257                 position_start = position;
25258                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25259                 position = position_start;
25260                 Utils::replaceToken("INDEX", position, index, source);
25261                 Utils::replaceToken("TYPE", position, type_name, source);
25262                 Utils::replaceToken("INDEX", position, index, source);
25263                 Utils::replaceToken("TYPE", position, type_name, source);
25264                 Utils::replaceToken("INDEX", position, index, source);
25265                 Utils::replaceToken("TYPE", position, type_name, source);
25266                 Utils::replaceToken("INDEX", position, index, source);
25267                 Utils::replaceToken("TYPE", position, type_name, source);
25268         }
25269         else
25270         {
25271                 switch (test_case.m_stage)
25272                 {
25273                 case Utils::Shader::GEOMETRY:
25274                         switch (stage)
25275                         {
25276                         case Utils::Shader::FRAGMENT:
25277                                 source = fs;
25278                                 break;
25279                         case Utils::Shader::VERTEX:
25280                                 source = vs;
25281                                 break;
25282                         default:
25283                                 source = "";
25284                         }
25285                         break;
25286                 case Utils::Shader::TESS_CTRL:
25287                         switch (stage)
25288                         {
25289                         case Utils::Shader::FRAGMENT:
25290                                 source = fs;
25291                                 break;
25292                         case Utils::Shader::VERTEX:
25293                                 source = vs;
25294                                 break;
25295                         default:
25296                                 source = "";
25297                         }
25298                         break;
25299                 case Utils::Shader::TESS_EVAL:
25300                         switch (stage)
25301                         {
25302                         case Utils::Shader::FRAGMENT:
25303                                 source = fs;
25304                                 break;
25305                         case Utils::Shader::TESS_CTRL:
25306                                 source = tcs;
25307                                 break;
25308                         case Utils::Shader::VERTEX:
25309                                 source = vs;
25310                                 break;
25311                         default:
25312                                 source = "";
25313                         }
25314                         break;
25315                 case Utils::Shader::VERTEX:
25316                         switch (stage)
25317                         {
25318                         case Utils::Shader::FRAGMENT:
25319                                 source = fs;
25320                                 break;
25321                         default:
25322                                 source = "";
25323                         }
25324                         break;
25325                 default:
25326                         TCU_FAIL("Invalid enum");
25327                         break;
25328                 }
25329         }
25330
25331         return source;
25332 }
25333
25334 /** Get description of test case
25335  *
25336  * @param test_case_index Index of test case
25337  *
25338  * @return Test case description
25339  **/
25340 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25341 {
25342         std::stringstream stream;
25343         testCase&                 test_case = m_test_cases[test_case_index];
25344
25345         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25346                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25347                    << test_case.m_offset_goten;
25348
25349         return stream.str();
25350 }
25351
25352 /** Get number of test cases
25353  *
25354  * @return Number of test cases
25355  **/
25356 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25357 {
25358         return static_cast<GLuint>(m_test_cases.size());
25359 }
25360
25361 /** Selects if "compute" stage is relevant for test
25362  *
25363  * @param ignored
25364  *
25365  * @return false
25366  **/
25367 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25368 {
25369         return false;
25370 }
25371
25372 /** Prepare all test cases
25373  *
25374  **/
25375 void XFBOutputOverlappingTest::testInit()
25376 {
25377         const GLuint n_types = getTypesNumber();
25378
25379         for (GLuint i = 0; i < n_types; ++i)
25380         {
25381                 const Utils::Type& type                   = getType(i);
25382                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25383
25384                 /* Skip scalars, not applicable as:
25385                  *
25386                  *     The offset must be a multiple of the size of the first component of the first
25387                  *     qualified variable or block member, or a compile-time error results.
25388                  */
25389                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25390                 {
25391                         continue;
25392                 }
25393
25394                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25395                 {
25396                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25397                                 (Utils::Shader::FRAGMENT == stage))
25398                         {
25399                                 continue;
25400                         }
25401
25402                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25403                                                                    (Utils::Shader::STAGES)stage, type };
25404
25405                         m_test_cases.push_back(test_case);
25406                 }
25407         }
25408 }
25409
25410 /** Constructor
25411  *
25412  * @param context Test framework context
25413  **/
25414 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25415         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25416                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25417 {
25418 }
25419
25420 /** Source for given test case and stage
25421  *
25422  * @param test_case_index Index of test case
25423  * @param stage           Shader stage
25424  *
25425  * @return Shader source
25426  **/
25427 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25428 {
25429         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25430         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25431                                                                    "    if (vec4(0) == result)\n"
25432                                                                    "    {\n"
25433                                                                    "        gohanINDEX = TYPE(1);\n"
25434                                                                    "    }\n";
25435         static const GLchar* fs = "#version 430 core\n"
25436                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25437                                                           "\n"
25438                                                           "in  vec4 gs_fs;\n"
25439                                                           "out vec4 fs_out;\n"
25440                                                           "\n"
25441                                                           "void main()\n"
25442                                                           "{\n"
25443                                                           "    fs_out = gs_fs;\n"
25444                                                           "}\n"
25445                                                           "\n";
25446         static const GLchar* gs_tested = "#version 430 core\n"
25447                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25448                                                                          "\n"
25449                                                                          "layout(points)                           in;\n"
25450                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25451                                                                          "\n"
25452                                                                          "VAR_DEFINITION"
25453                                                                          "\n"
25454                                                                          "in  vec4 tes_gs[];\n"
25455                                                                          "out vec4 gs_fs;\n"
25456                                                                          "\n"
25457                                                                          "void main()\n"
25458                                                                          "{\n"
25459                                                                          "    vec4 result = tes_gs[0];\n"
25460                                                                          "\n"
25461                                                                          "VARIABLE_USE"
25462                                                                          "\n"
25463                                                                          "    gs_fs = result;\n"
25464                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25465                                                                          "    EmitVertex();\n"
25466                                                                          "    gs_fs = result;\n"
25467                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25468                                                                          "    EmitVertex();\n"
25469                                                                          "    gs_fs = result;\n"
25470                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25471                                                                          "    EmitVertex();\n"
25472                                                                          "    gs_fs = result;\n"
25473                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25474                                                                          "    EmitVertex();\n"
25475                                                                          "}\n"
25476                                                                          "\n";
25477         static const GLchar* tcs = "#version 430 core\n"
25478                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25479                                                            "\n"
25480                                                            "layout(vertices = 1) out;\n"
25481                                                            "\n"
25482                                                            "in  vec4 vs_tcs[];\n"
25483                                                            "out vec4 tcs_tes[];\n"
25484                                                            "\n"
25485                                                            "void main()\n"
25486                                                            "{\n"
25487                                                            "\n"
25488                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25489                                                            "\n"
25490                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25491                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25492                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25493                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25494                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25495                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25496                                                            "}\n"
25497                                                            "\n";
25498         static const GLchar* tcs_tested = "#version 430 core\n"
25499                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25500                                                                           "\n"
25501                                                                           "layout(vertices = 1) out;\n"
25502                                                                           "\n"
25503                                                                           "VAR_DEFINITION"
25504                                                                           "\n"
25505                                                                           "in  vec4 vs_tcs[];\n"
25506                                                                           "out vec4 tcs_tes[];\n"
25507                                                                           "\n"
25508                                                                           "void main()\n"
25509                                                                           "{\n"
25510                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25511                                                                           "\n"
25512                                                                           "VARIABLE_USE"
25513                                                                           "\n"
25514                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25515                                                                           "\n"
25516                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25517                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25518                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25519                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25520                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25521                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25522                                                                           "}\n"
25523                                                                           "\n";
25524         static const GLchar* tes_tested = "#version 430 core\n"
25525                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25526                                                                           "\n"
25527                                                                           "layout(isolines, point_mode) in;\n"
25528                                                                           "\n"
25529                                                                           "VAR_DEFINITION"
25530                                                                           "\n"
25531                                                                           "in  vec4 tcs_tes[];\n"
25532                                                                           "out vec4 tes_gs;\n"
25533                                                                           "\n"
25534                                                                           "void main()\n"
25535                                                                           "{\n"
25536                                                                           "    vec4 result = tcs_tes[0];\n"
25537                                                                           "\n"
25538                                                                           "VARIABLE_USE"
25539                                                                           "\n"
25540                                                                           "    tes_gs += result;\n"
25541                                                                           "}\n"
25542                                                                           "\n";
25543         static const GLchar* vs = "#version 430 core\n"
25544                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25545                                                           "\n"
25546                                                           "in  vec4 in_vs;\n"
25547                                                           "out vec4 vs_tcs;\n"
25548                                                           "\n"
25549                                                           "void main()\n"
25550                                                           "{\n"
25551                                                           "    vs_tcs = in_vs;\n"
25552                                                           "}\n"
25553                                                           "\n";
25554         static const GLchar* vs_tested = "#version 430 core\n"
25555                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25556                                                                          "\n"
25557                                                                          "VAR_DEFINITION"
25558                                                                          "\n"
25559                                                                          "in  vec4 in_vs;\n"
25560                                                                          "out vec4 vs_tcs;\n"
25561                                                                          "\n"
25562                                                                          "void main()\n"
25563                                                                          "{\n"
25564                                                                          "    vec4 result = in_vs;\n"
25565                                                                          "\n"
25566                                                                          "VARIABLE_USE"
25567                                                                          "\n"
25568                                                                          "    vs_tcs = result;\n"
25569                                                                          "}\n"
25570                                                                          "\n";
25571
25572         std::string source;
25573         testCase&   test_case = m_test_cases[test_case_index];
25574
25575         if (test_case.m_stage == stage)
25576         {
25577                 const GLchar* array = "";
25578                 GLchar            buffer[16];
25579                 const GLchar* index                      = "";
25580                 size_t            position               = 0;
25581                 size_t            position_start = 0;
25582                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25583
25584                 sprintf(buffer, "%d", test_case.m_offset);
25585
25586                 switch (stage)
25587                 {
25588                 case Utils::Shader::GEOMETRY:
25589                         source = gs_tested;
25590                         array  = "[]";
25591                         index  = "[0]";
25592                         break;
25593                 case Utils::Shader::TESS_CTRL:
25594                         source = tcs_tested;
25595                         array  = "[]";
25596                         index  = "[gl_InvocationID]";
25597                         break;
25598                 case Utils::Shader::TESS_EVAL:
25599                         source = tes_tested;
25600                         array  = "[]";
25601                         index  = "[0]";
25602                         break;
25603                 case Utils::Shader::VERTEX:
25604                         source = vs_tested;
25605                         break;
25606                 default:
25607                         TCU_FAIL("Invalid enum");
25608                 }
25609
25610                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25611                 position = 0;
25612                 Utils::replaceToken("OFFSET", position, buffer, source);
25613                 Utils::replaceToken("TYPE", position, type_name, source);
25614                 Utils::replaceToken("ARRAY", position, array, source);
25615                 position_start = position;
25616                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25617                 position = position_start;
25618                 Utils::replaceToken("INDEX", position, index, source);
25619                 Utils::replaceToken("TYPE", position, type_name, source);
25620                 Utils::replaceToken("INDEX", position, index, source);
25621                 Utils::replaceToken("TYPE", position, type_name, source);
25622         }
25623         else
25624         {
25625                 switch (test_case.m_stage)
25626                 {
25627                 case Utils::Shader::GEOMETRY:
25628                         switch (stage)
25629                         {
25630                         case Utils::Shader::FRAGMENT:
25631                                 source = fs;
25632                                 break;
25633                         case Utils::Shader::VERTEX:
25634                                 source = vs;
25635                                 break;
25636                         default:
25637                                 source = "";
25638                         }
25639                         break;
25640                 case Utils::Shader::TESS_CTRL:
25641                         switch (stage)
25642                         {
25643                         case Utils::Shader::FRAGMENT:
25644                                 source = fs;
25645                                 break;
25646                         case Utils::Shader::VERTEX:
25647                                 source = vs;
25648                                 break;
25649                         default:
25650                                 source = "";
25651                         }
25652                         break;
25653                 case Utils::Shader::TESS_EVAL:
25654                         switch (stage)
25655                         {
25656                         case Utils::Shader::FRAGMENT:
25657                                 source = fs;
25658                                 break;
25659                         case Utils::Shader::TESS_CTRL:
25660                                 source = tcs;
25661                                 break;
25662                         case Utils::Shader::VERTEX:
25663                                 source = vs;
25664                                 break;
25665                         default:
25666                                 source = "";
25667                         }
25668                         break;
25669                 case Utils::Shader::VERTEX:
25670                         switch (stage)
25671                         {
25672                         case Utils::Shader::FRAGMENT:
25673                                 source = fs;
25674                                 break;
25675                         default:
25676                                 source = "";
25677                         }
25678                         break;
25679                 default:
25680                         TCU_FAIL("Invalid enum");
25681                         break;
25682                 }
25683         }
25684
25685         return source;
25686 }
25687
25688 /** Get description of test case
25689  *
25690  * @param test_case_index Index of test case
25691  *
25692  * @return Test case description
25693  **/
25694 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25695 {
25696         std::stringstream stream;
25697         testCase&                 test_case = m_test_cases[test_case_index];
25698
25699         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25700                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25701
25702         return stream.str();
25703 }
25704
25705 /** Get number of test cases
25706  *
25707  * @return Number of test cases
25708  **/
25709 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25710 {
25711         return static_cast<GLuint>(m_test_cases.size());
25712 }
25713
25714 /** Selects if "compute" stage is relevant for test
25715  *
25716  * @param ignored
25717  *
25718  * @return false
25719  **/
25720 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25721 {
25722         return false;
25723 }
25724
25725 /** Prepare all test cases
25726  *
25727  **/
25728 void XFBInvalidOffsetAlignmentTest::testInit()
25729 {
25730         const GLuint n_types = getTypesNumber();
25731
25732         for (GLuint i = 0; i < n_types; ++i)
25733         {
25734                 const Utils::Type& type                   = getType(i);
25735                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25736
25737                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25738                 {
25739                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25740                                 (Utils::Shader::FRAGMENT == stage))
25741                         {
25742                                 continue;
25743                         }
25744
25745                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25746                         {
25747                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25748
25749                                 m_test_cases.push_back(test_case);
25750                         }
25751                 }
25752         }
25753 }
25754
25755 /** Constructor
25756  *
25757  * @param context Test context
25758  **/
25759 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25760         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25761                                          "Test verifies that inactive variables are captured")
25762 {
25763         /* Nothing to be done here */
25764 }
25765
25766 /** Execute drawArrays for single vertex
25767  *
25768  * @param test_case_index
25769  *
25770  * @return true
25771  **/
25772 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(GLuint test_case_index)
25773 {
25774         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25775         GLenum                   primitive_type = GL_PATCHES;
25776
25777         if (TEST_VS == test_case_index)
25778         {
25779                 primitive_type = GL_POINTS;
25780         }
25781
25782         gl.disable(GL_RASTERIZER_DISCARD);
25783         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25784
25785         gl.beginTransformFeedback(GL_POINTS);
25786         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25787
25788         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25789         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25790
25791         gl.endTransformFeedback();
25792         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25793
25794         return true;
25795 }
25796
25797 /** Get descriptors of buffers necessary for test
25798  *
25799  * @param ignored
25800  * @param out_descriptors Descriptors of buffers used by test
25801  **/
25802 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25803                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25804 {
25805         const Utils::Type& type = Utils::Type::vec4;
25806
25807         /* Test needs single uniform and xfb */
25808         out_descriptors.resize(2);
25809
25810         /* Get references */
25811         bufferDescriptor& uniform = out_descriptors[0];
25812         bufferDescriptor& xfb    = out_descriptors[1];
25813
25814         /* Index */
25815         uniform.m_index = 0;
25816         xfb.m_index             = 0;
25817
25818         /* Target */
25819         uniform.m_target = Utils::Buffer::Uniform;
25820         xfb.m_target     = Utils::Buffer::Transform_feedback;
25821
25822         /* Data */
25823         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25824         const std::vector<GLubyte>& goten_data = type.GenerateData();
25825
25826         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25827
25828         /* Uniform data */
25829         uniform.m_initial_data.resize(2 * type_size);
25830         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25831         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25832
25833         /* XFB data */
25834         xfb.m_initial_data.resize(3 * type_size);
25835         xfb.m_expected_data.resize(3 * type_size);
25836
25837         for (GLuint i = 0; i < 3 * type_size; ++i)
25838         {
25839                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25840                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25841         }
25842
25843         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25844         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25845 }
25846
25847 /** Get body of main function for given shader stage
25848  *
25849  * @param test_case_index  Index of test case
25850  * @param stage            Shader stage
25851  * @param out_assignments  Set to empty
25852  * @param out_calculations Set to empty
25853  **/
25854 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25855                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25856 {
25857         out_calculations = "";
25858
25859         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25860                                                                          "    gohan = uni_gohan;\n";
25861         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25862
25863         const GLchar* assignments = "";
25864
25865         switch (stage)
25866         {
25867         case Utils::Shader::FRAGMENT:
25868                 assignments = fs;
25869                 break;
25870
25871         case Utils::Shader::GEOMETRY:
25872                 if (TEST_GS == test_case_index)
25873                 {
25874                         assignments = vs_tes_gs;
25875                 }
25876                 break;
25877
25878         case Utils::Shader::TESS_CTRL:
25879                 break;
25880
25881         case Utils::Shader::TESS_EVAL:
25882                 if (TEST_TES == test_case_index)
25883                 {
25884                         assignments = vs_tes_gs;
25885                 }
25886                 break;
25887
25888         case Utils::Shader::VERTEX:
25889                 if (TEST_VS == test_case_index)
25890                 {
25891                         assignments = vs_tes_gs;
25892                 }
25893                 break;
25894
25895         default:
25896                 TCU_FAIL("Invalid enum");
25897         }
25898
25899         out_assignments = assignments;
25900 }
25901
25902 /** Get interface of shader
25903  *
25904  * @param test_case_index  Index of test case
25905  * @param stage            Shader stage
25906  * @param out_interface    Set to ""
25907  **/
25908 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25909                                                                                                                           std::string& out_interface)
25910 {
25911         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25912                                                                          "\n"
25913                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25914                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25915                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25916                                                                          "\n"
25917                                                                          "layout(binding = 0) uniform block {\n"
25918                                                                          "    vec4 uni_gohan;\n"
25919                                                                          "    vec4 uni_goten;\n"
25920                                                                          "};\n";
25921         static const GLchar* fs = "in vec4 goku;\n"
25922                                                           "in vec4 gohan;\n"
25923                                                           "in vec4 goten;\n"
25924                                                           "out vec4 fs_out;\n";
25925
25926         const GLchar* interface = "";
25927
25928         switch (stage)
25929         {
25930         case Utils::Shader::FRAGMENT:
25931                 interface = fs;
25932                 break;
25933
25934         case Utils::Shader::GEOMETRY:
25935                 if (TEST_GS == test_case_index)
25936                 {
25937                         interface = vs_tes_gs;
25938                 }
25939                 break;
25940
25941         case Utils::Shader::TESS_CTRL:
25942                 break;
25943
25944         case Utils::Shader::TESS_EVAL:
25945                 if (TEST_TES == test_case_index)
25946                 {
25947                         interface = vs_tes_gs;
25948                 }
25949                 break;
25950
25951         case Utils::Shader::VERTEX:
25952                 if (TEST_VS == test_case_index)
25953                 {
25954                         interface = vs_tes_gs;
25955                 }
25956                 break;
25957
25958         default:
25959                 TCU_FAIL("Invalid enum");
25960         }
25961
25962         out_interface = interface;
25963 }
25964
25965 /** Get source code of shader
25966  *
25967  * @param test_case_index Index of test case
25968  * @param stage           Shader stage
25969  *
25970  * @return Source
25971  **/
25972 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25973 {
25974         std::string source;
25975
25976         switch (test_case_index)
25977         {
25978         case TEST_VS:
25979                 switch (stage)
25980                 {
25981                 case Utils::Shader::FRAGMENT:
25982                 case Utils::Shader::VERTEX:
25983                         source = BufferTestBase::getShaderSource(test_case_index, stage);
25984                         break;
25985                 default:
25986                         break;
25987                 }
25988                 break;
25989
25990         case TEST_TES:
25991                 switch (stage)
25992                 {
25993                 case Utils::Shader::FRAGMENT:
25994                 case Utils::Shader::TESS_CTRL:
25995                 case Utils::Shader::TESS_EVAL:
25996                 case Utils::Shader::VERTEX:
25997                         source = BufferTestBase::getShaderSource(test_case_index, stage);
25998                         break;
25999                 default:
26000                         break;
26001                 }
26002                 break;
26003
26004         case TEST_GS:
26005                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26006                 break;
26007
26008         default:
26009                 TCU_FAIL("Invalid enum");
26010                 break;
26011         }
26012
26013         /* */
26014         return source;
26015 }
26016
26017 /** Get name of test case
26018  *
26019  * @param test_case_index Index of test case
26020  *
26021  * @return Name of tested stage
26022  **/
26023 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26024 {
26025         const GLchar* name = 0;
26026
26027         switch (test_case_index)
26028         {
26029         case TEST_VS:
26030                 name = "vertex";
26031                 break;
26032         case TEST_TES:
26033                 name = "tesselation evaluation";
26034                 break;
26035         case TEST_GS:
26036                 name = "geometry";
26037                 break;
26038         default:
26039                 TCU_FAIL("Invalid enum");
26040         }
26041
26042         return name;
26043 }
26044
26045 /** Returns number of test cases
26046  *
26047  * @return TEST_MAX
26048  **/
26049 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26050 {
26051         return TEST_MAX;
26052 }
26053
26054 /** Inspects program to check if all resources are as expected
26055  *
26056  * @param ignored
26057  * @param program         Program instance
26058  * @param out_stream      Error message
26059  *
26060  * @return true if everything is ok, false otherwise
26061  **/
26062 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26063                                                                                                                   std::stringstream& out_stream)
26064 {
26065         GLint                      stride       = 0;
26066         const Utils::Type& type          = Utils::Type::vec4;
26067         const GLuint       type_size = type.GetSize();
26068
26069         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26070                                                 1 /* buf_size */, &stride);
26071
26072         if ((GLint)(3 * type_size) != stride)
26073         {
26074                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26075
26076                 return false;
26077         }
26078
26079         return true;
26080 }
26081
26082 /** Verify contents of buffers
26083  *
26084  * @param buffers Collection of buffers to be verified
26085  *
26086  * @return true if everything is as expected, false otherwise
26087  **/
26088 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26089 {
26090         bool result = true;
26091
26092         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26093         Utils::Buffer*                  buffer   = pair.m_buffer;
26094         bufferDescriptor*               descriptor = pair.m_descriptor;
26095
26096         /* Get pointer to contents of buffer */
26097         buffer->Bind();
26098         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26099
26100         /* Get pointer to expected data */
26101         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26102
26103         /* Compare */
26104         static const GLuint vec4_size = 16;
26105
26106         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26107         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26108
26109         if ((0 != res_gohan) || (0 != res_goten))
26110         {
26111                 m_context.getTestContext().getLog()
26112                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26113                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26114
26115                 result = false;
26116         }
26117
26118         /* Release buffer mapping */
26119         buffer->UnMap();
26120
26121         return result;
26122 }
26123
26124 /** Constructor
26125  *
26126  * @param context Test context
26127  **/
26128 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26129         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26130                                          "Test verifies that inactive components are not modified")
26131 {
26132         /* Nothing to be done here */
26133 }
26134
26135 /** Execute drawArrays for single vertex
26136  *
26137  * @param test_case_index
26138  *
26139  * @return true
26140  **/
26141 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(GLuint test_case_index)
26142 {
26143         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26144         GLenum                   primitive_type = GL_PATCHES;
26145
26146         if (TEST_VS == test_case_index)
26147         {
26148                 primitive_type = GL_POINTS;
26149         }
26150
26151         gl.disable(GL_RASTERIZER_DISCARD);
26152         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26153
26154         gl.beginTransformFeedback(GL_POINTS);
26155         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26156
26157         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26158         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26159
26160         gl.endTransformFeedback();
26161         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26162
26163         return true;
26164 }
26165
26166 /** Get descriptors of buffers necessary for test
26167  *
26168  * @param ignored
26169  * @param out_descriptors Descriptors of buffers used by test
26170  **/
26171 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26172                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26173 {
26174         const Utils::Type& type = Utils::Type::vec4;
26175
26176         /* Test needs single uniform and xfb */
26177         out_descriptors.resize(2);
26178
26179         /* Get references */
26180         bufferDescriptor& uniform = out_descriptors[0];
26181         bufferDescriptor& xfb    = out_descriptors[1];
26182
26183         /* Index */
26184         uniform.m_index = 0;
26185         xfb.m_index             = 0;
26186
26187         /* Target */
26188         uniform.m_target = Utils::Buffer::Uniform;
26189         xfb.m_target     = Utils::Buffer::Transform_feedback;
26190
26191         /* Data */
26192         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26193         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26194         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26195         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26196         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26197         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26198         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26199         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26200
26201         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26202         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26203
26204         /* Uniform data */
26205         uniform.m_initial_data.resize(8 * type_size);
26206         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26207         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26208         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26209         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26210         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26211         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26212         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26213         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26214
26215         /* XFB data */
26216         xfb.m_initial_data.resize(8 * type_size);
26217         xfb.m_expected_data.resize(8 * type_size);
26218
26219         for (GLuint i = 0; i < 8 * type_size; ++i)
26220         {
26221                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26222                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26223         }
26224
26225         /* goku - x, z - 32 */
26226         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26227         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26228
26229         /* gohan - y, w - 0 */
26230         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26231         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26232
26233         /* goten - x, y - 16 */
26234         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26235         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26236
26237         /* chichi - z, w - 48 */
26238         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26239         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26240
26241         /* vegeta - x - 112 */
26242         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26243
26244         /* trunks - y - 96 */
26245         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26246
26247         /* bra - z - 80 */
26248         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26249
26250         /* bulma - w - 64 */
26251         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26252 }
26253
26254 /** Get body of main function for given shader stage
26255  *
26256  * @param test_case_index  Index of test case
26257  * @param stage            Shader stage
26258  * @param out_assignments  Set to empty
26259  * @param out_calculations Set to empty
26260  **/
26261 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26262                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26263 {
26264         out_calculations = "";
26265
26266         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26267                                                                          "    goku.z    = uni_goku.z   ;\n"
26268                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26269                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26270                                                                          "    goten.x   = uni_goten.x  ;\n"
26271                                                                          "    goten.y   = uni_goten.y  ;\n"
26272                                                                          "    chichi.z  = uni_chichi.z ;\n"
26273                                                                          "    chichi.w  = uni_chichi.w ;\n"
26274                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26275                                                                          "    trunks.y  = uni_trunks.y ;\n"
26276                                                                          "    bra.z     = uni_bra.z    ;\n"
26277                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26278         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26279
26280         const GLchar* assignments = "";
26281
26282         switch (stage)
26283         {
26284         case Utils::Shader::FRAGMENT:
26285                 assignments = fs;
26286                 break;
26287
26288         case Utils::Shader::GEOMETRY:
26289                 if (TEST_GS == test_case_index)
26290                 {
26291                         assignments = vs_tes_gs;
26292                 }
26293                 break;
26294
26295         case Utils::Shader::TESS_CTRL:
26296                 break;
26297
26298         case Utils::Shader::TESS_EVAL:
26299                 if (TEST_TES == test_case_index)
26300                 {
26301                         assignments = vs_tes_gs;
26302                 }
26303                 break;
26304
26305         case Utils::Shader::VERTEX:
26306                 if (TEST_VS == test_case_index)
26307                 {
26308                         assignments = vs_tes_gs;
26309                 }
26310                 break;
26311
26312         default:
26313                 TCU_FAIL("Invalid enum");
26314         }
26315
26316         out_assignments = assignments;
26317 }
26318
26319 /** Get interface of shader
26320  *
26321  * @param test_case_index  Index of test case
26322  * @param stage            Shader stage
26323  * @param out_interface    Set to ""
26324  **/
26325 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26326                                                                                                                            std::string& out_interface)
26327 {
26328         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26329                                                                          "\n"
26330                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26331                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26332                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26333                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26334                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26335                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26336                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26337                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26338                                                                          "\n"
26339                                                                          "layout(binding = 0) uniform block {\n"
26340                                                                          "    vec4 uni_goku;\n"
26341                                                                          "    vec4 uni_gohan;\n"
26342                                                                          "    vec4 uni_goten;\n"
26343                                                                          "    vec4 uni_chichi;\n"
26344                                                                          "    vec4 uni_vegeta;\n"
26345                                                                          "    vec4 uni_trunks;\n"
26346                                                                          "    vec4 uni_bra;\n"
26347                                                                          "    vec4 uni_bulma;\n"
26348                                                                          "};\n";
26349         static const GLchar* fs = "in vec4 vegeta;\n"
26350                                                           "in vec4 trunks;\n"
26351                                                           "in vec4 bra;\n"
26352                                                           "in vec4 bulma;\n"
26353                                                           "in vec4 goku;\n"
26354                                                           "in vec4 gohan;\n"
26355                                                           "in vec4 goten;\n"
26356                                                           "in vec4 chichi;\n"
26357                                                           "\n"
26358                                                           "out vec4 fs_out;\n";
26359
26360         const GLchar* interface = "";
26361
26362         switch (stage)
26363         {
26364         case Utils::Shader::FRAGMENT:
26365                 interface = fs;
26366                 break;
26367
26368         case Utils::Shader::GEOMETRY:
26369                 if (TEST_GS == test_case_index)
26370                 {
26371                         interface = vs_tes_gs;
26372                 }
26373                 break;
26374
26375         case Utils::Shader::TESS_CTRL:
26376                 break;
26377
26378         case Utils::Shader::TESS_EVAL:
26379                 if (TEST_TES == test_case_index)
26380                 {
26381                         interface = vs_tes_gs;
26382                 }
26383                 break;
26384
26385         case Utils::Shader::VERTEX:
26386                 if (TEST_VS == test_case_index)
26387                 {
26388                         interface = vs_tes_gs;
26389                 }
26390                 break;
26391
26392         default:
26393                 TCU_FAIL("Invalid enum");
26394         }
26395
26396         out_interface = interface;
26397 }
26398
26399 /** Get source code of shader
26400  *
26401  * @param test_case_index Index of test case
26402  * @param stage           Shader stage
26403  *
26404  * @return Source
26405  **/
26406 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26407 {
26408         std::string source;
26409
26410         switch (test_case_index)
26411         {
26412         case TEST_VS:
26413                 switch (stage)
26414                 {
26415                 case Utils::Shader::FRAGMENT:
26416                 case Utils::Shader::VERTEX:
26417                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26418                         break;
26419                 default:
26420                         break;
26421                 }
26422                 break;
26423
26424         case TEST_TES:
26425                 switch (stage)
26426                 {
26427                 case Utils::Shader::FRAGMENT:
26428                 case Utils::Shader::TESS_CTRL:
26429                 case Utils::Shader::TESS_EVAL:
26430                 case Utils::Shader::VERTEX:
26431                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26432                         break;
26433                 default:
26434                         break;
26435                 }
26436                 break;
26437
26438         case TEST_GS:
26439                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26440                 break;
26441
26442         default:
26443                 TCU_FAIL("Invalid enum");
26444                 break;
26445         }
26446
26447         /* */
26448         return source;
26449 }
26450
26451 /** Get name of test case
26452  *
26453  * @param test_case_index Index of test case
26454  *
26455  * @return Name of tested stage
26456  **/
26457 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26458 {
26459         const GLchar* name = 0;
26460
26461         switch (test_case_index)
26462         {
26463         case TEST_VS:
26464                 name = "vertex";
26465                 break;
26466         case TEST_TES:
26467                 name = "tesselation evaluation";
26468                 break;
26469         case TEST_GS:
26470                 name = "geometry";
26471                 break;
26472         default:
26473                 TCU_FAIL("Invalid enum");
26474         }
26475
26476         return name;
26477 }
26478
26479 /** Returns number of test cases
26480  *
26481  * @return TEST_MAX
26482  **/
26483 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26484 {
26485         return TEST_MAX;
26486 }
26487
26488 /** Verify contents of buffers
26489  *
26490  * @param buffers Collection of buffers to be verified
26491  *
26492  * @return true if everything is as expected, false otherwise
26493  **/
26494 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26495 {
26496         bool result = true;
26497
26498         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26499         Utils::Buffer*                  buffer   = pair.m_buffer;
26500         bufferDescriptor*               descriptor = pair.m_descriptor;
26501
26502         /* Get pointer to contents of buffer */
26503         buffer->Bind();
26504         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26505
26506         /* Get pointer to expected data */
26507         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26508
26509         /* Compare */
26510         static const GLuint comp_size = 4;
26511         static const GLuint vec4_size = 16;
26512
26513         int res_goku_x =
26514                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26515         int res_goku_z =
26516                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26517
26518         int res_gohan_y =
26519                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26520         int res_gohan_w =
26521                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26522
26523         int res_goten_x =
26524                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26525         int res_goten_y =
26526                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26527
26528         int res_chichi_z =
26529                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26530         int res_chichi_w =
26531                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26532
26533         int res_vegeta_x =
26534                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26535
26536         int res_trunks_y =
26537                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26538
26539         int res_bra_z =
26540                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26541
26542         int res_bulma_w =
26543                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26544
26545         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26546                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26547                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26548         {
26549                 m_context.getTestContext().getLog()
26550                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26551                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26552
26553                 result = false;
26554         }
26555
26556         /* Release buffer mapping */
26557         buffer->UnMap();
26558
26559         return result;
26560 }
26561
26562 /** Constructor
26563  *
26564  * @param context Test context
26565  **/
26566 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26567         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26568                                          "Test verifies that inactive block members are captured")
26569 {
26570         /* Nothing to be done here */
26571 }
26572
26573 /** Execute drawArrays for single vertex
26574  *
26575  * @param test_case_index
26576  *
26577  * @return true
26578  **/
26579 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(GLuint test_case_index)
26580 {
26581         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26582         GLenum                   primitive_type = GL_PATCHES;
26583
26584         if (TEST_VS == test_case_index)
26585         {
26586                 primitive_type = GL_POINTS;
26587         }
26588
26589         gl.disable(GL_RASTERIZER_DISCARD);
26590         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26591
26592         gl.beginTransformFeedback(GL_POINTS);
26593         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26594
26595         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26596         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26597
26598         gl.endTransformFeedback();
26599         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26600
26601         return true;
26602 }
26603
26604 /** Get descriptors of buffers necessary for test
26605  *
26606  * @param ignored
26607  * @param out_descriptors Descriptors of buffers used by test
26608  **/
26609 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26610                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26611 {
26612         const Utils::Type& type = Utils::Type::vec4;
26613
26614         /* Test needs single uniform and xfb */
26615         out_descriptors.resize(2);
26616
26617         /* Get references */
26618         bufferDescriptor& uniform = out_descriptors[0];
26619         bufferDescriptor& xfb    = out_descriptors[1];
26620
26621         /* Index */
26622         uniform.m_index = 0;
26623         xfb.m_index             = 0;
26624
26625         /* Target */
26626         uniform.m_target = Utils::Buffer::Uniform;
26627         xfb.m_target     = Utils::Buffer::Transform_feedback;
26628
26629         /* Data */
26630         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26631         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26632
26633         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26634
26635         /* Uniform data */
26636         uniform.m_initial_data.resize(2 * type_size);
26637         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26638         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26639
26640         /* XFB data */
26641         xfb.m_initial_data.resize(4 * type_size);
26642         xfb.m_expected_data.resize(4 * type_size);
26643
26644         for (GLuint i = 0; i < 4 * type_size; ++i)
26645         {
26646                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26647                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26648         }
26649
26650         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26651         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26652 }
26653
26654 /** Get body of main function for given shader stage
26655  *
26656  * @param test_case_index  Index of test case
26657  * @param stage            Shader stage
26658  * @param out_assignments  Set to empty
26659  * @param out_calculations Set to empty
26660  **/
26661 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26662                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26663 {
26664         out_calculations = "";
26665
26666         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26667                                                                          "    gohan  = uni_gohan;\n";
26668         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26669
26670         const GLchar* assignments = "";
26671
26672         switch (stage)
26673         {
26674         case Utils::Shader::FRAGMENT:
26675                 assignments = fs;
26676                 break;
26677
26678         case Utils::Shader::GEOMETRY:
26679                 if (TEST_GS == test_case_index)
26680                 {
26681                         assignments = vs_tes_gs;
26682                 }
26683                 break;
26684
26685         case Utils::Shader::TESS_CTRL:
26686                 break;
26687
26688         case Utils::Shader::TESS_EVAL:
26689                 if (TEST_TES == test_case_index)
26690                 {
26691                         assignments = vs_tes_gs;
26692                 }
26693                 break;
26694
26695         case Utils::Shader::VERTEX:
26696                 if (TEST_VS == test_case_index)
26697                 {
26698                         assignments = vs_tes_gs;
26699                 }
26700                 break;
26701
26702         default:
26703                 TCU_FAIL("Invalid enum");
26704         }
26705
26706         out_assignments = assignments;
26707 }
26708
26709 /** Get interface of shader
26710  *
26711  * @param test_case_index  Index of test case
26712  * @param stage            Shader stage
26713  * @param out_interface    Set to ""
26714  **/
26715 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26716                                                                                                                                  std::string& out_interface)
26717 {
26718         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26719                                                                          "\n"
26720                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26721                                                                          "    vec4 gohan;\n"
26722                                                                          "    vec4 goten;\n"
26723                                                                          "    vec4 chichi;\n"
26724                                                                          "};\n"
26725                                                                          "\n"
26726                                                                          "layout(binding = 0) uniform block {\n"
26727                                                                          "    vec4 uni_gohan;\n"
26728                                                                          "    vec4 uni_chichi;\n"
26729                                                                          "};\n";
26730         static const GLchar* fs = "in Goku {\n"
26731                                                           "    vec4 gohan;\n"
26732                                                           "    vec4 goten;\n"
26733                                                           "    vec4 chichi;\n"
26734                                                           "};\n"
26735                                                           "out vec4 fs_out;\n";
26736
26737         const GLchar* interface = "";
26738
26739         switch (stage)
26740         {
26741         case Utils::Shader::FRAGMENT:
26742                 interface = fs;
26743                 break;
26744
26745         case Utils::Shader::GEOMETRY:
26746                 if (TEST_GS == test_case_index)
26747                 {
26748                         interface = vs_tes_gs;
26749                 }
26750                 break;
26751
26752         case Utils::Shader::TESS_CTRL:
26753                 break;
26754
26755         case Utils::Shader::TESS_EVAL:
26756                 if (TEST_TES == test_case_index)
26757                 {
26758                         interface = vs_tes_gs;
26759                 }
26760                 break;
26761
26762         case Utils::Shader::VERTEX:
26763                 if (TEST_VS == test_case_index)
26764                 {
26765                         interface = vs_tes_gs;
26766                 }
26767                 break;
26768
26769         default:
26770                 TCU_FAIL("Invalid enum");
26771         }
26772
26773         out_interface = interface;
26774 }
26775
26776 /** Get source code of shader
26777  *
26778  * @param test_case_index Index of test case
26779  * @param stage           Shader stage
26780  *
26781  * @return Source
26782  **/
26783 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26784                                                                                                                                          Utils::Shader::STAGES stage)
26785 {
26786         std::string source;
26787
26788         switch (test_case_index)
26789         {
26790         case TEST_VS:
26791                 switch (stage)
26792                 {
26793                 case Utils::Shader::FRAGMENT:
26794                 case Utils::Shader::VERTEX:
26795                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26796                         break;
26797                 default:
26798                         break;
26799                 }
26800                 break;
26801
26802         case TEST_TES:
26803                 switch (stage)
26804                 {
26805                 case Utils::Shader::FRAGMENT:
26806                 case Utils::Shader::TESS_CTRL:
26807                 case Utils::Shader::TESS_EVAL:
26808                 case Utils::Shader::VERTEX:
26809                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26810                         break;
26811                 default:
26812                         break;
26813                 }
26814                 break;
26815
26816         case TEST_GS:
26817                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26818                 break;
26819
26820         default:
26821                 TCU_FAIL("Invalid enum");
26822                 break;
26823         }
26824
26825         /* */
26826         return source;
26827 }
26828
26829 /** Get name of test case
26830  *
26831  * @param test_case_index Index of test case
26832  *
26833  * @return Name of tested stage
26834  **/
26835 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26836 {
26837         const GLchar* name = 0;
26838
26839         switch (test_case_index)
26840         {
26841         case TEST_VS:
26842                 name = "vertex";
26843                 break;
26844         case TEST_TES:
26845                 name = "tesselation evaluation";
26846                 break;
26847         case TEST_GS:
26848                 name = "geometry";
26849                 break;
26850         default:
26851                 TCU_FAIL("Invalid enum");
26852         }
26853
26854         return name;
26855 }
26856
26857 /** Returns number of test cases
26858  *
26859  * @return TEST_MAX
26860  **/
26861 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26862 {
26863         return TEST_MAX;
26864 }
26865
26866 /** Verify contents of buffers
26867  *
26868  * @param buffers Collection of buffers to be verified
26869  *
26870  * @return true if everything is as expected, false otherwise
26871  **/
26872 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26873 {
26874         bool result = true;
26875
26876         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26877         Utils::Buffer*                  buffer   = pair.m_buffer;
26878         bufferDescriptor*               descriptor = pair.m_descriptor;
26879
26880         /* Get pointer to contents of buffer */
26881         buffer->Bind();
26882         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26883
26884         /* Get pointer to expected data */
26885         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26886
26887         /* Compare */
26888         static const GLuint vec4_size = 16;
26889
26890         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26891         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26892         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26893
26894         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26895         {
26896                 m_context.getTestContext().getLog()
26897                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26898                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26899
26900                 result = false;
26901         }
26902
26903         /* Release buffer mapping */
26904         buffer->UnMap();
26905
26906         return result;
26907 }
26908
26909 /** Constructor
26910  *
26911  * @param context Test context
26912  **/
26913 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26914         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26915 {
26916         /* Nothing to be done here */
26917 }
26918
26919 /** Execute drawArrays for single vertex
26920  *
26921  * @param test_case_index
26922  *
26923  * @return true
26924  **/
26925 bool XFBCaptureStructTest::executeDrawCall(GLuint test_case_index)
26926 {
26927         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26928         GLenum                   primitive_type = GL_PATCHES;
26929
26930         if (TEST_VS == test_case_index)
26931         {
26932                 primitive_type = GL_POINTS;
26933         }
26934
26935         gl.disable(GL_RASTERIZER_DISCARD);
26936         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26937
26938         gl.beginTransformFeedback(GL_POINTS);
26939         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26940
26941         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26942         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26943
26944         gl.endTransformFeedback();
26945         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26946
26947         return true;
26948 }
26949
26950 /** Get descriptors of buffers necessary for test
26951  *
26952  * @param ignored
26953  * @param out_descriptors Descriptors of buffers used by test
26954  **/
26955 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26956                                                                                                 bufferDescriptor::Vector& out_descriptors)
26957 {
26958         const Utils::Type& type = Utils::Type::vec4;
26959
26960         /* Test needs single uniform and xfb */
26961         out_descriptors.resize(2);
26962
26963         /* Get references */
26964         bufferDescriptor& uniform = out_descriptors[0];
26965         bufferDescriptor& xfb    = out_descriptors[1];
26966
26967         /* Index */
26968         uniform.m_index = 0;
26969         xfb.m_index             = 0;
26970
26971         /* Target */
26972         uniform.m_target = Utils::Buffer::Uniform;
26973         xfb.m_target     = Utils::Buffer::Transform_feedback;
26974
26975         /* Data */
26976         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26977         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26978
26979         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26980
26981         /* Uniform data */
26982         uniform.m_initial_data.resize(2 * type_size);
26983         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26984         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26985
26986         /* XFB data */
26987         xfb.m_initial_data.resize(4 * type_size);
26988         xfb.m_expected_data.resize(4 * type_size);
26989
26990         for (GLuint i = 0; i < 4 * type_size; ++i)
26991         {
26992                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26993                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26994         }
26995
26996         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26997         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26998 }
26999
27000 /** Get body of main function for given shader stage
27001  *
27002  * @param test_case_index  Index of test case
27003  * @param stage            Shader stage
27004  * @param out_assignments  Set to empty
27005  * @param out_calculations Set to empty
27006  **/
27007 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27008                                                                                  std::string& out_assignments, std::string& out_calculations)
27009 {
27010         out_calculations = "";
27011
27012         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27013                                                                          "    goku.gohan  = uni_gohan;\n";
27014         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27015
27016         const GLchar* assignments = "";
27017
27018         switch (stage)
27019         {
27020         case Utils::Shader::FRAGMENT:
27021                 assignments = fs;
27022                 break;
27023
27024         case Utils::Shader::GEOMETRY:
27025                 if (TEST_GS == test_case_index)
27026                 {
27027                         assignments = vs_tes_gs;
27028                 }
27029                 break;
27030
27031         case Utils::Shader::TESS_CTRL:
27032                 break;
27033
27034         case Utils::Shader::TESS_EVAL:
27035                 if (TEST_TES == test_case_index)
27036                 {
27037                         assignments = vs_tes_gs;
27038                 }
27039                 break;
27040
27041         case Utils::Shader::VERTEX:
27042                 if (TEST_VS == test_case_index)
27043                 {
27044                         assignments = vs_tes_gs;
27045                 }
27046                 break;
27047
27048         default:
27049                 TCU_FAIL("Invalid enum");
27050         }
27051
27052         out_assignments = assignments;
27053 }
27054
27055 /** Get interface of shader
27056  *
27057  * @param test_case_index  Index of test case
27058  * @param stage            Shader stage
27059  * @param out_interface    Set to ""
27060  **/
27061 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27062                                                                                           std::string& out_interface)
27063 {
27064         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27065                                                                          "\n"
27066                                                                          "struct Goku {\n"
27067                                                                          "    vec4 gohan;\n"
27068                                                                          "    vec4 goten;\n"
27069                                                                          "    vec4 chichi;\n"
27070                                                                          "};\n"
27071                                                                          "\n"
27072                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27073                                                                          "\n"
27074                                                                          "layout(binding = 0, std140) uniform block {\n"
27075                                                                          "    vec4 uni_gohan;\n"
27076                                                                          "    vec4 uni_chichi;\n"
27077                                                                          "};\n";
27078         static const GLchar* fs = "struct Goku {\n"
27079                                                           "    vec4 gohan;\n"
27080                                                           "    vec4 goten;\n"
27081                                                           "    vec4 chichi;\n"
27082                                                           "};\n"
27083                                                           "\n"
27084                                                           "in Goku goku;\n"
27085                                                           "\n"
27086                                                           "out vec4 fs_out;\n";
27087
27088         const GLchar* interface = "";
27089
27090         switch (stage)
27091         {
27092         case Utils::Shader::FRAGMENT:
27093                 interface = fs;
27094                 break;
27095
27096         case Utils::Shader::GEOMETRY:
27097                 if (TEST_GS == test_case_index)
27098                 {
27099                         interface = vs_tes_gs;
27100                 }
27101                 break;
27102
27103         case Utils::Shader::TESS_CTRL:
27104                 break;
27105
27106         case Utils::Shader::TESS_EVAL:
27107                 if (TEST_TES == test_case_index)
27108                 {
27109                         interface = vs_tes_gs;
27110                 }
27111                 break;
27112
27113         case Utils::Shader::VERTEX:
27114                 if (TEST_VS == test_case_index)
27115                 {
27116                         interface = vs_tes_gs;
27117                 }
27118                 break;
27119
27120         default:
27121                 TCU_FAIL("Invalid enum");
27122         }
27123
27124         out_interface = interface;
27125 }
27126
27127 /** Get source code of shader
27128  *
27129  * @param test_case_index Index of test case
27130  * @param stage           Shader stage
27131  *
27132  * @return Source
27133  **/
27134 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27135 {
27136         std::string source;
27137
27138         switch (test_case_index)
27139         {
27140         case TEST_VS:
27141                 switch (stage)
27142                 {
27143                 case Utils::Shader::FRAGMENT:
27144                 case Utils::Shader::VERTEX:
27145                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27146                         break;
27147                 default:
27148                         break;
27149                 }
27150                 break;
27151
27152         case TEST_TES:
27153                 switch (stage)
27154                 {
27155                 case Utils::Shader::FRAGMENT:
27156                 case Utils::Shader::TESS_CTRL:
27157                 case Utils::Shader::TESS_EVAL:
27158                 case Utils::Shader::VERTEX:
27159                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27160                         break;
27161                 default:
27162                         break;
27163                 }
27164                 break;
27165
27166         case TEST_GS:
27167                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27168                 break;
27169
27170         default:
27171                 TCU_FAIL("Invalid enum");
27172                 break;
27173         }
27174
27175         /* */
27176         return source;
27177 }
27178
27179 /** Get name of test case
27180  *
27181  * @param test_case_index Index of test case
27182  *
27183  * @return Name of tested stage
27184  **/
27185 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27186 {
27187         const GLchar* name = 0;
27188
27189         switch (test_case_index)
27190         {
27191         case TEST_VS:
27192                 name = "vertex";
27193                 break;
27194         case TEST_TES:
27195                 name = "tesselation evaluation";
27196                 break;
27197         case TEST_GS:
27198                 name = "geometry";
27199                 break;
27200         default:
27201                 TCU_FAIL("Invalid enum");
27202         }
27203
27204         return name;
27205 }
27206
27207 /** Returns number of test cases
27208  *
27209  * @return TEST_MAX
27210  **/
27211 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27212 {
27213         return TEST_MAX;
27214 }
27215
27216 /** Verify contents of buffers
27217  *
27218  * @param buffers Collection of buffers to be verified
27219  *
27220  * @return true if everything is as expected, false otherwise
27221  **/
27222 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27223 {
27224         bool result = true;
27225
27226         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27227         Utils::Buffer*                  buffer   = pair.m_buffer;
27228         bufferDescriptor*               descriptor = pair.m_descriptor;
27229
27230         /* Get pointer to contents of buffer */
27231         buffer->Bind();
27232         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27233
27234         /* Get pointer to expected data */
27235         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27236
27237         /* Compare */
27238         static const GLuint vec4_size = 16;
27239
27240         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27241         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27242         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27243
27244         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27245         {
27246                 m_context.getTestContext().getLog()
27247                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27248                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27249
27250                 result = false;
27251         }
27252
27253         /* Release buffer mapping */
27254         buffer->UnMap();
27255
27256         return result;
27257 }
27258
27259 /** Constructor
27260  *
27261  * @param context Test framework context
27262  **/
27263 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27264         : NegativeTestBase(context, "xfb_capture_unsized_array",
27265                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27266 {
27267 }
27268
27269 /** Source for given test case and stage
27270  *
27271  * @param test_case_index Index of test case
27272  * @param stage           Shader stage
27273  *
27274  * @return Shader source
27275  **/
27276 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27277 {
27278         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27279         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27280         static const GLchar* fs                         = "#version 430 core\n"
27281                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27282                                                           "\n"
27283                                                           "in  vec4 gs_fs;\n"
27284                                                           "out vec4 fs_out;\n"
27285                                                           "\n"
27286                                                           "void main()\n"
27287                                                           "{\n"
27288                                                           "    fs_out = gs_fs;\n"
27289                                                           "}\n"
27290                                                           "\n";
27291         static const GLchar* gs_tested = "#version 430 core\n"
27292                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27293                                                                          "\n"
27294                                                                          "layout(points)                           in;\n"
27295                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27296                                                                          "\n"
27297                                                                          "VAR_DEFINITION"
27298                                                                          "\n"
27299                                                                          "in  vec4 tes_gs[];\n"
27300                                                                          "out vec4 gs_fs;\n"
27301                                                                          "\n"
27302                                                                          "void main()\n"
27303                                                                          "{\n"
27304                                                                          "    vec4 result = tes_gs[0];\n"
27305                                                                          "\n"
27306                                                                          "VARIABLE_USE"
27307                                                                          "\n"
27308                                                                          "    gs_fs = result;\n"
27309                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27310                                                                          "    EmitVertex();\n"
27311                                                                          "    gs_fs = result;\n"
27312                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27313                                                                          "    EmitVertex();\n"
27314                                                                          "    gs_fs = result;\n"
27315                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27316                                                                          "    EmitVertex();\n"
27317                                                                          "    gs_fs = result;\n"
27318                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27319                                                                          "    EmitVertex();\n"
27320                                                                          "}\n"
27321                                                                          "\n";
27322         static const GLchar* tcs = "#version 430 core\n"
27323                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27324                                                            "\n"
27325                                                            "layout(vertices = 1) out;\n"
27326                                                            "\n"
27327                                                            "in  vec4 vs_tcs[];\n"
27328                                                            "out vec4 tcs_tes[];\n"
27329                                                            "\n"
27330                                                            "void main()\n"
27331                                                            "{\n"
27332                                                            "\n"
27333                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27334                                                            "\n"
27335                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27336                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27337                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27338                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27339                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27340                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27341                                                            "}\n"
27342                                                            "\n";
27343         static const GLchar* tcs_tested = "#version 430 core\n"
27344                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27345                                                                           "\n"
27346                                                                           "layout(vertices = 1) out;\n"
27347                                                                           "\n"
27348                                                                           "VAR_DEFINITION"
27349                                                                           "\n"
27350                                                                           "in  vec4 vs_tcs[];\n"
27351                                                                           "out vec4 tcs_tes[];\n"
27352                                                                           "\n"
27353                                                                           "void main()\n"
27354                                                                           "{\n"
27355                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27356                                                                           "\n"
27357                                                                           "VARIABLE_USE"
27358                                                                           "\n"
27359                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27360                                                                           "\n"
27361                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27362                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27363                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27364                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27365                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27366                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27367                                                                           "}\n"
27368                                                                           "\n";
27369         static const GLchar* tes_tested = "#version 430 core\n"
27370                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27371                                                                           "\n"
27372                                                                           "layout(isolines, point_mode) in;\n"
27373                                                                           "\n"
27374                                                                           "VAR_DEFINITION"
27375                                                                           "\n"
27376                                                                           "in  vec4 tcs_tes[];\n"
27377                                                                           "out vec4 tes_gs;\n"
27378                                                                           "\n"
27379                                                                           "void main()\n"
27380                                                                           "{\n"
27381                                                                           "    vec4 result = tcs_tes[0];\n"
27382                                                                           "\n"
27383                                                                           "VARIABLE_USE"
27384                                                                           "\n"
27385                                                                           "    tes_gs += result;\n"
27386                                                                           "}\n"
27387                                                                           "\n";
27388         static const GLchar* vs = "#version 430 core\n"
27389                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27390                                                           "\n"
27391                                                           "in  vec4 in_vs;\n"
27392                                                           "out vec4 vs_tcs;\n"
27393                                                           "\n"
27394                                                           "void main()\n"
27395                                                           "{\n"
27396                                                           "    vs_tcs = in_vs;\n"
27397                                                           "}\n"
27398                                                           "\n";
27399         static const GLchar* vs_tested = "#version 430 core\n"
27400                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27401                                                                          "\n"
27402                                                                          "VAR_DEFINITION"
27403                                                                          "\n"
27404                                                                          "in  vec4 in_vs;\n"
27405                                                                          "out vec4 vs_tcs;\n"
27406                                                                          "\n"
27407                                                                          "void main()\n"
27408                                                                          "{\n"
27409                                                                          "    vec4 result = in_vs;\n"
27410                                                                          "\n"
27411                                                                          "VARIABLE_USE"
27412                                                                          "\n"
27413                                                                          "    vs_tcs = result;\n"
27414                                                                          "}\n"
27415                                                                          "\n";
27416
27417         std::string source;
27418         testCase&   test_case = m_test_cases[test_case_index];
27419
27420         if (test_case.m_stage == stage)
27421         {
27422                 const GLchar* array     = "";
27423                 const GLchar* index     = "";
27424                 size_t            position = 0;
27425
27426                 switch (stage)
27427                 {
27428                 case Utils::Shader::GEOMETRY:
27429                         source = gs_tested;
27430                         array  = "[]";
27431                         index  = "[0]";
27432                         break;
27433                 case Utils::Shader::TESS_CTRL:
27434                         source = tcs_tested;
27435                         array  = "[]";
27436                         index  = "[gl_InvocationID]";
27437                         break;
27438                 case Utils::Shader::TESS_EVAL:
27439                         source = tes_tested;
27440                         array  = "[]";
27441                         index  = "[0]";
27442                         break;
27443                 case Utils::Shader::VERTEX:
27444                         source = vs_tested;
27445                         break;
27446                 default:
27447                         TCU_FAIL("Invalid enum");
27448                 }
27449
27450                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27451                 position = 0;
27452                 Utils::replaceToken("ARRAY", position, array, source);
27453                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27454
27455                 Utils::replaceAllTokens("INDEX", index, source);
27456         }
27457         else
27458         {
27459                 switch (test_case.m_stage)
27460                 {
27461                 case Utils::Shader::GEOMETRY:
27462                         switch (stage)
27463                         {
27464                         case Utils::Shader::FRAGMENT:
27465                                 source = fs;
27466                                 break;
27467                         case Utils::Shader::VERTEX:
27468                                 source = vs;
27469                                 break;
27470                         default:
27471                                 source = "";
27472                         }
27473                         break;
27474                 case Utils::Shader::TESS_CTRL:
27475                         switch (stage)
27476                         {
27477                         case Utils::Shader::FRAGMENT:
27478                                 source = fs;
27479                                 break;
27480                         case Utils::Shader::VERTEX:
27481                                 source = vs;
27482                                 break;
27483                         default:
27484                                 source = "";
27485                         }
27486                         break;
27487                 case Utils::Shader::TESS_EVAL:
27488                         switch (stage)
27489                         {
27490                         case Utils::Shader::FRAGMENT:
27491                                 source = fs;
27492                                 break;
27493                         case Utils::Shader::TESS_CTRL:
27494                                 source = tcs;
27495                                 break;
27496                         case Utils::Shader::VERTEX:
27497                                 source = vs;
27498                                 break;
27499                         default:
27500                                 source = "";
27501                         }
27502                         break;
27503                 case Utils::Shader::VERTEX:
27504                         switch (stage)
27505                         {
27506                         case Utils::Shader::FRAGMENT:
27507                                 source = fs;
27508                                 break;
27509                         default:
27510                                 source = "";
27511                         }
27512                         break;
27513                 default:
27514                         TCU_FAIL("Invalid enum");
27515                         break;
27516                 }
27517         }
27518
27519         return source;
27520 }
27521
27522 /** Get description of test case
27523  *
27524  * @param test_case_index Index of test case
27525  *
27526  * @return Test case description
27527  **/
27528 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27529 {
27530         std::stringstream stream;
27531         testCase&                 test_case = m_test_cases[test_case_index];
27532
27533         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27534
27535         return stream.str();
27536 }
27537
27538 /** Get number of test cases
27539  *
27540  * @return Number of test cases
27541  **/
27542 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27543 {
27544         return static_cast<GLuint>(m_test_cases.size());
27545 }
27546
27547 /** Selects if "compute" stage is relevant for test
27548  *
27549  * @param ignored
27550  *
27551  * @return false
27552  **/
27553 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27554 {
27555         return false;
27556 }
27557
27558 /** Prepare all test cases
27559  *
27560  **/
27561 void XFBCaptureUnsizedArrayTest::testInit()
27562 {
27563         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27564         {
27565                 /* Not aplicable for */
27566                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27567                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27568                 {
27569                         continue;
27570                 }
27571
27572                 testCase test_case = { (Utils::Shader::STAGES)stage };
27573
27574                 m_test_cases.push_back(test_case);
27575         }
27576 }
27577 } /* EnhancedLayouts namespace */
27578
27579 /** Constructor.
27580  *
27581  *  @param context Rendering context.
27582  **/
27583 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27584         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27585 {
27586         /* Left blank on purpose */
27587 }
27588
27589 /** Initializes a texture_storage_multisample test group.
27590  *
27591  **/
27592 void EnhancedLayoutsTests::init(void)
27593 {
27594         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27595         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27596         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27597         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27598         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27599         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27600         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27601         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27602         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27603         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27604         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27605         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27606         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27607         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27608         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27609         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27610         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27611         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27612
27613         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27614         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27615         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27616         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27617         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27618         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27619         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27620         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27621         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27622         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27623         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27624         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27625         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27626         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27627         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27628         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27629         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27630         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27631         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27632         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27633         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27634         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27635         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27636         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27637         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27638         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27639         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27640         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27641         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27642         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27643         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27644         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27645         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27646         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27647         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27648         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27649         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27650         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27651         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27652         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27653         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27654         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27655         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27656         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27657         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27658 }
27659
27660 } /* gl4cts namespace */