60afa14ecbd0ad12eccabd1ea2b546d678bbecf3
[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 or if it's a vertex shader input.
504  **/
505 GLuint Type::GetLocations(bool is_vs_input) 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) || is_vs_input)
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.
524  * Note that this routine doesn't consider arrays and assumes
525  * column_major matrices.
526  *
527  * @return Formula:
528  *          - If std140 packaging and matrix; number of columns * base alignment
529  *          - Otherwise; number of elements * sizeof(base_type)
530  **/
531 GLuint Type::GetSize(const bool is_std140) const
532 {
533         const GLuint basic_type_size = GetTypeSize(m_basic_type);
534         const GLuint n_elements          = m_n_columns * m_n_rows;
535
536         if (is_std140 && m_n_columns > 1)
537         {
538                 return m_n_columns * GetBaseAlignment(false);
539         }
540
541         return basic_type_size * n_elements;
542 }
543
544 /** Get GLenum representing the type
545  *
546  * @return GLenum
547  **/
548 GLenum Type::GetTypeGLenum() const
549 {
550         static const GLenum float_lut[4][4] = {
551                 { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 },
552                 { 0, GL_FLOAT_MAT2, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4 },
553                 { 0, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3, GL_FLOAT_MAT3x4 },
554                 { 0, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3, GL_FLOAT_MAT4 },
555         };
556
557         static const GLenum double_lut[4][4] = {
558                 { GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4 },
559                 { 0, GL_DOUBLE_MAT2, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4 },
560                 { 0, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT3x4 },
561                 { 0, GL_DOUBLE_MAT4x2, GL_DOUBLE_MAT4x3, GL_DOUBLE_MAT4 },
562         };
563
564         static const GLenum int_lut[4] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
565
566         static const GLenum uint_lut[4] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3,
567                                                                                 GL_UNSIGNED_INT_VEC4 };
568
569         GLenum result = 0;
570
571         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
572         {
573                 return 0;
574         }
575
576         switch (m_basic_type)
577         {
578         case Float:
579                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
580                 break;
581         case Double:
582                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
583                 break;
584         case Int:
585                 result = int_lut[m_n_rows - 1];
586                 break;
587         case Uint:
588                 result = uint_lut[m_n_rows - 1];
589                 break;
590         default:
591                 TCU_FAIL("Invliad enum");
592         }
593
594         return result;
595 }
596
597 /** Calculate the numbe of components consumed by a type
598  *   according to 11.1.2.1 Output Variables
599  *
600  * @return Calculated number of components for the type
601  **/
602 GLuint Type::GetNumComponents() const
603 {
604         // Rule 3 of Section 7.6.2.2
605         // If the member is a three-component vector with components consuming N
606         // basic machine units, the base alignment is 4N.
607         GLuint num_components = (m_n_rows == 3 ? 4 : m_n_rows) * m_n_columns;
608
609         if (m_basic_type == Double)
610         {
611                 num_components *= 2;
612         }
613
614         return num_components;
615 }
616
617 /** Calculate stride for the type according to std140 rules
618  *
619  * @param alignment        Alignment of type
620  * @param n_columns        Number of columns
621  * @param n_array_elements Number of elements in array
622  *
623  * @return Calculated value
624  **/
625 GLuint Type::CalculateStd140Stride(GLuint alignment, GLuint n_columns, GLuint n_array_elements)
626 {
627         GLuint stride = alignment * n_columns;
628         if (0 != n_array_elements)
629         {
630                 stride *= n_array_elements;
631         }
632
633         return stride;
634 }
635
636 /** Check if glsl support matrices for specific basic type
637  *
638  * @param type Basic type
639  *
640  * @return true if matrices of <type> are supported, false otherwise
641  **/
642 bool Type::DoesTypeSupportMatrix(TYPES type)
643 {
644         bool result = false;
645
646         switch (type)
647         {
648         case Float:
649         case Double:
650                 result = true;
651                 break;
652         case Int:
653         case Uint:
654                 result = false;
655                 break;
656         default:
657                 TCU_FAIL("Invliad enum");
658         }
659
660         return result;
661 }
662
663 /** Creates instance of Type
664  *
665  * @param basic_type Select basic type of instance
666  * @param n_columns  Number of columns
667  * @param n_rows     Number of rows
668  *
669  * @return Type instance
670  **/
671 Type Type::GetType(TYPES basic_type, glw::GLuint n_columns, glw::GLuint n_rows)
672 {
673         Type type = { basic_type, n_columns, n_rows };
674
675         return type;
676 }
677
678 /** Get Size of given type in bytes
679  *
680  * @param type
681  *
682  * @return Size of type
683  **/
684 GLuint Type::GetTypeSize(TYPES type)
685 {
686         GLuint result = 0;
687
688         switch (type)
689         {
690         case Float:
691                 result = sizeof(GLfloat);
692                 break;
693         case Double:
694                 result = sizeof(GLdouble);
695                 break;
696         case Int:
697                 result = sizeof(GLint);
698                 break;
699         case Uint:
700                 result = sizeof(GLuint);
701                 break;
702         default:
703                 TCU_FAIL("Invalid enum");
704         }
705
706         return result;
707 }
708
709 /** Get GLenum representing given type
710  *
711  * @param type
712  *
713  * @return GLenum value
714  **/
715 GLenum Type::GetTypeGLenum(TYPES type)
716 {
717         GLenum result = 0;
718
719         switch (type)
720         {
721         case Float:
722                 result = GL_FLOAT;
723                 break;
724         case Double:
725                 result = GL_DOUBLE;
726                 break;
727         case Int:
728                 result = GL_INT;
729                 break;
730         case Uint:
731                 result = GL_UNSIGNED_INT;
732                 break;
733         default:
734                 TCU_FAIL("Invalid enum");
735         }
736
737         return result;
738 }
739
740 /** Get proper glUniformNdv routine for vectors with specified number of rows
741  *
742  * @param gl     GL functions
743  * @param n_rows Number of rows
744  *
745  * @return Function address
746  **/
747 uniformNdv getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
748 {
749         uniformNdv result = 0;
750
751         switch (n_rows)
752         {
753         case 1:
754                 result = gl.uniform1dv;
755                 break;
756         case 2:
757                 result = gl.uniform2dv;
758                 break;
759         case 3:
760                 result = gl.uniform3dv;
761                 break;
762         case 4:
763                 result = gl.uniform4dv;
764                 break;
765         default:
766                 TCU_FAIL("Invalid number of rows");
767         }
768
769         return result;
770 }
771
772 /** Get proper glUniformNfv routine for vectors with specified number of rows
773  *
774  * @param gl     GL functions
775  * @param n_rows Number of rows
776  *
777  * @return Function address
778  **/
779 uniformNfv getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
780 {
781         uniformNfv result = 0;
782
783         switch (n_rows)
784         {
785         case 1:
786                 result = gl.uniform1fv;
787                 break;
788         case 2:
789                 result = gl.uniform2fv;
790                 break;
791         case 3:
792                 result = gl.uniform3fv;
793                 break;
794         case 4:
795                 result = gl.uniform4fv;
796                 break;
797         default:
798                 TCU_FAIL("Invalid number of rows");
799         }
800
801         return result;
802 }
803
804 /** Get proper glUniformNiv routine for vectors with specified number of rows
805  *
806  * @param gl     GL functions
807  * @param n_rows Number of rows
808  *
809  * @return Function address
810  **/
811 uniformNiv getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
812 {
813         uniformNiv result = 0;
814
815         switch (n_rows)
816         {
817         case 1:
818                 result = gl.uniform1iv;
819                 break;
820         case 2:
821                 result = gl.uniform2iv;
822                 break;
823         case 3:
824                 result = gl.uniform3iv;
825                 break;
826         case 4:
827                 result = gl.uniform4iv;
828                 break;
829         default:
830                 TCU_FAIL("Invalid number of rows");
831         }
832
833         return result;
834 }
835
836 /** Get proper glUniformNuiv routine for vectors with specified number of rows
837  *
838  * @param gl     GL functions
839  * @param n_rows Number of rows
840  *
841  * @return Function address
842  **/
843 uniformNuiv getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
844 {
845         uniformNuiv result = 0;
846
847         switch (n_rows)
848         {
849         case 1:
850                 result = gl.uniform1uiv;
851                 break;
852         case 2:
853                 result = gl.uniform2uiv;
854                 break;
855         case 3:
856                 result = gl.uniform3uiv;
857                 break;
858         case 4:
859                 result = gl.uniform4uiv;
860                 break;
861         default:
862                 TCU_FAIL("Invalid number of rows");
863         }
864
865         return result;
866 }
867
868 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
869  *
870  * @param gl     GL functions
871  * @param n_rows Number of rows
872  *
873  * @return Function address
874  **/
875 uniformMatrixNdv getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
876 {
877         uniformMatrixNdv result = 0;
878
879         switch (n_columns)
880         {
881         case 2:
882                 switch (n_rows)
883                 {
884                 case 2:
885                         result = gl.uniformMatrix2dv;
886                         break;
887                 case 3:
888                         result = gl.uniformMatrix2x3dv;
889                         break;
890                 case 4:
891                         result = gl.uniformMatrix2x4dv;
892                         break;
893                 default:
894                         TCU_FAIL("Invalid number of rows");
895                 }
896                 break;
897         case 3:
898                 switch (n_rows)
899                 {
900                 case 2:
901                         result = gl.uniformMatrix3x2dv;
902                         break;
903                 case 3:
904                         result = gl.uniformMatrix3dv;
905                         break;
906                 case 4:
907                         result = gl.uniformMatrix3x4dv;
908                         break;
909                 default:
910                         TCU_FAIL("Invalid number of rows");
911                 }
912                 break;
913         case 4:
914                 switch (n_rows)
915                 {
916                 case 2:
917                         result = gl.uniformMatrix4x2dv;
918                         break;
919                 case 3:
920                         result = gl.uniformMatrix4x3dv;
921                         break;
922                 case 4:
923                         result = gl.uniformMatrix4dv;
924                         break;
925                 default:
926                         TCU_FAIL("Invalid number of rows");
927                 }
928                 break;
929         default:
930                 TCU_FAIL("Invalid number of columns");
931         }
932
933         return result;
934 }
935
936 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
937  *
938  * @param gl     GL functions
939  * @param n_rows Number of rows
940  *
941  * @return Function address
942  **/
943 uniformMatrixNfv getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
944 {
945         uniformMatrixNfv result = 0;
946
947         switch (n_columns)
948         {
949         case 2:
950                 switch (n_rows)
951                 {
952                 case 2:
953                         result = gl.uniformMatrix2fv;
954                         break;
955                 case 3:
956                         result = gl.uniformMatrix2x3fv;
957                         break;
958                 case 4:
959                         result = gl.uniformMatrix2x4fv;
960                         break;
961                 default:
962                         TCU_FAIL("Invalid number of rows");
963                 }
964                 break;
965         case 3:
966                 switch (n_rows)
967                 {
968                 case 2:
969                         result = gl.uniformMatrix3x2fv;
970                         break;
971                 case 3:
972                         result = gl.uniformMatrix3fv;
973                         break;
974                 case 4:
975                         result = gl.uniformMatrix3x4fv;
976                         break;
977                 default:
978                         TCU_FAIL("Invalid number of rows");
979                 }
980                 break;
981         case 4:
982                 switch (n_rows)
983                 {
984                 case 2:
985                         result = gl.uniformMatrix4x2fv;
986                         break;
987                 case 3:
988                         result = gl.uniformMatrix4x3fv;
989                         break;
990                 case 4:
991                         result = gl.uniformMatrix4fv;
992                         break;
993                 default:
994                         TCU_FAIL("Invalid number of rows");
995                 }
996                 break;
997         default:
998                 TCU_FAIL("Invalid number of columns");
999         }
1000
1001         return result;
1002 }
1003
1004 bool verifyVarying(Program& program, const std::string& parent_name, const Variable::Descriptor& desc,
1005                                    std::stringstream& stream, bool is_input)
1006 {
1007         GLint  component = 0;
1008         GLuint index     = 0;
1009         GLenum interface = GL_PROGRAM_INPUT;
1010         GLint  location  = 0;
1011
1012         if (false == is_input)
1013         {
1014                 interface = GL_PROGRAM_OUTPUT;
1015         }
1016
1017         const std::string& name = Utils::Variable::GetReference(parent_name, desc, Utils::Variable::BASIC, 0);
1018
1019         try
1020         {
1021                 index = program.GetResourceIndex(name, interface);
1022
1023                 program.GetResource(interface, index, GL_LOCATION, 1 /* size */, &location);
1024                 program.GetResource(interface, index, GL_LOCATION_COMPONENT, 1 /* size */, &component);
1025         }
1026         catch (std::exception& exc)
1027         {
1028                 stream << "Failed to query program for varying: " << desc.m_name << ". Reason: " << exc.what() << "\n";
1029
1030                 return false;
1031         }
1032
1033         bool result = true;
1034
1035         if (location != desc.m_expected_location)
1036         {
1037                 stream << "Attribute: " << desc.m_name << " - invalid location: " << location
1038                            << " expected: " << desc.m_expected_location << std::endl;
1039                 result = false;
1040         }
1041         if (component != desc.m_expected_component)
1042         {
1043                 stream << "Attribute: " << desc.m_name << " - invalid component: " << component
1044                            << " expected: " << desc.m_expected_component << std::endl;
1045                 result = false;
1046         }
1047
1048         return result;
1049 }
1050
1051 /** Query program resource for given variable and verify that everything is as expected
1052  *
1053  * @param program  Program object
1054  * @param variable Variable object
1055  * @param stream   Stream that will be used to log any error
1056  * @param is_input Selects if varying is input or output
1057  *
1058  * @return true if verification is positive, false otherwise
1059  **/
1060 bool checkVarying(Program& program, const Variable& variable, std::stringstream& stream, bool is_input)
1061 {
1062         bool result = true;
1063
1064         if (variable.IsBlock())
1065         {
1066                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1067                 const size_t      n_members = interface->m_members.size();
1068
1069                 for (size_t i = 0; i < n_members; ++i)
1070                 {
1071                         const Variable::Descriptor& member = interface->m_members[i];
1072                         bool member_result                                 = verifyVarying(program, interface->m_name, member, stream, is_input);
1073
1074                         if (false == member_result)
1075                         {
1076                                 result = false;
1077                         }
1078                 }
1079         }
1080         /*
1081          To query the the location of struct member by glGetProgramResource, we need pass the variable name "gs_fs_output[0].single",
1082          but in original implementation, the test pass the name "Data.single", which can't get any valid result.
1083          struct Data {
1084          dmat2 single;
1085          dmat2 array[1];
1086          };
1087          layout (location = 0) in Data gs_fs_output[1];
1088          */
1089         else if (variable.IsStruct())
1090         {
1091                 Utils::Interface* interface              = variable.m_descriptor.m_interface;
1092                 const size_t      n_members              = interface->m_members.size();
1093                 std::string               structVariable = variable.m_descriptor.m_name;
1094                 // If struct variable is an array
1095                 if (0 != variable.m_descriptor.m_n_array_elements)
1096                 {
1097                         for (GLuint i = 0; i < variable.m_descriptor.m_n_array_elements; i++)
1098                         {
1099                                 GLchar buffer[16];
1100                                 sprintf(buffer, "%d", i);
1101                                 structVariable.append("[");
1102                                 structVariable.append(buffer);
1103                                 structVariable.append("]");
1104                                 for (size_t j = 0; j < n_members; ++j)
1105                                 {
1106                                         const Variable::Descriptor& member = interface->m_members[j];
1107                                         bool member_result = verifyVarying(program, structVariable, member, stream, is_input);
1108
1109                                         if (false == member_result)
1110                                         {
1111                                                 result = false;
1112                                         }
1113                                 }
1114                         }
1115                 }
1116                 else
1117                 {
1118                         for (GLuint i = 0; i < n_members; ++i)
1119                         {
1120                                 const Variable::Descriptor& member = interface->m_members[i];
1121                                 bool member_result                                 = verifyVarying(program, structVariable, member, stream, is_input);
1122
1123                                 if (false == member_result)
1124                                 {
1125                                         result = false;
1126                                 }
1127                         }
1128                 }
1129         }
1130         else
1131         {
1132                 result = verifyVarying(program, "", variable.m_descriptor, stream, is_input);
1133         }
1134         return result;
1135 }
1136
1137 /** Query program resource for given variable and verify that everything is as expected
1138  *
1139  * @param program  Program object
1140  * @param variable Variable object
1141  * @param stream   Stream that will be used to log any error
1142  *
1143  * @return true if verification is positive, false otherwise
1144  **/
1145 bool checkUniform(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1146 {
1147         bool result = true;
1148
1149         if (false == variable.IsBlock())
1150         {
1151                 TCU_FAIL("Not implemented");
1152         }
1153         else
1154         {
1155                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1156
1157                 size_t size = interface->m_members.size();
1158
1159                 std::vector<GLuint>              indices;
1160                 std::vector<const char*> names;
1161                 std::vector<std::string> names_str;
1162                 std::vector<GLint>               offsets;
1163
1164                 indices.resize(size);
1165                 names.resize(size);
1166                 names_str.resize(size);
1167                 offsets.resize(size);
1168
1169                 for (size_t i = 0; i < size; ++i)
1170                 {
1171                         indices[i] = 0;
1172                         offsets[i] = 0;
1173
1174                         const std::string& name =
1175                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1176
1177                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1178                         {
1179                                 const std::string& member_name = Utils::Variable::GetReference(
1180                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1181
1182                                 names_str[i] = member_name;
1183                         }
1184                         else
1185                         {
1186                                 names_str[i] = name;
1187                         }
1188
1189                         names[i] = names_str[i].c_str();
1190                 }
1191
1192                 try
1193                 {
1194                         program.GetUniformIndices(static_cast<glw::GLsizei>(size), &names[0], &indices[0]);
1195                         program.GetActiveUniformsiv(static_cast<glw::GLsizei>(size), &indices[0], GL_UNIFORM_OFFSET, &offsets[0]);
1196                 }
1197                 catch (std::exception& exc)
1198                 {
1199                         stream << "Failed to query program for uniforms in block: " << variable.m_descriptor.m_name
1200                                    << ". Reason: " << exc.what() << "\n";
1201
1202                         return false;
1203                 }
1204
1205                 for (size_t i = 0; i < size; ++i)
1206                 {
1207                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1208
1209                         if (offsets[i] != (GLint)desc.m_offset)
1210                         {
1211                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offsets[i]
1212                                            << " expected: " << desc.m_offset << std::endl;
1213                                 result = false;
1214                         }
1215                 }
1216         }
1217
1218         return result;
1219 }
1220
1221 /** Query program resource for given variable and verify that everything is as expected
1222  *
1223  * @param program  Program object
1224  * @param variable Variable object
1225  * @param stream   Stream that will be used to log any error
1226  *
1227  * @return true if verification is positive, false otherwise
1228  **/
1229 bool checkSSB(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1230 {
1231         bool result = true;
1232
1233         if (false == variable.IsBlock())
1234         {
1235                 TCU_FAIL("Not implemented");
1236         }
1237         else
1238         {
1239                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1240
1241                 size_t size = interface->m_members.size();
1242
1243                 for (size_t i = 0; i < size; ++i)
1244                 {
1245                         GLuint          index   = 0;
1246                         std::string name_str = "";
1247                         GLint           offset   = 0;
1248
1249                         const std::string& name =
1250                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1251
1252                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1253                         {
1254                                 const std::string& member_name = Utils::Variable::GetReference(
1255                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1256
1257                                 name_str = member_name;
1258                         }
1259                         else
1260                         {
1261                                 name_str = name;
1262                         }
1263
1264                         try
1265                         {
1266                                 index = program.GetResourceIndex(name_str, GL_BUFFER_VARIABLE);
1267
1268                                 program.GetResource(GL_BUFFER_VARIABLE, index, GL_OFFSET, 1, &offset);
1269                         }
1270                         catch (std::exception& exc)
1271                         {
1272                                 stream << "Failed to query program for buffer variable: " << variable.m_descriptor.m_name
1273                                            << ". Reason: " << exc.what() << "\n";
1274
1275                                 return false;
1276                         }
1277
1278                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1279
1280                         if (offset != (GLint)desc.m_offset)
1281                         {
1282                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offset
1283                                            << " expected: " << desc.m_offset << std::endl;
1284                                 result = false;
1285                         }
1286                 }
1287         }
1288
1289         return result;
1290 }
1291
1292 /** Query program resources at given stage and verifies results
1293  *
1294  * @param program           Program object
1295  * @param program_interface Definition of program interface
1296  * @param stage             Stage to be verified
1297  * @param check_inputs      Select if inputs should be verified
1298  * @param check_outputs     Select if output should be verified
1299  * @param check_uniforms    Select if uniforms should be verified
1300  * @param check_ssbs        Select if buffers should be verified
1301  * @param stream            Stream that will be used to log any error
1302  *
1303  * @return true if verification is positive, false otherwise
1304  **/
1305 bool checkProgramStage(Program& program, const ProgramInterface& program_interface, Utils::Shader::STAGES stage,
1306                                            bool check_inputs, bool check_outputs, bool check_uniforms, bool check_ssbs,
1307                                            std::stringstream& stream)
1308 {
1309         typedef Variable::PtrVector::const_iterator const_iterator;
1310
1311         const ShaderInterface& interface = program_interface.GetShaderInterface(stage);
1312
1313         bool result = true;
1314
1315         /* Inputs */
1316         if (true == check_inputs)
1317         {
1318                 const Variable::PtrVector& inputs = interface.m_inputs;
1319
1320                 for (const_iterator it = inputs.begin(); it != inputs.end(); ++it)
1321                 {
1322                         if (false == checkVarying(program, **it, stream, true))
1323                         {
1324                                 result = false;
1325                         }
1326                 }
1327         }
1328
1329         /* Outputs */
1330         if (true == check_outputs)
1331         {
1332                 const Variable::PtrVector& outputs = interface.m_outputs;
1333
1334                 for (const_iterator it = outputs.begin(); it != outputs.end(); ++it)
1335                 {
1336                         if (false == checkVarying(program, **it, stream, false))
1337                         {
1338                                 result = false;
1339                         }
1340                 }
1341         }
1342
1343         /* Uniforms */
1344         if (true == check_uniforms)
1345         {
1346                 const Variable::PtrVector& uniforms = interface.m_uniforms;
1347
1348                 for (const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
1349                 {
1350                         if (false == checkUniform(program, **it, stream))
1351                         {
1352                                 result = false;
1353                         }
1354                 }
1355         }
1356
1357         /* SSBs */
1358         if (true == check_ssbs)
1359         {
1360                 const Variable::PtrVector& ssbs = interface.m_ssb_blocks;
1361
1362                 for (const_iterator it = ssbs.begin(); it != ssbs.end(); ++it)
1363                 {
1364                         if (false == checkSSB(program, **it, stream))
1365                         {
1366                                 result = false;
1367                         }
1368                 }
1369         }
1370
1371         return result;
1372 }
1373
1374 /** Query resources of monolithic compute program and verifies results
1375  *
1376  * @param program           Program object
1377  * @param program_interface Definition of program interface
1378  * @param stream            Stream that will be used to log any error
1379  *
1380  * @return true if verification is positive, false otherwise
1381  **/
1382 bool checkMonolithicComputeProgramInterface(Program& program, const ProgramInterface& program_interface,
1383                                                                                         std::stringstream& stream)
1384 {
1385         bool result = true;
1386
1387         if (false == checkProgramStage(program, program_interface, Shader::COMPUTE, false, false, true, true, stream))
1388         {
1389                 result = false;
1390         }
1391
1392         /* Done */
1393         return result;
1394 }
1395
1396 /** Query resources of monolithic draw program and verifies results
1397  *
1398  * @param program           Program object
1399  * @param program_interface Definition of program interface
1400  * @param stream            Stream that will be used to log any error
1401  *
1402  * @return true if verification is positive, false otherwise
1403  **/
1404 bool checkMonolithicDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1405                                                                                  std::stringstream& stream)
1406 {
1407         bool result = true;
1408
1409         if (false == checkProgramStage(program, program_interface, Shader::VERTEX, true, false, true, true, stream))
1410         {
1411                 result = false;
1412         }
1413
1414         /* Done */
1415         return result;
1416 }
1417
1418 /** Query resources of separable draw program and verifies results
1419  *
1420  * @param program           Program object
1421  * @param program_interface Definition of program interface
1422  * @param stream            Stream that will be used to log any error
1423  *
1424  * @return true if verification is positive, false otherwise
1425  **/
1426 bool checkSeparableDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1427                                                                                 Utils::Shader::STAGES stage, std::stringstream& stream)
1428 {
1429         bool result = true;
1430
1431         if (false == checkProgramStage(program, program_interface, stage, true, true, true, true, stream))
1432         {
1433                 result = false;
1434         }
1435
1436         /* Done */
1437         return result;
1438 }
1439
1440 /** Check if extension is supported
1441  *
1442  * @param context        Test context
1443  * @param extension_name Name of extension
1444  *
1445  * @return true if extension is supported, false otherwise
1446  **/
1447 bool isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1448 {
1449         const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1450
1451         if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1452         {
1453                 return false;
1454         }
1455
1456         return true;
1457 }
1458
1459 /** Check if GL context meets version requirements
1460  *
1461  * @param gl             Functions
1462  * @param required_major Minimum required MAJOR_VERSION
1463  * @param required_minor Minimum required MINOR_VERSION
1464  *
1465  * @return true if GL context version is at least as requested, false otherwise
1466  **/
1467 bool isGLVersionAtLeast(const Functions& gl, GLint required_major, GLint required_minor)
1468 {
1469         glw::GLint major = 0;
1470         glw::GLint minor = 0;
1471
1472         gl.getIntegerv(GL_MAJOR_VERSION, &major);
1473         gl.getIntegerv(GL_MINOR_VERSION, &minor);
1474
1475         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1476
1477         if (major > required_major)
1478         {
1479                 /* Major is higher than required one */
1480                 return true;
1481         }
1482         else if (major == required_major)
1483         {
1484                 if (minor >= required_minor)
1485                 {
1486                         /* Major is equal to required one */
1487                         /* Minor is higher than or equal to required one */
1488                         return true;
1489                 }
1490                 else
1491                 {
1492                         /* Major is equal to required one */
1493                         /* Minor is lower than required one */
1494                         return false;
1495                 }
1496         }
1497         else
1498         {
1499                 /* Major is lower than required one */
1500                 return false;
1501         }
1502 }
1503
1504 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1505  *
1506  * @param token           Token string
1507  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1508  * @param text            String that will be used as replacement for <token>
1509  * @param string          String to work on
1510  **/
1511 void replaceToken(const GLchar* token, size_t& search_position, const GLchar* text, std::string& string)
1512 {
1513         const size_t text_length        = strlen(text);
1514         const size_t token_length   = strlen(token);
1515         const size_t token_position = string.find(token, search_position);
1516
1517 #if DEBUG_REPLACE_TOKEN
1518         if (std::string::npos == token_position)
1519         {
1520                 string.append("\n\nInvalid token: ");
1521                 string.append(token);
1522
1523                 TCU_FAIL(string.c_str());
1524         }
1525 #endif /* DEBUG_REPLACE_TOKEN */
1526
1527         string.replace(token_position, token_length, text, text_length);
1528
1529         search_position = token_position + text_length;
1530 }
1531
1532 /** Replace all occurances of <token> with <text> in <string>
1533  *
1534  * @param token           Token string
1535  * @param text            String that will be used as replacement for <token>
1536  * @param string          String to work on
1537  **/
1538 void replaceAllTokens(const GLchar* token, const GLchar* text, std::string& string)
1539 {
1540         const size_t text_length  = strlen(text);
1541         const size_t token_length = strlen(token);
1542
1543         size_t search_position = 0;
1544
1545         while (1)
1546         {
1547                 const size_t token_position = string.find(token, search_position);
1548
1549                 if (std::string::npos == token_position)
1550                 {
1551                         break;
1552                 }
1553
1554                 search_position = token_position + text_length;
1555
1556                 string.replace(token_position, token_length, text, text_length);
1557         }
1558 }
1559
1560 /** Rounds up the value to the next power of 2.
1561  * This routine does not work for 0, see the url for explanations.
1562  *
1563  * @param value Starting point
1564  *
1565  * @return Calculated value
1566  **/
1567 glw::GLuint roundUpToPowerOf2(glw::GLuint value)
1568 {
1569         /* Taken from: graphics.stanford.edu/~seander/bithacks.html */
1570         --value;
1571
1572         value |= value >> 1;
1573         value |= value >> 2;
1574         value |= value >> 4;
1575         value |= value >> 8;
1576         value |= value >> 16;
1577
1578         ++value;
1579
1580         return value;
1581 }
1582
1583 /** Insert elements of list into string.
1584  * List in string is represented either by token "LIST" or "SEPARATORLIST".
1585  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>.
1586  * LIST is replaced with <element>SEPARATORLIST
1587  *
1588  * @param element         Element to be inserted
1589  * @param separator       Separator inserted between elements
1590  * @param search_position Position in string, where search for list should start
1591  * @param string          String
1592  **/
1593 void insertElementOfList(const GLchar* element, const GLchar* separator, size_t& search_position, std::string& string)
1594 {
1595         static const char* list         = g_list;
1596         static const char* sep_list = "SEPARATORLIST";
1597
1598         /* Try to get "list" positions */
1599         const size_t list_position       = string.find(list, search_position);
1600         const size_t sep_list_position = string.find(sep_list, search_position);
1601
1602         /* There is no list in string */
1603         if (std::string::npos == list_position)
1604         {
1605                 return;
1606         }
1607
1608         if (9 /* strlen(SEPARATOR) */ == list_position - sep_list_position)
1609         {
1610                 replaceToken("SEPARATOR", search_position, separator, string);
1611         }
1612
1613         /* Save search_position */
1614         const size_t start_position = search_position;
1615
1616         /* Prepare new element */
1617         replaceToken("LIST", search_position, "ELEMENTSEPARATORLIST", string);
1618
1619         /* Restore search_position */
1620         search_position = start_position;
1621
1622         /* Replace element and separator */
1623         replaceToken("ELEMENT", search_position, element, string);
1624 }
1625
1626 /** Close list in string.
1627  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>
1628  * LIST is replaced with ""
1629  *
1630  * @param separator       Separator inserted between elements
1631  * @param search_position Position in string, where search for list should start
1632  * @param string          String
1633  **/
1634 void endList(const glw::GLchar* separator, size_t& search_position, std::string& string)
1635 {
1636         const size_t sep_position = string.find("SEPARATOR", search_position);
1637         if (std::string::npos != sep_position)
1638         {
1639                 replaceToken("SEPARATOR", search_position, separator, string);
1640         }
1641
1642         replaceToken("LIST", search_position, "", string);
1643 }
1644
1645 /* Buffer constants */
1646 const GLuint Buffer::m_invalid_id = -1;
1647
1648 /** Constructor.
1649  *
1650  * @param context CTS context.
1651  **/
1652 Buffer::Buffer(deqp::Context& context) : m_id(m_invalid_id), m_buffer(Array), m_context(context)
1653 {
1654 }
1655
1656 /** Destructor
1657  *
1658  **/
1659 Buffer::~Buffer()
1660 {
1661         Release();
1662 }
1663
1664 /** Initialize buffer instance
1665  *
1666  * @param buffer Buffer type
1667  * @param usage  Buffer usage enum
1668  * @param size   <size> parameter
1669  * @param data   <data> parameter
1670  **/
1671 void Buffer::Init(BUFFERS buffer, USAGE usage, GLsizeiptr size, GLvoid* data)
1672 {
1673         /* Delete previous buffer instance */
1674         Release();
1675
1676         m_buffer = buffer;
1677
1678         const Functions& gl = m_context.getRenderContext().getFunctions();
1679
1680         Generate(gl, m_id);
1681         Bind(gl, m_id, m_buffer);
1682         Data(gl, m_buffer, usage, size, data);
1683 }
1684
1685 /** Release buffer instance
1686  *
1687  **/
1688 void Buffer::Release()
1689 {
1690         if (m_invalid_id != m_id)
1691         {
1692                 const Functions& gl = m_context.getRenderContext().getFunctions();
1693
1694                 gl.deleteBuffers(1, &m_id);
1695                 m_id = m_invalid_id;
1696         }
1697 }
1698
1699 /** Binds buffer to its target
1700  *
1701  **/
1702 void Buffer::Bind() const
1703 {
1704         const Functions& gl = m_context.getRenderContext().getFunctions();
1705
1706         Bind(gl, m_id, m_buffer);
1707 }
1708
1709 /** Binds indexed buffer
1710  *
1711  * @param index <index> parameter
1712  **/
1713 void Buffer::BindBase(GLuint index) const
1714 {
1715         const Functions& gl = m_context.getRenderContext().getFunctions();
1716
1717         BindBase(gl, m_id, m_buffer, index);
1718 }
1719
1720 /** Binds range of buffer
1721  *
1722  * @param index  <index> parameter
1723  * @param offset <offset> parameter
1724  * @param size   <size> parameter
1725  **/
1726 void Buffer::BindRange(GLuint index, GLintptr offset, GLsizeiptr size) const
1727 {
1728         const Functions& gl = m_context.getRenderContext().getFunctions();
1729
1730         BindRange(gl, m_id, m_buffer, index, offset, size);
1731 }
1732
1733 /** Allocate memory for buffer and sends initial content
1734  *
1735  * @param usage  Buffer usage enum
1736  * @param size   <size> parameter
1737  * @param data   <data> parameter
1738  **/
1739 void Buffer::Data(USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1740 {
1741         const Functions& gl = m_context.getRenderContext().getFunctions();
1742
1743         Data(gl, m_buffer, usage, size, data);
1744 }
1745
1746 /** Maps contents of buffer into CPU space
1747  *
1748  * @param access Requested access
1749  *
1750  * @return Pointer to memory region available for CPU
1751  **/
1752 GLvoid* Buffer::Map(ACCESS access)
1753 {
1754         const Functions& gl = m_context.getRenderContext().getFunctions();
1755
1756         return Map(gl, m_buffer, access);
1757 }
1758
1759 /** Allocate memory for buffer and sends initial content
1760  *
1761  * @param offset Offset in buffer
1762  * @param size   <size> parameter
1763  * @param data   <data> parameter
1764  **/
1765 void Buffer::SubData(glw::GLintptr offset, glw::GLsizeiptr size, glw::GLvoid* data)
1766 {
1767         const Functions& gl = m_context.getRenderContext().getFunctions();
1768
1769         SubData(gl, m_buffer, offset, size, data);
1770 }
1771
1772 /** Maps contents of buffer into CPU space
1773  **/
1774 void Buffer::UnMap()
1775 {
1776         const Functions& gl = m_context.getRenderContext().getFunctions();
1777
1778         return UnMap(gl, m_buffer);
1779 }
1780
1781 /** Bind buffer to given target
1782  *
1783  * @param gl     GL functions
1784  * @param id     Id of buffer
1785  * @param buffer Buffer enum
1786  **/
1787 void Buffer::Bind(const Functions& gl, GLuint id, BUFFERS buffer)
1788 {
1789         GLenum target = GetBufferGLenum(buffer);
1790
1791         gl.bindBuffer(target, id);
1792         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
1793 }
1794
1795 /** Binds indexed buffer
1796  *
1797  * @param gl     GL functions
1798  * @param id     Id of buffer
1799  * @param buffer Buffer enum
1800  * @param index  <index> parameter
1801  **/
1802 void Buffer::BindBase(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index)
1803 {
1804         GLenum target = GetBufferGLenum(buffer);
1805
1806         gl.bindBufferBase(target, index, id);
1807         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferBase");
1808 }
1809
1810 /** Binds buffer range
1811  *
1812  * @param gl     GL functions
1813  * @param id     Id of buffer
1814  * @param buffer Buffer enum
1815  * @param index  <index> parameter
1816  * @param offset <offset> parameter
1817  * @param size   <size> parameter
1818  **/
1819 void Buffer::BindRange(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1820 {
1821         GLenum target = GetBufferGLenum(buffer);
1822
1823         gl.bindBufferRange(target, index, id, offset, size);
1824         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
1825 }
1826
1827 /** Allocate memory for buffer and sends initial content
1828  *
1829  * @param gl     GL functions
1830  * @param buffer Buffer enum
1831  * @param usage  Buffer usage enum
1832  * @param size   <size> parameter
1833  * @param data   <data> parameter
1834  **/
1835 void Buffer::Data(const glw::Functions& gl, BUFFERS buffer, USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1836 {
1837         GLenum target   = GetBufferGLenum(buffer);
1838         GLenum gl_usage = GetUsageGLenum(usage);
1839
1840         gl.bufferData(target, size, data, gl_usage);
1841         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferData");
1842 }
1843
1844 /** Allocate memory for buffer and sends initial content
1845  *
1846  * @param gl     GL functions
1847  * @param buffer Buffer enum
1848  * @param offset Offset in buffer
1849  * @param size   <size> parameter
1850  * @param data   <data> parameter
1851  **/
1852 void Buffer::SubData(const glw::Functions& gl, BUFFERS buffer, glw::GLintptr offset, glw::GLsizeiptr size,
1853                                          glw::GLvoid* data)
1854 {
1855         GLenum target = GetBufferGLenum(buffer);
1856
1857         gl.bufferSubData(target, offset, size, data);
1858         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferSubData");
1859 }
1860
1861 /** Generate buffer
1862  *
1863  * @param gl     GL functions
1864  * @param out_id Id of buffer
1865  **/
1866 void Buffer::Generate(const Functions& gl, GLuint& out_id)
1867 {
1868         GLuint id = m_invalid_id;
1869
1870         gl.genBuffers(1, &id);
1871         GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
1872
1873         if (m_invalid_id == id)
1874         {
1875                 TCU_FAIL("Got invalid id");
1876         }
1877
1878         out_id = id;
1879 }
1880
1881 /** Maps buffer content
1882  *
1883  * @param gl     GL functions
1884  * @param buffer Buffer enum
1885  * @param access Access rights for mapped region
1886  *
1887  * @return Mapped memory
1888  **/
1889 void* Buffer::Map(const Functions& gl, BUFFERS buffer, ACCESS access)
1890 {
1891         GLenum target   = GetBufferGLenum(buffer);
1892         GLenum gl_access = GetAccessGLenum(access);
1893
1894         void* result = gl.mapBuffer(target, gl_access);
1895         GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
1896
1897         return result;
1898 }
1899
1900 /** Unmaps buffer
1901  *
1902  **/
1903 void Buffer::UnMap(const Functions& gl, BUFFERS buffer)
1904 {
1905         GLenum target = GetBufferGLenum(buffer);
1906
1907         gl.unmapBuffer(target);
1908         GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
1909 }
1910
1911 /** Return GLenum representation of requested access
1912  *
1913  * @param access Requested access
1914  *
1915  * @return GLenum value
1916  **/
1917 GLenum Buffer::GetAccessGLenum(ACCESS access)
1918 {
1919         GLenum result = 0;
1920
1921         switch (access)
1922         {
1923         case ReadOnly:
1924                 result = GL_READ_ONLY;
1925                 break;
1926         case WriteOnly:
1927                 result = GL_WRITE_ONLY;
1928                 break;
1929         case ReadWrite:
1930                 result = GL_READ_WRITE;
1931                 break;
1932         default:
1933                 TCU_FAIL("Invalid enum");
1934         }
1935
1936         return result;
1937 }
1938
1939 /** Return GLenum representation of requested buffer type
1940  *
1941  * @param buffer Requested buffer type
1942  *
1943  * @return GLenum value
1944  **/
1945 GLenum Buffer::GetBufferGLenum(BUFFERS buffer)
1946 {
1947         GLenum result = 0;
1948
1949         switch (buffer)
1950         {
1951         case Array:
1952                 result = GL_ARRAY_BUFFER;
1953                 break;
1954         case Element:
1955                 result = GL_ELEMENT_ARRAY_BUFFER;
1956                 break;
1957         case Shader_Storage:
1958                 result = GL_SHADER_STORAGE_BUFFER;
1959                 break;
1960         case Texture:
1961                 result = GL_TEXTURE_BUFFER;
1962                 break;
1963         case Transform_feedback:
1964                 result = GL_TRANSFORM_FEEDBACK_BUFFER;
1965                 break;
1966         case Uniform:
1967                 result = GL_UNIFORM_BUFFER;
1968                 break;
1969         default:
1970                 TCU_FAIL("Invalid enum");
1971         }
1972
1973         return result;
1974 }
1975
1976 /** Return GLenum representation of requested usage
1977  *
1978  * @param usage Requested usage
1979  *
1980  * @return GLenum value
1981  **/
1982 GLenum Buffer::GetUsageGLenum(USAGE usage)
1983 {
1984         GLenum result = 0;
1985
1986         switch (usage)
1987         {
1988         case DynamicCopy:
1989                 result = GL_DYNAMIC_COPY;
1990                 break;
1991         case DynamicDraw:
1992                 result = GL_DYNAMIC_DRAW;
1993                 break;
1994         case DynamicRead:
1995                 result = GL_DYNAMIC_READ;
1996                 break;
1997         case StaticCopy:
1998                 result = GL_STATIC_COPY;
1999                 break;
2000         case StaticDraw:
2001                 result = GL_STATIC_DRAW;
2002                 break;
2003         case StaticRead:
2004                 result = GL_STATIC_READ;
2005                 break;
2006         case StreamCopy:
2007                 result = GL_STREAM_COPY;
2008                 break;
2009         case StreamDraw:
2010                 result = GL_STREAM_DRAW;
2011                 break;
2012         case StreamRead:
2013                 result = GL_STREAM_READ;
2014                 break;
2015         default:
2016                 TCU_FAIL("Invalid enum");
2017         }
2018
2019         return result;
2020 }
2021
2022 /** Returns name of buffer target
2023  *
2024  * @param buffer Target enum
2025  *
2026  * @return Name of target
2027  **/
2028 const GLchar* Buffer::GetBufferName(BUFFERS buffer)
2029 {
2030         const GLchar* name = 0;
2031
2032         switch (buffer)
2033         {
2034         case Array:
2035                 name = "Array";
2036                 break;
2037         case Element:
2038                 name = "Element";
2039                 break;
2040         case Shader_Storage:
2041                 name = "Shader_Storage";
2042                 break;
2043         case Texture:
2044                 name = "Texture";
2045                 break;
2046         case Transform_feedback:
2047                 name = "Transform_feedback";
2048                 break;
2049         case Uniform:
2050                 name = "Uniform";
2051                 break;
2052         default:
2053                 TCU_FAIL("Invalid enum");
2054         }
2055
2056         return name;
2057 }
2058
2059 /* Framebuffer constants */
2060 const GLuint Framebuffer::m_invalid_id = -1;
2061
2062 /** Constructor
2063  *
2064  * @param context CTS context
2065  **/
2066 Framebuffer::Framebuffer(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2067 {
2068         /* Nothing to be done here */
2069 }
2070
2071 /** Destructor
2072  *
2073  **/
2074 Framebuffer::~Framebuffer()
2075 {
2076         Release();
2077 }
2078
2079 /** Initialize framebuffer instance
2080  *
2081  **/
2082 void Framebuffer::Init()
2083 {
2084         /* Delete previous instance */
2085         Release();
2086
2087         const Functions& gl = m_context.getRenderContext().getFunctions();
2088
2089         Generate(gl, m_id);
2090 }
2091
2092 /** Release framebuffer instance
2093  *
2094  **/
2095 void Framebuffer::Release()
2096 {
2097         if (m_invalid_id != m_id)
2098         {
2099                 const Functions& gl = m_context.getRenderContext().getFunctions();
2100
2101                 gl.deleteFramebuffers(1, &m_id);
2102                 m_id = m_invalid_id;
2103         }
2104 }
2105
2106 /** Attach texture to specified attachment
2107  *
2108  * @param attachment Attachment
2109  * @param texture_id Texture id
2110  * @param width      Texture width
2111  * @param height     Texture height
2112  **/
2113 void Framebuffer::AttachTexture(GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2114 {
2115         const Functions& gl = m_context.getRenderContext().getFunctions();
2116
2117         AttachTexture(gl, attachment, texture_id, width, height);
2118 }
2119
2120 /** Binds framebuffer to DRAW_FRAMEBUFFER
2121  *
2122  **/
2123 void Framebuffer::Bind()
2124 {
2125         const Functions& gl = m_context.getRenderContext().getFunctions();
2126
2127         Bind(gl, m_id);
2128 }
2129
2130 /** Clear framebuffer
2131  *
2132  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2133  **/
2134 void Framebuffer::Clear(GLenum mask)
2135 {
2136         const Functions& gl = m_context.getRenderContext().getFunctions();
2137
2138         Clear(gl, mask);
2139 }
2140
2141 /** Specifies clear color
2142  *
2143  * @param red   Red channel
2144  * @param green Green channel
2145  * @param blue  Blue channel
2146  * @param alpha Alpha channel
2147  **/
2148 void Framebuffer::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2149 {
2150         const Functions& gl = m_context.getRenderContext().getFunctions();
2151
2152         ClearColor(gl, red, green, blue, alpha);
2153 }
2154
2155 /** Attach texture to specified attachment
2156  *
2157  * @param gl         GL functions
2158  * @param attachment Attachment
2159  * @param texture_id Texture id
2160  * @param width      Texture width
2161  * @param height     Texture height
2162  **/
2163 void Framebuffer::AttachTexture(const Functions& gl, GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2164 {
2165         gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, attachment, texture_id, 0 /* level */);
2166         GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture");
2167
2168         gl.viewport(0 /* x */, 0 /* y */, width, height);
2169         GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
2170 }
2171
2172 /** Binds framebuffer to DRAW_FRAMEBUFFER
2173  *
2174  * @param gl GL functions
2175  * @param id ID of framebuffer
2176  **/
2177 void Framebuffer::Bind(const Functions& gl, GLuint id)
2178 {
2179         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, id);
2180         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
2181 }
2182
2183 /** Clear framebuffer
2184  *
2185  * @param gl   GL functions
2186  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2187  **/
2188 void Framebuffer::Clear(const Functions& gl, GLenum mask)
2189 {
2190         gl.clear(mask);
2191         GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
2192 }
2193
2194 /** Specifies clear color
2195  *
2196  * @param gl    GL functions
2197  * @param red   Red channel
2198  * @param green Green channel
2199  * @param blue  Blue channel
2200  * @param alpha Alpha channel
2201  **/
2202 void Framebuffer::ClearColor(const Functions& gl, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2203 {
2204         gl.clearColor(red, green, blue, alpha);
2205         GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
2206 }
2207
2208 /** Generate framebuffer
2209  *
2210  **/
2211 void Framebuffer::Generate(const Functions& gl, GLuint& out_id)
2212 {
2213         GLuint id = m_invalid_id;
2214
2215         gl.genFramebuffers(1, &id);
2216         GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
2217
2218         if (m_invalid_id == id)
2219         {
2220                 TCU_FAIL("Invalid id");
2221         }
2222
2223         out_id = id;
2224 }
2225
2226 /* Shader's constants */
2227 const GLuint Shader::m_invalid_id = 0;
2228
2229 /** Constructor.
2230  *
2231  * @param context CTS context.
2232  **/
2233 Shader::Shader(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2234 {
2235         /* Nothing to be done here */
2236 }
2237
2238 /** Destructor
2239  *
2240  **/
2241 Shader::~Shader()
2242 {
2243         Release();
2244 }
2245
2246 /** Initialize shader instance
2247  *
2248  * @param stage  Shader stage
2249  * @param source Source code
2250  **/
2251 void Shader::Init(STAGES stage, const std::string& source)
2252 {
2253         if (true == source.empty())
2254         {
2255                 /* No source == no shader */
2256                 return;
2257         }
2258
2259         /* Delete any previous shader */
2260         Release();
2261
2262         /* Create, set source and compile */
2263         const Functions& gl = m_context.getRenderContext().getFunctions();
2264
2265         Create(gl, stage, m_id);
2266         Source(gl, m_id, source);
2267
2268         try
2269         {
2270                 Compile(gl, m_id);
2271         }
2272         catch (const CompilationException& exc)
2273         {
2274                 throw InvalidSourceException(exc.what(), source, stage);
2275         }
2276 }
2277
2278 /** Release shader instance
2279  *
2280  **/
2281 void Shader::Release()
2282 {
2283         if (m_invalid_id != m_id)
2284         {
2285                 const Functions& gl = m_context.getRenderContext().getFunctions();
2286
2287                 gl.deleteShader(m_id);
2288                 m_id = m_invalid_id;
2289         }
2290 }
2291
2292 /** Compile shader
2293  *
2294  * @param gl GL functions
2295  * @param id Shader id
2296  **/
2297 void Shader::Compile(const Functions& gl, GLuint id)
2298 {
2299         GLint status = GL_FALSE;
2300
2301         /* Compile */
2302         gl.compileShader(id);
2303         GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
2304
2305         /* Get compilation status */
2306         gl.getShaderiv(id, GL_COMPILE_STATUS, &status);
2307         GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2308
2309         /* Log compilation error */
2310         if (GL_TRUE != status)
2311         {
2312                 glw::GLint  length = 0;
2313                 std::string message;
2314
2315                 /* Error log length */
2316                 gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &length);
2317                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2318
2319                 /* Prepare storage */
2320                 message.resize(length, 0);
2321
2322                 /* Get error log */
2323                 gl.getShaderInfoLog(id, length, 0, &message[0]);
2324                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
2325
2326                 throw CompilationException(message.c_str());
2327         }
2328 }
2329
2330 /** Create shader
2331  *
2332  * @param gl     GL functions
2333  * @param stage  Shader stage
2334  * @param out_id Shader id
2335  **/
2336 void Shader::Create(const Functions& gl, STAGES stage, GLuint& out_id)
2337 {
2338         const GLenum shaderType = GetShaderStageGLenum(stage);
2339         const GLuint id                 = gl.createShader(shaderType);
2340         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
2341
2342         if (m_invalid_id == id)
2343         {
2344                 TCU_FAIL("Failed to create shader");
2345         }
2346
2347         out_id = id;
2348 }
2349
2350 /** Set shader's source code
2351  *
2352  * @param gl     GL functions
2353  * @param id     Shader id
2354  * @param source Shader source code
2355  **/
2356 void Shader::Source(const Functions& gl, GLuint id, const std::string& source)
2357 {
2358         const GLchar* code = source.c_str();
2359
2360         gl.shaderSource(id, 1 /* count */, &code, 0 /* lengths */);
2361         GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
2362 }
2363
2364 /** Get GLenum repesenting shader stage
2365  *
2366  * @param stage Shader stage
2367  *
2368  * @return GLenum
2369  **/
2370 GLenum Shader::GetShaderStageGLenum(STAGES stage)
2371 {
2372         GLenum result = 0;
2373
2374         switch (stage)
2375         {
2376         case COMPUTE:
2377                 result = GL_COMPUTE_SHADER;
2378                 break;
2379         case FRAGMENT:
2380                 result = GL_FRAGMENT_SHADER;
2381                 break;
2382         case GEOMETRY:
2383                 result = GL_GEOMETRY_SHADER;
2384                 break;
2385         case TESS_CTRL:
2386                 result = GL_TESS_CONTROL_SHADER;
2387                 break;
2388         case TESS_EVAL:
2389                 result = GL_TESS_EVALUATION_SHADER;
2390                 break;
2391         case VERTEX:
2392                 result = GL_VERTEX_SHADER;
2393                 break;
2394         default:
2395                 TCU_FAIL("Invalid enum");
2396         }
2397
2398         return result;
2399 }
2400
2401 /** Get string representing name of shader stage
2402  *
2403  * @param stage Shader stage
2404  *
2405  * @return String with name of shader stage
2406  **/
2407 const glw::GLchar* Shader::GetStageName(STAGES stage)
2408 {
2409         const GLchar* result = 0;
2410
2411         switch (stage)
2412         {
2413         case COMPUTE:
2414                 result = "compute";
2415                 break;
2416         case VERTEX:
2417                 result = "vertex";
2418                 break;
2419         case TESS_CTRL:
2420                 result = "tessellation control";
2421                 break;
2422         case TESS_EVAL:
2423                 result = "tessellation evaluation";
2424                 break;
2425         case GEOMETRY:
2426                 result = "geometry";
2427                 break;
2428         case FRAGMENT:
2429                 result = "fragment";
2430                 break;
2431         default:
2432                 TCU_FAIL("Invalid enum");
2433         }
2434
2435         return result;
2436 }
2437
2438 /** Logs shader source
2439  *
2440  * @param context CTS context
2441  * @param source  Source of shader
2442  * @param stage   Shader stage
2443  **/
2444 void Shader::LogSource(deqp::Context& context, const std::string& source, STAGES stage)
2445 {
2446         /* Skip empty shaders */
2447         if (true == source.empty())
2448         {
2449                 return;
2450         }
2451
2452         context.getTestContext().getLog() << tcu::TestLog::Message
2453                                                                           << "Shader source. Stage: " << Shader::GetStageName(stage)
2454                                                                           << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(source);
2455 }
2456
2457 /** Constructor
2458  *
2459  * @param message Compilation error message
2460  **/
2461 Shader::CompilationException::CompilationException(const GLchar* message)
2462 {
2463         m_message = message;
2464 }
2465
2466 /** Returns error messages
2467  *
2468  * @return Compilation error message
2469  **/
2470 const char* Shader::CompilationException::what() const throw()
2471 {
2472         return m_message.c_str();
2473 }
2474
2475 /** Constructor
2476  *
2477  * @param message Compilation error message
2478  **/
2479 Shader::InvalidSourceException::InvalidSourceException(const GLchar* error_message, const std::string& source,
2480                                                                                                            STAGES stage)
2481         : m_message(error_message), m_source(source), m_stage(stage)
2482 {
2483 }
2484
2485 /** Returns error messages
2486  *
2487  * @return Compilation error message
2488  **/
2489 const char* Shader::InvalidSourceException::what() const throw()
2490 {
2491         return "Compilation error";
2492 }
2493
2494 /** Logs error message and shader sources **/
2495 void Shader::InvalidSourceException::log(deqp::Context& context) const
2496 {
2497         context.getTestContext().getLog() << tcu::TestLog::Message << "Failed to compile shader: " << m_message.c_str()
2498                                                                           << tcu::TestLog::EndMessage;
2499
2500         LogSource(context, m_source, m_stage);
2501 }
2502
2503 /* Program constants */
2504 const GLuint Pipeline::m_invalid_id = 0;
2505
2506 /** Constructor.
2507  *
2508  * @param context CTS context.
2509  **/
2510 Pipeline::Pipeline(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2511 {
2512         /* Nothing to be done here */
2513 }
2514
2515 /** Destructor
2516  *
2517  **/
2518 Pipeline::~Pipeline()
2519 {
2520         Release();
2521 }
2522
2523 /** Initialize pipline object
2524  *
2525  **/
2526 void Pipeline::Init()
2527 {
2528         Release();
2529
2530         const Functions& gl = m_context.getRenderContext().getFunctions();
2531
2532         /* Generate */
2533         gl.genProgramPipelines(1, &m_id);
2534         GLU_EXPECT_NO_ERROR(gl.getError(), "GenProgramPipelines");
2535 }
2536
2537 /** Release pipeline object
2538  *
2539  **/
2540 void Pipeline::Release()
2541 {
2542         if (m_invalid_id != m_id)
2543         {
2544                 const Functions& gl = m_context.getRenderContext().getFunctions();
2545
2546                 /* Generate */
2547                 gl.deleteProgramPipelines(1, &m_id);
2548                 GLU_EXPECT_NO_ERROR(gl.getError(), "DeleteProgramPipelines");
2549
2550                 m_id = m_invalid_id;
2551         }
2552 }
2553
2554 /** Bind pipeline
2555  *
2556  **/
2557 void Pipeline::Bind()
2558 {
2559         const Functions& gl = m_context.getRenderContext().getFunctions();
2560
2561         Bind(gl, m_id);
2562 }
2563
2564 /** Set which stages should be active
2565  *
2566  * @param program_id Id of program
2567  * @param stages     Logical combination of enums representing stages
2568  **/
2569 void Pipeline::UseProgramStages(GLuint program_id, GLenum stages)
2570 {
2571         const Functions& gl = m_context.getRenderContext().getFunctions();
2572
2573         UseProgramStages(gl, m_id, program_id, stages);
2574 }
2575
2576 /** Bind pipeline
2577  *
2578  * @param gl Functiions
2579  * @param id Pipeline id
2580  **/
2581 void Pipeline::Bind(const Functions& gl, GLuint id)
2582 {
2583         gl.bindProgramPipeline(id);
2584         GLU_EXPECT_NO_ERROR(gl.getError(), "BindProgramPipeline");
2585 }
2586
2587 /** Set which stages should be active
2588  *
2589  * @param gl         Functiions
2590  * @param id         Pipeline id
2591  * @param program_id Id of program
2592  * @param stages     Logical combination of enums representing stages
2593  **/
2594 void Pipeline::UseProgramStages(const Functions& gl, GLuint id, GLuint program_id, GLenum stages)
2595 {
2596         gl.useProgramStages(id, stages, program_id);
2597         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgramStages");
2598 }
2599
2600 /* Program constants */
2601 const GLuint Program::m_invalid_id = 0;
2602
2603 /** Constructor.
2604  *
2605  * @param context CTS context.
2606  **/
2607 Program::Program(deqp::Context& context)
2608         : m_id(m_invalid_id)
2609         , m_compute(context)
2610         , m_fragment(context)
2611         , m_geometry(context)
2612         , m_tess_ctrl(context)
2613         , m_tess_eval(context)
2614         , m_vertex(context)
2615         , m_context(context)
2616 {
2617         /* Nothing to be done here */
2618 }
2619
2620 /** Destructor
2621  *
2622  **/
2623 Program::~Program()
2624 {
2625         Release();
2626 }
2627
2628 /** Initialize program instance
2629  *
2630  * @param compute_shader                    Compute shader source code
2631  * @param fragment_shader                   Fragment shader source code
2632  * @param geometry_shader                   Geometry shader source code
2633  * @param tessellation_control_shader       Tessellation control shader source code
2634  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2635  * @param vertex_shader                     Vertex shader source code
2636  * @param captured_varyings                 Vector of variables to be captured with transfrom feedback
2637  * @param capture_interleaved               Select mode of transform feedback (separate or interleaved)
2638  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2639  **/
2640 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2641                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2642                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2643                                    const NameVector& captured_varyings, bool capture_interleaved, bool is_separable)
2644 {
2645         /* Delete previous program */
2646         Release();
2647
2648         /* GL entry points */
2649         const Functions& gl = m_context.getRenderContext().getFunctions();
2650
2651         /* Initialize shaders */
2652         m_compute.Init(Shader::COMPUTE, compute_shader);
2653         m_fragment.Init(Shader::FRAGMENT, fragment_shader);
2654         m_geometry.Init(Shader::GEOMETRY, geometry_shader);
2655         m_tess_ctrl.Init(Shader::TESS_CTRL, tessellation_control_shader);
2656         m_tess_eval.Init(Shader::TESS_EVAL, tessellation_evaluation_shader);
2657         m_vertex.Init(Shader::VERTEX, vertex_shader);
2658
2659         /* Create program, set up transform feedback and attach shaders */
2660         Create(gl, m_id);
2661         Capture(gl, m_id, captured_varyings, capture_interleaved);
2662         Attach(gl, m_id, m_compute.m_id);
2663         Attach(gl, m_id, m_fragment.m_id);
2664         Attach(gl, m_id, m_geometry.m_id);
2665         Attach(gl, m_id, m_tess_ctrl.m_id);
2666         Attach(gl, m_id, m_tess_eval.m_id);
2667         Attach(gl, m_id, m_vertex.m_id);
2668
2669         /* Set separable parameter */
2670         if (true == is_separable)
2671         {
2672                 gl.programParameteri(m_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
2673                 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
2674         }
2675
2676         try
2677         {
2678                 /* Link program */
2679                 Link(gl, m_id);
2680         }
2681         catch (const LinkageException& exc)
2682         {
2683                 throw BuildException(exc.what(), compute_shader, fragment_shader, geometry_shader, tessellation_control_shader,
2684                                                          tessellation_evaluation_shader, vertex_shader);
2685         }
2686 }
2687
2688 /** Initialize program instance
2689  *
2690  * @param compute_shader                    Compute shader source code
2691  * @param fragment_shader                   Fragment shader source code
2692  * @param geometry_shader                   Geometry shader source code
2693  * @param tessellation_control_shader       Tessellation control shader source code
2694  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2695  * @param vertex_shader                     Vertex shader source code
2696  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2697  **/
2698 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2699                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2700                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2701                                    bool is_separable)
2702 {
2703         NameVector captured_varying;
2704
2705         Init(compute_shader, fragment_shader, geometry_shader, tessellation_control_shader, tessellation_evaluation_shader,
2706                  vertex_shader, captured_varying, true, is_separable);
2707 }
2708
2709 /** Release program instance
2710  *
2711  **/
2712 void Program::Release()
2713 {
2714         const Functions& gl = m_context.getRenderContext().getFunctions();
2715
2716         if (m_invalid_id != m_id)
2717         {
2718                 Use(gl, m_invalid_id);
2719
2720                 gl.deleteProgram(m_id);
2721                 m_id = m_invalid_id;
2722         }
2723
2724         m_compute.Release();
2725         m_fragment.Release();
2726         m_geometry.Release();
2727         m_tess_ctrl.Release();
2728         m_tess_eval.Release();
2729         m_vertex.Release();
2730 }
2731
2732 /** Get <pname> for a set of active uniforms
2733  *
2734  * @param count   Number of indices
2735  * @param indices Indices of uniforms
2736  * @param pname   Queired pname
2737  * @param params  Array that will be filled with values of parameters
2738  **/
2739 void Program::GetActiveUniformsiv(GLsizei count, const GLuint* indices, GLenum pname, GLint* params) const
2740 {
2741         const Functions& gl = m_context.getRenderContext().getFunctions();
2742
2743         GetActiveUniformsiv(gl, m_id, count, indices, pname, params);
2744 }
2745
2746 /** Get location of attribute
2747  *
2748  * @param name Name of attribute
2749  *
2750  * @return Result of query
2751  **/
2752 glw::GLint Program::GetAttribLocation(const std::string& name) const
2753 {
2754         const Functions& gl = m_context.getRenderContext().getFunctions();
2755
2756         return GetAttribLocation(gl, m_id, name);
2757 }
2758
2759 /** Query resource
2760  *
2761  * @param interface Interface to be queried
2762  * @param index     Index of resource
2763  * @param property  Property to be queried
2764  * @param buf_size  Size of <params> buffer
2765  * @param params    Results of query
2766  **/
2767 void Program::GetResource(GLenum interface, GLuint index, GLenum property, GLsizei buf_size, GLint* params) const
2768 {
2769         const Functions& gl = m_context.getRenderContext().getFunctions();
2770
2771         GetResource(gl, m_id, interface, index, property, buf_size, params);
2772 }
2773
2774 /** Query for index of resource
2775  *
2776  * @param name      Name of resource
2777  * @param interface Interface to be queried
2778  *
2779  * @return Result of query
2780  **/
2781 glw::GLuint Program::GetResourceIndex(const std::string& name, GLenum interface) const
2782 {
2783         const Functions& gl = m_context.getRenderContext().getFunctions();
2784
2785         return GetResourceIndex(gl, m_id, name, interface);
2786 }
2787
2788 /** Get indices for a set of uniforms
2789  *
2790  * @param count   Count number of uniforms
2791  * @param names   Names of uniforms
2792  * @param indices Buffer that will be filled with indices
2793  **/
2794 void Program::GetUniformIndices(GLsizei count, const GLchar** names, GLuint* indices) const
2795 {
2796         const Functions& gl = m_context.getRenderContext().getFunctions();
2797
2798         GetUniformIndices(gl, m_id, count, names, indices);
2799 }
2800
2801 /** Get uniform location
2802  *
2803  * @param name Name of uniform
2804  *
2805  * @return Results of query
2806  **/
2807 glw::GLint Program::GetUniformLocation(const std::string& name) const
2808 {
2809         const Functions& gl = m_context.getRenderContext().getFunctions();
2810
2811         return GetUniformLocation(gl, m_id, name);
2812 }
2813
2814 /** Set program as active
2815  *
2816  **/
2817 void Program::Use() const
2818 {
2819         const Functions& gl = m_context.getRenderContext().getFunctions();
2820
2821         Use(gl, m_id);
2822 }
2823
2824 /** Attach shader to program
2825  *
2826  * @param gl         GL functions
2827  * @param program_id Id of program
2828  * @param shader_id  Id of shader
2829  **/
2830 void Program::Attach(const Functions& gl, GLuint program_id, GLuint shader_id)
2831 {
2832         /* Sanity checks */
2833         if ((m_invalid_id == program_id) || (Shader::m_invalid_id == shader_id))
2834         {
2835                 return;
2836         }
2837
2838         gl.attachShader(program_id, shader_id);
2839         GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
2840 }
2841
2842 /** Set up captured varyings
2843  *
2844  * @param gl                  GL functions
2845  * @param id                  Id of program
2846  * @param captured_varyings   Vector of varyings
2847  * @param capture_interleaved Selects if interleaved or separate mode should be used
2848  **/
2849 void Program::Capture(const Functions& gl, GLuint id, const NameVector& captured_varyings, bool capture_interleaved)
2850 {
2851         const size_t n_varyings = captured_varyings.size();
2852
2853         if (0 == n_varyings)
2854         {
2855                 /* empty list, skip */
2856                 return;
2857         }
2858
2859         std::vector<const GLchar*> varying_names;
2860         varying_names.resize(n_varyings);
2861
2862         for (size_t i = 0; i < n_varyings; ++i)
2863         {
2864                 varying_names[i] = captured_varyings[i].c_str();
2865         }
2866
2867         GLenum mode = 0;
2868         if (true == capture_interleaved)
2869         {
2870                 mode = GL_INTERLEAVED_ATTRIBS;
2871         }
2872         else
2873         {
2874                 mode = GL_SEPARATE_ATTRIBS;
2875         }
2876
2877         gl.transformFeedbackVaryings(id, static_cast<GLsizei>(n_varyings), &varying_names[0], mode);
2878         GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
2879 }
2880
2881 /** Create program instance
2882  *
2883  * @param gl     GL functions
2884  * @param out_id Id of program
2885  **/
2886 void Program::Create(const Functions& gl, GLuint& out_id)
2887 {
2888         const GLuint id = gl.createProgram();
2889         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
2890
2891         if (m_invalid_id == id)
2892         {
2893                 TCU_FAIL("Failed to create program");
2894         }
2895
2896         out_id = id;
2897 }
2898
2899 /** Get <pname> for a set of active uniforms
2900  *
2901  * @param gl         Functions
2902  * @param program_id Id of program
2903  * @param count      Number of indices
2904  * @param indices    Indices of uniforms
2905  * @param pname      Queired pname
2906  * @param params     Array that will be filled with values of parameters
2907  **/
2908 void Program::GetActiveUniformsiv(const Functions& gl, GLuint program_id, GLsizei count, const GLuint* indices,
2909                                                                   GLenum pname, GLint* params)
2910 {
2911         gl.getActiveUniformsiv(program_id, count, indices, pname, params);
2912         GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformsiv");
2913 }
2914
2915 /** Get indices for a set of uniforms
2916  *
2917  * @param gl         Functions
2918  * @param program_id Id of program
2919  * @param count      Count number of uniforms
2920  * @param names      Names of uniforms
2921  * @param indices    Buffer that will be filled with indices
2922  **/
2923 void Program::GetUniformIndices(const Functions& gl, GLuint program_id, GLsizei count, const GLchar** names,
2924                                                                 GLuint* indices)
2925 {
2926         gl.getUniformIndices(program_id, count, names, indices);
2927         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformIndices");
2928 }
2929
2930 /** Link program
2931  *
2932  * @param gl GL functions
2933  * @param id Id of program
2934  **/
2935 void Program::Link(const Functions& gl, GLuint id)
2936 {
2937         GLint status = GL_FALSE;
2938
2939         gl.linkProgram(id);
2940         GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
2941
2942         /* Get link status */
2943         gl.getProgramiv(id, GL_LINK_STATUS, &status);
2944         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2945
2946         /* Log link error */
2947         if (GL_TRUE != status)
2948         {
2949                 glw::GLint  length = 0;
2950                 std::string message;
2951
2952                 /* Get error log length */
2953                 gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &length);
2954                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2955
2956                 message.resize(length, 0);
2957
2958                 /* Get error log */
2959                 gl.getProgramInfoLog(id, length, 0, &message[0]);
2960                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
2961
2962                 throw LinkageException(message.c_str());
2963         }
2964 }
2965
2966 /** Set generic uniform
2967  *
2968  * @param gl       Functions
2969  * @param type     Type of uniform
2970  * @param count    Length of array
2971  * @param location Location of uniform
2972  * @param data     Data that will be used
2973  **/
2974 void Program::Uniform(const Functions& gl, const Type& type, GLsizei count, GLint location, const GLvoid* data)
2975 {
2976         if (-1 == location)
2977         {
2978                 TCU_FAIL("Uniform is inactive");
2979         }
2980
2981         switch (type.m_basic_type)
2982         {
2983         case Type::Double:
2984                 if (1 == type.m_n_columns)
2985                 {
2986                         getUniformNdv(gl, type.m_n_rows)(location, count, (const GLdouble*)data);
2987                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
2988                 }
2989                 else
2990                 {
2991                         getUniformMatrixNdv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLdouble*)data);
2992                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
2993                 }
2994                 break;
2995         case Type::Float:
2996                 if (1 == type.m_n_columns)
2997                 {
2998                         getUniformNfv(gl, type.m_n_rows)(location, count, (const GLfloat*)data);
2999                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
3000                 }
3001                 else
3002                 {
3003                         getUniformMatrixNfv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLfloat*)data);
3004                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
3005                 }
3006                 break;
3007         case Type::Int:
3008                 getUniformNiv(gl, type.m_n_rows)(location, count, (const GLint*)data);
3009                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
3010                 break;
3011         case Type::Uint:
3012                 getUniformNuiv(gl, type.m_n_rows)(location, count, (const GLuint*)data);
3013                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
3014                 break;
3015         default:
3016                 TCU_FAIL("Invalid enum");
3017         }
3018 }
3019
3020 /** Use program
3021  *
3022  * @param gl GL functions
3023  * @param id Id of program
3024  **/
3025 void Program::Use(const Functions& gl, GLuint id)
3026 {
3027         gl.useProgram(id);
3028         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
3029 }
3030
3031 /** Get location of attribute
3032  *
3033  * @param gl   GL functions
3034  * @param id   Id of program
3035  * @param name Name of attribute
3036  *
3037  * @return Location of attribute
3038  **/
3039 GLint Program::GetAttribLocation(const Functions& gl, GLuint id, const std::string& name)
3040 {
3041         GLint location = gl.getAttribLocation(id, name.c_str());
3042         GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
3043
3044         return location;
3045 }
3046
3047 /** Query resource
3048  *
3049  * @param gl        GL functions
3050  * @param id        Id of program
3051  * @param interface Interface to be queried
3052  * @param index     Index of resource
3053  * @param property  Property to be queried
3054  * @param buf_size  Size of <params> buffer
3055  * @param params    Results of query
3056  **/
3057 void Program::GetResource(const Functions& gl, GLuint id, GLenum interface, GLuint index, GLenum property,
3058                                                   GLsizei buf_size, GLint* params)
3059 {
3060         gl.getProgramResourceiv(id, interface, index, 1 /* propCount */, &property, buf_size /* bufSize */, 0 /* length */,
3061                                                         params);
3062         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceiv");
3063 }
3064
3065 /** Get index of resource
3066  *
3067  * @param gl        GL functions
3068  * @param id        Id of program
3069  * @param name      Name of resource
3070  * @param interface Program interface to queried
3071  *
3072  * @return Location of attribute
3073  **/
3074 GLuint Program::GetResourceIndex(const Functions& gl, GLuint id, const std::string& name, GLenum interface)
3075 {
3076         GLuint index = gl.getProgramResourceIndex(id, interface, name.c_str());
3077         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceIndex");
3078
3079         return index;
3080 }
3081
3082 /** Get location of attribute
3083  *
3084  * @param gl   GL functions
3085  * @param id   Id of program
3086  * @param name Name of attribute
3087  *
3088  * @return Location of uniform
3089  **/
3090 GLint Program::GetUniformLocation(const Functions& gl, GLuint id, const std::string& name)
3091 {
3092         GLint location = gl.getUniformLocation(id, name.c_str());
3093         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
3094
3095         return location;
3096 }
3097
3098 /** Constructor
3099  *
3100  * @param error_message    Error message
3101  * @param compute_shader   Source code for compute stage
3102  * @param fragment_shader  Source code for fragment stage
3103  * @param geometry_shader  Source code for geometry stage
3104  * @param tess_ctrl_shader Source code for tessellation control stage
3105  * @param tess_eval_shader Source code for tessellation evaluation stage
3106  * @param vertex_shader    Source code for vertex stage
3107  **/
3108 Program::BuildException::BuildException(const glw::GLchar* error_message, const std::string compute_shader,
3109                                                                                 const std::string fragment_shader, const std::string geometry_shader,
3110                                                                                 const std::string tess_ctrl_shader, const std::string tess_eval_shader,
3111                                                                                 const std::string vertex_shader)
3112         : m_error_message(error_message)
3113         , m_compute_shader(compute_shader)
3114         , m_fragment_shader(fragment_shader)
3115         , m_geometry_shader(geometry_shader)
3116         , m_tess_ctrl_shader(tess_ctrl_shader)
3117         , m_tess_eval_shader(tess_eval_shader)
3118         , m_vertex_shader(vertex_shader)
3119 {
3120 }
3121
3122 /** Overwrites std::exception::what method
3123  *
3124  * @return Message compossed from error message and shader sources
3125  **/
3126 const char* Program::BuildException::what() const throw()
3127 {
3128         return "Failed to link program";
3129 }
3130
3131 /** Logs error message and shader sources **/
3132 void Program::BuildException::log(deqp::Context& context) const
3133 {
3134         context.getTestContext().getLog() << tcu::TestLog::Message << "Link failure: " << m_error_message
3135                                                                           << tcu::TestLog::EndMessage;
3136
3137         Shader::LogSource(context, m_vertex_shader, Shader::VERTEX);
3138         Shader::LogSource(context, m_tess_ctrl_shader, Shader::TESS_CTRL);
3139         Shader::LogSource(context, m_tess_eval_shader, Shader::TESS_EVAL);
3140         Shader::LogSource(context, m_geometry_shader, Shader::GEOMETRY);
3141         Shader::LogSource(context, m_fragment_shader, Shader::FRAGMENT);
3142         Shader::LogSource(context, m_compute_shader, Shader::COMPUTE);
3143 }
3144
3145 /** Constructor
3146  *
3147  * @param message Linking error message
3148  **/
3149 Program::LinkageException::LinkageException(const glw::GLchar* message) : m_error_message(message)
3150 {
3151         /* Nothing to be done */
3152 }
3153
3154 /** Returns error messages
3155  *
3156  * @return Linking error message
3157  **/
3158 const char* Program::LinkageException::what() const throw()
3159 {
3160         return m_error_message.c_str();
3161 }
3162
3163 /* Texture constants */
3164 const GLuint Texture::m_invalid_id = -1;
3165
3166 /** Constructor.
3167  *
3168  * @param context CTS context.
3169  **/
3170 Texture::Texture(deqp::Context& context) : m_id(m_invalid_id), m_context(context), m_type(TEX_2D)
3171 {
3172         /* Nothing to done here */
3173 }
3174
3175 /** Destructor
3176  *
3177  **/
3178 Texture::~Texture()
3179 {
3180         Release();
3181 }
3182
3183 /** Initialize texture instance
3184  *
3185  * @param tex_type        Type of texture
3186  * @param width           Width of texture
3187  * @param height          Height of texture
3188  * @param depth           Depth of texture
3189  * @param internal_format Internal format of texture
3190  * @param format          Format of texture data
3191  * @param type            Type of texture data
3192  * @param data            Texture data
3193  **/
3194 void Texture::Init(TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum internal_format, GLenum format,
3195                                    GLenum type, GLvoid* data)
3196 {
3197         const Functions& gl = m_context.getRenderContext().getFunctions();
3198
3199         /* Delete previous texture */
3200         Release();
3201
3202         m_type = tex_type;
3203
3204         /* Generate, bind, allocate storage and upload data */
3205         Generate(gl, m_id);
3206         Bind(gl, m_id, tex_type);
3207         Storage(gl, tex_type, width, height, depth, internal_format);
3208         Update(gl, tex_type, width, height, depth, format, type, data);
3209 }
3210
3211 /** Initialize buffer texture
3212  *
3213  * @param internal_format Internal format of texture
3214  * @param buffer_id       Id of buffer that will be used as data source
3215  **/
3216 void Texture::Init(GLenum internal_format, GLuint buffer_id)
3217 {
3218         const Functions& gl = m_context.getRenderContext().getFunctions();
3219
3220         /* Delete previous texture */
3221         Release();
3222
3223         m_type = TEX_BUFFER;
3224
3225         /* Generate, bind and attach buffer */
3226         Generate(gl, m_id);
3227         Bind(gl, m_id, TEX_BUFFER);
3228         TexBuffer(gl, buffer_id, internal_format);
3229 }
3230
3231 /** Release texture instance
3232  *
3233  **/
3234 void Texture::Release()
3235 {
3236         if (m_invalid_id != m_id)
3237         {
3238                 const Functions& gl = m_context.getRenderContext().getFunctions();
3239
3240                 gl.deleteTextures(1, &m_id);
3241                 m_id = m_invalid_id;
3242         }
3243 }
3244
3245 /** Bind texture to its target
3246  *
3247  **/
3248 void Texture::Bind() const
3249 {
3250         const Functions& gl = m_context.getRenderContext().getFunctions();
3251
3252         Bind(gl, m_id, m_type);
3253 }
3254
3255 /** Get texture data
3256  *
3257  * @param format   Format of data
3258  * @param type     Type of data
3259  * @param out_data Buffer for data
3260  **/
3261 void Texture::Get(GLenum format, GLenum type, GLvoid* out_data) const
3262 {
3263         const Functions& gl = m_context.getRenderContext().getFunctions();
3264
3265         Bind(gl, m_id, m_type);
3266         Get(gl, m_type, format, type, out_data);
3267 }
3268
3269 /** Bind texture to target
3270  *
3271  * @param gl       GL functions
3272  * @param id       Id of texture
3273  * @param tex_type Type of texture
3274  **/
3275 void Texture::Bind(const Functions& gl, GLuint id, TYPES tex_type)
3276 {
3277         GLenum target = GetTargetGLenum(tex_type);
3278
3279         gl.bindTexture(target, id);
3280         GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
3281 }
3282
3283 /** Generate texture instance
3284  *
3285  * @param gl     GL functions
3286  * @param out_id Id of texture
3287  **/
3288 void Texture::Generate(const Functions& gl, GLuint& out_id)
3289 {
3290         GLuint id = m_invalid_id;
3291
3292         gl.genTextures(1, &id);
3293         GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
3294
3295         if (m_invalid_id == id)
3296         {
3297                 TCU_FAIL("Invalid id");
3298         }
3299
3300         out_id = id;
3301 }
3302
3303 /** Get texture data
3304  *
3305  * @param gl       GL functions
3306  * @param format   Format of data
3307  * @param type     Type of data
3308  * @param out_data Buffer for data
3309  **/
3310 void Texture::Get(const Functions& gl, TYPES tex_type, GLenum format, GLenum type, GLvoid* out_data)
3311 {
3312         GLenum target = GetTargetGLenum(tex_type);
3313
3314         if (TEX_CUBE != tex_type)
3315         {
3316                 gl.getTexImage(target, 0 /* level */, format, type, out_data);
3317                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3318         }
3319         else
3320         {
3321                 GLint width;
3322                 GLint height;
3323
3324                 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
3325                 {
3326                         TCU_FAIL("Not implemented");
3327                 }
3328
3329                 GLuint texel_size = 4;
3330
3331                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
3332                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3333
3334                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
3335                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3336
3337                 const GLuint image_size = width * height * texel_size;
3338
3339                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
3340                                            (GLvoid*)((GLchar*)out_data + (image_size * 0)));
3341                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
3342                                            (GLvoid*)((GLchar*)out_data + (image_size * 1)));
3343                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
3344                                            (GLvoid*)((GLchar*)out_data + (image_size * 2)));
3345                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
3346                                            (GLvoid*)((GLchar*)out_data + (image_size * 3)));
3347                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
3348                                            (GLvoid*)((GLchar*)out_data + (image_size * 4)));
3349                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
3350                                            (GLvoid*)((GLchar*)out_data + (image_size * 5)));
3351                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3352         }
3353 }
3354
3355 /** Allocate storage for texture
3356  *
3357  * @param gl              GL functions
3358  * @param tex_type        Type of texture
3359  * @param width           Width of texture
3360  * @param height          Height of texture
3361  * @param depth           Depth of texture
3362  * @param internal_format Internal format of texture
3363  **/
3364 void Texture::Storage(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth,
3365                                           GLenum internal_format)
3366 {
3367         static const GLuint levels = 1;
3368
3369         GLenum target = GetTargetGLenum(tex_type);
3370
3371         switch (tex_type)
3372         {
3373         case TEX_1D:
3374                 gl.texStorage1D(target, levels, internal_format, width);
3375                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3376                 break;
3377         case TEX_2D:
3378         case TEX_1D_ARRAY:
3379         case TEX_2D_RECT:
3380         case TEX_CUBE:
3381                 gl.texStorage2D(target, levels, internal_format, width, height);
3382                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3383                 break;
3384         case TEX_3D:
3385         case TEX_2D_ARRAY:
3386                 gl.texStorage3D(target, levels, internal_format, width, height, depth);
3387                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3388                 break;
3389         default:
3390                 TCU_FAIL("Invliad enum");
3391                 break;
3392         }
3393 }
3394
3395 /** Attach buffer as source of texture buffer data
3396  *
3397  * @param gl              GL functions
3398  * @param internal_format Internal format of texture
3399  * @param buffer_id       Id of buffer that will be used as data source
3400  **/
3401 void Texture::TexBuffer(const Functions& gl, GLenum internal_format, GLuint& buffer_id)
3402 {
3403         gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
3404         GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
3405 }
3406
3407 /** Update contents of texture
3408  *
3409  * @param gl       GL functions
3410  * @param tex_type Type of texture
3411  * @param width    Width of texture
3412  * @param height   Height of texture
3413  * @param format   Format of data
3414  * @param type     Type of data
3415  * @param data     Buffer with image data
3416  **/
3417 void Texture::Update(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum format,
3418                                          GLenum type, GLvoid* data)
3419 {
3420         static const GLuint level = 0;
3421
3422         GLenum target = GetTargetGLenum(tex_type);
3423
3424         switch (tex_type)
3425         {
3426         case TEX_1D:
3427                 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
3428                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3429                 break;
3430         case TEX_2D:
3431         case TEX_1D_ARRAY:
3432         case TEX_2D_RECT:
3433                 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
3434                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3435                 break;
3436         case TEX_CUBE:
3437                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3438                                                  data);
3439                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3440                                                  data);
3441                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3442                                                  data);
3443                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3444                                                  data);
3445                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3446                                                  data);
3447                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3448                                                  data);
3449                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3450                 break;
3451         case TEX_3D:
3452         case TEX_2D_ARRAY:
3453                 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
3454                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3455                 break;
3456         default:
3457                 TCU_FAIL("Invliad enum");
3458                 break;
3459         }
3460 }
3461
3462 /** Get target for given texture type
3463  *
3464  * @param type Type of texture
3465  *
3466  * @return Target
3467  **/
3468 GLenum Texture::GetTargetGLenum(TYPES type)
3469 {
3470         GLenum result = 0;
3471
3472         switch (type)
3473         {
3474         case TEX_BUFFER:
3475                 result = GL_TEXTURE_BUFFER;
3476                 break;
3477         case TEX_2D:
3478                 result = GL_TEXTURE_2D;
3479                 break;
3480         case TEX_2D_RECT:
3481                 result = GL_TEXTURE_RECTANGLE;
3482                 break;
3483         case TEX_2D_ARRAY:
3484                 result = GL_TEXTURE_2D_ARRAY;
3485                 break;
3486         case TEX_3D:
3487                 result = GL_TEXTURE_3D;
3488                 break;
3489         case TEX_CUBE:
3490                 result = GL_TEXTURE_CUBE_MAP;
3491                 break;
3492         case TEX_1D:
3493                 result = GL_TEXTURE_1D;
3494                 break;
3495         case TEX_1D_ARRAY:
3496                 result = GL_TEXTURE_1D_ARRAY;
3497                 break;
3498         }
3499
3500         return result;
3501 }
3502
3503 /* VertexArray constants */
3504 const GLuint VertexArray::m_invalid_id = -1;
3505
3506 /** Constructor.
3507  *
3508  * @param context CTS context.
3509  **/
3510 VertexArray::VertexArray(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
3511 {
3512 }
3513
3514 /** Destructor
3515  *
3516  **/
3517 VertexArray::~VertexArray()
3518 {
3519         Release();
3520 }
3521
3522 /** Initialize vertex array instance
3523  *
3524  **/
3525 void VertexArray::Init()
3526 {
3527         /* Delete previous instance */
3528         Release();
3529
3530         const Functions& gl = m_context.getRenderContext().getFunctions();
3531
3532         Generate(gl, m_id);
3533 }
3534
3535 /** Release vertex array object instance
3536  *
3537  **/
3538 void VertexArray::Release()
3539 {
3540         if (m_invalid_id != m_id)
3541         {
3542                 const Functions& gl = m_context.getRenderContext().getFunctions();
3543
3544                 gl.deleteVertexArrays(1, &m_id);
3545
3546                 m_id = m_invalid_id;
3547         }
3548 }
3549
3550 /** Set attribute in VAO
3551  *
3552  * @param index            Index of attribute
3553  * @param type             Type of attribute
3554  * @param n_array_elements Arary length
3555  * @param normalized       Selectis if values should be normalized
3556  * @param stride           Stride
3557  * @param pointer          Pointer to data, or offset in buffer
3558  **/
3559 void VertexArray::Attribute(GLuint index, const Type& type, GLuint n_array_elements, GLboolean normalized,
3560                                                         GLsizei stride, const GLvoid* pointer)
3561 {
3562         const Functions& gl = m_context.getRenderContext().getFunctions();
3563
3564         AttribPointer(gl, index, type, n_array_elements, normalized, stride, pointer);
3565         Enable(gl, index, type, n_array_elements);
3566 }
3567
3568 /** Binds Vertex array object
3569  *
3570  **/
3571 void VertexArray::Bind()
3572 {
3573         const Functions& gl = m_context.getRenderContext().getFunctions();
3574
3575         Bind(gl, m_id);
3576 }
3577
3578 /** Set attribute in VAO
3579  *
3580  * @param gl               Functions
3581  * @param index            Index of attribute
3582  * @param type             Type of attribute
3583  * @param n_array_elements Arary length
3584  * @param normalized       Selectis if values should be normalized
3585  * @param stride           Stride
3586  * @param pointer          Pointer to data, or offset in buffer
3587  **/
3588 void VertexArray::AttribPointer(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements,
3589                                                                 GLboolean normalized, GLsizei stride, const GLvoid* pointer)
3590 {
3591         const GLuint basic_type_size = Type::GetTypeSize(type.m_basic_type);
3592         const GLint  size                        = (GLint)type.m_n_rows;
3593         const GLuint column_size         = (GLuint)size * basic_type_size;
3594         const GLenum gl_type             = Type::GetTypeGLenum(type.m_basic_type);
3595
3596         GLuint offset = 0;
3597
3598         /* If attribute is not an array */
3599         if (0 == n_array_elements)
3600         {
3601                 n_array_elements = 1;
3602         }
3603
3604         /* For each element in array */
3605         for (GLuint element = 0; element < n_array_elements; ++element)
3606         {
3607                 /* For each column in matrix */
3608                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3609                 {
3610                         /* Calculate offset */
3611                         const GLvoid* ptr = (GLubyte*)pointer + offset;
3612
3613                         /* Set up attribute */
3614                         switch (type.m_basic_type)
3615                         {
3616                         case Type::Float:
3617                                 gl.vertexAttribPointer(index, size, gl_type, normalized, stride, ptr);
3618                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3619                                 break;
3620                         case Type::Int:
3621                         case Type::Uint:
3622                                 gl.vertexAttribIPointer(index, size, gl_type, stride, ptr);
3623                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
3624                                 break;
3625                         case Type::Double:
3626                                 gl.vertexAttribLPointer(index, size, gl_type, stride, ptr);
3627                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribLPointer");
3628                                 break;
3629                         default:
3630                                 TCU_FAIL("Invalid enum");
3631                         }
3632
3633                         /* Next location */
3634                         offset += column_size;
3635                         index += 1;
3636                 }
3637         }
3638 }
3639
3640 /** Binds Vertex array object
3641  *
3642  * @param gl GL functions
3643  * @param id ID of vertex array object
3644  **/
3645 void VertexArray::Bind(const glw::Functions& gl, glw::GLuint id)
3646 {
3647         gl.bindVertexArray(id);
3648         GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
3649 }
3650
3651 /** Disable attribute in VAO
3652  *
3653  * @param gl               Functions
3654  * @param index            Index of attribute
3655  * @param type             Type of attribute
3656  * @param n_array_elements Arary length
3657  **/
3658 void VertexArray::Disable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3659 {
3660         /* If attribute is not an array */
3661         if (0 == n_array_elements)
3662         {
3663                 n_array_elements = 1;
3664         }
3665
3666         /* For each element in array */
3667         for (GLuint element = 0; element < n_array_elements; ++element)
3668         {
3669                 /* For each column in matrix */
3670                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3671                 {
3672                         /* Enable attribute array */
3673                         gl.disableVertexAttribArray(index);
3674                         GLU_EXPECT_NO_ERROR(gl.getError(), "DisableVertexAttribArray");
3675
3676                         /* Next location */
3677                         index += 1;
3678                 }
3679         }
3680 }
3681
3682 /** Set divisor for attribute
3683  *
3684  * @param gl               Functions
3685  * @param index            Index of attribute
3686  * @param divisor          New divisor value
3687  **/
3688 void VertexArray::Divisor(const Functions& gl, GLuint index, GLuint divisor)
3689 {
3690         gl.vertexAttribDivisor(index, divisor);
3691         GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribDivisor");
3692 }
3693
3694 /** Enables attribute in VAO
3695  *
3696  * @param gl               Functions
3697  * @param index            Index of attribute
3698  * @param type             Type of attribute
3699  * @param n_array_elements Arary length
3700  **/
3701 void VertexArray::Enable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3702 {
3703         /* If attribute is not an array */
3704         if (0 == n_array_elements)
3705         {
3706                 n_array_elements = 1;
3707         }
3708
3709         /* For each element in array */
3710         for (GLuint element = 0; element < n_array_elements; ++element)
3711         {
3712                 /* For each column in matrix */
3713                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3714                 {
3715                         /* Enable attribute array */
3716                         gl.enableVertexAttribArray(index);
3717                         GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3718
3719                         /* Next location */
3720                         index += 1;
3721                 }
3722         }
3723 }
3724
3725 /** Generates Vertex array object
3726  *
3727  * @param gl     GL functions
3728  * @param out_id ID of vertex array object
3729  **/
3730 void VertexArray::Generate(const glw::Functions& gl, glw::GLuint& out_id)
3731 {
3732         GLuint id = m_invalid_id;
3733
3734         gl.genVertexArrays(1, &id);
3735         GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
3736
3737         if (m_invalid_id == id)
3738         {
3739                 TCU_FAIL("Invalid id");
3740         }
3741
3742         out_id = id;
3743 }
3744
3745 /* Constatns used by Variable */
3746 const GLint Variable::m_automatic_location = -1;
3747
3748 /** Copy constructor
3749  *
3750  **/
3751 Variable::Variable(const Variable& var)
3752         : m_data(var.m_data)
3753         , m_data_size(var.m_data_size)
3754         , m_descriptor(var.m_descriptor.m_name.c_str(), var.m_descriptor.m_qualifiers.c_str(),
3755                                    var.m_descriptor.m_expected_component, var.m_descriptor.m_expected_location,
3756                                    var.m_descriptor.m_builtin, var.m_descriptor.m_normalized, var.m_descriptor.m_n_array_elements,
3757                                    var.m_descriptor.m_expected_stride_of_element, var.m_descriptor.m_offset)
3758         , m_storage(var.m_storage)
3759 {
3760         m_descriptor.m_type = var.m_descriptor.m_type;
3761
3762         if (BUILTIN != var.m_descriptor.m_type)
3763         {
3764                 m_descriptor.m_interface = var.m_descriptor.m_interface;
3765         }
3766 }
3767
3768 /** Get code that defines variable
3769  *
3770  * @param flavour Provides info if variable is array or not
3771  *
3772  * @return String with code
3773  **/
3774 std::string Variable::GetDefinition(FLAVOUR flavour) const
3775 {
3776         return m_descriptor.GetDefinition(flavour, m_storage);
3777 }
3778
3779 /** Calcualtes stride of variable
3780  *
3781  * @return Calculated value
3782  **/
3783 GLuint Variable::GetStride() const
3784 {
3785         GLint variable_stride = 0;
3786
3787         if (0 == m_descriptor.m_n_array_elements)
3788         {
3789                 variable_stride = m_descriptor.m_expected_stride_of_element;
3790         }
3791         else
3792         {
3793                 variable_stride = m_descriptor.m_expected_stride_of_element * m_descriptor.m_n_array_elements;
3794         }
3795
3796         return variable_stride;
3797 }
3798
3799 /** Check if variable is block
3800  *
3801  * @return true if variable type is block, false otherwise
3802  **/
3803 bool Variable::IsBlock() const
3804 {
3805         if (BUILTIN == m_descriptor.m_type)
3806         {
3807                 return false;
3808         }
3809
3810         const Interface* interface = m_descriptor.m_interface;
3811         if (0 == interface)
3812         {
3813                 TCU_FAIL("Nullptr");
3814         }
3815
3816         return (Interface::BLOCK == interface->m_type);
3817 }
3818
3819 /** Check if variable is struct
3820  *
3821  * @return true if variable type is struct, false otherwise
3822  **/
3823 bool Variable::IsStruct() const
3824 {
3825         if (BUILTIN == m_descriptor.m_type)
3826         {
3827                 return false;
3828         }
3829
3830         const Interface* interface = m_descriptor.m_interface;
3831         if (0 == interface)
3832         {
3833                 TCU_FAIL("Nullptr");
3834         }
3835
3836         return (Interface::STRUCT == interface->m_type);
3837 }
3838 /** Get code that reference variable
3839  *
3840  * @param parent_name Name of parent
3841  * @param variable    Descriptor of variable
3842  * @param flavour     Provides info about how variable should be referenced
3843  * @param array_index Index of array, ignored when variable is not array
3844  *
3845  * @return String with code
3846  **/
3847 std::string Variable::GetReference(const std::string& parent_name, const Descriptor& variable, FLAVOUR flavour,
3848                                                                    GLuint array_index)
3849 {
3850         std::string name;
3851
3852         /* Prepare name */
3853         if (false == parent_name.empty())
3854         {
3855                 name = parent_name;
3856                 name.append(".");
3857                 name.append(variable.m_name);
3858         }
3859         else
3860         {
3861                 name = variable.m_name;
3862         }
3863
3864         /* */
3865         switch (flavour)
3866         {
3867         case Utils::Variable::BASIC:
3868                 break;
3869
3870         case Utils::Variable::ARRAY:
3871                 name.append("[0]");
3872                 break;
3873
3874         case Utils::Variable::INDEXED_BY_INVOCATION_ID:
3875                 name.append("[gl_InvocationID]");
3876                 break;
3877         }
3878
3879         /* Assumption that both variables have same lengths */
3880         if (0 != variable.m_n_array_elements)
3881         {
3882                 GLchar buffer[16];
3883                 sprintf(buffer, "%d", array_index);
3884                 name.append("[");
3885                 name.append(buffer);
3886                 name.append("]");
3887         }
3888
3889         return name;
3890 }
3891
3892 /** Get "flavour" of varying
3893  *
3894  * @param stage     Stage of shader
3895  * @param direction Selects if varying is in or out
3896  *
3897  * @return Flavour
3898  **/
3899 Variable::FLAVOUR Variable::GetFlavour(Shader::STAGES stage, VARYING_DIRECTION direction)
3900 {
3901         FLAVOUR result = BASIC;
3902
3903         switch (stage)
3904         {
3905         case Shader::GEOMETRY:
3906         case Shader::TESS_EVAL:
3907                 if (INPUT == direction)
3908                 {
3909                         result = ARRAY;
3910                 }
3911                 break;
3912         case Shader::TESS_CTRL:
3913                 result = INDEXED_BY_INVOCATION_ID;
3914                 break;
3915         default:
3916                 break;
3917         }
3918
3919         return result;
3920 }
3921
3922 /** Constructor, for built-in types
3923  *
3924  * @param name                       Name
3925  * @param qualifiers                 Qualifiers
3926  * @param expected_component         Expected component of variable
3927  * @param expected_location          Expected location
3928  * @param type                       Type
3929  * @param normalized                 Selects if data should be normalized
3930  * @param n_array_elements           Length of array
3931  * @param expected_stride_of_element Expected stride of element
3932  * @param offset                     Offset
3933  **/
3934 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
3935                                                                  GLint expected_location, const Type& type, GLboolean normalized,
3936                                                                  GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
3937         : m_expected_component(expected_component)
3938         , m_expected_location(expected_location)
3939         , m_expected_stride_of_element(expected_stride_of_element)
3940         , m_n_array_elements(n_array_elements)
3941         , m_name(name)
3942         , m_normalized(normalized)
3943         , m_offset(offset)
3944         , m_qualifiers(qualifiers)
3945         , m_type(BUILTIN)
3946         , m_builtin(type)
3947 {
3948 }
3949
3950 /** Constructor, for interface types
3951  *
3952  * @param name                       Name
3953  * @param qualifiers                 Qualifiers
3954  * @param expected_component         Expected component of variable
3955  * @param expected_location          Expected location
3956  * @param interface                  Interface of variable
3957  * @param n_array_elements           Length of array
3958  * @param expected_stride_of_element Expected stride of element
3959  * @param offset                     Offset
3960  **/
3961 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_componenet,
3962                                                                  GLint expected_location, Interface* interface, GLuint n_array_elements,
3963                                                                  GLint expected_stride_of_element, GLuint offset)
3964         : m_expected_component(expected_componenet)
3965         , m_expected_location(expected_location)
3966         , m_expected_stride_of_element(expected_stride_of_element)
3967         , m_n_array_elements(n_array_elements)
3968         , m_name(name)
3969         , m_normalized(GL_FALSE)
3970         , m_offset(offset)
3971         , m_qualifiers(qualifiers)
3972         , m_type(INTERFACE)
3973         , m_interface(interface)
3974 {
3975 }
3976
3977 /** Get definition of variable
3978  *
3979  * @param flavour Flavour of variable
3980  * @param storage Storage used for variable
3981  *
3982  * @return code with defintion
3983  **/
3984 std::string Variable::Descriptor::GetDefinition(FLAVOUR flavour, STORAGE storage) const
3985 {
3986         static const GLchar* basic_template = "QUALIFIERS STORAGETYPE NAMEARRAY;";
3987         static const GLchar* array_template = "QUALIFIERS STORAGETYPE NAME[]ARRAY;";
3988         const GLchar*            storage_str    = 0;
3989
3990         std::string definition;
3991         size_t          position = 0;
3992
3993         /* Select definition template */
3994         switch (flavour)
3995         {
3996         case BASIC:
3997                 definition = basic_template;
3998                 break;
3999         case ARRAY:
4000         case INDEXED_BY_INVOCATION_ID:
4001                 definition = array_template;
4002                 break;
4003         default:
4004                 TCU_FAIL("Invliad enum");
4005                 break;
4006         }
4007
4008         if (BUILTIN != m_type)
4009         {
4010                 if (0 == m_interface)
4011                 {
4012                         TCU_FAIL("Nullptr");
4013                 }
4014         }
4015
4016         /* Qualifiers */
4017         if (true == m_qualifiers.empty())
4018         {
4019                 replaceToken("QUALIFIERS ", position, "", definition);
4020         }
4021         else
4022         {
4023                 replaceToken("QUALIFIERS", position, m_qualifiers.c_str(), definition);
4024         }
4025
4026         // According to spec: int, uint, and double type must always be declared with flat qualifier
4027         bool flat_qualifier = false;
4028         if (m_type != BUILTIN && m_interface != NULL)
4029         {
4030                 if (m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Int ||
4031                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Uint ||
4032                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Double)
4033                 {
4034                         flat_qualifier = true;
4035                 }
4036         }
4037         /* Storage */
4038         switch (storage)
4039         {
4040         case VARYING_INPUT:
4041                 storage_str = flat_qualifier ? "flat in " : "in ";
4042                 break;
4043         case VARYING_OUTPUT:
4044                 storage_str = "out ";
4045                 break;
4046         case UNIFORM:
4047                 storage_str = "uniform ";
4048                 break;
4049         case SSB:
4050                 storage_str = "buffer ";
4051                 break;
4052         case MEMBER:
4053                 storage_str = "";
4054                 break;
4055         default:
4056                 TCU_FAIL("Invalid enum");
4057                 break;
4058         }
4059
4060         replaceToken("STORAGE", position, storage_str, definition);
4061
4062         /* Type */
4063         if (BUILTIN == m_type)
4064         {
4065                 replaceToken("TYPE", position, m_builtin.GetGLSLTypeName(), definition);
4066         }
4067         else
4068         {
4069                 if (Interface::STRUCT == m_interface->m_type)
4070                 {
4071                         replaceToken("TYPE", position, m_interface->m_name.c_str(), definition);
4072                 }
4073                 else
4074                 {
4075                         const std::string& block_definition = m_interface->GetDefinition();
4076
4077                         replaceToken("TYPE", position, block_definition.c_str(), definition);
4078                 }
4079         }
4080
4081         /* Name */
4082         replaceToken("NAME", position, m_name.c_str(), definition);
4083
4084         /* Array size */
4085         if (0 == m_n_array_elements)
4086         {
4087                 replaceToken("ARRAY", position, "", definition);
4088         }
4089         else
4090         {
4091                 char buffer[16];
4092                 sprintf(buffer, "[%d]", m_n_array_elements);
4093
4094                 replaceToken("ARRAY", position, buffer, definition);
4095         }
4096
4097         /* Done */
4098         return definition;
4099 }
4100
4101 /** Get definitions for variables collected in vector
4102  *
4103  * @param vector  Collection of variables
4104  * @param flavour Flavour of variables
4105  *
4106  * @return Code with definitions
4107  **/
4108 std::string GetDefinitions(const Variable::PtrVector& vector, Variable::FLAVOUR flavour)
4109 {
4110         std::string list         = Utils::g_list;
4111         size_t          position = 0;
4112
4113         for (GLuint i = 0; i < vector.size(); ++i)
4114         {
4115                 Utils::insertElementOfList(vector[i]->GetDefinition(flavour).c_str(), "\n", position, list);
4116         }
4117
4118         Utils::endList("", position, list);
4119
4120         return list;
4121 }
4122
4123 /** Get definitions for interfaces collected in vector
4124  *
4125  * @param vector Collection of interfaces
4126  *
4127  * @return Code with definitions
4128  **/
4129 std::string GetDefinitions(const Interface::PtrVector& vector)
4130 {
4131         std::string list         = Utils::g_list;
4132         size_t          position = 0;
4133
4134         for (GLuint i = 0; i < vector.size(); ++i)
4135         {
4136                 Utils::insertElementOfList(vector[i]->GetDefinition().c_str(), "\n", position, list);
4137         }
4138
4139         Utils::endList("", position, list);
4140
4141         return list;
4142 }
4143
4144 /** Constructor
4145  *
4146  * @param name Name
4147  * @param type Type of interface
4148  **/
4149 Interface::Interface(const GLchar* name, Interface::TYPE type) : m_name(name), m_type(type)
4150 {
4151 }
4152
4153 /** Adds member to interface
4154  *
4155  * @param member Descriptor of new member
4156  *
4157  * @return Pointer to just created member
4158  **/
4159 Variable::Descriptor* Interface::AddMember(const Variable::Descriptor& member)
4160 {
4161         m_members.push_back(member);
4162
4163         return &m_members.back();
4164 }
4165
4166 /** Get definition of interface
4167  *
4168  * @param Code with definition
4169  **/
4170 std::string Interface::GetDefinition() const
4171 {
4172         std::string definition;
4173         size_t          position = 0;
4174
4175         const GLchar* member_list = "    MEMBER_DEFINITION\nMEMBER_LIST";
4176
4177         if (STRUCT == m_type)
4178         {
4179                 definition = "struct NAME {\nMEMBER_LIST};";
4180         }
4181         else
4182         {
4183                 definition = "NAME {\nMEMBER_LIST}";
4184         }
4185
4186         /* Name */
4187         replaceToken("NAME", position, m_name.c_str(), definition);
4188
4189         /* Member list */
4190         for (GLuint i = 0; i < m_members.size(); ++i)
4191         {
4192                 const size_t       start_position       = position;
4193                 const std::string& member_definition = m_members[i].GetDefinition(Variable::BASIC, Variable::MEMBER);
4194
4195                 /* Member list */
4196                 replaceToken("MEMBER_LIST", position, member_list, definition);
4197
4198                 /* Move back position */
4199                 position = start_position;
4200
4201                 /* Member definition */
4202                 replaceToken("MEMBER_DEFINITION", position, member_definition.c_str(), definition);
4203         }
4204
4205         /* Remove last member list */
4206         replaceToken("MEMBER_LIST", position, "", definition);
4207
4208         /* Done */
4209         return definition;
4210 }
4211
4212 /** Adds member of built-in type to interface
4213  *
4214  * @param name                       Name
4215  * @param qualifiers                 Qualifiers
4216  * @param expected_component         Expected component of variable
4217  * @param expected_location          Expected location
4218  * @param type                       Type
4219  * @param normalized                 Selects if data should be normalized
4220  * @param n_array_elements           Length of array
4221  * @param expected_stride_of_element Expected stride of element
4222  * @param offset                     Offset
4223  *
4224  * @return Pointer to just created member
4225  **/
4226 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4227                                                                                 GLint expected_location, const Type& type, GLboolean normalized,
4228                                                                                 GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
4229 {
4230         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, type, normalized,
4231                                                                                   n_array_elements, expected_stride_of_element, offset));
4232 }
4233
4234 /** Adds member of interface type to interface
4235  *
4236  * @param name                       Name
4237  * @param qualifiers                 Qualifiers
4238  * @param expected_component         Expected component of variable
4239  * @param expected_location          Expected location
4240  * @param type                       Type
4241  * @param normalized                 Selects if data should be normalized
4242  * @param n_array_elements           Length of array
4243  * @param expected_stride_of_element Expected stride of element
4244  * @param offset                     Offset
4245  *
4246  * @return Pointer to just created member
4247  **/
4248 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4249                                                                                 GLint expected_location, Interface* nterface, GLuint n_array_elements,
4250                                                                                 GLint expected_stride_of_element, GLuint offset)
4251 {
4252         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, nterface,
4253                                                                                   n_array_elements, expected_stride_of_element, offset));
4254 }
4255
4256 /** Clears contents of vector of pointers
4257  *
4258  * @tparam T Type of elements
4259  *
4260  * @param vector Collection to be cleared
4261  **/
4262 template <typename T>
4263 void clearPtrVector(std::vector<T*>& vector)
4264 {
4265         for (size_t i = 0; i < vector.size(); ++i)
4266         {
4267                 T* t = vector[i];
4268
4269                 vector[i] = 0;
4270
4271                 if (0 != t)
4272                 {
4273                         delete t;
4274                 }
4275         }
4276
4277         vector.clear();
4278 }
4279
4280 /** Constructor
4281  *
4282  * @param stage Stage described by that interface
4283  **/
4284 ShaderInterface::ShaderInterface(Shader::STAGES stage) : m_stage(stage)
4285 {
4286         /* Nothing to be done */
4287 }
4288
4289 /** Get definitions of globals
4290  *
4291  * @return Code with definitions
4292  **/
4293 std::string ShaderInterface::GetDefinitionsGlobals() const
4294 {
4295         return m_globals;
4296 }
4297
4298 /** Get definitions of inputs
4299  *
4300  * @return Code with definitions
4301  **/
4302 std::string ShaderInterface::GetDefinitionsInputs() const
4303 {
4304         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::INPUT);
4305
4306         return GetDefinitions(m_inputs, flavour);
4307 }
4308
4309 /** Get definitions of outputs
4310  *
4311  * @return Code with definitions
4312  **/
4313 std::string ShaderInterface::GetDefinitionsOutputs() const
4314 {
4315         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::OUTPUT);
4316
4317         return GetDefinitions(m_outputs, flavour);
4318 }
4319
4320 /** Get definitions of buffers
4321  *
4322  * @return Code with definitions
4323  **/
4324 std::string ShaderInterface::GetDefinitionsSSBs() const
4325 {
4326         return GetDefinitions(m_ssb_blocks, Variable::BASIC);
4327 }
4328
4329 /** Get definitions of uniforms
4330  *
4331  * @return Code with definitions
4332  **/
4333 std::string ShaderInterface::GetDefinitionsUniforms() const
4334 {
4335         return GetDefinitions(m_uniforms, Variable::BASIC);
4336 }
4337
4338 /** Constructor
4339  *
4340  * @param in  Input variable
4341  * @param out Output variable
4342  **/
4343 VaryingConnection::VaryingConnection(Variable* in, Variable* out) : m_in(in), m_out(out)
4344 {
4345         /* NBothing to be done here */
4346 }
4347
4348 /** Adds new varying connection to given stage
4349  *
4350  * @param stage Shader stage
4351  * @param in    In varying
4352  * @param out   Out varying
4353  **/
4354 void VaryingPassthrough::Add(Shader::STAGES stage, Variable* in, Variable* out)
4355 {
4356         VaryingConnection::Vector& vector = Get(stage);
4357
4358         vector.push_back(VaryingConnection(in, out));
4359 }
4360
4361 /** Get all passthrough connections for given stage
4362  *
4363  * @param stage Shader stage
4364  *
4365  * @return Vector of connections
4366  **/
4367 VaryingConnection::Vector& VaryingPassthrough::Get(Shader::STAGES stage)
4368 {
4369         VaryingConnection::Vector* result = 0;
4370
4371         switch (stage)
4372         {
4373         case Shader::FRAGMENT:
4374                 result = &m_fragment;
4375                 break;
4376         case Shader::GEOMETRY:
4377                 result = &m_geometry;
4378                 break;
4379         case Shader::TESS_CTRL:
4380                 result = &m_tess_ctrl;
4381                 break;
4382         case Shader::TESS_EVAL:
4383                 result = &m_tess_eval;
4384                 break;
4385         case Shader::VERTEX:
4386                 result = &m_vertex;
4387                 break;
4388         default:
4389                 TCU_FAIL("Invalid enum");
4390         }
4391
4392         return *result;
4393 }
4394
4395 /** Constructor
4396  *
4397  **/
4398 ProgramInterface::ProgramInterface()
4399         : m_compute(Shader::COMPUTE)
4400         , m_vertex(Shader::VERTEX)
4401         , m_tess_ctrl(Shader::TESS_CTRL)
4402         , m_tess_eval(Shader::TESS_EVAL)
4403         , m_geometry(Shader::GEOMETRY)
4404         , m_fragment(Shader::FRAGMENT)
4405 {
4406 }
4407
4408 /** Destructor
4409  *
4410  **/
4411 ProgramInterface::~ProgramInterface()
4412 {
4413         clearPtrVector(m_blocks);
4414         clearPtrVector(m_structures);
4415 }
4416
4417 /** Adds new interface
4418  *
4419  * @param name
4420  * @param type
4421  *
4422  * @return Pointer to created interface
4423  **/
4424 Interface* ProgramInterface::AddInterface(const GLchar* name, Interface::TYPE type)
4425 {
4426         Interface* interface = 0;
4427
4428         if (Interface::STRUCT == type)
4429         {
4430                 interface = new Interface(name, type);
4431
4432                 m_structures.push_back(interface);
4433         }
4434         else
4435         {
4436                 interface = new Interface(name, type);
4437
4438                 m_blocks.push_back(interface);
4439         }
4440
4441         return interface;
4442 }
4443
4444 /** Adds new block interface
4445  *
4446  * @param name
4447  *
4448  * @return Pointer to created interface
4449  **/
4450 Interface* ProgramInterface::Block(const GLchar* name)
4451 {
4452         return AddInterface(name, Interface::BLOCK);
4453 }
4454
4455 /** Get interface of given shader stage
4456  *
4457  * @param stage Shader stage
4458  *
4459  * @return Reference to stage interface
4460  **/
4461 ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage)
4462 {
4463         ShaderInterface* interface = 0;
4464
4465         switch (stage)
4466         {
4467         case Shader::COMPUTE:
4468                 interface = &m_compute;
4469                 break;
4470         case Shader::FRAGMENT:
4471                 interface = &m_fragment;
4472                 break;
4473         case Shader::GEOMETRY:
4474                 interface = &m_geometry;
4475                 break;
4476         case Shader::TESS_CTRL:
4477                 interface = &m_tess_ctrl;
4478                 break;
4479         case Shader::TESS_EVAL:
4480                 interface = &m_tess_eval;
4481                 break;
4482         case Shader::VERTEX:
4483                 interface = &m_vertex;
4484                 break;
4485         default:
4486                 TCU_FAIL("Invalid enum");
4487         }
4488
4489         return *interface;
4490 }
4491
4492 /** Get interface of given shader stage
4493  *
4494  * @param stage Shader stage
4495  *
4496  * @return Reference to stage interface
4497  **/
4498 const ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage) const
4499 {
4500         const ShaderInterface* interface = 0;
4501
4502         switch (stage)
4503         {
4504         case Shader::COMPUTE:
4505                 interface = &m_compute;
4506                 break;
4507         case Shader::FRAGMENT:
4508                 interface = &m_fragment;
4509                 break;
4510         case Shader::GEOMETRY:
4511                 interface = &m_geometry;
4512                 break;
4513         case Shader::TESS_CTRL:
4514                 interface = &m_tess_ctrl;
4515                 break;
4516         case Shader::TESS_EVAL:
4517                 interface = &m_tess_eval;
4518                 break;
4519         case Shader::VERTEX:
4520                 interface = &m_vertex;
4521                 break;
4522         default:
4523                 TCU_FAIL("Invalid enum");
4524         }
4525
4526         return *interface;
4527 }
4528
4529 /** Clone interface of Vertex shader stage to other stages
4530  * It creates matching inputs, outputs, uniforms and buffers in other stages.
4531  * There are no additional outputs for FRAGMENT shader generated.
4532  *
4533  * @param varying_passthrough Collection of varyings connections
4534  **/
4535 void ProgramInterface::CloneVertexInterface(VaryingPassthrough& varying_passthrough)
4536 {
4537         /* VS outputs >> TCS inputs >> TCS outputs >> ..  >> FS inputs */
4538         for (size_t i = 0; i < m_vertex.m_outputs.size(); ++i)
4539         {
4540                 const Variable& vs_var = *m_vertex.m_outputs[i];
4541                 const GLchar*   prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4542
4543                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4544                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4545                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4546                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4547         }
4548
4549         /* Copy uniforms from VS to other stages */
4550         for (size_t i = 0; i < m_vertex.m_uniforms.size(); ++i)
4551         {
4552                 Variable&        vs_var = *m_vertex.m_uniforms[i];
4553                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4554
4555                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4556                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4557                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4558                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4559                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4560
4561                 /* Uniform blocks needs unique binding */
4562                 if (true == vs_var.IsBlock())
4563                 {
4564                         replaceBinding(vs_var, Shader::VERTEX);
4565                 }
4566         }
4567
4568         /* Copy SSBs from VS to other stages */
4569         for (size_t i = 0; i < m_vertex.m_ssb_blocks.size(); ++i)
4570         {
4571                 Variable&        vs_var = *m_vertex.m_ssb_blocks[i];
4572                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4573
4574                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4575                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4576                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4577                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4578                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4579
4580                 /* SSBs blocks needs unique binding */
4581                 if (true == vs_var.IsBlock())
4582                 {
4583                         replaceBinding(vs_var, Shader::VERTEX);
4584                 }
4585         }
4586
4587         m_compute.m_globals   = m_vertex.m_globals;
4588         m_fragment.m_globals  = m_vertex.m_globals;
4589         m_geometry.m_globals  = m_vertex.m_globals;
4590         m_tess_ctrl.m_globals = m_vertex.m_globals;
4591         m_tess_eval.m_globals = m_vertex.m_globals;
4592 }
4593
4594 /** Clone variable for specific stage
4595  *
4596  * @param variable            Variable
4597  * @param stage               Requested stage
4598  * @param prefix              Prefix used in variable name that is specific for original stage
4599  * @param varying_passthrough Collection of varyings connections
4600  **/
4601 void ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage, const GLchar* prefix,
4602                                                                                          VaryingPassthrough& varying_passthrough)
4603 {
4604         switch (variable.m_storage)
4605         {
4606         case Variable::VARYING_OUTPUT:
4607         {
4608                 Variable* in = cloneVariableForStage(variable, stage, Variable::VARYING_INPUT, prefix);
4609
4610                 if (Shader::FRAGMENT != stage)
4611                 {
4612                         Variable* out = cloneVariableForStage(variable, stage, Variable::VARYING_OUTPUT, prefix);
4613                         varying_passthrough.Add(stage, in, out);
4614                 }
4615         }
4616         break;
4617         case Variable::UNIFORM:
4618         case Variable::SSB:
4619                 cloneVariableForStage(variable, stage, variable.m_storage, prefix);
4620                 break;
4621         default:
4622                 TCU_FAIL("Invalid enum");
4623                 break;
4624         }
4625 }
4626
4627 /** Clone variable for specific stage
4628  *
4629  * @param variable Variable
4630  * @param stage    Requested stage
4631  * @param storage  Storage used by variable
4632  * @param prefix   Prefix used in variable name that is specific for original stage
4633  *
4634  * @return New variable
4635  **/
4636 Variable* ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage,
4637                                                                                                   Variable::STORAGE storage, const GLchar* prefix)
4638 {
4639         /* Initialize with original variable */
4640         Variable* var = new Variable(variable);
4641         if (0 == var)
4642         {
4643                 TCU_FAIL("Memory allocation");
4644         }
4645
4646         /* Set up storage */
4647         var->m_storage = storage;
4648
4649         /* Get name */
4650         std::string name = variable.m_descriptor.m_name;
4651
4652         /* Prefix name with stage ID, empty means default block */
4653         if (false == name.empty())
4654         {
4655                 size_t            position       = 0;
4656                 const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4657                 Utils::replaceToken(prefix, position, stage_prefix, name);
4658         }
4659         var->m_descriptor.m_name = name;
4660
4661         /* Clone block */
4662         const bool is_block = variable.IsBlock();
4663         if (true == is_block)
4664         {
4665                 const Interface* interface = variable.m_descriptor.m_interface;
4666
4667                 Interface* block = CloneBlockForStage(*interface, stage, storage, prefix);
4668
4669                 var->m_descriptor.m_interface = block;
4670         }
4671
4672         /* Store variable */
4673         ShaderInterface& si             = GetShaderInterface(stage);
4674         Variable*                result = 0;
4675
4676         switch (storage)
4677         {
4678         case Variable::VARYING_INPUT:
4679                 si.m_inputs.push_back(var);
4680                 result = si.m_inputs.back();
4681                 break;
4682         case Variable::VARYING_OUTPUT:
4683                 si.m_outputs.push_back(var);
4684                 result = si.m_outputs.back();
4685                 break;
4686         case Variable::UNIFORM:
4687                 /* Uniform blocks needs unique binding */
4688                 if (true == is_block)
4689                 {
4690                         replaceBinding(*var, stage);
4691                 }
4692
4693                 si.m_uniforms.push_back(var);
4694                 result = si.m_uniforms.back();
4695                 break;
4696         case Variable::SSB:
4697                 /* SSBs needs unique binding */
4698                 if (true == is_block)
4699                 {
4700                         replaceBinding(*var, stage);
4701                 }
4702
4703                 si.m_ssb_blocks.push_back(var);
4704                 result = si.m_ssb_blocks.back();
4705                 break;
4706         default:
4707                 TCU_FAIL("Invalid enum");
4708                 break;
4709         }
4710
4711         return result;
4712 }
4713
4714 /** clone block to specific stage
4715  *
4716  * @param block   Block to be copied
4717  * @param stage   Specific stage
4718  * @param storage Storage used by block
4719  * @param prefix  Prefix used in block name
4720  *
4721  * @return New interface
4722  **/
4723 Interface* ProgramInterface::CloneBlockForStage(const Interface& block, Shader::STAGES stage, Variable::STORAGE storage,
4724                                                                                                 const GLchar* prefix)
4725 {
4726         /* Get name */
4727         std::string name = block.m_name;
4728
4729         /* Prefix name with stage ID */
4730         size_t            position       = 0;
4731         const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4732         Utils::replaceToken(prefix, position, stage_prefix, name);
4733
4734         Interface* ptr = GetBlock(name.c_str());
4735
4736         if (0 == ptr)
4737         {
4738                 ptr = AddInterface(name.c_str(), Interface::BLOCK);
4739         }
4740
4741         ptr->m_members = block.m_members;
4742
4743         return ptr;
4744 }
4745
4746 /** Get stage specific prefix used in names
4747  *
4748  * @param stage   Stage
4749  * @param storage Storage class
4750  *
4751  * @return String
4752  **/
4753 const GLchar* ProgramInterface::GetStagePrefix(Shader::STAGES stage, Variable::STORAGE storage)
4754 {
4755         static const GLchar* lut[Shader::STAGE_MAX][Variable::STORAGE_MAX] = {
4756                 /*          IN          OUT         UNIFORM     SSB        MEMBER       */
4757                 /* CS  */ { 0, 0, "cs_uni_", "cs_buf_", "" },
4758                 /* VS  */ { "in_vs_", "vs_tcs_", "vs_uni_", "vs_buf_", "" },
4759                 /* TCS */ { "vs_tcs_", "tcs_tes_", "tcs_uni_", "tcs_buf_", "" },
4760                 /* TES */ { "tcs_tes_", "tes_gs_", "tes_uni_", "tes_buf_", "" },
4761                 /* GS  */ { "tes_gs_", "gs_fs_", "gs_uni_", "gs_buf_", "" },
4762                 /* FS  */ { "gs_fs_", "fs_out_", "fs_uni_", "fs_buf_", "" },
4763         };
4764
4765         const GLchar* result = 0;
4766
4767         result = lut[stage][storage];
4768
4769         return result;
4770 }
4771
4772 /** Get definitions of all structures used in program interface
4773  *
4774  * @return String with code
4775  **/
4776 std::string ProgramInterface::GetDefinitionsStructures() const
4777 {
4778         return GetDefinitions(m_structures);
4779 }
4780
4781 /** Get interface code for stage
4782  *
4783  * @param stage Specific stage
4784  *
4785  * @return String with code
4786  **/
4787 std::string ProgramInterface::GetInterfaceForStage(Shader::STAGES stage) const
4788 {
4789         size_t          position  = 0;
4790         std::string interface = "/* Globals */\n"
4791                                                         "GLOBALS\n"
4792                                                         "\n"
4793                                                         "/* Structures */\n"
4794                                                         "STRUCTURES\n"
4795                                                         "\n"
4796                                                         "/* Uniforms */\n"
4797                                                         "UNIFORMS\n"
4798                                                         "\n"
4799                                                         "/* Inputs */\n"
4800                                                         "INPUTS\n"
4801                                                         "\n"
4802                                                         "/* Outputs */\n"
4803                                                         "OUTPUTS\n"
4804                                                         "\n"
4805                                                         "/* Storage */\n"
4806                                                         "STORAGE\n";
4807
4808         const ShaderInterface& si = GetShaderInterface(stage);
4809
4810         const std::string& structures = GetDefinitionsStructures();
4811
4812         const std::string& globals  = si.GetDefinitionsGlobals();
4813         const std::string& inputs   = si.GetDefinitionsInputs();
4814         const std::string& outputs  = si.GetDefinitionsOutputs();
4815         const std::string& uniforms = si.GetDefinitionsUniforms();
4816         const std::string& ssbs         = si.GetDefinitionsSSBs();
4817
4818         replaceToken("GLOBALS", position, globals.c_str(), interface);
4819         replaceToken("STRUCTURES", position, structures.c_str(), interface);
4820         replaceToken("UNIFORMS", position, uniforms.c_str(), interface);
4821         replaceToken("INPUTS", position, inputs.c_str(), interface);
4822         replaceToken("OUTPUTS", position, outputs.c_str(), interface);
4823         replaceToken("STORAGE", position, ssbs.c_str(), interface);
4824
4825         return interface;
4826 }
4827
4828 /** Functional object used in find_if algorithm, in search for interface of given name
4829  *
4830  **/
4831 struct matchInterfaceName
4832 {
4833         matchInterfaceName(const GLchar* name) : m_name(name)
4834         {
4835         }
4836
4837         bool operator()(const Interface* interface)
4838         {
4839                 return 0 == interface->m_name.compare(m_name);
4840         }
4841
4842         const GLchar* m_name;
4843 };
4844
4845 /** Finds interface of given name in given vector of interfaces
4846  *
4847  * @param vector Collection of interfaces
4848  * @param name   Requested name
4849  *
4850  * @return Pointer to interface if available, 0 otherwise
4851  **/
4852 static Interface* findInterfaceByName(Interface::PtrVector& vector, const GLchar* name)
4853 {
4854         Interface::PtrVector::iterator it = std::find_if(vector.begin(), vector.end(), matchInterfaceName(name));
4855
4856         if (vector.end() != it)
4857         {
4858                 return *it;
4859         }
4860         else
4861         {
4862                 return 0;
4863         }
4864 }
4865
4866 /** Search for block of given name
4867  *
4868  * @param name Name of block
4869  *
4870  * @return Pointer to block or 0
4871  **/
4872 Interface* ProgramInterface::GetBlock(const GLchar* name)
4873 {
4874         return findInterfaceByName(m_blocks, name);
4875 }
4876
4877 /** Search for structure of given name
4878  *
4879  * @param name Name of structure
4880  *
4881  * @return Pointer to structure or 0
4882  **/
4883 Interface* ProgramInterface::GetStructure(const GLchar* name)
4884 {
4885         return findInterfaceByName(m_structures, name);
4886 }
4887
4888 /** Adds new sturcture to interface
4889  *
4890  * @param name Name of structure
4891  *
4892  * @return Created structure
4893  **/
4894 Interface* ProgramInterface::Structure(const GLchar* name)
4895 {
4896         return AddInterface(name, Interface::STRUCT);
4897 }
4898
4899 /** Replace "BINDING" token in qualifiers string to value specific for given stage
4900  *
4901  * @param variable Variable to modify
4902  * @param stage    Requested stage
4903  **/
4904 void ProgramInterface::replaceBinding(Variable& variable, Shader::STAGES stage)
4905 {
4906         GLchar binding[16];
4907         sprintf(binding, "%d", stage);
4908         replaceAllTokens("BINDING", binding, variable.m_descriptor.m_qualifiers);
4909 }
4910 } /* Utils namespace */
4911
4912 /** Debuging procedure. Logs parameters.
4913  *
4914  * @param source   As specified in GL spec.
4915  * @param type     As specified in GL spec.
4916  * @param id       As specified in GL spec.
4917  * @param severity As specified in GL spec.
4918  * @param ignored
4919  * @param message  As specified in GL spec.
4920  * @param info     Pointer to instance of Context used by test.
4921  */
4922 void GLW_APIENTRY debug_proc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /* length */,
4923                                                          const GLchar* message, void* info)
4924 {
4925         deqp::Context* ctx = (deqp::Context*)info;
4926
4927         const GLchar* source_str   = "Unknown";
4928         const GLchar* type_str   = "Unknown";
4929         const GLchar* severity_str = "Unknown";
4930
4931         switch (source)
4932         {
4933         case GL_DEBUG_SOURCE_API:
4934                 source_str = "API";
4935                 break;
4936         case GL_DEBUG_SOURCE_APPLICATION:
4937                 source_str = "APP";
4938                 break;
4939         case GL_DEBUG_SOURCE_OTHER:
4940                 source_str = "OTR";
4941                 break;
4942         case GL_DEBUG_SOURCE_SHADER_COMPILER:
4943                 source_str = "COM";
4944                 break;
4945         case GL_DEBUG_SOURCE_THIRD_PARTY:
4946                 source_str = "3RD";
4947                 break;
4948         case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
4949                 source_str = "WS";
4950                 break;
4951         default:
4952                 break;
4953         }
4954
4955         switch (type)
4956         {
4957         case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
4958                 type_str = "DEPRECATED_BEHAVIOR";
4959                 break;
4960         case GL_DEBUG_TYPE_ERROR:
4961                 type_str = "ERROR";
4962                 break;
4963         case GL_DEBUG_TYPE_MARKER:
4964                 type_str = "MARKER";
4965                 break;
4966         case GL_DEBUG_TYPE_OTHER:
4967                 type_str = "OTHER";
4968                 break;
4969         case GL_DEBUG_TYPE_PERFORMANCE:
4970                 type_str = "PERFORMANCE";
4971                 break;
4972         case GL_DEBUG_TYPE_POP_GROUP:
4973                 type_str = "POP_GROUP";
4974                 break;
4975         case GL_DEBUG_TYPE_PORTABILITY:
4976                 type_str = "PORTABILITY";
4977                 break;
4978         case GL_DEBUG_TYPE_PUSH_GROUP:
4979                 type_str = "PUSH_GROUP";
4980                 break;
4981         case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
4982                 type_str = "UNDEFINED_BEHAVIOR";
4983                 break;
4984         default:
4985                 break;
4986         }
4987
4988         switch (severity)
4989         {
4990         case GL_DEBUG_SEVERITY_HIGH:
4991                 severity_str = "H";
4992                 break;
4993         case GL_DEBUG_SEVERITY_LOW:
4994                 severity_str = "L";
4995                 break;
4996         case GL_DEBUG_SEVERITY_MEDIUM:
4997                 severity_str = "M";
4998                 break;
4999         case GL_DEBUG_SEVERITY_NOTIFICATION:
5000                 severity_str = "N";
5001                 break;
5002         default:
5003                 break;
5004         }
5005
5006         ctx->getTestContext().getLog() << tcu::TestLog::Message << "DEBUG_INFO: " << std::setw(3) << source_str << "|"
5007                                                                    << severity_str << "|" << std::setw(18) << type_str << "|" << std::setw(12) << id
5008                                                                    << ": " << message << tcu::TestLog::EndMessage;
5009 }
5010
5011 /** Constructor
5012  *
5013  * @param context          Test context
5014  * @param test_name        Test name
5015  * @param test_description Test description
5016  **/
5017 TestBase::TestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5018         : TestCase(context, test_name, test_description)
5019 {
5020         /* Nothing to be done here */
5021 }
5022
5023 /** Execute test
5024  *
5025  * @return tcu::TestNode::STOP otherwise
5026  **/
5027 tcu::TestNode::IterateResult TestBase::iterate()
5028 {
5029         bool test_result;
5030
5031 #if DEBUG_ENBALE_MESSAGE_CALLBACK
5032         const Functions& gl = m_context.getRenderContext().getFunctions();
5033
5034         gl.debugMessageCallback(debug_proc, &m_context);
5035         GLU_EXPECT_NO_ERROR(gl.getError(), "DebugMessageCallback");
5036 #endif /* DEBUG_ENBALE_MESSAGE_CALLBACK */
5037
5038         try
5039         {
5040                 /* Execute test */
5041                 test_result = test();
5042         }
5043         catch (std::exception& exc)
5044         {
5045                 TCU_FAIL(exc.what());
5046         }
5047
5048         /* Set result */
5049         if (true == test_result)
5050         {
5051                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
5052         }
5053         else
5054         {
5055                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5056         }
5057
5058         /* Done */
5059         return tcu::TestNode::STOP;
5060 }
5061
5062 /** Get last input location available for given type at specific stage
5063  *
5064  * @param stage        Shader stage
5065  * @param type         Input type
5066  * @param array_length Length of input array
5067  *
5068  * @return Last location index
5069  **/
5070 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5071 {
5072         GLint  divide           = 4; /* 4 components per location */
5073         GLint  param            = 0;
5074         GLenum pname            = 0;
5075         GLint  paramPrev        = 0;
5076         GLenum pnamePrev        = 0;
5077
5078         /* Select pnmae */
5079         switch (stage)
5080         {
5081         case Utils::Shader::FRAGMENT:
5082                 pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5083                 pnamePrev = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5084                 break;
5085         case Utils::Shader::GEOMETRY:
5086                 pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5087                 pnamePrev = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5088                 break;
5089         case Utils::Shader::TESS_CTRL:
5090                 pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5091                 pnamePrev = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5092                 break;
5093         case Utils::Shader::TESS_EVAL:
5094                 pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5095                 pnamePrev = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5096                 break;
5097         case Utils::Shader::VERTEX:
5098                 pname  = GL_MAX_VERTEX_ATTRIBS;
5099                 divide = 1;
5100                 break;
5101         default:
5102                 TCU_FAIL("Invalid enum");
5103                 break;
5104         }
5105
5106         /* Zero means no array, but 1 slot is required */
5107         if (0 == array_length)
5108         {
5109                 array_length += 1;
5110         }
5111
5112         /* Get MAX */
5113         const Functions& gl = m_context.getRenderContext().getFunctions();
5114
5115         gl.getIntegerv(pname, &param);
5116         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5117
5118         if (pnamePrev) {
5119                 gl.getIntegerv(pnamePrev, &paramPrev);
5120                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5121
5122                 /* Don't read from a location that doesn't exist in the previous stage */
5123                 param = de::min(param, paramPrev);
5124         }
5125
5126 /* Calculate */
5127 #if WRKARD_VARYINGLOCATIONSTEST
5128
5129         const GLint n_avl_locations = 16;
5130
5131 #else
5132
5133         const GLint n_avl_locations = param / divide;
5134
5135 #endif
5136
5137         const GLuint n_req_location = type.GetLocations(stage == Utils::Shader::VERTEX) * array_length;
5138
5139         return n_avl_locations - n_req_location; /* last is max - 1 */
5140 }
5141
5142 /** Get last output location available for given type at specific stage
5143  *
5144  * @param stage        Shader stage
5145  * @param type         Input type
5146  * @param array_length Length of input array
5147  *
5148  * @return Last location index
5149  **/
5150 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5151 {
5152         GLint  param            = 0;
5153         GLenum pname            = 0;
5154         GLint  paramNext        = 0;
5155         GLenum pnameNext        = 0;
5156
5157         /* Select pname */
5158         switch (stage)
5159         {
5160         case Utils::Shader::GEOMETRY:
5161                 pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5162                 pnameNext = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5163                 break;
5164         case Utils::Shader::TESS_CTRL:
5165                 pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5166                 pnameNext = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5167                 break;
5168         case Utils::Shader::TESS_EVAL:
5169                 pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5170                 pnameNext = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5171                 break;
5172         case Utils::Shader::VERTEX:
5173                 pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5174                 pnameNext = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5175                 break;
5176         default:
5177                 TCU_FAIL("Invalid enum");
5178                 break;
5179         }
5180
5181         /* Zero means no array, but 1 slot is required */
5182         if (0 == array_length)
5183         {
5184                 array_length += 1;
5185         }
5186
5187         /* Get MAX */
5188         const Functions& gl = m_context.getRenderContext().getFunctions();
5189
5190         gl.getIntegerv(pname, &param);
5191         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5192
5193         gl.getIntegerv(pnameNext, &paramNext);
5194         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5195
5196 /* Calculate */
5197 #if WRKARD_VARYINGLOCATIONSTEST
5198
5199         const GLint n_avl_locations = 16;
5200
5201 #else
5202
5203         /* Don't write to a location that doesn't exist in the next stage */
5204         param = de::min(param, paramNext);
5205
5206         const GLint n_avl_locations = param / 4; /* 4 components per location */
5207
5208 #endif
5209
5210         const GLuint n_req_location = type.GetLocations() * array_length;
5211
5212         return n_avl_locations - n_req_location; /* last is max - 1 */
5213 }
5214
5215 /** Basic implementation
5216  *
5217  * @param ignored
5218  *
5219  * @return Empty string
5220  **/
5221 std::string TestBase::getTestCaseName(GLuint /* test_case_index */)
5222 {
5223         std::string result;
5224
5225         return result;
5226 }
5227
5228 /** Basic implementation
5229  *
5230  * @return 1
5231  **/
5232 GLuint TestBase::getTestCaseNumber()
5233 {
5234         return 1;
5235 }
5236
5237 /** Check if flat qualifier is required for given type, stage and storage
5238  *
5239  * @param stage        Shader stage
5240  * @param type         Input type
5241  * @param storage      Storage of variable
5242  *
5243  * @return Last location index
5244  **/
5245 bool TestBase::isFlatRequired(Utils::Shader::STAGES stage, const Utils::Type& type,
5246                                                           Utils::Variable::STORAGE storage) const
5247 {
5248         /* Float types do not need flat at all */
5249         if (Utils::Type::Float == type.m_basic_type)
5250         {
5251                 return false;
5252         }
5253
5254         /* Inputs to fragment shader */
5255         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_INPUT == storage))
5256         {
5257                 return true;
5258         }
5259
5260         /* Outputs from geometry shader */
5261         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_OUTPUT == storage))
5262         {
5263                 return true;
5264         }
5265
5266         return false;
5267 }
5268
5269 /** Basic implementation of testInit method
5270  *
5271  **/
5272 void TestBase::testInit()
5273 {
5274 }
5275
5276 /** Calculate stride for interface
5277  *
5278  * @param interface Interface
5279  *
5280  * @return Calculated value
5281  **/
5282 GLuint TestBase::calculateStride(const Utils::Interface& interface) const
5283 {
5284         const size_t n_members = interface.m_members.size();
5285
5286         GLuint stride = 0;
5287
5288         for (size_t i = 0; i < n_members; ++i)
5289         {
5290                 const Utils::Variable::Descriptor& member                 = interface.m_members[i];
5291                 const GLuint                                       member_offset  = member.m_offset;
5292                 const GLuint                                       member_stride  = member.m_expected_stride_of_element;
5293                 const GLuint                                       member_ends_at = member_offset + member_stride;
5294
5295                 stride = std::max(stride, member_ends_at);
5296         }
5297
5298         return stride;
5299 }
5300
5301 /** Generate data for interface. This routine is recursive
5302  *
5303  * @param interface Interface
5304  * @param offset    Offset in out_data
5305  * @param out_data  Buffer to be filled
5306  **/
5307 void TestBase::generateData(const Utils::Interface& interface, GLuint offset, std::vector<GLubyte>& out_data) const
5308 {
5309         const size_t n_members = interface.m_members.size();
5310         GLubyte*         ptr       = &out_data[offset];
5311
5312         for (size_t i = 0; i < n_members; ++i)
5313         {
5314                 const Utils::Variable::Descriptor& member                = interface.m_members[i];
5315                 const GLuint                                       member_offset = member.m_offset;
5316                 const GLuint n_elements = (0 == member.m_n_array_elements) ? 1 : member.m_n_array_elements;
5317
5318                 for (GLuint element = 0; element < n_elements; ++element)
5319                 {
5320                         const GLuint element_offset = element * member.m_expected_stride_of_element;
5321                         const GLuint data_offfset   = member_offset + element_offset;
5322
5323                         if (Utils::Variable::BUILTIN == member.m_type)
5324                         {
5325                                 const std::vector<GLubyte>& data = member.m_builtin.GenerateData();
5326
5327                                 memcpy(ptr + data_offfset, &data[0], data.size());
5328                         }
5329                         else
5330                         {
5331                                 generateData(*member.m_interface, offset + data_offfset, out_data);
5332                         }
5333                 }
5334         }
5335 }
5336
5337 /** Get type at index
5338  *
5339  * @param index Index of requested type
5340  *
5341  * @return Type
5342  **/
5343 Utils::Type TestBase::getType(GLuint index) const
5344 {
5345         Utils::Type type;
5346
5347         switch (index)
5348         {
5349         case 0:
5350                 type = Utils::Type::_double;
5351                 break;
5352         case 1:
5353                 type = Utils::Type::dmat2;
5354                 break;
5355         case 2:
5356                 type = Utils::Type::dmat2x3;
5357                 break;
5358         case 3:
5359                 type = Utils::Type::dmat2x4;
5360                 break;
5361         case 4:
5362                 type = Utils::Type::dmat3;
5363                 break;
5364         case 5:
5365                 type = Utils::Type::dmat3x2;
5366                 break;
5367         case 6:
5368                 type = Utils::Type::dmat3x4;
5369                 break;
5370         case 7:
5371                 type = Utils::Type::dmat4;
5372                 break;
5373         case 8:
5374                 type = Utils::Type::dmat4x2;
5375                 break;
5376         case 9:
5377                 type = Utils::Type::dmat4x3;
5378                 break;
5379         case 10:
5380                 type = Utils::Type::dvec2;
5381                 break;
5382         case 11:
5383                 type = Utils::Type::dvec3;
5384                 break;
5385         case 12:
5386                 type = Utils::Type::dvec4;
5387                 break;
5388         case 13:
5389                 type = Utils::Type::_float;
5390                 break;
5391         case 14:
5392                 type = Utils::Type::mat2;
5393                 break;
5394         case 15:
5395                 type = Utils::Type::mat2x3;
5396                 break;
5397         case 16:
5398                 type = Utils::Type::mat2x4;
5399                 break;
5400         case 17:
5401                 type = Utils::Type::mat3;
5402                 break;
5403         case 18:
5404                 type = Utils::Type::mat3x2;
5405                 break;
5406         case 19:
5407                 type = Utils::Type::mat3x4;
5408                 break;
5409         case 20:
5410                 type = Utils::Type::mat4;
5411                 break;
5412         case 21:
5413                 type = Utils::Type::mat4x2;
5414                 break;
5415         case 22:
5416                 type = Utils::Type::mat4x3;
5417                 break;
5418         case 23:
5419                 type = Utils::Type::vec2;
5420                 break;
5421         case 24:
5422                 type = Utils::Type::vec3;
5423                 break;
5424         case 25:
5425                 type = Utils::Type::vec4;
5426                 break;
5427         case 26:
5428                 type = Utils::Type::_int;
5429                 break;
5430         case 27:
5431                 type = Utils::Type::ivec2;
5432                 break;
5433         case 28:
5434                 type = Utils::Type::ivec3;
5435                 break;
5436         case 29:
5437                 type = Utils::Type::ivec4;
5438                 break;
5439         case 30:
5440                 type = Utils::Type::uint;
5441                 break;
5442         case 31:
5443                 type = Utils::Type::uvec2;
5444                 break;
5445         case 32:
5446                 type = Utils::Type::uvec3;
5447                 break;
5448         case 33:
5449                 type = Utils::Type::uvec4;
5450                 break;
5451         default:
5452                 TCU_FAIL("invalid enum");
5453         }
5454
5455         return type;
5456 }
5457
5458 /** Get name of type at index
5459  *
5460  * @param index Index of type
5461  *
5462  * @return Name
5463  **/
5464 std::string TestBase::getTypeName(GLuint index) const
5465 {
5466         std::string name = getType(index).GetGLSLTypeName();
5467
5468         return name;
5469 }
5470
5471 /** Get number of types
5472  *
5473  * @return 34
5474  **/
5475 glw::GLuint TestBase::getTypesNumber() const
5476 {
5477         return 34;
5478 }
5479
5480 /** Execute test
5481  *
5482  * @return true if test pass, false otherwise
5483  **/
5484 bool TestBase::test()
5485 {
5486         bool   result           = true;
5487         GLuint n_test_cases = 0;
5488
5489         /* Prepare test */
5490         testInit();
5491
5492         /* GL entry points */
5493         const Functions& gl = m_context.getRenderContext().getFunctions();
5494
5495         /* Tessellation patch set up */
5496         gl.patchParameteri(GL_PATCH_VERTICES, 1);
5497         GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
5498
5499         /* Get number of test cases */
5500         n_test_cases = getTestCaseNumber();
5501
5502 #if DEBUG_REPEAT_TEST_CASE
5503
5504         while (1)
5505         {
5506                 GLuint test_case = DEBUG_REPEATED_TEST_CASE;
5507
5508 #else /* DEBUG_REPEAT_TEST_CASE */
5509
5510         for (GLuint test_case = 0; test_case < n_test_cases; ++test_case)
5511         {
5512 #endif /* DEBUG_REPEAT_TEST_CASE */
5513
5514                 bool case_result = true;
5515
5516                 /* Execute case */
5517                 if (false == testCase(test_case))
5518                 {
5519                         case_result = false;
5520                 }
5521
5522                 /* Log failure */
5523                 if (false == case_result)
5524                 {
5525                         const std::string& test_case_name = getTestCaseName(test_case);
5526
5527                         if (false == test_case_name.empty())
5528                         {
5529                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5530                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5531                         }
5532                         else
5533                         {
5534                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5535                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5536                         }
5537
5538                         result = false;
5539                 }
5540         }
5541
5542         /* Done */
5543         return result;
5544 }
5545
5546 /* Constants used by BufferTestBase */
5547 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5548
5549 /** Constructor
5550  *
5551  * @param context          Test context
5552  * @param test_name        Name of test
5553  * @param test_description Description of test
5554  **/
5555 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5556         : TestBase(context, test_name, test_description)
5557 {
5558 }
5559
5560 /** Execute drawArrays for single vertex
5561  *
5562  * @param ignored
5563  *
5564  * @return true
5565  **/
5566 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5567 {
5568         const Functions& gl = m_context.getRenderContext().getFunctions();
5569
5570         gl.disable(GL_RASTERIZER_DISCARD);
5571         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5572
5573         gl.beginTransformFeedback(GL_POINTS);
5574         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5575
5576         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5577         if (tesEnabled == false)
5578         {
5579                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5580         }
5581         else
5582         {
5583                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5584         }
5585
5586         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5587
5588         gl.endTransformFeedback();
5589         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5590
5591         return true;
5592 }
5593
5594 /** Get descriptors of buffers necessary for test
5595  *
5596  * @param ignored
5597  * @param ignored
5598  **/
5599 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5600                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5601 {
5602         /* Nothhing to be done */
5603 }
5604
5605 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5606  *
5607  * @param ignored
5608  * @param ignored
5609  **/
5610 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5611                                                                                  Utils::Program::NameVector& /* captured_varyings */,
5612                                                                                  GLint* /* xfb_components */)
5613 {
5614         /* Nothing to be done */
5615 }
5616
5617 /** Get body of main function for given shader stage
5618  *
5619  * @param ignored
5620  * @param ignored
5621  * @param out_assignments  Set to empty
5622  * @param out_calculations Set to empty
5623  **/
5624 void BufferTestBase::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5625                                                                    std::string& out_assignments, std::string& out_calculations)
5626 {
5627         out_assignments  = "";
5628         out_calculations = "";
5629 }
5630
5631 /** Get interface of shader
5632  *
5633  * @param ignored
5634  * @param ignored
5635  * @param out_interface Set to ""
5636  **/
5637 void BufferTestBase::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5638                                                                                 std::string& out_interface)
5639 {
5640         out_interface = "";
5641 }
5642
5643 /** Get source code of shader
5644  *
5645  * @param test_case_index Index of test case
5646  * @param stage           Shader stage
5647  *
5648  * @return Source
5649  **/
5650 std::string BufferTestBase::getShaderSource(glw::GLuint test_case_index, Utils::Shader::STAGES stage)
5651 {
5652         std::string assignments;
5653         std::string calculations;
5654         std::string interface;
5655
5656         /* */
5657         getShaderBody(test_case_index, stage, assignments, calculations);
5658         getShaderInterface(test_case_index, stage, interface);
5659
5660         /* */
5661         std::string source = getShaderTemplate(stage);
5662
5663         /* */
5664         size_t position = 0;
5665         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
5666         Utils::replaceToken("CALCULATIONS", position, calculations.c_str(), source);
5667         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
5668
5669         /* */
5670         return source;
5671 }
5672
5673 /** Inspects program to check if all resources are as expected
5674  *
5675  * @param ignored
5676  * @param ignored
5677  * @param ignored
5678  *
5679  * @return true
5680  **/
5681 bool BufferTestBase::inspectProgram(GLuint /* test_case_index */, Utils::Program& /* program */,
5682                                                                         std::stringstream& /* out_stream */)
5683 {
5684         return true;
5685 }
5686
5687 /** Runs test case
5688  *
5689  * @param test_case_index Id of test case
5690  *
5691  * @return true if test case pass, false otherwise
5692  **/
5693 bool BufferTestBase::testCase(GLuint test_case_index)
5694 {
5695         try
5696         {
5697                 bufferCollection                   buffers;
5698                 Utils::Program::NameVector captured_varyings;
5699                 bufferDescriptor::Vector   descriptors;
5700                 Utils::Program                     program(m_context);
5701                 Utils::VertexArray                 vao(m_context);
5702
5703                 /* Get captured varyings */
5704                 GLint xfb_components;
5705                 getCapturedVaryings(test_case_index, captured_varyings, &xfb_components);
5706
5707                 /* Don't generate shaders that try to capture more XFB components than the implementation's limit */
5708                 if (captured_varyings.size() > 0)
5709                 {
5710                         const Functions& gl     = m_context.getRenderContext().getFunctions();
5711
5712                         GLint max_xfb_components;
5713                         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_components);
5714                         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5715
5716                         if (xfb_components > max_xfb_components)
5717                                 return true;
5718                 }
5719
5720                 /* Get shader sources */
5721                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5722                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5723                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5724                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5725                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5726
5727                 /* Set up program */
5728                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5729                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5730
5731                 /* Inspection */
5732                 {
5733                         std::stringstream stream;
5734                         if (false == inspectProgram(test_case_index, program, stream))
5735                         {
5736                                 m_context.getTestContext().getLog()
5737                                         << tcu::TestLog::Message
5738                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5739                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5740                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5741                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5742                                         << tcu::TestLog::KernelSource(fragment_shader);
5743
5744                                 return false;
5745                         }
5746                 }
5747
5748                 program.Use();
5749
5750                 /* Set up buffers */
5751                 getBufferDescriptors(test_case_index, descriptors);
5752                 cleanBuffers();
5753                 prepareBuffers(descriptors, buffers);
5754
5755                 /* Set up vao */
5756                 vao.Init();
5757                 vao.Bind();
5758
5759                 /* Draw */
5760                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5761
5762 #if USE_NSIGHT
5763                 m_context.getRenderContext().postIterate();
5764 #endif
5765
5766                 if (false == result)
5767                 {
5768                         m_context.getTestContext().getLog()
5769                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5770                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5771                                 << tcu::TestLog::KernelSource(fragment_shader);
5772
5773                         return false;
5774                 }
5775
5776                 /* Verify result */
5777                 if (false == verifyBuffers(buffers))
5778                 {
5779                         m_context.getTestContext().getLog()
5780                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5781                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5782                                 << tcu::TestLog::KernelSource(fragment_shader);
5783
5784                         return false;
5785                 }
5786         }
5787         catch (Utils::Shader::InvalidSourceException& exc)
5788         {
5789                 exc.log(m_context);
5790                 TCU_FAIL(exc.what());
5791         }
5792         catch (Utils::Program::BuildException& exc)
5793         {
5794                 exc.log(m_context);
5795                 TCU_FAIL(exc.what());
5796         }
5797
5798         /* Done */
5799         return true;
5800 }
5801
5802 /** Verify contents of buffers
5803  *
5804  * @param buffers Collection of buffers to be verified
5805  *
5806  * @return true if everything is as expected, false otherwise
5807  **/
5808 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5809 {
5810         bool result = true;
5811
5812         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5813                  ++it)
5814         {
5815                 bufferCollection::pair& pair       = *it;
5816                 Utils::Buffer*                  buffer   = pair.m_buffer;
5817                 bufferDescriptor*               descriptor = pair.m_descriptor;
5818                 size_t                                  size       = descriptor->m_expected_data.size();
5819
5820                 /* Skip buffers that have no expected data */
5821                 if (0 == size)
5822                 {
5823                         continue;
5824                 }
5825
5826                 /* Get pointer to contents of buffer */
5827                 buffer->Bind();
5828                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5829
5830                 /* Get pointer to expected data */
5831                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5832
5833                 /* Compare */
5834                 int res = memcmp(buffer_data, expected_data, size);
5835
5836                 if (0 != res)
5837                 {
5838                         m_context.getTestContext().getLog()
5839                                 << tcu::TestLog::Message
5840                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5841                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5842
5843                         result = false;
5844                 }
5845
5846                 /* Release buffer mapping */
5847                 buffer->UnMap();
5848         }
5849
5850         return result;
5851 }
5852
5853 /** Unbinds all uniforms and xfb
5854  *
5855  **/
5856 void BufferTestBase::cleanBuffers()
5857 {
5858         const Functions& gl = m_context.getRenderContext().getFunctions();
5859
5860         GLint max_uni = 0;
5861         GLint max_xfb = 0;
5862
5863         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5864         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5865         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5866
5867         for (GLint i = 0; i < max_uni; ++i)
5868         {
5869                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5870         }
5871
5872         for (GLint i = 0; i < max_xfb; ++i)
5873         {
5874                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5875         }
5876 }
5877
5878 /** Get template of shader for given stage
5879  *
5880  * @param stage Stage
5881  *
5882  * @return Template of shader source
5883  **/
5884 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5885 {
5886         static const GLchar* compute_shader_template = "#version 430 core\n"
5887                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5888                                                                                                    "\n"
5889                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5890                                                                                                    "\n"
5891                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5892                                                                                                    "\n"
5893                                                                                                    "INTERFACE"
5894                                                                                                    "\n"
5895                                                                                                    "void main()\n"
5896                                                                                                    "{\n"
5897                                                                                                    "CALCULATIONS"
5898                                                                                                    "\n"
5899                                                                                                    "ASSIGNMENTS"
5900                                                                                                    "}\n"
5901                                                                                                    "\n";
5902
5903         static const GLchar* fragment_shader_template = "#version 430 core\n"
5904                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5905                                                                                                         "\n"
5906                                                                                                         "INTERFACE"
5907                                                                                                         "\n"
5908                                                                                                         "void main()\n"
5909                                                                                                         "{\n"
5910                                                                                                         "CALCULATIONS"
5911                                                                                                         "\n"
5912                                                                                                         "ASSIGNMENTS"
5913                                                                                                         "}\n"
5914                                                                                                         "\n";
5915
5916         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5917         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5918         static const GLchar* geometry_shader_template = "#version 430 core\n"
5919                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5920                                                                                                         "\n"
5921                                                                                                         "layout(points)                   in;\n"
5922                                                                                                         "layout(points, max_vertices = 3) out;\n"
5923                                                                                                         "\n"
5924                                                                                                         "INTERFACE"
5925                                                                                                         "\n"
5926                                                                                                         "void main()\n"
5927                                                                                                         "{\n"
5928                                                                                                         "CALCULATIONS"
5929                                                                                                         "\n"
5930                                                                                                         "\n"
5931                                                                                                         "ASSIGNMENTS"
5932                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5933                                                                                                         "    EmitVertex();\n"
5934                                                                                                         "}\n"
5935                                                                                                         "\n";
5936
5937         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5938                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5939                                                                                                          "\n"
5940                                                                                                          "layout(vertices = 1) out;\n"
5941                                                                                                          "\n"
5942                                                                                                          "INTERFACE"
5943                                                                                                          "\n"
5944                                                                                                          "void main()\n"
5945                                                                                                          "{\n"
5946                                                                                                          "CALCULATIONS"
5947                                                                                                          "\n"
5948                                                                                                          "ASSIGNMENTS"
5949                                                                                                          "\n"
5950                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5951                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5952                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5953                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5954                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5955                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5956                                                                                                          "}\n"
5957                                                                                                          "\n";
5958
5959         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5960                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5961                                                                                                          "\n"
5962                                                                                                          "layout(isolines, point_mode) in;\n"
5963                                                                                                          "\n"
5964                                                                                                          "INTERFACE"
5965                                                                                                          "\n"
5966                                                                                                          "void main()\n"
5967                                                                                                          "{\n"
5968                                                                                                          "CALCULATIONS"
5969                                                                                                          "\n"
5970                                                                                                          "ASSIGNMENTS"
5971                                                                                                          "}\n"
5972                                                                                                          "\n";
5973
5974         static const GLchar* vertex_shader_template = "#version 430 core\n"
5975                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5976                                                                                                   "\n"
5977                                                                                                   "INTERFACE"
5978                                                                                                   "\n"
5979                                                                                                   "void main()\n"
5980                                                                                                   "{\n"
5981                                                                                                   "CALCULATIONS"
5982                                                                                                   "\n"
5983                                                                                                   "ASSIGNMENTS"
5984                                                                                                   "}\n"
5985                                                                                                   "\n";
5986
5987         const GLchar* result = 0;
5988
5989         switch (stage)
5990         {
5991         case Utils::Shader::COMPUTE:
5992                 result = compute_shader_template;
5993                 break;
5994         case Utils::Shader::FRAGMENT:
5995                 result = fragment_shader_template;
5996                 break;
5997         case Utils::Shader::GEOMETRY:
5998                 result = geometry_shader_template;
5999                 break;
6000         case Utils::Shader::TESS_CTRL:
6001                 result = tess_ctrl_shader_template;
6002                 break;
6003         case Utils::Shader::TESS_EVAL:
6004                 result = tess_eval_shader_template;
6005                 break;
6006         case Utils::Shader::VERTEX:
6007                 result = vertex_shader_template;
6008                 break;
6009         default:
6010                 TCU_FAIL("Invalid enum");
6011         }
6012
6013         return result;
6014 }
6015
6016 /** Prepare buffer according to descriptor
6017  *
6018  * @param buffer Buffer to prepare
6019  * @param desc   Descriptor
6020  **/
6021 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
6022 {
6023         GLsizeiptr size = 0;
6024         GLvoid* data = 0;
6025
6026         if (false == desc.m_initial_data.empty())
6027         {
6028                 size = desc.m_initial_data.size();
6029                 data = &desc.m_initial_data[0];
6030         }
6031         else if (false == desc.m_expected_data.empty())
6032         {
6033                 size = desc.m_expected_data.size();
6034         }
6035
6036         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
6037
6038         if (bufferDescriptor::m_non_indexed != desc.m_index)
6039         {
6040                 buffer.BindBase(desc.m_index);
6041         }
6042         else
6043         {
6044                 buffer.Bind();
6045         }
6046 }
6047
6048 /** Prepare collection of buffer
6049  *
6050  * @param descriptors Collection of descriptors
6051  * @param out_buffers Collection of buffers
6052  **/
6053 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6054 {
6055         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6056         {
6057                 bufferCollection::pair pair;
6058
6059                 pair.m_buffer = new Utils::Buffer(m_context);
6060                 if (0 == pair.m_buffer)
6061                 {
6062                         TCU_FAIL("Memory allocation failed");
6063                 }
6064
6065                 pair.m_descriptor = &(*it);
6066
6067                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6068
6069                 out_buffers.m_vector.push_back(pair);
6070         }
6071 }
6072
6073 /** Destructor
6074  *
6075  **/
6076 BufferTestBase::bufferCollection::~bufferCollection()
6077 {
6078         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6079         {
6080                 if (0 != it->m_buffer)
6081                 {
6082                         delete it->m_buffer;
6083                         it->m_buffer = 0;
6084                 }
6085         }
6086 }
6087
6088 /** Constructor
6089  *
6090  * @param context          Test context
6091  * @param test_name        Name of test
6092  * @param test_description Description of test
6093  **/
6094 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6095         : TestBase(context, test_name, test_description)
6096 {
6097 }
6098
6099 /** Selects if "compute" stage is relevant for test
6100  *
6101  * @param ignored
6102  *
6103  * @return true
6104  **/
6105 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6106 {
6107         return true;
6108 }
6109
6110 /** Selects if compilation failure is expected result
6111  *
6112  * @param ignored
6113  *
6114  * @return true
6115  **/
6116 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6117 {
6118         return true;
6119 }
6120
6121 /** Runs test case
6122  *
6123  * @param test_case_index Id of test case
6124  *
6125  * @return true if test case pass, false otherwise
6126  **/
6127 bool NegativeTestBase::testCase(GLuint test_case_index)
6128 {
6129         bool test_case_result = true;
6130
6131         /* Compute */
6132         if (true == isComputeRelevant(test_case_index))
6133         {
6134                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6135                 bool                       is_build_error         = false;
6136                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6137                 Utils::Program   program(m_context);
6138
6139                 try
6140                 {
6141                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6142                                                  false /* separable */);
6143                 }
6144                 catch (Utils::Shader::InvalidSourceException& exc)
6145                 {
6146                         if (false == is_failure_expected)
6147                         {
6148                                 m_context.getTestContext().getLog()
6149                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6150                                 exc.log(m_context);
6151                         }
6152
6153 #if DEBUG_NEG_LOG_ERROR
6154
6155                         else
6156                         {
6157                                 m_context.getTestContext().getLog()
6158                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6159                                         << tcu::TestLog::EndMessage;
6160                                 exc.log(m_context);
6161                         }
6162
6163 #endif /* DEBUG_NEG_LOG_ERROR */
6164
6165                         is_build_error = true;
6166                 }
6167                 catch (Utils::Program::BuildException& exc)
6168                 {
6169                         if (false == is_failure_expected)
6170                         {
6171                                 m_context.getTestContext().getLog()
6172                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6173                                 exc.log(m_context);
6174                         }
6175
6176 #if DEBUG_NEG_LOG_ERROR
6177
6178                         else
6179                         {
6180                                 m_context.getTestContext().getLog()
6181                                         << tcu::TestLog::Message
6182                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6183                                 exc.log(m_context);
6184                         }
6185
6186 #endif /* DEBUG_NEG_LOG_ERROR */
6187
6188                         is_build_error = true;
6189                 }
6190
6191                 if (is_build_error != is_failure_expected)
6192                 {
6193                         if (!is_build_error)
6194                         {
6195                                 m_context.getTestContext().getLog()
6196                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6197                                 Utils::Shader::LogSource(m_context, cs_source, Utils::Shader::COMPUTE);
6198                         }
6199                         test_case_result = false;
6200                 }
6201         }
6202         else /* Draw */
6203         {
6204                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6205                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6206                 bool                       is_build_error         = false;
6207                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6208                 Utils::Program   program(m_context);
6209                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6210                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6211                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6212
6213                 try
6214                 {
6215                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6216                 }
6217                 catch (Utils::Shader::InvalidSourceException& exc)
6218                 {
6219                         if (false == is_failure_expected)
6220                         {
6221                                 m_context.getTestContext().getLog()
6222                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6223                                 exc.log(m_context);
6224                         }
6225
6226 #if DEBUG_NEG_LOG_ERROR
6227
6228                         else
6229                         {
6230                                 m_context.getTestContext().getLog()
6231                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6232                                         << tcu::TestLog::EndMessage;
6233                                 exc.log(m_context);
6234                         }
6235
6236 #endif /* DEBUG_NEG_LOG_ERROR */
6237
6238                         is_build_error = true;
6239                 }
6240                 catch (Utils::Program::BuildException& exc)
6241                 {
6242                         if (false == is_failure_expected)
6243                         {
6244                                 m_context.getTestContext().getLog()
6245                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6246                                 exc.log(m_context);
6247                         }
6248
6249 #if DEBUG_NEG_LOG_ERROR
6250
6251                         else
6252                         {
6253                                 m_context.getTestContext().getLog()
6254                                         << tcu::TestLog::Message
6255                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6256                                 exc.log(m_context);
6257                         }
6258
6259 #endif /* DEBUG_NEG_LOG_ERROR */
6260
6261                         is_build_error = true;
6262                 }
6263
6264                 if (is_build_error != is_failure_expected)
6265                 {
6266                         if (!is_build_error)
6267                         {
6268                                 m_context.getTestContext().getLog()
6269                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6270                                 Utils::Shader::LogSource(m_context, vs_source, Utils::Shader::VERTEX);
6271                                 Utils::Shader::LogSource(m_context, tcs_source, Utils::Shader::TESS_CTRL);
6272                                 Utils::Shader::LogSource(m_context, tes_source, Utils::Shader::TESS_EVAL);
6273                                 Utils::Shader::LogSource(m_context, gs_source, Utils::Shader::GEOMETRY);
6274                                 Utils::Shader::LogSource(m_context, fs_source, Utils::Shader::FRAGMENT);
6275                         }
6276                         test_case_result = false;
6277                 }
6278         }
6279
6280         return test_case_result;
6281 }
6282
6283 /* Constants used by TextureTestBase */
6284 const glw::GLuint TextureTestBase::m_width  = 16;
6285 const glw::GLuint TextureTestBase::m_height = 16;
6286
6287 /** Constructor
6288  *
6289  * @param context          Test context
6290  * @param test_name        Name of test
6291  * @param test_description Description of test
6292  **/
6293 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6294         : TestBase(context, test_name, test_description)
6295 {
6296 }
6297
6298 /** Get locations for all inputs with automatic_location
6299  *
6300  * @param program           Program object
6301  * @param program_interface Interface of program
6302  **/
6303 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6304 {
6305         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6306
6307         Utils::Variable::PtrVector& inputs = si.m_inputs;
6308
6309         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6310         {
6311                 /* Test does not specify location, query value and set */
6312                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6313                 {
6314                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6315                         GLint  location = 0;
6316
6317                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6318
6319                         (*it)->m_descriptor.m_expected_location = location;
6320                 }
6321         }
6322 }
6323
6324 /** Verifies contents of drawn image
6325  *
6326  * @param ignored
6327  * @param color_0 Verified image
6328  *
6329  * @return true if image is filled with 1, false otherwise
6330  **/
6331 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6332 {
6333         static const GLuint size                   = m_width * m_height;
6334         static const GLuint expected_color = 1;
6335
6336         std::vector<GLuint> data;
6337         data.resize(size);
6338
6339         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6340
6341         for (GLuint i = 0; i < size; ++i)
6342         {
6343                 const GLuint color = data[i];
6344
6345                 if (expected_color != color)
6346                 {
6347                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6348                                                                                                 << tcu::TestLog::EndMessage;
6349                         return false;
6350                 }
6351         }
6352
6353         return true;
6354 }
6355
6356 /** Execute dispatch compute for 16x16x1
6357  *
6358  * @param ignored
6359  **/
6360 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6361 {
6362         const Functions& gl = m_context.getRenderContext().getFunctions();
6363
6364         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6365         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6366 }
6367
6368 /** Execute drawArrays for single vertex
6369  *
6370  * @param ignored
6371  **/
6372 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6373 {
6374         const Functions& gl = m_context.getRenderContext().getFunctions();
6375
6376         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6377         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6378 }
6379
6380 /** Prepare code snippet that will pass in variables to out variables
6381  *
6382  * @param ignored
6383  * @param varying_passthrough Collection of connections between in and out variables
6384  * @param stage               Shader stage
6385  *
6386  * @return Code that pass in variables to next stage
6387  **/
6388 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6389                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6390 {
6391         static const GLchar* separator = "\n    ";
6392
6393         /* Skip for compute shader */
6394         if (Utils::Shader::COMPUTE == stage)
6395         {
6396                 return "";
6397         }
6398
6399         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6400
6401         std::string result   = Utils::g_list;
6402         size_t          position = 0;
6403
6404         for (GLuint i = 0; i < vector.size(); ++i)
6405         {
6406
6407                 Utils::VaryingConnection& connection = vector[i];
6408
6409                 Utils::Variable* in  = connection.m_in;
6410                 Utils::Variable* out = connection.m_out;
6411
6412                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6413                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6414
6415                 const std::string passthrough =
6416                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6417
6418                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6419         }
6420
6421         Utils::endList("", position, result);
6422
6423         return result;
6424 }
6425
6426 /** Basic implementation of method getProgramInterface
6427  *
6428  * @param ignored
6429  * @param ignored
6430  * @param ignored
6431  **/
6432 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6433                                                                                   Utils::ProgramInterface& /* program_interface */,
6434                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6435 {
6436 }
6437
6438 /** Prepare code snippet that will verify in and uniform variables
6439  *
6440  * @param ignored
6441  * @param program_interface Interface of program
6442  * @param stage             Shader stage
6443  *
6444  * @return Code that verify variables
6445  **/
6446 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6447                                                                                                         Utils::ProgramInterface& program_interface,
6448                                                                                                         Utils::Shader::STAGES   stage)
6449 {
6450         static const GLchar* separator = " ||\n        ";
6451
6452         std::string verification = "if (LIST)\n"
6453                                                            "    {\n"
6454                                                            "        result = 0u;\n"
6455                                                            "    }\n";
6456
6457         /* Get flavour of in and out variables */
6458         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6459
6460         /* Get interface for shader stage */
6461         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6462
6463         /* There are no varialbes to verify */
6464         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6465         {
6466                 return "";
6467         }
6468
6469         /* For each in variable insert verification code */
6470         size_t position = 0;
6471
6472         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6473         {
6474                 const Utils::Variable& var                              = *si.m_inputs[i];
6475                 const std::string&       var_verification = getVariableVerification("", var.m_data, var.m_descriptor, in_flavour);
6476
6477                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6478         }
6479
6480         /* For each unifrom variable insert verification code */
6481         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6482         {
6483                 const Utils::Variable& var = *si.m_uniforms[i];
6484                 const std::string&       var_verification =
6485                         getVariableVerification("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6486
6487                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6488         }
6489
6490         /* For each ssb variable insert verification code */
6491         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6492         {
6493                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6494                 const std::string&       var_verification =
6495                         getVariableVerification("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6496
6497                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6498         }
6499
6500         Utils::endList("", position, verification);
6501
6502 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6503
6504         {
6505                 GLchar buffer[16];
6506                 sprintf(buffer, "%d", stage + 10);
6507                 Utils::replaceToken("0u", position, buffer, verification);
6508         }
6509
6510 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6511
6512         if (Utils::Shader::VERTEX == stage)
6513         {
6514                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6515         }
6516         else
6517         {
6518                 Utils::replaceToken("0u", position, "31u", verification);
6519         }
6520
6521 #endif
6522
6523         /* Done */
6524         return verification;
6525 }
6526
6527 /** Selects if "compute" stage is relevant for test
6528  *
6529  * @param ignored
6530  *
6531  * @return true
6532  **/
6533 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6534 {
6535         return true;
6536 }
6537
6538 /** Selects if "draw" stages are relevant for test
6539  *
6540  * @param ignored
6541  *
6542  * @return true
6543  **/
6544 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6545 {
6546         return true;
6547 }
6548
6549 /** Prepare code that will do assignment of single in to single out
6550  *
6551  * @param in_parent_name  Name of parent in variable
6552  * @param in_variable     Descriptor of in variable
6553  * @param in_flavour      Flavoud of in variable
6554  * @param out_parent_name Name of parent out variable
6555  * @param out_variable    Descriptor of out variable
6556  * @param out_flavour     Flavoud of out variable
6557  *
6558  * @return Code that does OUT = IN
6559  **/
6560 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6561                                                                                                         const Utils::Variable::Descriptor& in_variable,
6562                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6563                                                                                                         const std::string&                                 out_parent_name,
6564                                                                                                         const Utils::Variable::Descriptor& out_variable,
6565                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6566 {
6567         bool                             done             = false;
6568         GLuint                           index            = 0;
6569         GLuint                           member_index = 0;
6570         size_t                           position        = 0;
6571         std::string                      result           = Utils::g_list;
6572         static const GLchar* separator  = ";\n    ";
6573
6574         /* For each member of each array element */
6575         do
6576         {
6577                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6578                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6579                 std::string               passthrough;
6580
6581                 /* Prepare verification */
6582                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6583                 {
6584                         size_t pass_position = 0;
6585
6586                         passthrough = "OUT = IN;";
6587
6588                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6589                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6590
6591                         /* Increment index */
6592                         ++index;
6593                 }
6594                 else
6595                 {
6596                         const Utils::Interface* in_interface  = in_variable.m_interface;
6597                         const Utils::Interface* out_interface = out_variable.m_interface;
6598
6599                         if ((0 == in_interface) || (0 == out_interface))
6600                         {
6601                                 TCU_FAIL("Nullptr");
6602                         }
6603
6604                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6605                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6606
6607                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6608                                                                                                  Utils::Variable::BASIC);
6609
6610                         /* Increment member_index */
6611                         ++member_index;
6612
6613                         /* Increment index and reset member_index if all members were processed */
6614                         if (in_interface->m_members.size() == member_index)
6615                         {
6616                                 ++index;
6617                                 member_index = 0;
6618                         }
6619                 }
6620
6621                 /* Check if loop should end */
6622                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6623                 {
6624                         done = true;
6625                 }
6626
6627                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6628
6629         } while (true != done);
6630
6631         Utils::endList("", position, result);
6632
6633         /* Done */
6634         return result;
6635 }
6636
6637 /** Get verification of single variable
6638  *
6639  * @param parent_name Name of parent variable
6640  * @param data        Data that should be used as EXPECTED
6641  * @param variable    Descriptor of variable
6642  * @param flavour     Flavour of variable
6643  *
6644  * @return Code that does (EXPECTED != VALUE) ||
6645  **/
6646 std::string TextureTestBase::getVariableVerification(const std::string& parent_name, const GLvoid* data,
6647                                                                                                          const Utils::Variable::Descriptor& variable,
6648                                                                                                          Utils::Variable::FLAVOUR                       flavour)
6649 {
6650         static const GLchar* logic_op   = " ||\n        ";
6651         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6652         size_t                           position   = 0;
6653         std::string                      result         = Utils::g_list;
6654         GLint                            stride         = variable.m_expected_stride_of_element;
6655
6656         /* For each each array element */
6657         for (GLuint element = 0; element < n_elements; ++element)
6658         {
6659                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6660
6661                 /* Calculate data pointer */
6662                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6663
6664                 /* Prepare verification */
6665                 if (Utils::Variable::BUILTIN == variable.m_type)
6666                 {
6667                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6668                         std::string                verification;
6669                         size_t                     verification_position = 0;
6670
6671                         verification = "(EXPECTED != NAME)";
6672
6673                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6674                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6675
6676                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6677                 }
6678                 else
6679                 {
6680                         const Utils::Interface* interface = variable.m_interface;
6681
6682                         if (0 == interface)
6683                         {
6684                                 TCU_FAIL("Nullptr");
6685                         }
6686
6687                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6688
6689                         /* for each member */
6690                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6691                         {
6692                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6693
6694                                 /* Get verification of member */
6695                                 const std::string& verification =
6696                                         getVariableVerification(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6697
6698                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6699                         }
6700                 }
6701         }
6702
6703         Utils::endList("", position, result);
6704
6705         return result;
6706 }
6707
6708 /** Prepare attributes, vertex array object and array buffer
6709  *
6710  * @param test_case_index   Index of test case
6711  * @param program_interface Interface of program
6712  * @param buffer            Array buffer
6713  * @param vao               Vertex array object
6714  **/
6715 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6716                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6717 {
6718         bool use_component_qualifier = useComponentQualifier(test_case_index);
6719
6720         /* Get shader interface */
6721         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6722
6723         /* Bind vao and buffer */
6724         vao.Bind();
6725         buffer.Bind();
6726
6727         /* Skip if there are no input variables in vertex shader */
6728         if (0 == si.m_inputs.size())
6729         {
6730                 return;
6731         }
6732
6733         const Functions& gl = m_context.getRenderContext().getFunctions();
6734
6735         /* Calculate vertex stride and check */
6736         GLint max_inputs;
6737         gl.getIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_inputs);
6738         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
6739
6740         /* dvec3/4 vertex inputs use a single location but require 2x16B slots */
6741         GLint max_slots = max_inputs * 2;
6742
6743         /* Compute used slots */
6744         std::vector<GLint> slot_sizes;
6745         slot_sizes.resize(max_slots);
6746         std::fill(slot_sizes.begin(), slot_sizes.end(), 0);
6747         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6748         {
6749                 Utils::Variable& variable = *si.m_inputs[i];
6750
6751                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6752
6753                 GLint base_slot = variable.m_descriptor.m_expected_location + variable.m_descriptor.m_offset / 16;
6754                 GLint ends_at = variable.m_descriptor.m_offset % 16 + variable_size;
6755
6756                 GLint array_length = std::max(1u, variable.m_descriptor.m_n_array_elements);
6757                 for (GLint loc = 0; loc < array_length; loc++) {
6758                         GLint slot = base_slot + loc;
6759                         slot_sizes[slot] = std::max(slot_sizes[slot], ends_at);
6760                 }
6761         }
6762
6763         /* Compute the offsets where we need to put vertex buffer data for each slot */
6764         std::vector<GLint> slot_offsets;
6765         slot_offsets.resize(max_slots);
6766         std::fill(slot_offsets.begin(), slot_offsets.end(), -1);
6767         GLint buffer_size = 0;
6768         for (GLint i = 0; i < max_slots; i++)
6769         {
6770                 if (slot_sizes[i] == 0)
6771                         continue;
6772                 slot_offsets[i] = buffer_size;
6773                 buffer_size += slot_sizes[i];
6774         }
6775
6776         /* Prepare buffer data and set up vao */
6777         std::vector<GLubyte> buffer_data;
6778         buffer_data.resize(buffer_size);
6779
6780         GLubyte* ptr = &buffer_data[0];
6781
6782         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6783         {
6784                 Utils::Variable& variable = *si.m_inputs[i];
6785
6786                 GLint base_slot = variable.m_descriptor.m_expected_location + variable.m_descriptor.m_offset / 16;
6787                 GLint variable_offset = variable.m_descriptor.m_offset % 16;
6788                 GLint array_length = std::max(1u, variable.m_descriptor.m_n_array_elements);
6789                 for (GLint loc = 0; loc < array_length; loc++) {
6790                         GLint slot = base_slot + loc;
6791                         memcpy(ptr + slot_offsets[slot] + variable_offset, variable.m_data, variable.m_data_size);
6792                 }
6793
6794                 if (false == use_component_qualifier)
6795                 {
6796                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6797                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6798                                                   variable.GetStride(), (GLvoid*)(intptr_t)(slot_offsets[base_slot] + variable_offset));
6799                 }
6800                 else if (0 == variable.m_descriptor.m_expected_component)
6801                 {
6802                         /* Components can only be applied to vectors.
6803                          Assumption that test use all 4 components */
6804                         const Utils::Type& type =
6805                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6806
6807                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6808                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6809                                                   (GLvoid*)(intptr_t)(slot_offsets[base_slot] + variable_offset));
6810                 }
6811         }
6812
6813         /* Update buffer */
6814         buffer.Data(Utils::Buffer::StaticDraw, buffer_size, ptr);
6815 }
6816
6817 /** Get locations for all outputs with automatic_location
6818  *
6819  * @param program           Program object
6820  * @param program_interface Interface of program
6821  **/
6822 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6823 {
6824         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6825         Utils::Variable::PtrVector& outputs = si.m_outputs;
6826
6827         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6828         {
6829                 /* Test does not specify location, query value and set */
6830                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6831                 {
6832                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6833                         GLint  location = 0;
6834
6835                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6836
6837                         (*it)->m_descriptor.m_expected_location = location;
6838                 }
6839         }
6840 }
6841
6842 /** Prepare framebuffer with single texture as color attachment
6843  *
6844  * @param framebuffer     Framebuffer
6845  * @param color_0_texture Texture that will used as color attachment
6846  **/
6847 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6848 {
6849         /* Prepare data */
6850         std::vector<GLuint> texture_data;
6851         texture_data.resize(m_width * m_height);
6852
6853         for (GLuint i = 0; i < texture_data.size(); ++i)
6854         {
6855                 texture_data[i] = 0x20406080;
6856         }
6857
6858         /* Prepare texture */
6859         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6860                                                  &texture_data[0]);
6861
6862         /* Prepare framebuffer */
6863         framebuffer.Init();
6864         framebuffer.Bind();
6865         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6866
6867         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6868         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6869 }
6870
6871 /** Prepare iamge unit for compute shader
6872  *
6873  * @param location      Uniform location
6874  * @param image_texture Texture that will used as color attachment
6875  **/
6876 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6877 {
6878         static const GLuint image_unit = 0;
6879
6880         std::vector<GLuint> texture_data;
6881         texture_data.resize(m_width * m_height);
6882
6883         for (GLuint i = 0; i < texture_data.size(); ++i)
6884         {
6885                 texture_data[i] = 0x20406080;
6886         }
6887
6888         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6889                                            &texture_data[0]);
6890
6891         const Functions& gl = m_context.getRenderContext().getFunctions();
6892
6893         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6894                                                 GL_WRITE_ONLY, GL_R32UI);
6895         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6896
6897         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6898 }
6899
6900 /** Basic implementation
6901  *
6902  * @param ignored
6903  * @param si        Shader interface
6904  * @param program   Program
6905  * @param cs_buffer Buffer for ssb blocks
6906  **/
6907 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6908                                                                   Utils::Buffer& buffer)
6909 {
6910         /* Skip if there are no input variables in vertex shader */
6911         if (0 == si.m_ssb_blocks.size())
6912         {
6913                 return;
6914         }
6915
6916         /* Calculate vertex stride */
6917         GLint ssbs_stride = 0;
6918
6919         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6920         {
6921                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6922
6923                 if (false == variable.IsBlock())
6924                 {
6925                         continue;
6926                 }
6927
6928                 GLint variable_stride = variable.GetStride();
6929
6930                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6931
6932                 ssbs_stride = std::max(ssbs_stride, ends_at);
6933         }
6934
6935         /* Set active program */
6936         program.Use();
6937
6938         /* Allocate */
6939         buffer.Bind();
6940         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6941
6942         /* Set up uniforms */
6943         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6944         {
6945                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6946
6947                 /* prepareUnifor should work fine for ssb blocks */
6948                 prepareUniform(program, variable, buffer);
6949         }
6950 }
6951
6952 /** Basic implementation
6953  *
6954  * @param test_case_index   Test case index
6955  * @param program_interface Program interface
6956  * @param program           Program
6957  * @param cs_buffer         Buffer for compute shader stage
6958  **/
6959 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6960                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6961 {
6962         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6963
6964         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6965
6966         prepareSSBs(test_case_index, cs, program, cs_buffer);
6967
6968         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6969 }
6970
6971 /** Basic implementation
6972  *
6973  * @param test_case_index   Test case index
6974  * @param program_interface Program interface
6975  * @param program           Program
6976  * @param fs_buffer         Buffer for fragment shader stage
6977  * @param gs_buffer         Buffer for geometry shader stage
6978  * @param tcs_buffer        Buffer for tessellation control shader stage
6979  * @param tes_buffer        Buffer for tessellation evaluation shader stage
6980  * @param vs_buffer         Buffer for vertex shader stage
6981  **/
6982 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6983                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6984                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6985 {
6986         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6987         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6988         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6989         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6990         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6991
6992         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6993         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6994         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6995         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6996         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6997
6998         prepareSSBs(test_case_index, fs, program, fs_buffer);
6999         prepareSSBs(test_case_index, gs, program, gs_buffer);
7000         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
7001         prepareSSBs(test_case_index, tes, program, tes_buffer);
7002         prepareSSBs(test_case_index, vs, program, vs_buffer);
7003
7004         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7005         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7006         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7007         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7008         vs_buffer.BindBase(Utils::Shader::VERTEX);
7009 }
7010
7011 /** Updates buffer data with variable
7012  *
7013  * @param program  Program object
7014  * @param variable Variable
7015  * @param buffer   Buffer
7016  **/
7017 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
7018 {
7019         const Functions& gl = m_context.getRenderContext().getFunctions();
7020
7021         GLsizei count = variable.m_descriptor.m_n_array_elements;
7022         if (0 == count)
7023         {
7024                 count = 1;
7025         }
7026
7027         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
7028         {
7029                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
7030                                                 variable.m_data);
7031         }
7032         else
7033         {
7034                 const bool is_block = variable.IsBlock();
7035
7036                 if (false == is_block)
7037                 {
7038                         TCU_FAIL("Not implemented");
7039                 }
7040                 else
7041                 {
7042                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
7043                                                    variable.m_data);
7044                 }
7045         }
7046 }
7047
7048 /** Basic implementation
7049  *
7050  * @param ignored
7051  * @param si        Shader interface
7052  * @param program   Program
7053  * @param cs_buffer Buffer for uniform blocks
7054  **/
7055 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
7056                                                                           Utils::Buffer& buffer)
7057 {
7058         /* Skip if there are no input variables in vertex shader */
7059         if (0 == si.m_uniforms.size())
7060         {
7061                 return;
7062         }
7063
7064         /* Calculate vertex stride */
7065         GLint uniforms_stride = 0;
7066
7067         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7068         {
7069                 Utils::Variable& variable = *si.m_uniforms[i];
7070
7071                 if (false == variable.IsBlock())
7072                 {
7073                         continue;
7074                 }
7075
7076                 GLint variable_stride = variable.GetStride();
7077
7078                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
7079
7080                 uniforms_stride = std::max(uniforms_stride, ends_at);
7081         }
7082
7083         /* Set active program */
7084         program.Use();
7085
7086         /* Allocate */
7087         buffer.Bind();
7088         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
7089
7090         /* Set up uniforms */
7091         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7092         {
7093                 Utils::Variable& variable = *si.m_uniforms[i];
7094
7095                 prepareUniform(program, variable, buffer);
7096         }
7097 }
7098
7099 /** Basic implementation
7100  *
7101  * @param test_case_index   Test case index
7102  * @param program_interface Program interface
7103  * @param program           Program
7104  * @param cs_buffer         Buffer for compute shader stage
7105  **/
7106 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7107                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7108 {
7109         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7110
7111         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7112
7113         prepareUniforms(test_case_index, cs, program, cs_buffer);
7114
7115         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7116 }
7117
7118 /** Basic implementation
7119  *
7120  * @param test_case_index   Test case index
7121  * @param program_interface Program interface
7122  * @param program           Program
7123  * @param fs_buffer         Buffer for fragment shader stage
7124  * @param gs_buffer         Buffer for geometry shader stage
7125  * @param tcs_buffer        Buffer for tessellation control shader stage
7126  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7127  * @param vs_buffer         Buffer for vertex shader stage
7128  **/
7129 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7130                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7131                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7132 {
7133         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7134         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7135         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7136         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7137         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7138
7139         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7140         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7141         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7142         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7143         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7144
7145         prepareUniforms(test_case_index, fs, program, fs_buffer);
7146         prepareUniforms(test_case_index, gs, program, gs_buffer);
7147         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7148         prepareUniforms(test_case_index, tes, program, tes_buffer);
7149         prepareUniforms(test_case_index, vs, program, vs_buffer);
7150
7151         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7152         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7153         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7154         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7155         vs_buffer.BindBase(Utils::Shader::VERTEX);
7156 }
7157
7158 /** Basic implementation
7159  *
7160  * @param test_case_index   Test case index
7161  * @param program_interface Program interface
7162  * @param program           Program
7163  * @param fs_buffer         Buffer for fragment shader stage
7164  * @param gs_buffer         Buffer for geometry shader stage
7165  * @param tcs_buffer        Buffer for tessellation control shader stage
7166  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7167  * @param vs_buffer         Buffer for vertex shader stage
7168  **/
7169 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7170                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7171                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7172                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7173                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7174 {
7175         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7176         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7177         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7178         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7179         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7180
7181         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7182         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7183         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7184         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7185         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7186
7187         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7188         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7189
7190         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7191         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7192
7193         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7194         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7195
7196         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7197         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7198
7199         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7200         vs_buffer.BindBase(Utils::Shader::VERTEX);
7201 }
7202
7203 /** Prepare source for shader
7204  *
7205  * @param test_case_index     Index of test case
7206  * @param program_interface   Interface of program
7207  * @param varying_passthrough Collection of connection between in and out variables
7208  * @param stage               Shader stage
7209  *
7210  * @return Source of shader
7211  **/
7212 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7213                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7214                                                                                          Utils::Shader::STAGES          stage)
7215 {
7216         /* Get strings */
7217         const GLchar*     shader_template  = getShaderTemplate(stage);
7218         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7219
7220         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7221
7222         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7223
7224         const GLchar* per_vertex = "";
7225
7226         std::string source   = shader_template;
7227         size_t          position = 0;
7228
7229         /* Replace tokens in template */
7230         if (Utils::Shader::GEOMETRY == stage)
7231         {
7232                 if (false == useMonolithicProgram(test_case_index))
7233                 {
7234                         per_vertex = "out gl_PerVertex {\n"
7235                                                  "vec4 gl_Position;\n"
7236                                                  "};\n"
7237                                                  "\n";
7238                 }
7239
7240                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7241         }
7242
7243         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7244         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7245
7246         if (false == verification.empty())
7247         {
7248                 Utils::replaceAllTokens("ELSE", "    else ", source);
7249         }
7250         else
7251         {
7252                 Utils::replaceAllTokens("ELSE", "", source);
7253         }
7254
7255         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7256
7257         /* Done */
7258         return source;
7259 }
7260
7261 /** Returns template of shader for given stage
7262  *
7263  * @param stage Shade stage
7264  *
7265  * @return Proper template
7266  **/
7267 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7268 {
7269
7270         static const GLchar* compute_shader_template =
7271                 "#version 430 core\n"
7272                 "#extension GL_ARB_enhanced_layouts : require\n"
7273                 "\n"
7274                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7275                 "\n"
7276                 "writeonly uniform uimage2D uni_image;\n"
7277                 "\n"
7278                 "INTERFACE"
7279                 "\n"
7280                 "void main()\n"
7281                 "{\n"
7282                 "    uint result = 1u;\n"
7283                 "\n"
7284                 "    VERIFICATION"
7285                 "\n"
7286                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7287                 "}\n"
7288                 "\n";
7289
7290         static const GLchar* fragment_shader_template = "#version 430 core\n"
7291                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7292                                                                                                         "\n"
7293                                                                                                         "flat in  uint gs_fs_result;\n"
7294                                                                                                         "     out uint fs_out_result;\n"
7295                                                                                                         "\n"
7296                                                                                                         "INTERFACE"
7297                                                                                                         "\n"
7298                                                                                                         "void main()\n"
7299                                                                                                         "{\n"
7300                                                                                                         "    uint result = 1u;\n"
7301                                                                                                         "\n"
7302                                                                                                         "    if (1u != gs_fs_result)\n"
7303                                                                                                         "    {\n"
7304                                                                                                         "         result = gs_fs_result;\n"
7305                                                                                                         "    }\n"
7306                                                                                                         "ELSEVERIFICATION"
7307                                                                                                         "\n"
7308                                                                                                         "    fs_out_result = result;\n"
7309                                                                                                         "    PASSTHROUGH\n"
7310                                                                                                         "}\n"
7311                                                                                                         "\n";
7312
7313         static const GLchar* geometry_shader_template =
7314                 "#version 430 core\n"
7315                 "#extension GL_ARB_enhanced_layouts : require\n"
7316                 "\n"
7317                 "layout(points)                           in;\n"
7318                 "layout(triangle_strip, max_vertices = 4) out;\n"
7319                 "\n"
7320                 "     in  uint tes_gs_result[];\n"
7321                 "flat out uint gs_fs_result;\n"
7322                 "\n"
7323                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7324                 "INTERFACE"
7325                 "\n"
7326                 "void main()\n"
7327                 "{\n"
7328                 "    uint result = 1u;\n"
7329                 "\n"
7330                 "    if (1u != tes_gs_result[0])\n"
7331                 "    {\n"
7332                 "         result = tes_gs_result[0];\n"
7333                 "    }\n"
7334                 "ELSEVERIFICATION"
7335                 "\n"
7336                 "    gs_fs_result = result;\n"
7337                 "    PASSTHROUGH\n"
7338                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7339                 "    EmitVertex();\n"
7340                 "    gs_fs_result = result;\n"
7341                 "    PASSTHROUGH\n"
7342                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7343                 "    EmitVertex();\n"
7344                 "    gs_fs_result = result;\n"
7345                 "    PASSTHROUGH\n"
7346                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7347                 "    EmitVertex();\n"
7348                 "    gs_fs_result = result;\n"
7349                 "    PASSTHROUGH\n"
7350                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7351                 "    EmitVertex();\n"
7352                 "}\n"
7353                 "\n";
7354
7355         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7356                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7357                                                                                                          "\n"
7358                                                                                                          "layout(vertices = 1) out;\n"
7359                                                                                                          "\n"
7360                                                                                                          "in  uint vs_tcs_result[];\n"
7361                                                                                                          "out uint tcs_tes_result[];\n"
7362                                                                                                          "\n"
7363                                                                                                          "INTERFACE"
7364                                                                                                          "\n"
7365                                                                                                          "void main()\n"
7366                                                                                                          "{\n"
7367                                                                                                          "    uint result = 1u;\n"
7368                                                                                                          "\n"
7369                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7370                                                                                                          "    {\n"
7371                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7372                                                                                                          "    }\n"
7373                                                                                                          "ELSEVERIFICATION"
7374                                                                                                          "\n"
7375                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7376                                                                                                          "\n"
7377                                                                                                          "    PASSTHROUGH\n"
7378                                                                                                          "\n"
7379                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7380                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7381                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7382                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7383                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7384                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7385                                                                                                          "}\n"
7386                                                                                                          "\n";
7387
7388         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7389                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7390                                                                                                          "\n"
7391                                                                                                          "layout(isolines, point_mode) in;\n"
7392                                                                                                          "\n"
7393                                                                                                          "in  uint tcs_tes_result[];\n"
7394                                                                                                          "out uint tes_gs_result;\n"
7395                                                                                                          "\n"
7396                                                                                                          "INTERFACE"
7397                                                                                                          "\n"
7398                                                                                                          "void main()\n"
7399                                                                                                          "{\n"
7400                                                                                                          "    uint result = 1u;\n"
7401                                                                                                          "\n"
7402                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7403                                                                                                          "    {\n"
7404                                                                                                          "         result = tcs_tes_result[0];\n"
7405                                                                                                          "    }\n"
7406                                                                                                          "ELSEVERIFICATION"
7407                                                                                                          "\n"
7408                                                                                                          "    tes_gs_result = result;\n"
7409                                                                                                          "\n"
7410                                                                                                          "    PASSTHROUGH\n"
7411                                                                                                          "}\n"
7412                                                                                                          "\n";
7413
7414         static const GLchar* vertex_shader_template = "#version 430 core\n"
7415                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7416                                                                                                   "\n"
7417                                                                                                   "out uint vs_tcs_result;\n"
7418                                                                                                   "\n"
7419                                                                                                   "INTERFACE"
7420                                                                                                   "\n"
7421                                                                                                   "void main()\n"
7422                                                                                                   "{\n"
7423                                                                                                   "    uint result = 1u;\n"
7424                                                                                                   "\n"
7425                                                                                                   "    VERIFICATION\n"
7426                                                                                                   "\n"
7427                                                                                                   "    vs_tcs_result = result;\n"
7428                                                                                                   "\n"
7429                                                                                                   "    PASSTHROUGH\n"
7430                                                                                                   "}\n"
7431                                                                                                   "\n";
7432
7433         const GLchar* result = 0;
7434
7435         switch (stage)
7436         {
7437         case Utils::Shader::COMPUTE:
7438                 result = compute_shader_template;
7439                 break;
7440         case Utils::Shader::FRAGMENT:
7441                 result = fragment_shader_template;
7442                 break;
7443         case Utils::Shader::GEOMETRY:
7444                 result = geometry_shader_template;
7445                 break;
7446         case Utils::Shader::TESS_CTRL:
7447                 result = tess_ctrl_shader_template;
7448                 break;
7449         case Utils::Shader::TESS_EVAL:
7450                 result = tess_eval_shader_template;
7451                 break;
7452         case Utils::Shader::VERTEX:
7453                 result = vertex_shader_template;
7454                 break;
7455         default:
7456                 TCU_FAIL("Invalid enum");
7457         }
7458
7459         return result;
7460 }
7461
7462 /** Runs test case
7463  *
7464  * @param test_case_index Id of test case
7465  *
7466  * @return true if test case pass, false otherwise
7467  **/
7468 bool TextureTestBase::testCase(GLuint test_case_index)
7469 {
7470         try
7471         {
7472                 if (true == useMonolithicProgram(test_case_index))
7473                 {
7474                         return testMonolithic(test_case_index);
7475                 }
7476                 else
7477                 {
7478                         return testSeparable(test_case_index);
7479                 }
7480         }
7481         catch (Utils::Shader::InvalidSourceException& exc)
7482         {
7483                 exc.log(m_context);
7484                 TCU_FAIL(exc.what());
7485         }
7486         catch (Utils::Program::BuildException& exc)
7487         {
7488                 TCU_FAIL(exc.what());
7489         }
7490 }
7491
7492 /** Runs "draw" test with monolithic program
7493  *
7494  * @param test_case_index Id of test case
7495  **/
7496 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7497 {
7498         Utils::ProgramInterface   program_interface;
7499         Utils::VaryingPassthrough varying_passthrough;
7500
7501         /* */
7502         const std::string& test_name = getTestCaseName(test_case_index);
7503
7504         /* */
7505         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7506
7507         bool result = true;
7508         /* Draw */
7509         if (true == isDrawRelevant(test_case_index))
7510         {
7511                 Utils::Buffer     buffer_attr(m_context);
7512                 Utils::Buffer     buffer_ssb_fs(m_context);
7513                 Utils::Buffer     buffer_ssb_gs(m_context);
7514                 Utils::Buffer     buffer_ssb_tcs(m_context);
7515                 Utils::Buffer     buffer_ssb_tes(m_context);
7516                 Utils::Buffer     buffer_ssb_vs(m_context);
7517                 Utils::Buffer     buffer_u_fs(m_context);
7518                 Utils::Buffer     buffer_u_gs(m_context);
7519                 Utils::Buffer     buffer_u_tcs(m_context);
7520                 Utils::Buffer     buffer_u_tes(m_context);
7521                 Utils::Buffer     buffer_u_vs(m_context);
7522                 Utils::Framebuffer framebuffer(m_context);
7523                 Utils::Program   program(m_context);
7524                 Utils::Texture   texture_fb(m_context);
7525                 Utils::VertexArray vao(m_context);
7526
7527                 /* */
7528                 const std::string& fragment_shader =
7529                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7530                 const std::string& geometry_shader =
7531                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7532                 const std::string& tess_ctrl_shader =
7533                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7534                 const std::string& tess_eval_shader =
7535                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7536                 const std::string& vertex_shader =
7537                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7538
7539                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7540                                          vertex_shader, false /* is_separable */);
7541
7542                 /* */
7543                 prepareAttribLocation(program, program_interface);
7544                 prepareFragmentDataLoc(program, program_interface);
7545
7546                 /* */
7547                 std::stringstream stream;
7548                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7549                 {
7550                         m_context.getTestContext().getLog()
7551                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7552                                 << ". Inspection of draw program interface failed:\n"
7553                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7554                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7555                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7556
7557                         return false;
7558                 }
7559
7560                 /* */
7561                 program.Use();
7562
7563                 /* */
7564                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7565                 vao.Init();
7566                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7567
7568                 /* */
7569                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7570                                                 buffer_u_tes, buffer_u_vs);
7571
7572                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7573                                         buffer_ssb_tes, buffer_ssb_vs);
7574
7575                 /* */
7576                 prepareFramebuffer(framebuffer, texture_fb);
7577
7578                 /* Draw */
7579                 executeDrawCall(test_case_index);
7580
7581 #if USE_NSIGHT
7582                 m_context.getRenderContext().postIterate();
7583 #endif
7584
7585                 /* Check results */
7586                 if (false == checkResults(test_case_index, texture_fb))
7587                 {
7588                         m_context.getTestContext().getLog()
7589                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7590                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7591                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7592                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7593
7594                         result = false;
7595                 }
7596         }
7597
7598         /* Compute */
7599         if (true == isComputeRelevant(test_case_index))
7600         {
7601                 Utils::Buffer     buffer_ssb_cs(m_context);
7602                 Utils::Buffer     buffer_u_cs(m_context);
7603                 Utils::Program   program(m_context);
7604                 Utils::Texture   texture_im(m_context);
7605                 Utils::VertexArray vao(m_context);
7606
7607                 /* */
7608                 const std::string& compute_shader =
7609                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7610
7611                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7612                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7613
7614                 /* */
7615                 {
7616                         std::stringstream stream;
7617
7618                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7619                         {
7620                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7621                                                                                                         << ". Inspection of compute program interface failed:\n"
7622                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7623
7624                                 return false;
7625                         }
7626                 }
7627
7628                 /* */
7629                 program.Use();
7630
7631                 /* */
7632                 vao.Init();
7633                 vao.Bind();
7634
7635                 /* */
7636                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7637
7638                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7639
7640                 /* */
7641                 GLint image_location = program.GetUniformLocation("uni_image");
7642                 prepareImage(image_location, texture_im);
7643
7644                 /* Draw */
7645                 executeDispatchCall(test_case_index);
7646
7647 #if USE_NSIGHT
7648                 m_context.getRenderContext().postIterate();
7649 #endif
7650
7651                 /* Check results */
7652                 if (false == checkResults(test_case_index, texture_im))
7653                 {
7654                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7655                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7656                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7657
7658                         result = false;
7659                 }
7660         }
7661
7662         return result;
7663 }
7664
7665 /** Runs "draw" test with separable program
7666  *
7667  * @param test_case_index Id of test case
7668  **/
7669 bool TextureTestBase::testSeparable(GLuint test_case_index)
7670 {
7671         Utils::ProgramInterface   program_interface;
7672         Utils::VaryingPassthrough varying_passthrough;
7673
7674         /* */
7675         const std::string& test_name = getTestCaseName(test_case_index);
7676
7677         /* */
7678         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7679
7680         bool result = true;
7681         /* Draw */
7682         if (true == isDrawRelevant(test_case_index))
7683         {
7684                 Utils::Buffer     buffer_attr(m_context);
7685                 Utils::Buffer     buffer_u_fs(m_context);
7686                 Utils::Buffer     buffer_u_gs(m_context);
7687                 Utils::Buffer     buffer_u_tcs(m_context);
7688                 Utils::Buffer     buffer_u_tes(m_context);
7689                 Utils::Buffer     buffer_u_vs(m_context);
7690                 Utils::Framebuffer framebuffer(m_context);
7691                 Utils::Pipeline pipeline(m_context);
7692                 Utils::Program   program_fs(m_context);
7693                 Utils::Program   program_gs(m_context);
7694                 Utils::Program   program_tcs(m_context);
7695                 Utils::Program   program_tes(m_context);
7696                 Utils::Program   program_vs(m_context);
7697                 Utils::Texture   texture_fb(m_context);
7698                 Utils::VertexArray vao(m_context);
7699
7700                 /* */
7701                 const std::string& fs =
7702                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7703                 const std::string& gs =
7704                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7705                 const std::string& tcs =
7706                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7707                 const std::string& tes =
7708                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7709                 const std::string& vs =
7710                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7711
7712                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7713                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7714                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7715                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7716                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7717
7718                 /* */
7719                 prepareAttribLocation(program_vs, program_interface);
7720                 prepareFragmentDataLoc(program_vs, program_interface);
7721
7722                 /* */
7723                 std::stringstream stream;
7724                 if ((false ==
7725                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7726                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7727                                                                                                                                 stream)) ||
7728                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7729                                                                                                                                 stream)) ||
7730                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7731                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7732                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7733                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7734                 {
7735                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7736                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7737                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7738                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7739                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7740                                                                                                 << tcu::TestLog::KernelSource(fs);
7741
7742                         return false;
7743                 }
7744
7745                 /* */
7746                 pipeline.Init();
7747                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7748                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7749                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7750                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7751                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7752                 pipeline.Bind();
7753
7754                 /* */
7755
7756                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7757                 vao.Init();
7758                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7759
7760                 /* */
7761                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7762                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7763
7764                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7765
7766                 /* */
7767                 prepareFramebuffer(framebuffer, texture_fb);
7768
7769                 /* Draw */
7770                 executeDrawCall(test_case_index);
7771
7772 #if USE_NSIGHT
7773                 m_context.getRenderContext().postIterate();
7774 #endif
7775
7776                 /* Check results */
7777                 if (false == checkResults(test_case_index, texture_fb))
7778                 {
7779                         m_context.getTestContext().getLog()
7780                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7781                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7782                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7783
7784                         result = false;
7785                 }
7786         }
7787
7788         /* Compute */
7789         if (true == isComputeRelevant(test_case_index))
7790         {
7791                 Utils::Buffer     buffer_u_cs(m_context);
7792                 Utils::Program   program(m_context);
7793                 Utils::Texture   texture_im(m_context);
7794                 Utils::VertexArray vao(m_context);
7795
7796                 /* */
7797                 const std::string& compute_shader =
7798                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7799
7800                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7801                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7802
7803                 /* */
7804                 {
7805                         std::stringstream stream;
7806
7807                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7808                         {
7809                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7810                                                                                                         << ". Inspection of compute program interface failed:\n"
7811                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7812
7813                                 return false;
7814                         }
7815                 }
7816
7817                 /* */
7818                 program.Use();
7819
7820                 /* */
7821                 vao.Init();
7822                 vao.Bind();
7823
7824                 /* */
7825                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7826
7827                 /* */
7828                 GLint image_location = program.GetUniformLocation("uni_image");
7829                 prepareImage(image_location, texture_im);
7830
7831                 /* Draw */
7832                 executeDispatchCall(test_case_index);
7833
7834 #if USE_NSIGHT
7835                 m_context.getRenderContext().postIterate();
7836 #endif
7837
7838                 /* Check results */
7839                 if (false == checkResults(test_case_index, texture_im))
7840                 {
7841                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7842                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7843                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7844
7845                         result = false;
7846                 }
7847         }
7848
7849         return result;
7850 }
7851
7852 /** Basic implementation
7853  *
7854  * @param ignored
7855  *
7856  * @return false
7857  **/
7858 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7859 {
7860         return false;
7861 }
7862
7863 /** Basic implementation
7864  *
7865  * @param ignored
7866  *
7867  * @return true
7868  **/
7869 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7870 {
7871         return true;
7872 }
7873
7874 /** Constructor
7875  *
7876  * @param context Test framework context
7877  **/
7878 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7879         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7880 {
7881         /* Nothing to be done here */
7882 }
7883
7884 /** Execute test
7885  *
7886  * @return tcu::TestNode::STOP otherwise
7887  **/
7888 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7889 {
7890         static const GLuint expected_comp = 64;
7891         static const GLuint expected_xfb  = 4;
7892         static const GLuint expected_sep  = 4;
7893         GLint                           max_comp          = 0;
7894         GLint                           max_xfb           = 0;
7895         GLint                           max_sep           = 0;
7896         bool                            test_result   = true;
7897
7898         const Functions& gl = m_context.getRenderContext().getFunctions();
7899
7900         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7901         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7902         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7903         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7904         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7905         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7906
7907         if (expected_xfb > (GLuint)max_xfb)
7908         {
7909                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7910                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7911                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7912
7913                 test_result = false;
7914         }
7915
7916         if (expected_comp > (GLuint)max_comp)
7917         {
7918                 m_context.getTestContext().getLog()
7919                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7920                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7921
7922                 test_result = false;
7923         }
7924
7925         if (expected_sep > (GLuint)max_sep)
7926         {
7927                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7928                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7929                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7930
7931                 test_result = false;
7932         }
7933
7934         /* Set result */
7935         if (true == test_result)
7936         {
7937                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7938         }
7939         else
7940         {
7941                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7942         }
7943
7944         /* Done */
7945         return tcu::TestNode::STOP;
7946 }
7947
7948 /** Constructor
7949  *
7950  * @param context Test framework context
7951  **/
7952 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7953         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7954 {
7955         /* Nothing to be done here */
7956 }
7957
7958 /** Execute test
7959  *
7960  * @return tcu::TestNode::STOP otherwise
7961  **/
7962 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7963 {
7964         GLint              length = 0;
7965         GLchar             name[64];
7966         GLint              param = 0;
7967         Utils::Program program(m_context);
7968         bool               test_result = true;
7969
7970         const Functions& gl = m_context.getRenderContext().getFunctions();
7971
7972         try
7973         {
7974                 program.Init("" /* cs */, "#version 430 core\n"
7975                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7976                                                                   "\n"
7977                                                                   "in  vec4 vs_fs;\n"
7978                                                                   "out vec4 fs_out;\n"
7979                                                                   "\n"
7980                                                                   "void main()\n"
7981                                                                   "{\n"
7982                                                                   "    fs_out = vs_fs;\n"
7983                                                                   "}\n"
7984                                                                   "\n" /* fs */,
7985                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7986                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7987                                                                                                                           "\n"
7988                                                                                                                           "in  vec4 in_vs;\n"
7989                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7990                                                                                                                           "\n"
7991                                                                                                                           "void main()\n"
7992                                                                                                                           "{\n"
7993                                                                                                                           "    vs_fs = in_vs;\n"
7994                                                                                                                           "}\n"
7995                                                                                                                           "\n" /* vs */,
7996                                          false /* separable */);
7997         }
7998         catch (Utils::Shader::InvalidSourceException& exc)
7999         {
8000                 exc.log(m_context);
8001                 TCU_FAIL(exc.what());
8002         }
8003         catch (Utils::Program::BuildException& exc)
8004         {
8005                 TCU_FAIL(exc.what());
8006         }
8007
8008         /*
8009          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
8010          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
8011          * following:
8012          *   * MAX_NAME_LENGTH,
8013          *   * MAX_NUM_ACTIVE_VARIABLES;
8014          */
8015         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
8016         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
8017                            test_result);
8018
8019         /*
8020          * - GetProgramResourceIndex should generate INVALID_ENUM when
8021          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
8022          */
8023         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
8024         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
8025         /*
8026          * - GetProgramResourceName should generate INVALID_ENUM when
8027          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
8028          */
8029         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
8030                                                           name);
8031         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
8032
8033         /* Set result */
8034         if (true == test_result)
8035         {
8036                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
8037         }
8038         else
8039         {
8040                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
8041         }
8042
8043         /* Done */
8044         return tcu::TestNode::STOP;
8045 }
8046
8047 /** Check if error is the expected one.
8048  *
8049  * @param expected_error Expected error
8050  * @param message        Message to log in case of error
8051  * @param test_result    Test result, set to false in case of invalid error
8052  **/
8053 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
8054 {
8055         const Functions& gl = m_context.getRenderContext().getFunctions();
8056
8057         GLenum error = gl.getError();
8058
8059         if (error != expected_error)
8060         {
8061                 m_context.getTestContext().getLog()
8062                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
8063                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
8064
8065                 test_result = false;
8066         }
8067 }
8068
8069 /** Constructor
8070  *
8071  * @param context Test framework context
8072  **/
8073 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
8074         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
8075 {
8076         /* Nothing to be done here */
8077 }
8078
8079 /** Source for given test case and stage
8080  *
8081  * @param test_case_index Index of test case
8082  * @param stage           Shader stage
8083  *
8084  * @return Shader source
8085  **/
8086 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
8087 {
8088         static const GLchar* cs = "#version 430 core\n"
8089                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8090                                                           "\n"
8091                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8092                                                           "\n"
8093                                                           "writeonly uniform uimage2D uni_image;\n"
8094                                                           "\n"
8095                                                           "void main()\n"
8096                                                           "{\n"
8097                                                           "    uint result = 1u;\n"
8098                                                           "    CONSTANT = 3;\n"
8099                                                           "\n"
8100                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8101                                                           "}\n"
8102                                                           "\n";
8103         static const GLchar* fs = "#version 430 core\n"
8104                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8105                                                           "\n"
8106                                                           "in  vec4 gs_fs;\n"
8107                                                           "out vec4 fs_out;\n"
8108                                                           "\n"
8109                                                           "void main()\n"
8110                                                           "{\n"
8111                                                           "ASSIGNMENT"
8112                                                           "    fs_out = gs_fs;\n"
8113                                                           "}\n"
8114                                                           "\n";
8115         static const GLchar* gs = "#version 430 core\n"
8116                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8117                                                           "\n"
8118                                                           "layout(points)                           in;\n"
8119                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8120                                                           "\n"
8121                                                           "in  vec4 tes_gs[];\n"
8122                                                           "out vec4 gs_fs;\n"
8123                                                           "\n"
8124                                                           "void main()\n"
8125                                                           "{\n"
8126                                                           "ASSIGNMENT"
8127                                                           "    gs_fs = tes_gs[0];\n"
8128                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8129                                                           "    EmitVertex();\n"
8130                                                           "    gs_fs = tes_gs[0];\n"
8131                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8132                                                           "    EmitVertex();\n"
8133                                                           "    gs_fs = tes_gs[0];\n"
8134                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8135                                                           "    EmitVertex();\n"
8136                                                           "    gs_fs = tes_gs[0];\n"
8137                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8138                                                           "    EmitVertex();\n"
8139                                                           "}\n"
8140                                                           "\n";
8141         static const GLchar* tcs = "#version 430 core\n"
8142                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8143                                                            "\n"
8144                                                            "layout(vertices = 1) out;\n"
8145                                                            "\n"
8146                                                            "in  vec4 vs_tcs[];\n"
8147                                                            "out vec4 tcs_tes[];\n"
8148                                                            "\n"
8149                                                            "void main()\n"
8150                                                            "{\n"
8151                                                            "\n"
8152                                                            "ASSIGNMENT"
8153                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8154                                                            "\n"
8155                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8156                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8157                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8158                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8159                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8160                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8161                                                            "}\n"
8162                                                            "\n";
8163         static const GLchar* tes = "#version 430 core\n"
8164                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8165                                                            "\n"
8166                                                            "layout(isolines, point_mode) in;\n"
8167                                                            "\n"
8168                                                            "in  vec4 tcs_tes[];\n"
8169                                                            "out vec4 tes_gs;\n"
8170                                                            "\n"
8171                                                            "void main()\n"
8172                                                            "{\n"
8173                                                            "ASSIGNMENT"
8174                                                            "    tes_gs = tcs_tes[0];\n"
8175                                                            "}\n"
8176                                                            "\n";
8177         static const GLchar* vs = "#version 430 core\n"
8178                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8179                                                           "\n"
8180                                                           "in  vec4 in_vs;\n"
8181                                                           "out vec4 vs_tcs;\n"
8182                                                           "\n"
8183                                                           "void main()\n"
8184                                                           "{\n"
8185                                                           "ASSIGNMENT"
8186                                                           "    vs_tcs = in_vs;\n"
8187                                                           "}\n"
8188                                                           "\n";
8189
8190         std::string source;
8191         testCase&   test_case = m_test_cases[test_case_index];
8192
8193         if (Utils::Shader::COMPUTE == test_case.m_stage)
8194         {
8195                 size_t position = 0;
8196
8197                 source = cs;
8198
8199                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8200         }
8201         else
8202         {
8203                 std::string assignment = "    CONSTANT = 3;\n";
8204                 size_t          position   = 0;
8205
8206                 switch (stage)
8207                 {
8208                 case Utils::Shader::FRAGMENT:
8209                         source = fs;
8210                         break;
8211                 case Utils::Shader::GEOMETRY:
8212                         source = gs;
8213                         break;
8214                 case Utils::Shader::TESS_CTRL:
8215                         source = tcs;
8216                         break;
8217                 case Utils::Shader::TESS_EVAL:
8218                         source = tes;
8219                         break;
8220                 case Utils::Shader::VERTEX:
8221                         source = vs;
8222                         break;
8223                 default:
8224                         TCU_FAIL("Invalid enum");
8225                 }
8226
8227                 if (test_case.m_stage == stage)
8228                 {
8229                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8230                 }
8231                 else
8232                 {
8233                         assignment = "";
8234                 }
8235
8236                 position = 0;
8237                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8238         }
8239
8240         return source;
8241 }
8242
8243 /** Get description of test case
8244  *
8245  * @param test_case_index Index of test case
8246  *
8247  * @return Constant name
8248  **/
8249 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8250 {
8251         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8252
8253         return result;
8254 }
8255
8256 /** Get number of test cases
8257  *
8258  * @return Number of test cases
8259  **/
8260 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8261 {
8262         return static_cast<GLuint>(m_test_cases.size());
8263 }
8264
8265 /** Selects if "compute" stage is relevant for test
8266  *
8267  * @param test_case_index Index of test case
8268  *
8269  * @return true when tested stage is compute
8270  **/
8271 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8272 {
8273         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8274 }
8275
8276 /** Prepare all test cases
8277  *
8278  **/
8279 void GLSLContantImmutablityTest::testInit()
8280 {
8281         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8282         {
8283                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8284                 {
8285                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8286
8287                         m_test_cases.push_back(test_case);
8288                 }
8289         }
8290 }
8291
8292 /** Get name of glsl constant
8293  *
8294  * @param Constant id
8295  *
8296  * @return Name of constant used in GLSL
8297  **/
8298 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8299 {
8300         const GLchar* name = "";
8301
8302         switch (constant)
8303         {
8304         case GL_ARB_ENHANCED_LAYOUTS:
8305                 name = "GL_ARB_enhanced_layouts";
8306                 break;
8307         case GL_MAX_XFB:
8308                 name = "gl_MaxTransformFeedbackBuffers";
8309                 break;
8310         case GL_MAX_XFB_INT_COMP:
8311                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8312                 break;
8313         default:
8314                 TCU_FAIL("Invalid enum");
8315         }
8316
8317         return name;
8318 }
8319
8320 /** Constructor
8321  *
8322  * @param context Test framework context
8323  **/
8324 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8325         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8326 {
8327 }
8328
8329 /** Selects if "compute" stage is relevant for test
8330  *
8331  * @param ignored
8332  *
8333  * @return false
8334  **/
8335 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8336 {
8337         return false;
8338 }
8339
8340 /** Prepare code snippet that will verify in and uniform variables
8341  *
8342  * @param ignored
8343  * @param ignored
8344  * @param stage   Shader stage
8345  *
8346  * @return Code that verify variables
8347  **/
8348 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8349                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8350                                                                                                                   Utils::Shader::STAGES stage)
8351 {
8352         /* Get constants */
8353         const Functions& gl = m_context.getRenderContext().getFunctions();
8354
8355         GLint max_transform_feedback_buffers                            = 0;
8356         GLint max_transform_feedback_interleaved_components = 0;
8357
8358         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8359         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8360         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8361         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8362
8363         std::string verification;
8364
8365         if (Utils::Shader::VERTEX == stage)
8366         {
8367                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8368                                            "    {\n"
8369                                            "        result = 0;\n"
8370                                            "    }\n"
8371                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8372                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8373                                            "    {\n"
8374                                            "        result = 0;\n"
8375                                            "    }\n"
8376                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8377                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8378                                            "    {\n"
8379                                            "        result = 0;\n"
8380                                            "    }\n";
8381
8382                 size_t position = 0;
8383                 GLchar buffer[16];
8384
8385                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8386                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8387
8388                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8389                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8390         }
8391         else
8392         {
8393                 verification = "";
8394         }
8395
8396         return verification;
8397 }
8398
8399 /** Constructor
8400  *
8401  * @param context Test framework context
8402  **/
8403 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8404         : TextureTestBase(context, "glsl_constant_integral_expression",
8405                                           "Test verifies that symbols can be used as constant integral expressions")
8406 {
8407 }
8408
8409 /** Get interface of program
8410  *
8411  * @param ignored
8412  * @param program_interface Interface of program
8413  * @param ignored
8414  **/
8415 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8416                                                                                                                          Utils::ProgramInterface& program_interface,
8417                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8418 {
8419         /* Get constants */
8420         const Functions& gl = m_context.getRenderContext().getFunctions();
8421
8422         GLint max_transform_feedback_buffers                            = 0;
8423         GLint max_transform_feedback_interleaved_components = 0;
8424
8425         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8426         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8427         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8428         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8429
8430         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8431         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8432
8433         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8434         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8435
8436         /* Globals */
8437         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8438                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8439                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8440
8441         size_t position = 0;
8442         GLchar buffer[16];
8443
8444         sprintf(buffer, "%d", gohan_div);
8445         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8446
8447         sprintf(buffer, "%d", goten_div);
8448         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8449
8450         program_interface.m_vertex.m_globals    = globals;
8451         program_interface.m_tess_ctrl.m_globals = globals;
8452         program_interface.m_tess_eval.m_globals = globals;
8453         program_interface.m_geometry.m_globals  = globals;
8454         program_interface.m_fragment.m_globals  = globals;
8455         program_interface.m_compute.m_globals   = globals;
8456 }
8457
8458 /** Prepare code snippet that will verify in and uniform variables
8459  *
8460  * @param ignored
8461  * @param ignored
8462  * @param ignored
8463  *
8464  * @return Code that verify variables
8465  **/
8466 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8467                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8468                                                                                                                                            Utils::Shader::STAGES /* stage */)
8469 {
8470         std::string verification = "{\n"
8471                                                            "        uint goku_sum = 0;\n"
8472                                                            "        uint gohan_sum = 0;\n"
8473                                                            "        uint goten_sum = 0;\n"
8474                                                            "\n"
8475                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8476                                                            "        {\n"
8477                                                            "            goku_sum += goku[i];\n"
8478                                                            "        }\n"
8479                                                            "\n"
8480                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8481                                                            "        {\n"
8482                                                            "            gohan_sum += gohan[i];\n"
8483                                                            "        }\n"
8484                                                            "\n"
8485                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8486                                                            "        {\n"
8487                                                            "            goten_sum += goten[i];\n"
8488                                                            "        }\n"
8489                                                            "\n"
8490                                                            "        if ( (1u != goku_sum)  &&\n"
8491                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8492                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8493                                                            "        {\n"
8494                                                            "            result = 0u;\n"
8495                                                            "        }\n"
8496                                                            "    }\n";
8497
8498         size_t position = 0;
8499         GLchar buffer[16];
8500
8501         sprintf(buffer, "%d", m_gohan_length);
8502         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8503
8504         sprintf(buffer, "%d", m_goten_length);
8505         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8506
8507         return verification;
8508 }
8509
8510 /** Prepare unifroms
8511  *
8512  * @param ignored
8513  * @param ignored
8514  * @param program Program object
8515  * @param ignored
8516  **/
8517 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8518                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8519                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8520 {
8521         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8522
8523         const Functions& gl = m_context.getRenderContext().getFunctions();
8524
8525         GLint goku_location  = program.GetUniformLocation("goku");
8526         GLint gohan_location = program.GetUniformLocation("gohan");
8527         GLint goten_location = program.GetUniformLocation("goten");
8528
8529         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8530         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8531         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8532 }
8533
8534 /** Prepare unifroms
8535  *
8536  * @param test_case_index   Pass as param to first implemetnation
8537  * @param program_interface Pass as param to first implemetnation
8538  * @param program           Pass as param to first implemetnation
8539  * @param ignored
8540  * @param ignored
8541  * @param ignored
8542  * @param ignored
8543  * @param vs_buffer         Pass as param to first implemetnation
8544  **/
8545 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8546                                                                                                                  Utils::ProgramInterface& program_interface,
8547                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8548                                                                                                                  Utils::Buffer& /* gs_buffer */,
8549                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8550                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8551 {
8552         /* Call first implementation */
8553         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8554 }
8555
8556 /** Constructor
8557  *
8558  * @param context Test framework context
8559  **/
8560 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8561         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8562                                           "Test verifies offsets and alignment of uniform buffer members")
8563 {
8564 }
8565
8566 /** Get interface of program
8567  *
8568  * @param test_case_index     Test case index
8569  * @param program_interface   Interface of program
8570  * @param varying_passthrough Collection of connections between in and out variables
8571  **/
8572 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8573                                                                                                                            Utils::ProgramInterface&   program_interface,
8574                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8575 {
8576         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8577                                                   "const int type_align = TYPE_ALIGN;\n"
8578                                                   "const int type_size  = TYPE_SIZE;\n";
8579
8580         Utils::Type  type                = getType(test_case_index);
8581         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8582         const GLuint base_align  = type.GetBaseAlignment(false);
8583         const GLuint array_align = type.GetBaseAlignment(true);
8584         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8585         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8586
8587         /* Calculate offsets */
8588         const GLuint first_offset  = 0;
8589         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8590
8591 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8592
8593         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8594         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8595         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8596         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8597         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8598         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8599
8600 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8601
8602         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8603         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8604         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8605         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8606         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8607         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8608
8609 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8610
8611         /* Prepare data */
8612         const std::vector<GLubyte>& first  = type.GenerateData();
8613         const std::vector<GLubyte>& second = type.GenerateData();
8614         const std::vector<GLubyte>& third  = type.GenerateData();
8615         const std::vector<GLubyte>& fourth = type.GenerateData();
8616
8617         m_data.resize(eigth_offset + base_stride);
8618         GLubyte* ptr = &m_data[0];
8619         memcpy(ptr + first_offset, &first[0], first.size());
8620         memcpy(ptr + second_offset, &second[0], second.size());
8621         memcpy(ptr + third_offset, &third[0], third.size());
8622         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8623         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8624         memcpy(ptr + sixth_offset, &third[0], third.size());
8625         memcpy(ptr + seventh_offset, &second[0], second.size());
8626         memcpy(ptr + eigth_offset, &first[0], first.size());
8627
8628         /* Prepare globals */
8629         size_t position = 0;
8630         GLchar buffer[16];
8631
8632         sprintf(buffer, "%d", basic_size);
8633         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8634
8635         sprintf(buffer, "%d", type_align);
8636         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8637
8638         sprintf(buffer, "%d", base_stride);
8639         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8640
8641         /* Prepare Block */
8642         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8643
8644         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8645                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8646                                                  first_offset);
8647
8648         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8649                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8650                                                  0 /* n_array_elements */, base_stride, second_offset);
8651
8652         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8653                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8654                                                  third_offset);
8655
8656         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8657                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8658                                                  fourth_offset);
8659
8660         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8661                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8662
8663         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8664                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8665
8666         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8667                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8668                                                  eigth_offset);
8669
8670         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8671
8672         /* Add globals */
8673         vs_si.m_globals = globals;
8674
8675         /* Add uniform BLOCK */
8676         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8677                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8678
8679         /* */
8680         program_interface.CloneVertexInterface(varying_passthrough);
8681 }
8682
8683 /** Get type name
8684  *
8685  * @param test_case_index Index of test case
8686  *
8687  * @return Name of type test in test_case_index
8688  **/
8689 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8690 {
8691         return getTypeName(test_case_index);
8692 }
8693
8694 /** Returns number of types to test
8695  *
8696  * @return Number of types, 34
8697  **/
8698 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8699 {
8700         return getTypesNumber();
8701 }
8702
8703 /** Prepare code snippet that will verify in and uniform variables
8704  *
8705  * @param ignored
8706  * @param ignored
8707  * @param stage   Shader stage
8708  *
8709  * @return Code that verify variables
8710  **/
8711 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8712         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8713 {
8714         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8715                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8716                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8717                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8718                                                            "    {\n"
8719                                                            "        result = 0;\n"
8720                                                            "    }";
8721
8722         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8723
8724         Utils::replaceAllTokens("PREFIX", prefix, verification);
8725
8726         return verification;
8727 }
8728
8729 /** Constructor
8730  *
8731  * @param context Test framework context
8732  **/
8733 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8734         : NegativeTestBase(
8735                   context, "uniform_block_layout_qualifier_conflict",
8736                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8737 {
8738         /* Nothing to be done here */
8739 }
8740
8741 /** Source for given test case and stage
8742  *
8743  * @param test_case_index Index of test case
8744  * @param stage           Shader stage
8745  *
8746  * @return Shader source
8747  **/
8748 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8749                                                                                                                                          Utils::Shader::STAGES stage)
8750 {
8751         static const GLchar* cs = "#version 430 core\n"
8752                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8753                                                           "\n"
8754                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8755                                                           "\n"
8756                                                           "LAYOUTuniform Block {\n"
8757                                                           "    layout(offset = 16) vec4 boy;\n"
8758                                                           "    layout(align  = 64) vec4 man;\n"
8759                                                           "} uni_block;\n"
8760                                                           "\n"
8761                                                           "writeonly uniform image2D uni_image;\n"
8762                                                           "\n"
8763                                                           "void main()\n"
8764                                                           "{\n"
8765                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8766                                                           "\n"
8767                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8768                                                           "}\n"
8769                                                           "\n";
8770         static const GLchar* fs = "#version 430 core\n"
8771                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8772                                                           "\n"
8773                                                           "LAYOUTuniform Block {\n"
8774                                                           "    layout(offset = 16) vec4 boy;\n"
8775                                                           "    layout(align  = 64) vec4 man;\n"
8776                                                           "} uni_block;\n"
8777                                                           "\n"
8778                                                           "in  vec4 gs_fs;\n"
8779                                                           "out vec4 fs_out;\n"
8780                                                           "\n"
8781                                                           "void main()\n"
8782                                                           "{\n"
8783                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8784                                                           "}\n"
8785                                                           "\n";
8786         static const GLchar* gs = "#version 430 core\n"
8787                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8788                                                           "\n"
8789                                                           "layout(points)                           in;\n"
8790                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8791                                                           "\n"
8792                                                           "LAYOUTuniform Block {\n"
8793                                                           "    layout(offset = 16) vec4 boy;\n"
8794                                                           "    layout(align  = 64) vec4 man;\n"
8795                                                           "} uni_block;\n"
8796                                                           "\n"
8797                                                           "in  vec4 tes_gs[];\n"
8798                                                           "out vec4 gs_fs;\n"
8799                                                           "\n"
8800                                                           "void main()\n"
8801                                                           "{\n"
8802                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8803                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8804                                                           "    EmitVertex();\n"
8805                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8806                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8807                                                           "    EmitVertex();\n"
8808                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8809                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8810                                                           "    EmitVertex();\n"
8811                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8812                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8813                                                           "    EmitVertex();\n"
8814                                                           "}\n"
8815                                                           "\n";
8816         static const GLchar* tcs =
8817                 "#version 430 core\n"
8818                 "#extension GL_ARB_enhanced_layouts : require\n"
8819                 "\n"
8820                 "layout(vertices = 1) out;\n"
8821                 "\n"
8822                 "LAYOUTuniform Block {\n"
8823                 "    layout(offset = 16) vec4 boy;\n"
8824                 "    layout(align  = 64) vec4 man;\n"
8825                 "} uni_block;\n"
8826                 "\n"
8827                 "in  vec4 vs_tcs[];\n"
8828                 "out vec4 tcs_tes[];\n"
8829                 "\n"
8830                 "void main()\n"
8831                 "{\n"
8832                 "\n"
8833                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8834                 "\n"
8835                 "    gl_TessLevelOuter[0] = 1.0;\n"
8836                 "    gl_TessLevelOuter[1] = 1.0;\n"
8837                 "    gl_TessLevelOuter[2] = 1.0;\n"
8838                 "    gl_TessLevelOuter[3] = 1.0;\n"
8839                 "    gl_TessLevelInner[0] = 1.0;\n"
8840                 "    gl_TessLevelInner[1] = 1.0;\n"
8841                 "}\n"
8842                 "\n";
8843         static const GLchar* tes = "#version 430 core\n"
8844                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8845                                                            "\n"
8846                                                            "layout(isolines, point_mode) in;\n"
8847                                                            "\n"
8848                                                            "LAYOUTuniform Block {\n"
8849                                                            "    layout(offset = 16) vec4 boy;\n"
8850                                                            "    layout(align  = 64) vec4 man;\n"
8851                                                            "} uni_block;\n"
8852                                                            "\n"
8853                                                            "in  vec4 tcs_tes[];\n"
8854                                                            "out vec4 tes_gs;\n"
8855                                                            "\n"
8856                                                            "void main()\n"
8857                                                            "{\n"
8858                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8859                                                            "}\n"
8860                                                            "\n";
8861         static const GLchar* vs = "#version 430 core\n"
8862                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8863                                                           "\n"
8864                                                           "LAYOUTuniform Block {\n"
8865                                                           "    layout(offset = 16) vec4 boy;\n"
8866                                                           "    layout(align  = 64) vec4 man;\n"
8867                                                           "} uni_block;\n"
8868                                                           "\n"
8869                                                           "in  vec4 in_vs;\n"
8870                                                           "out vec4 vs_tcs;\n"
8871                                                           "\n"
8872                                                           "void main()\n"
8873                                                           "{\n"
8874                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8875                                                           "}\n"
8876                                                           "\n";
8877
8878         std::string   layout    = "";
8879         size_t            position  = 0;
8880         testCase&        test_case = m_test_cases[test_case_index];
8881         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8882         std::string   source;
8883
8884         if (0 != qualifier[0])
8885         {
8886                 size_t layout_position = 0;
8887
8888                 layout = "layout (QUALIFIER) ";
8889
8890                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8891         }
8892
8893         switch (stage)
8894         {
8895         case Utils::Shader::COMPUTE:
8896                 source = cs;
8897                 break;
8898         case Utils::Shader::FRAGMENT:
8899                 source = fs;
8900                 break;
8901         case Utils::Shader::GEOMETRY:
8902                 source = gs;
8903                 break;
8904         case Utils::Shader::TESS_CTRL:
8905                 source = tcs;
8906                 break;
8907         case Utils::Shader::TESS_EVAL:
8908                 source = tes;
8909                 break;
8910         case Utils::Shader::VERTEX:
8911                 source = vs;
8912                 break;
8913         default:
8914                 TCU_FAIL("Invalid enum");
8915         }
8916
8917         if (test_case.m_stage == stage)
8918         {
8919                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8920         }
8921         else
8922         {
8923                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8924         }
8925
8926         return source;
8927 }
8928
8929 /** Get description of test case
8930  *
8931  * @param test_case_index Index of test case
8932  *
8933  * @return Qualifier name
8934  **/
8935 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8936 {
8937         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8938
8939         return result;
8940 }
8941
8942 /** Get number of test cases
8943  *
8944  * @return Number of test cases
8945  **/
8946 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8947 {
8948         return static_cast<GLuint>(m_test_cases.size());
8949 }
8950
8951 /** Selects if "compute" stage is relevant for test
8952  *
8953  * @param test_case_index Index of test case
8954  *
8955  * @return true when tested stage is compute
8956  **/
8957 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8958 {
8959         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8960 }
8961
8962 /** Selects if compilation failure is expected result
8963  *
8964  * @param test_case_index Index of test case
8965  *
8966  * @return false for STD140 cases, true otherwise
8967  **/
8968 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8969 {
8970         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8971 }
8972
8973 /** Prepare all test cases
8974  *
8975  **/
8976 void UniformBlockLayoutQualifierConflictTest::testInit()
8977 {
8978         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8979         {
8980                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8981                 {
8982                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8983
8984                         m_test_cases.push_back(test_case);
8985                 }
8986         }
8987 }
8988
8989 /** Get name of glsl constant
8990  *
8991  * @param Constant id
8992  *
8993  * @return Name of constant used in GLSL
8994  **/
8995 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8996 {
8997         const GLchar* name = "";
8998
8999         switch (qualifier)
9000         {
9001         case DEFAULT:
9002                 name = "";
9003                 break;
9004         case STD140:
9005                 name = "std140";
9006                 break;
9007         case SHARED:
9008                 name = "shared";
9009                 break;
9010         case PACKED:
9011                 name = "packed";
9012                 break;
9013         default:
9014                 TCU_FAIL("Invalid enum");
9015         }
9016
9017         return name;
9018 }
9019
9020 /** Constructor
9021  *
9022  * @param context Test framework context
9023  **/
9024 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
9025         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
9026                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
9027 {
9028         /* Nothing to be done here */
9029 }
9030
9031 /** Constructor
9032  *
9033  * @param context     Test framework context
9034  * @param name        Test name
9035  * @param description Test description
9036  **/
9037 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
9038         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
9039         : NegativeTestBase(context, name, description)
9040 {
9041         /* Nothing to be done here */
9042 }
9043
9044 /** Source for given test case and stage
9045  *
9046  * @param test_case_index Index of test case
9047  * @param stage           Shader stage
9048  *
9049  * @return Shader source
9050  **/
9051 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
9052                                                                                                                                                   Utils::Shader::STAGES stage)
9053 {
9054         static const GLchar* cs = "#version 430 core\n"
9055                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9056                                                           "\n"
9057                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9058                                                           "\n"
9059                                                           "layout (std140) uniform Block {\n"
9060                                                           "    layout (offset = OFFSET) TYPE member;\n"
9061                                                           "} block;\n"
9062                                                           "\n"
9063                                                           "writeonly uniform image2D uni_image;\n"
9064                                                           "\n"
9065                                                           "void main()\n"
9066                                                           "{\n"
9067                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9068                                                           "\n"
9069                                                           "    if (TYPE(1) == block.member)\n"
9070                                                           "    {\n"
9071                                                           "        result = vec4(1, 1, 1, 1);\n"
9072                                                           "    }\n"
9073                                                           "\n"
9074                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9075                                                           "}\n"
9076                                                           "\n";
9077         static const GLchar* fs = "#version 430 core\n"
9078                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9079                                                           "\n"
9080                                                           "in  vec4 gs_fs;\n"
9081                                                           "out vec4 fs_out;\n"
9082                                                           "\n"
9083                                                           "void main()\n"
9084                                                           "{\n"
9085                                                           "    fs_out = gs_fs;\n"
9086                                                           "}\n"
9087                                                           "\n";
9088         static const GLchar* fs_tested = "#version 430 core\n"
9089                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9090                                                                          "\n"
9091                                                                          "layout (std140) uniform Block {\n"
9092                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9093                                                                          "} block;\n"
9094                                                                          "\n"
9095                                                                          "in  vec4 gs_fs;\n"
9096                                                                          "out vec4 fs_out;\n"
9097                                                                          "\n"
9098                                                                          "void main()\n"
9099                                                                          "{\n"
9100                                                                          "    if (TYPE(1) == block.member)\n"
9101                                                                          "    {\n"
9102                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9103                                                                          "    }\n"
9104                                                                          "\n"
9105                                                                          "    fs_out += gs_fs;\n"
9106                                                                          "}\n"
9107                                                                          "\n";
9108         static const GLchar* gs = "#version 430 core\n"
9109                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9110                                                           "\n"
9111                                                           "layout(points)                           in;\n"
9112                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9113                                                           "\n"
9114                                                           "in  vec4 tes_gs[];\n"
9115                                                           "out vec4 gs_fs;\n"
9116                                                           "\n"
9117                                                           "void main()\n"
9118                                                           "{\n"
9119                                                           "    gs_fs = tes_gs[0];\n"
9120                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9121                                                           "    EmitVertex();\n"
9122                                                           "    gs_fs = tes_gs[0];\n"
9123                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9124                                                           "    EmitVertex();\n"
9125                                                           "    gs_fs = tes_gs[0];\n"
9126                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9127                                                           "    EmitVertex();\n"
9128                                                           "    gs_fs = tes_gs[0];\n"
9129                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9130                                                           "    EmitVertex();\n"
9131                                                           "}\n"
9132                                                           "\n";
9133         static const GLchar* gs_tested = "#version 430 core\n"
9134                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9135                                                                          "\n"
9136                                                                          "layout(points)                           in;\n"
9137                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9138                                                                          "\n"
9139                                                                          "layout (std140) uniform Block {\n"
9140                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9141                                                                          "} block;\n"
9142                                                                          "\n"
9143                                                                          "in  vec4 tes_gs[];\n"
9144                                                                          "out vec4 gs_fs;\n"
9145                                                                          "\n"
9146                                                                          "void main()\n"
9147                                                                          "{\n"
9148                                                                          "    if (TYPE(1) == block.member)\n"
9149                                                                          "    {\n"
9150                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9151                                                                          "    }\n"
9152                                                                          "\n"
9153                                                                          "    gs_fs += tes_gs[0];\n"
9154                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9155                                                                          "    EmitVertex();\n"
9156                                                                          "    gs_fs += tes_gs[0];\n"
9157                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9158                                                                          "    EmitVertex();\n"
9159                                                                          "    gs_fs += tes_gs[0];\n"
9160                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9161                                                                          "    EmitVertex();\n"
9162                                                                          "    gs_fs += tes_gs[0];\n"
9163                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9164                                                                          "    EmitVertex();\n"
9165                                                                          "}\n"
9166                                                                          "\n";
9167         static const GLchar* tcs = "#version 430 core\n"
9168                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9169                                                            "\n"
9170                                                            "layout(vertices = 1) out;\n"
9171                                                            "\n"
9172                                                            "in  vec4 vs_tcs[];\n"
9173                                                            "out vec4 tcs_tes[];\n"
9174                                                            "\n"
9175                                                            "void main()\n"
9176                                                            "{\n"
9177                                                            "\n"
9178                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9179                                                            "\n"
9180                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9181                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9182                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9183                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9184                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9185                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9186                                                            "}\n"
9187                                                            "\n";
9188         static const GLchar* tcs_tested = "#version 430 core\n"
9189                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9190                                                                           "\n"
9191                                                                           "layout(vertices = 1) out;\n"
9192                                                                           "\n"
9193                                                                           "layout (std140) uniform Block {\n"
9194                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9195                                                                           "} block;\n"
9196                                                                           "\n"
9197                                                                           "in  vec4 vs_tcs[];\n"
9198                                                                           "out vec4 tcs_tes[];\n"
9199                                                                           "\n"
9200                                                                           "void main()\n"
9201                                                                           "{\n"
9202                                                                           "    if (TYPE(1) == block.member)\n"
9203                                                                           "    {\n"
9204                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9205                                                                           "    }\n"
9206                                                                           "\n"
9207                                                                           "\n"
9208                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9209                                                                           "\n"
9210                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9211                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9212                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9213                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9214                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9215                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9216                                                                           "}\n"
9217                                                                           "\n";
9218         static const GLchar* tes = "#version 430 core\n"
9219                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9220                                                            "\n"
9221                                                            "layout(isolines, point_mode) in;\n"
9222                                                            "\n"
9223                                                            "in  vec4 tcs_tes[];\n"
9224                                                            "out vec4 tes_gs;\n"
9225                                                            "\n"
9226                                                            "void main()\n"
9227                                                            "{\n"
9228                                                            "    tes_gs = tcs_tes[0];\n"
9229                                                            "}\n"
9230                                                            "\n";
9231         static const GLchar* tes_tested = "#version 430 core\n"
9232                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9233                                                                           "\n"
9234                                                                           "layout(isolines, point_mode) in;\n"
9235                                                                           "\n"
9236                                                                           "layout (std140) uniform Block {\n"
9237                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9238                                                                           "} block;\n"
9239                                                                           "\n"
9240                                                                           "in  vec4 tcs_tes[];\n"
9241                                                                           "out vec4 tes_gs;\n"
9242                                                                           "\n"
9243                                                                           "void main()\n"
9244                                                                           "{\n"
9245                                                                           "    if (TYPE(1) == block.member)\n"
9246                                                                           "    {\n"
9247                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9248                                                                           "    }\n"
9249                                                                           "\n"
9250                                                                           "    tes_gs += tcs_tes[0];\n"
9251                                                                           "}\n"
9252                                                                           "\n";
9253         static const GLchar* vs = "#version 430 core\n"
9254                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9255                                                           "\n"
9256                                                           "in  vec4 in_vs;\n"
9257                                                           "out vec4 vs_tcs;\n"
9258                                                           "\n"
9259                                                           "void main()\n"
9260                                                           "{\n"
9261                                                           "    vs_tcs = in_vs;\n"
9262                                                           "}\n"
9263                                                           "\n";
9264         static const GLchar* vs_tested = "#version 430 core\n"
9265                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9266                                                                          "\n"
9267                                                                          "layout (std140) uniform Block {\n"
9268                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9269                                                                          "} block;\n"
9270                                                                          "\n"
9271                                                                          "in  vec4 in_vs;\n"
9272                                                                          "out vec4 vs_tcs;\n"
9273                                                                          "\n"
9274                                                                          "void main()\n"
9275                                                                          "{\n"
9276                                                                          "    if (TYPE(1) == block.member)\n"
9277                                                                          "    {\n"
9278                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9279                                                                          "    }\n"
9280                                                                          "\n"
9281                                                                          "    vs_tcs += in_vs;\n"
9282                                                                          "}\n"
9283                                                                          "\n";
9284
9285         std::string source;
9286         testCase&   test_case = m_test_cases[test_case_index];
9287
9288         if (test_case.m_stage == stage)
9289         {
9290                 GLchar                     buffer[16];
9291                 const GLuint       offset       = test_case.m_offset;
9292                 size_t                     position  = 0;
9293                 const Utils::Type& type          = test_case.m_type;
9294                 const GLchar*     type_name = type.GetGLSLTypeName();
9295
9296                 sprintf(buffer, "%d", offset);
9297
9298                 switch (stage)
9299                 {
9300                 case Utils::Shader::COMPUTE:
9301                         source = cs;
9302                         break;
9303                 case Utils::Shader::FRAGMENT:
9304                         source = fs_tested;
9305                         break;
9306                 case Utils::Shader::GEOMETRY:
9307                         source = gs_tested;
9308                         break;
9309                 case Utils::Shader::TESS_CTRL:
9310                         source = tcs_tested;
9311                         break;
9312                 case Utils::Shader::TESS_EVAL:
9313                         source = tes_tested;
9314                         break;
9315                 case Utils::Shader::VERTEX:
9316                         source = vs_tested;
9317                         break;
9318                 default:
9319                         TCU_FAIL("Invalid enum");
9320                 }
9321
9322                 Utils::replaceToken("OFFSET", position, buffer, source);
9323                 Utils::replaceToken("TYPE", position, type_name, source);
9324                 Utils::replaceToken("TYPE", position, type_name, source);
9325         }
9326         else
9327         {
9328                 switch (stage)
9329                 {
9330                 case Utils::Shader::FRAGMENT:
9331                         source = fs;
9332                         break;
9333                 case Utils::Shader::GEOMETRY:
9334                         source = gs;
9335                         break;
9336                 case Utils::Shader::TESS_CTRL:
9337                         source = tcs;
9338                         break;
9339                 case Utils::Shader::TESS_EVAL:
9340                         source = tes;
9341                         break;
9342                 case Utils::Shader::VERTEX:
9343                         source = vs;
9344                         break;
9345                 default:
9346                         TCU_FAIL("Invalid enum");
9347                 }
9348         }
9349
9350         return source;
9351 }
9352
9353 /** Get description of test case
9354  *
9355  * @param test_case_index Index of test case
9356  *
9357  * @return Type name and offset
9358  **/
9359 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9360 {
9361         std::stringstream stream;
9362         testCase&                 test_case = m_test_cases[test_case_index];
9363
9364         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9365
9366         return stream.str();
9367 }
9368
9369 /** Get number of test cases
9370  *
9371  * @return Number of test cases
9372  **/
9373 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9374 {
9375         return static_cast<GLuint>(m_test_cases.size());
9376 }
9377
9378 /** Get the maximum size for an uniform block
9379  *
9380  * @return The maximum size in basic machine units of a uniform block.
9381  **/
9382 GLint UniformBlockMemberInvalidOffsetAlignmentTest::getMaxBlockSize()
9383 {
9384         const Functions& gl               = m_context.getRenderContext().getFunctions();
9385         GLint                    max_size = 0;
9386
9387         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9388         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9389
9390         return max_size;
9391 }
9392
9393 /** Selects if "compute" stage is relevant for test
9394  *
9395  * @param test_case_index Index of test case
9396  *
9397  * @return true when tested stage is compute
9398  **/
9399 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9400 {
9401         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9402 }
9403
9404 /** Selects if compilation failure is expected result
9405  *
9406  * @param test_case_index Index of test case
9407  *
9408  * @return should_fail field from testCase
9409  **/
9410 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9411 {
9412         return m_test_cases[test_case_index].m_should_fail;
9413 }
9414
9415 /** Checks if stage is supported
9416  *
9417  * @param stage ignored
9418  *
9419  * @return true
9420  **/
9421 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9422 {
9423         return true;
9424 }
9425
9426 /** Prepare all test cases
9427  *
9428  **/
9429 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9430 {
9431         const GLuint n_types = getTypesNumber();
9432         bool             stage_support[Utils::Shader::STAGE_MAX];
9433
9434         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9435         {
9436                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9437         }
9438
9439         for (GLuint i = 0; i < n_types; ++i)
9440         {
9441                 const Utils::Type& type           = getType(i);
9442                 const GLuint       alignment  = type.GetBaseAlignment(false);
9443                 const GLuint       type_size  = type.GetSize(true);
9444                 const GLuint       sec_to_end = getMaxBlockSize() - 2 * type_size;
9445
9446                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9447                 {
9448                         if (false == stage_support[stage])
9449                         {
9450                                 continue;
9451                         }
9452
9453                         for (GLuint offset = 0; offset <= type_size; ++offset)
9454                         {
9455                                 const GLuint modulo              = offset % alignment;
9456                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9457                                 const bool   should_fail = !is_aligned;
9458
9459                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9460
9461                                 m_test_cases.push_back(test_case);
9462                         }
9463
9464                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9465                         {
9466                                 const GLuint modulo              = offset % alignment;
9467                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9468                                 const bool   should_fail = !is_aligned;
9469
9470                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9471
9472                                 m_test_cases.push_back(test_case);
9473                         }
9474                 }
9475         }
9476 }
9477
9478 /** Constructor
9479  *
9480  * @param context Test framework context
9481  **/
9482 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9483         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9484                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9485 {
9486         /* Nothing to be done here */
9487 }
9488
9489 /** Constructor
9490  *
9491  * @param context Test framework context
9492  * @param name        Test name
9493  * @param description Test description
9494  **/
9495 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9496                                                                                                                                                                    const glw::GLchar* name,
9497                                                                                                                                                                    const glw::GLchar* description)
9498         : NegativeTestBase(context, name, description)
9499 {
9500         /* Nothing to be done here */
9501 }
9502
9503 /** Source for given test case and stage
9504  *
9505  * @param test_case_index Index of test case
9506  * @param stage           Shader stage
9507  *
9508  * @return Shader source
9509  **/
9510 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9511                                                                                                                                           Utils::Shader::STAGES stage)
9512 {
9513         static const GLchar* cs = "#version 430 core\n"
9514                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9515                                                           "\n"
9516                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9517                                                           "\n"
9518                                                           "layout (std140) uniform Block {\n"
9519                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9520                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9521                                                           "} block;\n"
9522                                                           "\n"
9523                                                           "writeonly uniform image2D uni_image;\n"
9524                                                           "\n"
9525                                                           "void main()\n"
9526                                                           "{\n"
9527                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9528                                                           "\n"
9529                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9530                                                           "        (MAN_TYPE(0) == block.man) )\n"
9531                                                           "    {\n"
9532                                                           "        result = vec4(1, 1, 1, 1);\n"
9533                                                           "    }\n"
9534                                                           "\n"
9535                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9536                                                           "}\n"
9537                                                           "\n";
9538         static const GLchar* fs = "#version 430 core\n"
9539                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9540                                                           "\n"
9541                                                           "in  vec4 gs_fs;\n"
9542                                                           "out vec4 fs_out;\n"
9543                                                           "\n"
9544                                                           "void main()\n"
9545                                                           "{\n"
9546                                                           "    fs_out = gs_fs;\n"
9547                                                           "}\n"
9548                                                           "\n";
9549         static const GLchar* fs_tested = "#version 430 core\n"
9550                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9551                                                                          "\n"
9552                                                                          "layout (std140) uniform Block {\n"
9553                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9554                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9555                                                                          "} block;\n"
9556                                                                          "\n"
9557                                                                          "in  vec4 gs_fs;\n"
9558                                                                          "out vec4 fs_out;\n"
9559                                                                          "\n"
9560                                                                          "void main()\n"
9561                                                                          "{\n"
9562                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9563                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9564                                                                          "    {\n"
9565                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9566                                                                          "    }\n"
9567                                                                          "\n"
9568                                                                          "    fs_out += gs_fs;\n"
9569                                                                          "}\n"
9570                                                                          "\n";
9571         static const GLchar* gs = "#version 430 core\n"
9572                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9573                                                           "\n"
9574                                                           "layout(points)                           in;\n"
9575                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9576                                                           "\n"
9577                                                           "in  vec4 tes_gs[];\n"
9578                                                           "out vec4 gs_fs;\n"
9579                                                           "\n"
9580                                                           "void main()\n"
9581                                                           "{\n"
9582                                                           "    gs_fs = tes_gs[0];\n"
9583                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9584                                                           "    EmitVertex();\n"
9585                                                           "    gs_fs = tes_gs[0];\n"
9586                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9587                                                           "    EmitVertex();\n"
9588                                                           "    gs_fs = tes_gs[0];\n"
9589                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9590                                                           "    EmitVertex();\n"
9591                                                           "    gs_fs = tes_gs[0];\n"
9592                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9593                                                           "    EmitVertex();\n"
9594                                                           "}\n"
9595                                                           "\n";
9596         static const GLchar* gs_tested = "#version 430 core\n"
9597                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9598                                                                          "\n"
9599                                                                          "layout(points)                           in;\n"
9600                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9601                                                                          "\n"
9602                                                                          "layout (std140) uniform Block {\n"
9603                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9604                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9605                                                                          "} block;\n"
9606                                                                          "\n"
9607                                                                          "in  vec4 tes_gs[];\n"
9608                                                                          "out vec4 gs_fs;\n"
9609                                                                          "\n"
9610                                                                          "void main()\n"
9611                                                                          "{\n"
9612                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9613                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9614                                                                          "    {\n"
9615                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9616                                                                          "    }\n"
9617                                                                          "\n"
9618                                                                          "    gs_fs += tes_gs[0];\n"
9619                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9620                                                                          "    EmitVertex();\n"
9621                                                                          "    gs_fs += tes_gs[0];\n"
9622                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9623                                                                          "    EmitVertex();\n"
9624                                                                          "    gs_fs += tes_gs[0];\n"
9625                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9626                                                                          "    EmitVertex();\n"
9627                                                                          "    gs_fs += tes_gs[0];\n"
9628                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9629                                                                          "    EmitVertex();\n"
9630                                                                          "}\n"
9631                                                                          "\n";
9632         static const GLchar* tcs = "#version 430 core\n"
9633                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9634                                                            "\n"
9635                                                            "layout(vertices = 1) out;\n"
9636                                                            "\n"
9637                                                            "in  vec4 vs_tcs[];\n"
9638                                                            "out vec4 tcs_tes[];\n"
9639                                                            "\n"
9640                                                            "void main()\n"
9641                                                            "{\n"
9642                                                            "\n"
9643                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9644                                                            "\n"
9645                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9646                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9647                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9648                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9649                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9650                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9651                                                            "}\n"
9652                                                            "\n";
9653         static const GLchar* tcs_tested = "#version 430 core\n"
9654                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9655                                                                           "\n"
9656                                                                           "layout(vertices = 1) out;\n"
9657                                                                           "\n"
9658                                                                           "layout (std140) uniform Block {\n"
9659                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9660                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9661                                                                           "} block;\n"
9662                                                                           "\n"
9663                                                                           "in  vec4 vs_tcs[];\n"
9664                                                                           "out vec4 tcs_tes[];\n"
9665                                                                           "\n"
9666                                                                           "void main()\n"
9667                                                                           "{\n"
9668                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9669                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9670                                                                           "    {\n"
9671                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9672                                                                           "    }\n"
9673                                                                           "\n"
9674                                                                           "\n"
9675                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9676                                                                           "\n"
9677                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9678                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9679                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9680                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9681                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9682                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9683                                                                           "}\n"
9684                                                                           "\n";
9685         static const GLchar* tes = "#version 430 core\n"
9686                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9687                                                            "\n"
9688                                                            "layout(isolines, point_mode) in;\n"
9689                                                            "\n"
9690                                                            "in  vec4 tcs_tes[];\n"
9691                                                            "out vec4 tes_gs;\n"
9692                                                            "\n"
9693                                                            "void main()\n"
9694                                                            "{\n"
9695                                                            "    tes_gs = tcs_tes[0];\n"
9696                                                            "}\n"
9697                                                            "\n";
9698         static const GLchar* tes_tested = "#version 430 core\n"
9699                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9700                                                                           "\n"
9701                                                                           "layout(isolines, point_mode) in;\n"
9702                                                                           "\n"
9703                                                                           "layout (std140) uniform Block {\n"
9704                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9705                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9706                                                                           "} block;\n"
9707                                                                           "\n"
9708                                                                           "in  vec4 tcs_tes[];\n"
9709                                                                           "out vec4 tes_gs;\n"
9710                                                                           "\n"
9711                                                                           "void main()\n"
9712                                                                           "{\n"
9713                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9714                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9715                                                                           "    {\n"
9716                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9717                                                                           "    }\n"
9718                                                                           "\n"
9719                                                                           "    tes_gs += tcs_tes[0];\n"
9720                                                                           "}\n"
9721                                                                           "\n";
9722         static const GLchar* vs = "#version 430 core\n"
9723                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9724                                                           "\n"
9725                                                           "in  vec4 in_vs;\n"
9726                                                           "out vec4 vs_tcs;\n"
9727                                                           "\n"
9728                                                           "void main()\n"
9729                                                           "{\n"
9730                                                           "    vs_tcs = in_vs;\n"
9731                                                           "}\n"
9732                                                           "\n";
9733         static const GLchar* vs_tested = "#version 430 core\n"
9734                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9735                                                                          "\n"
9736                                                                          "layout (std140) uniform Block {\n"
9737                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9738                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9739                                                                          "} block;\n"
9740                                                                          "\n"
9741                                                                          "in  vec4 in_vs;\n"
9742                                                                          "out vec4 vs_tcs;\n"
9743                                                                          "\n"
9744                                                                          "void main()\n"
9745                                                                          "{\n"
9746                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9747                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9748                                                                          "    {\n"
9749                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9750                                                                          "    }\n"
9751                                                                          "\n"
9752                                                                          "    vs_tcs += in_vs;\n"
9753                                                                          "}\n"
9754                                                                          "\n";
9755
9756         std::string source;
9757         testCase&   test_case = m_test_cases[test_case_index];
9758
9759         if (test_case.m_stage == stage)
9760         {
9761                 GLchar                     buffer[16];
9762                 const GLuint       boy_offset   = test_case.m_boy_offset;
9763                 const Utils::Type& boy_type              = test_case.m_boy_type;
9764                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9765                 const GLuint       man_offset   = test_case.m_man_offset;
9766                 const Utils::Type& man_type              = test_case.m_man_type;
9767                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9768                 size_t                     position              = 0;
9769
9770                 switch (stage)
9771                 {
9772                 case Utils::Shader::COMPUTE:
9773                         source = cs;
9774                         break;
9775                 case Utils::Shader::FRAGMENT:
9776                         source = fs_tested;
9777                         break;
9778                 case Utils::Shader::GEOMETRY:
9779                         source = gs_tested;
9780                         break;
9781                 case Utils::Shader::TESS_CTRL:
9782                         source = tcs_tested;
9783                         break;
9784                 case Utils::Shader::TESS_EVAL:
9785                         source = tes_tested;
9786                         break;
9787                 case Utils::Shader::VERTEX:
9788                         source = vs_tested;
9789                         break;
9790                 default:
9791                         TCU_FAIL("Invalid enum");
9792                 }
9793
9794                 sprintf(buffer, "%d", boy_offset);
9795                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9796                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9797                 sprintf(buffer, "%d", man_offset);
9798                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9799                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9800                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9801                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9802         }
9803         else
9804         {
9805                 switch (stage)
9806                 {
9807                 case Utils::Shader::FRAGMENT:
9808                         source = fs;
9809                         break;
9810                 case Utils::Shader::GEOMETRY:
9811                         source = gs;
9812                         break;
9813                 case Utils::Shader::TESS_CTRL:
9814                         source = tcs;
9815                         break;
9816                 case Utils::Shader::TESS_EVAL:
9817                         source = tes;
9818                         break;
9819                 case Utils::Shader::VERTEX:
9820                         source = vs;
9821                         break;
9822                 default:
9823                         TCU_FAIL("Invalid enum");
9824                 }
9825         }
9826
9827         return source;
9828 }
9829
9830 /** Get description of test case
9831  *
9832  * @param test_case_index Index of test case
9833  *
9834  * @return Type name and offset
9835  **/
9836 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9837 {
9838         std::stringstream stream;
9839         testCase&                 test_case = m_test_cases[test_case_index];
9840
9841         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9842                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9843
9844         return stream.str();
9845 }
9846
9847 /** Get number of test cases
9848  *
9849  * @return Number of test cases
9850  **/
9851 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9852 {
9853         return static_cast<GLuint>(m_test_cases.size());
9854 }
9855
9856 /** Selects if "compute" stage is relevant for test
9857  *
9858  * @param test_case_index Index of test case
9859  *
9860  * @return true when tested stage is compute
9861  **/
9862 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9863 {
9864         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9865 }
9866
9867 /** Checks if stage is supported
9868  *
9869  * @param stage ignored
9870  *
9871  * @return true
9872  **/
9873 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9874 {
9875         return true;
9876 }
9877
9878 /** Prepare all test cases
9879  *
9880  **/
9881 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9882 {
9883         const GLuint n_types = getTypesNumber();
9884         bool             stage_support[Utils::Shader::STAGE_MAX];
9885
9886         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9887         {
9888                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9889         }
9890
9891         for (GLuint i = 0; i < n_types; ++i)
9892         {
9893                 const Utils::Type& boy_type = getType(i);
9894                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9895
9896                 for (GLuint j = 0; j < n_types; ++j)
9897                 {
9898                         const Utils::Type& man_type  = getType(j);
9899                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9900                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9901
9902                         const GLuint boy_offset           = lcm(boy_size, man_size);
9903                         const GLuint man_after_start  = boy_offset + 1;
9904                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9905                         const GLuint man_before_start = boy_offset - man_align;
9906                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9907
9908                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9909                         {
9910                                 if (false == stage_support[stage])
9911                                 {
9912                                         continue;
9913                                 }
9914
9915                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9916                                 {
9917                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9918                                                                                    (Utils::Shader::STAGES)stage };
9919
9920                                         m_test_cases.push_back(test_case);
9921                                 }
9922
9923                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9924                                 {
9925                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9926                                                                                    (Utils::Shader::STAGES)stage };
9927
9928                                         m_test_cases.push_back(test_case);
9929                                 }
9930
9931                                 /* Boy offset, should be fine for both types */
9932                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9933
9934                                 m_test_cases.push_back(test_case);
9935                         }
9936                 }
9937         }
9938 }
9939
9940 /** Find greatest common divisor for a and b
9941  *
9942  * @param a A argument
9943  * @param b B argument
9944  *
9945  * @return Found gcd value
9946  **/
9947 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9948 {
9949         if ((0 != a) && (0 == b))
9950         {
9951                 return a;
9952         }
9953         else
9954         {
9955                 GLuint greater = std::max(a, b);
9956                 GLuint lesser  = std::min(a, b);
9957
9958                 return gcd(lesser, greater % lesser);
9959         }
9960 }
9961
9962 /** Find lowest common multiple for a and b
9963  *
9964  * @param a A argument
9965  * @param b B argument
9966  *
9967  * @return Found gcd value
9968  **/
9969 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9970 {
9971         return (a * b) / gcd(a, b);
9972 }
9973
9974 /** Constructor
9975  *
9976  * @param context Test framework context
9977  **/
9978 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9979         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9980                                            "Test verifies that align qualifier requires value that is a power of 2")
9981 {
9982         /* Nothing to be done here */
9983 }
9984
9985 /** Constructor
9986  *
9987  * @param context Test framework context
9988  * @param name        Test name
9989  * @param description Test description
9990  **/
9991 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9992                                                                                                                                                            const glw::GLchar* name,
9993                                                                                                                                                            const glw::GLchar* description)
9994         : NegativeTestBase(context, name, description)
9995 {
9996         /* Nothing to be done here */
9997 }
9998
9999 /** Source for given test case and stage
10000  *
10001  * @param test_case_index Index of test case
10002  * @param stage           Shader stage
10003  *
10004  * @return Shader source
10005  **/
10006 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10007 {
10008         static const GLchar* cs = "#version 430 core\n"
10009                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10010                                                           "\n"
10011                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10012                                                           "\n"
10013                                                           "layout (std140) uniform Block {\n"
10014                                                           "    vec4 boy;\n"
10015                                                           "    layout (align = ALIGN) TYPE man;\n"
10016                                                           "} block;\n"
10017                                                           "\n"
10018                                                           "writeonly uniform image2D uni_image;\n"
10019                                                           "\n"
10020                                                           "void main()\n"
10021                                                           "{\n"
10022                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
10023                                                           "\n"
10024                                                           "    if (TYPE(0) == block.man)\n"
10025                                                           "    {\n"
10026                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
10027                                                           "    }\n"
10028                                                           "\n"
10029                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10030                                                           "}\n"
10031                                                           "\n";
10032         static const GLchar* fs = "#version 430 core\n"
10033                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10034                                                           "\n"
10035                                                           "in  vec4 gs_fs;\n"
10036                                                           "out vec4 fs_out;\n"
10037                                                           "\n"
10038                                                           "void main()\n"
10039                                                           "{\n"
10040                                                           "    fs_out = gs_fs;\n"
10041                                                           "}\n"
10042                                                           "\n";
10043         static const GLchar* fs_tested = "#version 430 core\n"
10044                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10045                                                                          "\n"
10046                                                                          "layout (std140) uniform Block {\n"
10047                                                                          "    vec4 boy;\n"
10048                                                                          "    layout (align = ALIGN) TYPE man;\n"
10049                                                                          "} block;\n"
10050                                                                          "\n"
10051                                                                          "in  vec4 gs_fs;\n"
10052                                                                          "out vec4 fs_out;\n"
10053                                                                          "\n"
10054                                                                          "void main()\n"
10055                                                                          "{\n"
10056                                                                          "    if (TYPE(0) == block.man)\n"
10057                                                                          "    {\n"
10058                                                                          "        fs_out = block.boy;\n"
10059                                                                          "    }\n"
10060                                                                          "\n"
10061                                                                          "    fs_out += gs_fs;\n"
10062                                                                          "}\n"
10063                                                                          "\n";
10064         static const GLchar* gs = "#version 430 core\n"
10065                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10066                                                           "\n"
10067                                                           "layout(points)                           in;\n"
10068                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10069                                                           "\n"
10070                                                           "in  vec4 tes_gs[];\n"
10071                                                           "out vec4 gs_fs;\n"
10072                                                           "\n"
10073                                                           "void main()\n"
10074                                                           "{\n"
10075                                                           "    gs_fs = tes_gs[0];\n"
10076                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10077                                                           "    EmitVertex();\n"
10078                                                           "    gs_fs = tes_gs[0];\n"
10079                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10080                                                           "    EmitVertex();\n"
10081                                                           "    gs_fs = tes_gs[0];\n"
10082                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10083                                                           "    EmitVertex();\n"
10084                                                           "    gs_fs = tes_gs[0];\n"
10085                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10086                                                           "    EmitVertex();\n"
10087                                                           "}\n"
10088                                                           "\n";
10089         static const GLchar* gs_tested = "#version 430 core\n"
10090                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10091                                                                          "\n"
10092                                                                          "layout(points)                           in;\n"
10093                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
10094                                                                          "\n"
10095                                                                          "layout (std140) uniform Block {\n"
10096                                                                          "    vec4 boy;\n"
10097                                                                          "    layout (align = ALIGN) TYPE man;\n"
10098                                                                          "} block;\n"
10099                                                                          "\n"
10100                                                                          "in  vec4 tes_gs[];\n"
10101                                                                          "out vec4 gs_fs;\n"
10102                                                                          "\n"
10103                                                                          "void main()\n"
10104                                                                          "{\n"
10105                                                                          "    if (TYPE(0) == block.man)\n"
10106                                                                          "    {\n"
10107                                                                          "        gs_fs = block.boy;\n"
10108                                                                          "    }\n"
10109                                                                          "\n"
10110                                                                          "    gs_fs += tes_gs[0];\n"
10111                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10112                                                                          "    EmitVertex();\n"
10113                                                                          "    gs_fs += tes_gs[0];\n"
10114                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10115                                                                          "    EmitVertex();\n"
10116                                                                          "    gs_fs += tes_gs[0];\n"
10117                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10118                                                                          "    EmitVertex();\n"
10119                                                                          "    gs_fs += tes_gs[0];\n"
10120                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10121                                                                          "    EmitVertex();\n"
10122                                                                          "}\n"
10123                                                                          "\n";
10124         static const GLchar* tcs = "#version 430 core\n"
10125                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10126                                                            "\n"
10127                                                            "layout(vertices = 1) out;\n"
10128                                                            "\n"
10129                                                            "in  vec4 vs_tcs[];\n"
10130                                                            "out vec4 tcs_tes[];\n"
10131                                                            "\n"
10132                                                            "void main()\n"
10133                                                            "{\n"
10134                                                            "\n"
10135                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10136                                                            "\n"
10137                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10138                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10139                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10140                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10141                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10142                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10143                                                            "}\n"
10144                                                            "\n";
10145         static const GLchar* tcs_tested = "#version 430 core\n"
10146                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10147                                                                           "\n"
10148                                                                           "layout(vertices = 1) out;\n"
10149                                                                           "\n"
10150                                                                           "layout (std140) uniform Block {\n"
10151                                                                           "    vec4 boy;\n"
10152                                                                           "    layout (align = ALIGN) TYPE man;\n"
10153                                                                           "} block;\n"
10154                                                                           "\n"
10155                                                                           "in  vec4 vs_tcs[];\n"
10156                                                                           "out vec4 tcs_tes[];\n"
10157                                                                           "\n"
10158                                                                           "void main()\n"
10159                                                                           "{\n"
10160                                                                           "    if (TYPE(0) == block.man)\n"
10161                                                                           "    {\n"
10162                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10163                                                                           "    }\n"
10164                                                                           "\n"
10165                                                                           "\n"
10166                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10167                                                                           "\n"
10168                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10169                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10170                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10171                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10172                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10173                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10174                                                                           "}\n"
10175                                                                           "\n";
10176         static const GLchar* tes = "#version 430 core\n"
10177                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10178                                                            "\n"
10179                                                            "layout(isolines, point_mode) in;\n"
10180                                                            "\n"
10181                                                            "in  vec4 tcs_tes[];\n"
10182                                                            "out vec4 tes_gs;\n"
10183                                                            "\n"
10184                                                            "void main()\n"
10185                                                            "{\n"
10186                                                            "    tes_gs = tcs_tes[0];\n"
10187                                                            "}\n"
10188                                                            "\n";
10189         static const GLchar* tes_tested = "#version 430 core\n"
10190                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10191                                                                           "\n"
10192                                                                           "layout(isolines, point_mode) in;\n"
10193                                                                           "\n"
10194                                                                           "layout (std140) uniform Block {\n"
10195                                                                           "    vec4 boy;\n"
10196                                                                           "    layout (align = ALIGN) TYPE man;\n"
10197                                                                           "} block;\n"
10198                                                                           "\n"
10199                                                                           "in  vec4 tcs_tes[];\n"
10200                                                                           "out vec4 tes_gs;\n"
10201                                                                           "\n"
10202                                                                           "void main()\n"
10203                                                                           "{\n"
10204                                                                           "    if (TYPE(0) == block.man)\n"
10205                                                                           "    {\n"
10206                                                                           "        tes_gs = block.boy;\n"
10207                                                                           "    }\n"
10208                                                                           "\n"
10209                                                                           "    tes_gs += tcs_tes[0];\n"
10210                                                                           "}\n"
10211                                                                           "\n";
10212         static const GLchar* vs = "#version 430 core\n"
10213                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10214                                                           "\n"
10215                                                           "in  vec4 in_vs;\n"
10216                                                           "out vec4 vs_tcs;\n"
10217                                                           "\n"
10218                                                           "void main()\n"
10219                                                           "{\n"
10220                                                           "    vs_tcs = in_vs;\n"
10221                                                           "}\n"
10222                                                           "\n";
10223         static const GLchar* vs_tested = "#version 430 core\n"
10224                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10225                                                                          "\n"
10226                                                                          "layout (std140) uniform Block {\n"
10227                                                                          "    vec4 boy;\n"
10228                                                                          "    layout (align = ALIGN) TYPE man;\n"
10229                                                                          "} block;\n"
10230                                                                          "\n"
10231                                                                          "in  vec4 in_vs;\n"
10232                                                                          "out vec4 vs_tcs;\n"
10233                                                                          "\n"
10234                                                                          "void main()\n"
10235                                                                          "{\n"
10236                                                                          "    if (TYPE(0) == block.man)\n"
10237                                                                          "    {\n"
10238                                                                          "        vs_tcs = block.boy;\n"
10239                                                                          "    }\n"
10240                                                                          "\n"
10241                                                                          "    vs_tcs += in_vs;\n"
10242                                                                          "}\n"
10243                                                                          "\n";
10244
10245         std::string source;
10246         testCase&   test_case = m_test_cases[test_case_index];
10247
10248         if (test_case.m_stage == stage)
10249         {
10250                 GLchar                     buffer[16];
10251                 const GLuint       alignment = test_case.m_alignment;
10252                 const Utils::Type& type          = test_case.m_type;
10253                 const GLchar*     type_name = type.GetGLSLTypeName();
10254                 size_t                     position  = 0;
10255
10256                 switch (stage)
10257                 {
10258                 case Utils::Shader::COMPUTE:
10259                         source = cs;
10260                         break;
10261                 case Utils::Shader::FRAGMENT:
10262                         source = fs_tested;
10263                         break;
10264                 case Utils::Shader::GEOMETRY:
10265                         source = gs_tested;
10266                         break;
10267                 case Utils::Shader::TESS_CTRL:
10268                         source = tcs_tested;
10269                         break;
10270                 case Utils::Shader::TESS_EVAL:
10271                         source = tes_tested;
10272                         break;
10273                 case Utils::Shader::VERTEX:
10274                         source = vs_tested;
10275                         break;
10276                 default:
10277                         TCU_FAIL("Invalid enum");
10278                 }
10279
10280                 sprintf(buffer, "%d", alignment);
10281                 Utils::replaceToken("ALIGN", position, buffer, source);
10282                 Utils::replaceToken("TYPE", position, type_name, source);
10283                 Utils::replaceToken("TYPE", position, type_name, source);
10284         }
10285         else
10286         {
10287                 switch (stage)
10288                 {
10289                 case Utils::Shader::FRAGMENT:
10290                         source = fs;
10291                         break;
10292                 case Utils::Shader::GEOMETRY:
10293                         source = gs;
10294                         break;
10295                 case Utils::Shader::TESS_CTRL:
10296                         source = tcs;
10297                         break;
10298                 case Utils::Shader::TESS_EVAL:
10299                         source = tes;
10300                         break;
10301                 case Utils::Shader::VERTEX:
10302                         source = vs;
10303                         break;
10304                 default:
10305                         TCU_FAIL("Invalid enum");
10306                 }
10307         }
10308
10309         return source;
10310 }
10311
10312 /** Get description of test case
10313  *
10314  * @param test_case_index Index of test case
10315  *
10316  * @return Type name and offset
10317  **/
10318 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10319 {
10320         std::stringstream stream;
10321         testCase&                 test_case = m_test_cases[test_case_index];
10322
10323         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10324
10325         return stream.str();
10326 }
10327
10328 /** Get number of test cases
10329  *
10330  * @return Number of test cases
10331  **/
10332 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10333 {
10334         return static_cast<GLuint>(m_test_cases.size());
10335 }
10336
10337 /** Selects if "compute" stage is relevant for test
10338  *
10339  * @param test_case_index Index of test case
10340  *
10341  * @return true when tested stage is compute
10342  **/
10343 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10344 {
10345         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10346 }
10347
10348 /** Checks if stage is supported
10349  *
10350  * @param ignored
10351  *
10352  * @return true
10353  **/
10354 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10355 {
10356         return true;
10357 }
10358
10359 /** Selects if compilation failure is expected result
10360  *
10361  * @param test_case_index Index of test case
10362  *
10363  * @return should_fail field from testCase
10364  **/
10365 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10366 {
10367         return m_test_cases[test_case_index].m_should_fail;
10368 }
10369
10370 /** Prepare all test cases
10371  *
10372  **/
10373 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10374 {
10375         static const GLuint dmat4_size = 128;
10376         const GLuint            n_types = getTypesNumber();
10377         bool                            stage_support[Utils::Shader::STAGE_MAX];
10378
10379         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10380         {
10381                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10382         }
10383
10384         for (GLuint j = 0; j < n_types; ++j)
10385         {
10386                 const Utils::Type& type = getType(j);
10387
10388                 for (GLuint align = 0; align <= dmat4_size; ++align)
10389                 {
10390
10391 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10392
10393                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10394
10395 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10396
10397                         const bool should_fail = !isPowerOf2(align);
10398
10399 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10400
10401                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10402                         {
10403                                 if (false == stage_support[stage])
10404                                 {
10405                                         continue;
10406                                 }
10407
10408                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10409
10410                                 m_test_cases.push_back(test_case);
10411                         }
10412                 }
10413         }
10414 }
10415
10416 /** Check if value is power of 2
10417  *
10418  * @param val Tested value
10419  *
10420  * @return true if val is power of 2, false otherwise
10421  **/
10422 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10423 {
10424         if (0 == val)
10425         {
10426                 return false;
10427         }
10428
10429         return (0 == (val & (val - 1)));
10430 }
10431
10432 /** Constructor
10433  *
10434  * @param context Test framework context
10435  **/
10436 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10437         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10438 {
10439 }
10440
10441 /** Get interface of program
10442  *
10443  * @param ignored
10444  * @param program_interface Interface of program
10445  * @param varying_passthrough Collection of connections between in and out variables
10446  **/
10447 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10448                                                                                                         Utils::ProgramInterface&   program_interface,
10449                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10450 {
10451         static const Utils::Type vec4 = Utils::Type::vec4;
10452
10453 #if WRKARD_UNIFORMBLOCKALIGNMENT
10454
10455         static const GLuint block_align = 16;
10456
10457 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10458
10459         static const GLuint block_align = 64;
10460
10461 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10462
10463         static const GLuint vec4_stride = 16;
10464         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10465
10466         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10467          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10468          */
10469         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10470         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10471         const GLuint third_offset =
10472                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10473         const GLuint fourth_offset =
10474                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10475         const GLuint fifth_offset =
10476                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10477         const GLuint sixth_offset =
10478                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10479
10480         Utils::Interface* structure = program_interface.Structure("Data");
10481
10482         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10483                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10484
10485         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10486                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10487                                           Utils::Type::vec4.GetSize() /* offset */);
10488
10489         /* Prepare Block */
10490         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10491
10492         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10493                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10494
10495         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10496                                                  0 /* n_array_elements */, data_stride, second_offset);
10497
10498         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10499                                                  2 /* n_array_elements */, data_stride, third_offset);
10500
10501         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10502                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10503
10504         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10505                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10506
10507         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10508                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10509
10510         const GLuint stride = calculateStride(*vs_uni_block);
10511         m_data.resize(stride);
10512         generateData(*vs_uni_block, 0, m_data);
10513
10514         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10515
10516 /* Add uniform BLOCK */
10517 #if WRKARD_UNIFORMBLOCKALIGNMENT
10518         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10519                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10520 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10521         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10522                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10523 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10524
10525         program_interface.CloneVertexInterface(varying_passthrough);
10526 }
10527
10528 /** Constructor
10529  *
10530  * @param context Test framework context
10531  **/
10532 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10533         : TextureTestBase(context, "ssb_member_offset_and_align",
10534                                           "Test verifies offsets and alignment of storage buffer members")
10535 {
10536 }
10537
10538 /** Get interface of program
10539  *
10540  * @param test_case_index     Test case index
10541  * @param program_interface   Interface of program
10542  * @param varying_passthrough Collection of connections between in and out variables
10543  **/
10544 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10545                                                                                                           Utils::ProgramInterface&   program_interface,
10546                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10547 {
10548         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10549                                                   "const int type_align = TYPE_ALIGN;\n"
10550                                                   "const int type_size  = TYPE_SIZE;\n";
10551
10552         Utils::Type  type                = getType(test_case_index);
10553         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10554         const GLuint base_align  = type.GetBaseAlignment(false);
10555         const GLuint array_align = type.GetBaseAlignment(true);
10556         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10557         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10558
10559         /* Calculate offsets */
10560         const GLuint first_offset  = 0;
10561         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10562
10563 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10564
10565         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10566         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10567         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10568         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10569         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10570         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10571
10572 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10573
10574         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10575         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10576         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10577         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10578         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10579         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10580
10581 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10582
10583         /* Prepare data */
10584         const std::vector<GLubyte>& first  = type.GenerateData();
10585         const std::vector<GLubyte>& second = type.GenerateData();
10586         const std::vector<GLubyte>& third  = type.GenerateData();
10587         const std::vector<GLubyte>& fourth = type.GenerateData();
10588
10589         m_data.resize(eigth_offset + base_stride);
10590         GLubyte* ptr = &m_data[0];
10591         memcpy(ptr + first_offset, &first[0], first.size());
10592         memcpy(ptr + second_offset, &second[0], second.size());
10593         memcpy(ptr + third_offset, &third[0], third.size());
10594         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10595         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10596         memcpy(ptr + sixth_offset, &third[0], third.size());
10597         memcpy(ptr + seventh_offset, &second[0], second.size());
10598         memcpy(ptr + eigth_offset, &first[0], first.size());
10599
10600         /* Prepare globals */
10601         size_t position = 0;
10602         GLchar buffer[16];
10603
10604         sprintf(buffer, "%d", basic_size);
10605         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10606
10607         sprintf(buffer, "%d", type_align);
10608         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10609
10610         sprintf(buffer, "%d", base_stride);
10611         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10612
10613         /* Prepare Block */
10614         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10615
10616         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10617                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10618                                                  first_offset);
10619
10620         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10621                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10622                                                  0 /* n_array_elements */, base_stride, second_offset);
10623
10624         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10625                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10626                                                  third_offset);
10627
10628         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10629                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10630                                                  fourth_offset);
10631
10632         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10633                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10634
10635         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10636                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10637
10638         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10639                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10640                                                  eigth_offset);
10641
10642         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10643
10644         /* Add globals */
10645         vs_si.m_globals = globals;
10646
10647         /* Add uniform BLOCK */
10648         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10649                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10650
10651         /* */
10652         program_interface.CloneVertexInterface(varying_passthrough);
10653 }
10654
10655 /** Get type name
10656  *
10657  * @param test_case_index Index of test case
10658  *
10659  * @return Name of type test in test_case_index
10660  **/
10661 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10662 {
10663         return getTypeName(test_case_index);
10664 }
10665
10666 /** Returns number of types to test
10667  *
10668  * @return Number of types, 34
10669  **/
10670 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10671 {
10672         return getTypesNumber();
10673 }
10674
10675 /** Prepare code snippet that will verify in and uniform variables
10676  *
10677  * @param ignored
10678  * @param ignored
10679  * @param stage   Shader stage
10680  *
10681  * @return Code that verify variables
10682  **/
10683 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10684                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10685                                                                                                                                 Utils::Shader::STAGES stage)
10686 {
10687         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10688                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10689                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10690                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10691                                                            "    {\n"
10692                                                            "        result = 0;\n"
10693                                                            "    }";
10694
10695         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10696
10697         Utils::replaceAllTokens("PREFIX", prefix, verification);
10698
10699         return verification;
10700 }
10701
10702 /** Selects if "draw" stages are relevant for test
10703  *
10704  * @param ignored
10705  *
10706  * @return true if all stages support shader storage buffers, false otherwise
10707  **/
10708 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10709 {
10710         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10711         GLint                    gs_supported_buffers  = 0;
10712         GLint                    tcs_supported_buffers = 0;
10713         GLint                    tes_supported_buffers = 0;
10714         GLint                    vs_supported_buffers  = 0;
10715
10716         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10717         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10718         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10719         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10720
10721         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10722
10723         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10724                         (1 <= vs_supported_buffers));
10725 }
10726
10727 /** Constructor
10728  *
10729  * @param context Test framework context
10730  **/
10731 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10732         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10733                                                                                                                                  "offset and/or align qualifiers are used with storage "
10734                                                                                                                                  "block")
10735 {
10736         /* Nothing to be done here */
10737 }
10738
10739 /** Source for given test case and stage
10740  *
10741  * @param test_case_index Index of test case
10742  * @param stage           Shader stage
10743  *
10744  * @return Shader source
10745  **/
10746 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10747 {
10748         static const GLchar* cs = "#version 430 core\n"
10749                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10750                                                           "\n"
10751                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10752                                                           "\n"
10753                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10754                                                           "    layout(offset = 16) vec4 boy;\n"
10755                                                           "    layout(align  = 64) vec4 man;\n"
10756                                                           "} uni_block;\n"
10757                                                           "\n"
10758                                                           "writeonly uniform image2D uni_image;\n"
10759                                                           "\n"
10760                                                           "void main()\n"
10761                                                           "{\n"
10762                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10763                                                           "\n"
10764                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10765                                                           "}\n"
10766                                                           "\n";
10767         static const GLchar* fs = "#version 430 core\n"
10768                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10769                                                           "\n"
10770                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10771                                                           "    layout(offset = 16) vec4 boy;\n"
10772                                                           "    layout(align  = 64) vec4 man;\n"
10773                                                           "} uni_block;\n"
10774                                                           "\n"
10775                                                           "in  vec4 gs_fs;\n"
10776                                                           "out vec4 fs_out;\n"
10777                                                           "\n"
10778                                                           "void main()\n"
10779                                                           "{\n"
10780                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10781                                                           "}\n"
10782                                                           "\n";
10783         static const GLchar* gs = "#version 430 core\n"
10784                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10785                                                           "\n"
10786                                                           "layout(points)                           in;\n"
10787                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10788                                                           "\n"
10789                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10790                                                           "    layout(offset = 16) vec4 boy;\n"
10791                                                           "    layout(align  = 64) vec4 man;\n"
10792                                                           "} uni_block;\n"
10793                                                           "\n"
10794                                                           "in  vec4 tes_gs[];\n"
10795                                                           "out vec4 gs_fs;\n"
10796                                                           "\n"
10797                                                           "void main()\n"
10798                                                           "{\n"
10799                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10800                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10801                                                           "    EmitVertex();\n"
10802                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10803                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10804                                                           "    EmitVertex();\n"
10805                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10806                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10807                                                           "    EmitVertex();\n"
10808                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10809                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10810                                                           "    EmitVertex();\n"
10811                                                           "}\n"
10812                                                           "\n";
10813         static const GLchar* tcs =
10814                 "#version 430 core\n"
10815                 "#extension GL_ARB_enhanced_layouts : require\n"
10816                 "\n"
10817                 "layout(vertices = 1) out;\n"
10818                 "\n"
10819                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10820                 "    layout(offset = 16) vec4 boy;\n"
10821                 "    layout(align  = 64) vec4 man;\n"
10822                 "} uni_block;\n"
10823                 "\n"
10824                 "in  vec4 vs_tcs[];\n"
10825                 "out vec4 tcs_tes[];\n"
10826                 "\n"
10827                 "void main()\n"
10828                 "{\n"
10829                 "\n"
10830                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10831                 "\n"
10832                 "    gl_TessLevelOuter[0] = 1.0;\n"
10833                 "    gl_TessLevelOuter[1] = 1.0;\n"
10834                 "    gl_TessLevelOuter[2] = 1.0;\n"
10835                 "    gl_TessLevelOuter[3] = 1.0;\n"
10836                 "    gl_TessLevelInner[0] = 1.0;\n"
10837                 "    gl_TessLevelInner[1] = 1.0;\n"
10838                 "}\n"
10839                 "\n";
10840         static const GLchar* tes = "#version 430 core\n"
10841                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10842                                                            "\n"
10843                                                            "layout(isolines, point_mode) in;\n"
10844                                                            "\n"
10845                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10846                                                            "    layout(offset = 16) vec4 boy;\n"
10847                                                            "    layout(align  = 64) vec4 man;\n"
10848                                                            "} uni_block;\n"
10849                                                            "\n"
10850                                                            "in  vec4 tcs_tes[];\n"
10851                                                            "out vec4 tes_gs;\n"
10852                                                            "\n"
10853                                                            "void main()\n"
10854                                                            "{\n"
10855                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10856                                                            "}\n"
10857                                                            "\n";
10858         static const GLchar* vs = "#version 430 core\n"
10859                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10860                                                           "\n"
10861                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10862                                                           "    layout(offset = 16) vec4 boy;\n"
10863                                                           "    layout(align  = 64) vec4 man;\n"
10864                                                           "} uni_block;\n"
10865                                                           "\n"
10866                                                           "in  vec4 in_vs;\n"
10867                                                           "out vec4 vs_tcs;\n"
10868                                                           "\n"
10869                                                           "void main()\n"
10870                                                           "{\n"
10871                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10872                                                           "}\n"
10873                                                           "\n";
10874
10875         GLchar          buffer[16];
10876         size_t          position = 0;
10877         std::string source;
10878         testCase&   test_case = m_test_cases[test_case_index];
10879         std::string qualifier = getQualifierName(test_case.m_qualifier);
10880
10881         if (false == qualifier.empty())
10882         {
10883                 qualifier.append(", ");
10884         }
10885
10886         sprintf(buffer, "%d", stage);
10887
10888         switch (stage)
10889         {
10890         case Utils::Shader::COMPUTE:
10891                 source = cs;
10892                 break;
10893         case Utils::Shader::FRAGMENT:
10894                 source = fs;
10895                 break;
10896         case Utils::Shader::GEOMETRY:
10897                 source = gs;
10898                 break;
10899         case Utils::Shader::TESS_CTRL:
10900                 source = tcs;
10901                 break;
10902         case Utils::Shader::TESS_EVAL:
10903                 source = tes;
10904                 break;
10905         case Utils::Shader::VERTEX:
10906                 source = vs;
10907                 break;
10908         default:
10909                 TCU_FAIL("Invalid enum");
10910         }
10911
10912         if (test_case.m_stage == stage)
10913         {
10914                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10915         }
10916         else
10917         {
10918                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10919         }
10920
10921         Utils::replaceToken("BINDING", position, buffer, source);
10922
10923         return source;
10924 }
10925
10926 /** Get description of test case
10927  *
10928  * @param test_case_index Index of test case
10929  *
10930  * @return Qualifier name
10931  **/
10932 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10933 {
10934         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10935
10936         return result;
10937 }
10938
10939 /** Get number of test cases
10940  *
10941  * @return Number of test cases
10942  **/
10943 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10944 {
10945         return static_cast<GLuint>(m_test_cases.size());
10946 }
10947
10948 /** Selects if "compute" stage is relevant for test
10949  *
10950  * @param test_case_index Index of test case
10951  *
10952  * @return true when tested stage is compute
10953  **/
10954 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10955 {
10956         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10957 }
10958
10959 /** Selects if compilation failure is expected result
10960  *
10961  * @param test_case_index Index of test case
10962  *
10963  * @return false for STD140 and STD430 cases, true otherwise
10964  **/
10965 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10966 {
10967         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10968
10969         return !((STD140 == qualifier) || (STD430 == qualifier));
10970 }
10971
10972 /** Checks if stage is supported
10973  *
10974  * @param stage Shader stage
10975  *
10976  * @return true if supported, false otherwise
10977  **/
10978 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10979 {
10980         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10981         GLint                    max_supported_buffers = 0;
10982         GLenum                   pname                             = 0;
10983
10984         switch (stage)
10985         {
10986         case Utils::Shader::COMPUTE:
10987                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10988                 break;
10989         case Utils::Shader::FRAGMENT:
10990                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10991                 break;
10992         case Utils::Shader::GEOMETRY:
10993                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10994                 break;
10995         case Utils::Shader::TESS_CTRL:
10996                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10997                 break;
10998         case Utils::Shader::TESS_EVAL:
10999                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11000                 break;
11001         case Utils::Shader::VERTEX:
11002                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11003                 break;
11004         default:
11005                 TCU_FAIL("Invalid enum");
11006         }
11007
11008         gl.getIntegerv(pname, &max_supported_buffers);
11009         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11010
11011         return 1 <= max_supported_buffers;
11012 }
11013
11014 /** Prepare all test cases
11015  *
11016  **/
11017 void SSBLayoutQualifierConflictTest::testInit()
11018 {
11019         bool stage_support[Utils::Shader::STAGE_MAX];
11020
11021         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
11022         {
11023                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
11024         }
11025
11026         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
11027         {
11028                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
11029                 {
11030                         if (false == stage_support[stage])
11031                         {
11032                                 continue;
11033                         }
11034
11035                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
11036
11037                         m_test_cases.push_back(test_case);
11038                 }
11039         }
11040 }
11041
11042 /** Get name of glsl constant
11043  *
11044  * @param Constant id
11045  *
11046  * @return Name of constant used in GLSL
11047  **/
11048 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
11049 {
11050         const GLchar* name = "";
11051
11052         switch (qualifier)
11053         {
11054         case DEFAULT:
11055                 name = "";
11056                 break;
11057         case STD140:
11058                 name = "std140";
11059                 break;
11060         case STD430:
11061                 name = "std430";
11062                 break;
11063         case SHARED:
11064                 name = "shared";
11065                 break;
11066         case PACKED:
11067                 name = "packed";
11068                 break;
11069         default:
11070                 TCU_FAIL("Invalid enum");
11071         }
11072
11073         return name;
11074 }
11075
11076 /** Constructor
11077  *
11078  * @param context Test framework context
11079  **/
11080 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
11081         : UniformBlockMemberInvalidOffsetAlignmentTest(
11082                   context, "ssb_member_invalid_offset_alignment",
11083                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
11084 {
11085         /* Nothing to be done here */
11086 }
11087
11088 /** Get the maximum size for a shader storage block
11089  *
11090  * @return The maximum size in basic machine units of a shader storage block.
11091  **/
11092 GLint SSBMemberInvalidOffsetAlignmentTest::getMaxBlockSize()
11093 {
11094         const Functions& gl               = m_context.getRenderContext().getFunctions();
11095         GLint                    max_size = 0;
11096
11097         gl.getIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_size);
11098         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11099
11100         return max_size;
11101 }
11102
11103 /** Source for given test case and stage
11104  *
11105  * @param test_case_index Index of test case
11106  * @param stage           Shader stage
11107  *
11108  * @return Shader source
11109  **/
11110 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11111 {
11112         static const GLchar* cs = "#version 430 core\n"
11113                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11114                                                           "\n"
11115                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11116                                                           "\n"
11117                                                           "layout (std140) buffer Block {\n"
11118                                                           "    layout (offset = OFFSET) TYPE member;\n"
11119                                                           "} block;\n"
11120                                                           "\n"
11121                                                           "writeonly uniform image2D uni_image;\n"
11122                                                           "\n"
11123                                                           "void main()\n"
11124                                                           "{\n"
11125                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11126                                                           "\n"
11127                                                           "    if (TYPE(1) == block.member)\n"
11128                                                           "    {\n"
11129                                                           "        result = vec4(1, 1, 1, 1);\n"
11130                                                           "    }\n"
11131                                                           "\n"
11132                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11133                                                           "}\n"
11134                                                           "\n";
11135         static const GLchar* fs = "#version 430 core\n"
11136                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11137                                                           "\n"
11138                                                           "in  vec4 gs_fs;\n"
11139                                                           "out vec4 fs_out;\n"
11140                                                           "\n"
11141                                                           "void main()\n"
11142                                                           "{\n"
11143                                                           "    fs_out = gs_fs;\n"
11144                                                           "}\n"
11145                                                           "\n";
11146         static const GLchar* fs_tested = "#version 430 core\n"
11147                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11148                                                                          "\n"
11149                                                                          "layout (std140) buffer Block {\n"
11150                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11151                                                                          "} block;\n"
11152                                                                          "\n"
11153                                                                          "in  vec4 gs_fs;\n"
11154                                                                          "out vec4 fs_out;\n"
11155                                                                          "\n"
11156                                                                          "void main()\n"
11157                                                                          "{\n"
11158                                                                          "    if (TYPE(1) == block.member)\n"
11159                                                                          "    {\n"
11160                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11161                                                                          "    }\n"
11162                                                                          "\n"
11163                                                                          "    fs_out += gs_fs;\n"
11164                                                                          "}\n"
11165                                                                          "\n";
11166         static const GLchar* gs = "#version 430 core\n"
11167                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11168                                                           "\n"
11169                                                           "layout(points)                           in;\n"
11170                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11171                                                           "\n"
11172                                                           "in  vec4 tes_gs[];\n"
11173                                                           "out vec4 gs_fs;\n"
11174                                                           "\n"
11175                                                           "void main()\n"
11176                                                           "{\n"
11177                                                           "    gs_fs = tes_gs[0];\n"
11178                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11179                                                           "    EmitVertex();\n"
11180                                                           "    gs_fs = tes_gs[0];\n"
11181                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11182                                                           "    EmitVertex();\n"
11183                                                           "    gs_fs = tes_gs[0];\n"
11184                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11185                                                           "    EmitVertex();\n"
11186                                                           "    gs_fs = tes_gs[0];\n"
11187                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11188                                                           "    EmitVertex();\n"
11189                                                           "}\n"
11190                                                           "\n";
11191         static const GLchar* gs_tested = "#version 430 core\n"
11192                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11193                                                                          "\n"
11194                                                                          "layout(points)                           in;\n"
11195                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11196                                                                          "\n"
11197                                                                          "layout (std140) buffer Block {\n"
11198                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11199                                                                          "} block;\n"
11200                                                                          "\n"
11201                                                                          "in  vec4 tes_gs[];\n"
11202                                                                          "out vec4 gs_fs;\n"
11203                                                                          "\n"
11204                                                                          "void main()\n"
11205                                                                          "{\n"
11206                                                                          "    if (TYPE(1) == block.member)\n"
11207                                                                          "    {\n"
11208                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11209                                                                          "    }\n"
11210                                                                          "\n"
11211                                                                          "    gs_fs += tes_gs[0];\n"
11212                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11213                                                                          "    EmitVertex();\n"
11214                                                                          "    gs_fs += tes_gs[0];\n"
11215                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11216                                                                          "    EmitVertex();\n"
11217                                                                          "    gs_fs += tes_gs[0];\n"
11218                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11219                                                                          "    EmitVertex();\n"
11220                                                                          "    gs_fs += tes_gs[0];\n"
11221                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11222                                                                          "    EmitVertex();\n"
11223                                                                          "}\n"
11224                                                                          "\n";
11225         static const GLchar* tcs = "#version 430 core\n"
11226                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11227                                                            "\n"
11228                                                            "layout(vertices = 1) out;\n"
11229                                                            "\n"
11230                                                            "in  vec4 vs_tcs[];\n"
11231                                                            "out vec4 tcs_tes[];\n"
11232                                                            "\n"
11233                                                            "void main()\n"
11234                                                            "{\n"
11235                                                            "\n"
11236                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11237                                                            "\n"
11238                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11239                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11240                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11241                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11242                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11243                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11244                                                            "}\n"
11245                                                            "\n";
11246         static const GLchar* tcs_tested = "#version 430 core\n"
11247                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11248                                                                           "\n"
11249                                                                           "layout(vertices = 1) out;\n"
11250                                                                           "\n"
11251                                                                           "layout (std140) buffer Block {\n"
11252                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11253                                                                           "} block;\n"
11254                                                                           "\n"
11255                                                                           "in  vec4 vs_tcs[];\n"
11256                                                                           "out vec4 tcs_tes[];\n"
11257                                                                           "\n"
11258                                                                           "void main()\n"
11259                                                                           "{\n"
11260                                                                           "    if (TYPE(1) == block.member)\n"
11261                                                                           "    {\n"
11262                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11263                                                                           "    }\n"
11264                                                                           "\n"
11265                                                                           "\n"
11266                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11267                                                                           "\n"
11268                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11269                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11270                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11271                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11272                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11273                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11274                                                                           "}\n"
11275                                                                           "\n";
11276         static const GLchar* tes = "#version 430 core\n"
11277                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11278                                                            "\n"
11279                                                            "layout(isolines, point_mode) in;\n"
11280                                                            "\n"
11281                                                            "in  vec4 tcs_tes[];\n"
11282                                                            "out vec4 tes_gs;\n"
11283                                                            "\n"
11284                                                            "void main()\n"
11285                                                            "{\n"
11286                                                            "    tes_gs = tcs_tes[0];\n"
11287                                                            "}\n"
11288                                                            "\n";
11289         static const GLchar* tes_tested = "#version 430 core\n"
11290                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11291                                                                           "\n"
11292                                                                           "layout(isolines, point_mode) in;\n"
11293                                                                           "\n"
11294                                                                           "layout (std140) buffer Block {\n"
11295                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11296                                                                           "} block;\n"
11297                                                                           "\n"
11298                                                                           "in  vec4 tcs_tes[];\n"
11299                                                                           "out vec4 tes_gs;\n"
11300                                                                           "\n"
11301                                                                           "void main()\n"
11302                                                                           "{\n"
11303                                                                           "    if (TYPE(1) == block.member)\n"
11304                                                                           "    {\n"
11305                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11306                                                                           "    }\n"
11307                                                                           "\n"
11308                                                                           "    tes_gs += tcs_tes[0];\n"
11309                                                                           "}\n"
11310                                                                           "\n";
11311         static const GLchar* vs = "#version 430 core\n"
11312                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11313                                                           "\n"
11314                                                           "in  vec4 in_vs;\n"
11315                                                           "out vec4 vs_tcs;\n"
11316                                                           "\n"
11317                                                           "void main()\n"
11318                                                           "{\n"
11319                                                           "    vs_tcs = in_vs;\n"
11320                                                           "}\n"
11321                                                           "\n";
11322         static const GLchar* vs_tested = "#version 430 core\n"
11323                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11324                                                                          "\n"
11325                                                                          "layout (std140) buffer Block {\n"
11326                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11327                                                                          "} block;\n"
11328                                                                          "\n"
11329                                                                          "in  vec4 in_vs;\n"
11330                                                                          "out vec4 vs_tcs;\n"
11331                                                                          "\n"
11332                                                                          "void main()\n"
11333                                                                          "{\n"
11334                                                                          "    if (TYPE(1) == block.member)\n"
11335                                                                          "    {\n"
11336                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11337                                                                          "    }\n"
11338                                                                          "\n"
11339                                                                          "    vs_tcs += in_vs;\n"
11340                                                                          "}\n"
11341                                                                          "\n";
11342
11343         std::string source;
11344         testCase&   test_case = m_test_cases[test_case_index];
11345
11346         if (test_case.m_stage == stage)
11347         {
11348                 GLchar                     buffer[16];
11349                 const GLuint       offset       = test_case.m_offset;
11350                 size_t                     position  = 0;
11351                 const Utils::Type& type          = test_case.m_type;
11352                 const GLchar*     type_name = type.GetGLSLTypeName();
11353
11354                 sprintf(buffer, "%d", offset);
11355
11356                 switch (stage)
11357                 {
11358                 case Utils::Shader::COMPUTE:
11359                         source = cs;
11360                         break;
11361                 case Utils::Shader::FRAGMENT:
11362                         source = fs_tested;
11363                         break;
11364                 case Utils::Shader::GEOMETRY:
11365                         source = gs_tested;
11366                         break;
11367                 case Utils::Shader::TESS_CTRL:
11368                         source = tcs_tested;
11369                         break;
11370                 case Utils::Shader::TESS_EVAL:
11371                         source = tes_tested;
11372                         break;
11373                 case Utils::Shader::VERTEX:
11374                         source = vs_tested;
11375                         break;
11376                 default:
11377                         TCU_FAIL("Invalid enum");
11378                 }
11379
11380                 Utils::replaceToken("OFFSET", position, buffer, source);
11381                 Utils::replaceToken("TYPE", position, type_name, source);
11382                 Utils::replaceToken("TYPE", position, type_name, source);
11383         }
11384         else
11385         {
11386                 switch (stage)
11387                 {
11388                 case Utils::Shader::FRAGMENT:
11389                         source = fs;
11390                         break;
11391                 case Utils::Shader::GEOMETRY:
11392                         source = gs;
11393                         break;
11394                 case Utils::Shader::TESS_CTRL:
11395                         source = tcs;
11396                         break;
11397                 case Utils::Shader::TESS_EVAL:
11398                         source = tes;
11399                         break;
11400                 case Utils::Shader::VERTEX:
11401                         source = vs;
11402                         break;
11403                 default:
11404                         TCU_FAIL("Invalid enum");
11405                 }
11406         }
11407
11408         return source;
11409 }
11410
11411 /** Checks if stage is supported
11412  *
11413  * @param stage Shader stage
11414  *
11415  * @return true if supported, false otherwise
11416  **/
11417 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11418 {
11419         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11420         GLint                    max_supported_buffers = 0;
11421         GLenum                   pname                             = 0;
11422
11423         switch (stage)
11424         {
11425         case Utils::Shader::COMPUTE:
11426                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11427                 break;
11428         case Utils::Shader::FRAGMENT:
11429                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11430                 break;
11431         case Utils::Shader::GEOMETRY:
11432                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11433                 break;
11434         case Utils::Shader::TESS_CTRL:
11435                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11436                 break;
11437         case Utils::Shader::TESS_EVAL:
11438                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11439                 break;
11440         case Utils::Shader::VERTEX:
11441                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11442                 break;
11443         default:
11444                 TCU_FAIL("Invalid enum");
11445         }
11446
11447         gl.getIntegerv(pname, &max_supported_buffers);
11448         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11449
11450         return 1 <= max_supported_buffers;
11451 }
11452
11453 /** Constructor
11454  *
11455  * @param context Test framework context
11456  **/
11457 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11458         : UniformBlockMemberOverlappingOffsetsTest(
11459                   context, "ssb_member_overlapping_offsets",
11460                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11461 {
11462         /* Nothing to be done here */
11463 }
11464
11465 /** Source for given test case and stage
11466  *
11467  * @param test_case_index Index of test case
11468  * @param stage           Shader stage
11469  *
11470  * @return Shader source
11471  **/
11472 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11473 {
11474         static const GLchar* cs = "#version 430 core\n"
11475                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11476                                                           "\n"
11477                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11478                                                           "\n"
11479                                                           "layout (std140) buffer Block {\n"
11480                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11481                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11482                                                           "} block;\n"
11483                                                           "\n"
11484                                                           "writeonly uniform image2D uni_image;\n"
11485                                                           "\n"
11486                                                           "void main()\n"
11487                                                           "{\n"
11488                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11489                                                           "\n"
11490                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11491                                                           "        (MAN_TYPE(0) == block.man) )\n"
11492                                                           "    {\n"
11493                                                           "        result = vec4(1, 1, 1, 1);\n"
11494                                                           "    }\n"
11495                                                           "\n"
11496                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11497                                                           "}\n"
11498                                                           "\n";
11499         static const GLchar* fs = "#version 430 core\n"
11500                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11501                                                           "\n"
11502                                                           "in  vec4 gs_fs;\n"
11503                                                           "out vec4 fs_out;\n"
11504                                                           "\n"
11505                                                           "void main()\n"
11506                                                           "{\n"
11507                                                           "    fs_out = gs_fs;\n"
11508                                                           "}\n"
11509                                                           "\n";
11510         static const GLchar* fs_tested = "#version 430 core\n"
11511                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11512                                                                          "\n"
11513                                                                          "layout (std140) buffer Block {\n"
11514                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11515                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11516                                                                          "} block;\n"
11517                                                                          "\n"
11518                                                                          "in  vec4 gs_fs;\n"
11519                                                                          "out vec4 fs_out;\n"
11520                                                                          "\n"
11521                                                                          "void main()\n"
11522                                                                          "{\n"
11523                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11524                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11525                                                                          "    {\n"
11526                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11527                                                                          "    }\n"
11528                                                                          "\n"
11529                                                                          "    fs_out += gs_fs;\n"
11530                                                                          "}\n"
11531                                                                          "\n";
11532         static const GLchar* gs = "#version 430 core\n"
11533                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11534                                                           "\n"
11535                                                           "layout(points)                           in;\n"
11536                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11537                                                           "\n"
11538                                                           "in  vec4 tes_gs[];\n"
11539                                                           "out vec4 gs_fs;\n"
11540                                                           "\n"
11541                                                           "void main()\n"
11542                                                           "{\n"
11543                                                           "    gs_fs = tes_gs[0];\n"
11544                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11545                                                           "    EmitVertex();\n"
11546                                                           "    gs_fs = tes_gs[0];\n"
11547                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11548                                                           "    EmitVertex();\n"
11549                                                           "    gs_fs = tes_gs[0];\n"
11550                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11551                                                           "    EmitVertex();\n"
11552                                                           "    gs_fs = tes_gs[0];\n"
11553                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11554                                                           "    EmitVertex();\n"
11555                                                           "}\n"
11556                                                           "\n";
11557         static const GLchar* gs_tested = "#version 430 core\n"
11558                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11559                                                                          "\n"
11560                                                                          "layout(points)                           in;\n"
11561                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11562                                                                          "\n"
11563                                                                          "layout (std140) buffer Block {\n"
11564                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11565                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11566                                                                          "} block;\n"
11567                                                                          "\n"
11568                                                                          "in  vec4 tes_gs[];\n"
11569                                                                          "out vec4 gs_fs;\n"
11570                                                                          "\n"
11571                                                                          "void main()\n"
11572                                                                          "{\n"
11573                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11574                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11575                                                                          "    {\n"
11576                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11577                                                                          "    }\n"
11578                                                                          "\n"
11579                                                                          "    gs_fs += tes_gs[0];\n"
11580                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11581                                                                          "    EmitVertex();\n"
11582                                                                          "    gs_fs += tes_gs[0];\n"
11583                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11584                                                                          "    EmitVertex();\n"
11585                                                                          "    gs_fs += tes_gs[0];\n"
11586                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11587                                                                          "    EmitVertex();\n"
11588                                                                          "    gs_fs += tes_gs[0];\n"
11589                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11590                                                                          "    EmitVertex();\n"
11591                                                                          "}\n"
11592                                                                          "\n";
11593         static const GLchar* tcs = "#version 430 core\n"
11594                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11595                                                            "\n"
11596                                                            "layout(vertices = 1) out;\n"
11597                                                            "\n"
11598                                                            "in  vec4 vs_tcs[];\n"
11599                                                            "out vec4 tcs_tes[];\n"
11600                                                            "\n"
11601                                                            "void main()\n"
11602                                                            "{\n"
11603                                                            "\n"
11604                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11605                                                            "\n"
11606                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11607                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11608                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11609                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11610                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11611                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11612                                                            "}\n"
11613                                                            "\n";
11614         static const GLchar* tcs_tested = "#version 430 core\n"
11615                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11616                                                                           "\n"
11617                                                                           "layout(vertices = 1) out;\n"
11618                                                                           "\n"
11619                                                                           "layout (std140) buffer Block {\n"
11620                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11621                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11622                                                                           "} block;\n"
11623                                                                           "\n"
11624                                                                           "in  vec4 vs_tcs[];\n"
11625                                                                           "out vec4 tcs_tes[];\n"
11626                                                                           "\n"
11627                                                                           "void main()\n"
11628                                                                           "{\n"
11629                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11630                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11631                                                                           "    {\n"
11632                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11633                                                                           "    }\n"
11634                                                                           "\n"
11635                                                                           "\n"
11636                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11637                                                                           "\n"
11638                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11639                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11640                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11641                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11642                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11643                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11644                                                                           "}\n"
11645                                                                           "\n";
11646         static const GLchar* tes = "#version 430 core\n"
11647                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11648                                                            "\n"
11649                                                            "layout(isolines, point_mode) in;\n"
11650                                                            "\n"
11651                                                            "in  vec4 tcs_tes[];\n"
11652                                                            "out vec4 tes_gs;\n"
11653                                                            "\n"
11654                                                            "void main()\n"
11655                                                            "{\n"
11656                                                            "    tes_gs = tcs_tes[0];\n"
11657                                                            "}\n"
11658                                                            "\n";
11659         static const GLchar* tes_tested = "#version 430 core\n"
11660                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11661                                                                           "\n"
11662                                                                           "layout(isolines, point_mode) in;\n"
11663                                                                           "\n"
11664                                                                           "layout (std140) buffer Block {\n"
11665                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11666                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11667                                                                           "} block;\n"
11668                                                                           "\n"
11669                                                                           "in  vec4 tcs_tes[];\n"
11670                                                                           "out vec4 tes_gs;\n"
11671                                                                           "\n"
11672                                                                           "void main()\n"
11673                                                                           "{\n"
11674                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11675                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11676                                                                           "    {\n"
11677                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11678                                                                           "    }\n"
11679                                                                           "\n"
11680                                                                           "    tes_gs += tcs_tes[0];\n"
11681                                                                           "}\n"
11682                                                                           "\n";
11683         static const GLchar* vs = "#version 430 core\n"
11684                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11685                                                           "\n"
11686                                                           "in  vec4 in_vs;\n"
11687                                                           "out vec4 vs_tcs;\n"
11688                                                           "\n"
11689                                                           "void main()\n"
11690                                                           "{\n"
11691                                                           "    vs_tcs = in_vs;\n"
11692                                                           "}\n"
11693                                                           "\n";
11694         static const GLchar* vs_tested = "#version 430 core\n"
11695                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11696                                                                          "\n"
11697                                                                          "layout (std140) buffer Block {\n"
11698                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11699                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11700                                                                          "} block;\n"
11701                                                                          "\n"
11702                                                                          "in  vec4 in_vs;\n"
11703                                                                          "out vec4 vs_tcs;\n"
11704                                                                          "\n"
11705                                                                          "void main()\n"
11706                                                                          "{\n"
11707                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11708                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11709                                                                          "    {\n"
11710                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11711                                                                          "    }\n"
11712                                                                          "\n"
11713                                                                          "    vs_tcs += in_vs;\n"
11714                                                                          "}\n"
11715                                                                          "\n";
11716
11717         std::string source;
11718         testCase&   test_case = m_test_cases[test_case_index];
11719
11720         if (test_case.m_stage == stage)
11721         {
11722                 GLchar                     buffer[16];
11723                 const GLuint       boy_offset   = test_case.m_boy_offset;
11724                 const Utils::Type& boy_type              = test_case.m_boy_type;
11725                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11726                 const GLuint       man_offset   = test_case.m_man_offset;
11727                 const Utils::Type& man_type              = test_case.m_man_type;
11728                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11729                 size_t                     position              = 0;
11730
11731                 switch (stage)
11732                 {
11733                 case Utils::Shader::COMPUTE:
11734                         source = cs;
11735                         break;
11736                 case Utils::Shader::FRAGMENT:
11737                         source = fs_tested;
11738                         break;
11739                 case Utils::Shader::GEOMETRY:
11740                         source = gs_tested;
11741                         break;
11742                 case Utils::Shader::TESS_CTRL:
11743                         source = tcs_tested;
11744                         break;
11745                 case Utils::Shader::TESS_EVAL:
11746                         source = tes_tested;
11747                         break;
11748                 case Utils::Shader::VERTEX:
11749                         source = vs_tested;
11750                         break;
11751                 default:
11752                         TCU_FAIL("Invalid enum");
11753                 }
11754
11755                 sprintf(buffer, "%d", boy_offset);
11756                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11757                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11758                 sprintf(buffer, "%d", man_offset);
11759                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11760                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11761                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11762                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11763         }
11764         else
11765         {
11766                 switch (stage)
11767                 {
11768                 case Utils::Shader::FRAGMENT:
11769                         source = fs;
11770                         break;
11771                 case Utils::Shader::GEOMETRY:
11772                         source = gs;
11773                         break;
11774                 case Utils::Shader::TESS_CTRL:
11775                         source = tcs;
11776                         break;
11777                 case Utils::Shader::TESS_EVAL:
11778                         source = tes;
11779                         break;
11780                 case Utils::Shader::VERTEX:
11781                         source = vs;
11782                         break;
11783                 default:
11784                         TCU_FAIL("Invalid enum");
11785                 }
11786         }
11787
11788         return source;
11789 }
11790
11791 /** Checks if stage is supported
11792  *
11793  * @param stage Shader stage
11794  *
11795  * @return true if supported, false otherwise
11796  **/
11797 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11798 {
11799         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11800         GLint                    max_supported_buffers = 0;
11801         GLenum                   pname                             = 0;
11802
11803         switch (stage)
11804         {
11805         case Utils::Shader::COMPUTE:
11806                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11807                 break;
11808         case Utils::Shader::FRAGMENT:
11809                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11810                 break;
11811         case Utils::Shader::GEOMETRY:
11812                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11813                 break;
11814         case Utils::Shader::TESS_CTRL:
11815                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11816                 break;
11817         case Utils::Shader::TESS_EVAL:
11818                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11819                 break;
11820         case Utils::Shader::VERTEX:
11821                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11822                 break;
11823         default:
11824                 TCU_FAIL("Invalid enum");
11825         }
11826
11827         gl.getIntegerv(pname, &max_supported_buffers);
11828         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11829
11830         return 1 <= max_supported_buffers;
11831 }
11832
11833 /** Constructor
11834  *
11835  * @param context Test framework context
11836  **/
11837 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11838         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11839                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11840 {
11841         /* Nothing to be done here */
11842 }
11843
11844 /** Source for given test case and stage
11845  *
11846  * @param test_case_index Index of test case
11847  * @param stage           Shader stage
11848  *
11849  * @return Shader source
11850  **/
11851 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11852 {
11853         static const GLchar* cs = "#version 430 core\n"
11854                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11855                                                           "\n"
11856                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11857                                                           "\n"
11858                                                           "layout (std140) buffer Block {\n"
11859                                                           "    vec4 boy;\n"
11860                                                           "    layout (align = ALIGN) TYPE man;\n"
11861                                                           "} block;\n"
11862                                                           "\n"
11863                                                           "writeonly uniform image2D uni_image;\n"
11864                                                           "\n"
11865                                                           "void main()\n"
11866                                                           "{\n"
11867                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11868                                                           "\n"
11869                                                           "    if (TYPE(0) == block.man)\n"
11870                                                           "    {\n"
11871                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11872                                                           "    }\n"
11873                                                           "\n"
11874                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11875                                                           "}\n"
11876                                                           "\n";
11877         static const GLchar* fs = "#version 430 core\n"
11878                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11879                                                           "\n"
11880                                                           "in  vec4 gs_fs;\n"
11881                                                           "out vec4 fs_out;\n"
11882                                                           "\n"
11883                                                           "void main()\n"
11884                                                           "{\n"
11885                                                           "    fs_out = gs_fs;\n"
11886                                                           "}\n"
11887                                                           "\n";
11888         static const GLchar* fs_tested = "#version 430 core\n"
11889                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11890                                                                          "\n"
11891                                                                          "layout (std140) buffer Block {\n"
11892                                                                          "    vec4 boy;\n"
11893                                                                          "    layout (align = ALIGN) TYPE man;\n"
11894                                                                          "} block;\n"
11895                                                                          "\n"
11896                                                                          "in  vec4 gs_fs;\n"
11897                                                                          "out vec4 fs_out;\n"
11898                                                                          "\n"
11899                                                                          "void main()\n"
11900                                                                          "{\n"
11901                                                                          "    if (TYPE(0) == block.man)\n"
11902                                                                          "    {\n"
11903                                                                          "        fs_out = block.boy;\n"
11904                                                                          "    }\n"
11905                                                                          "\n"
11906                                                                          "    fs_out += gs_fs;\n"
11907                                                                          "}\n"
11908                                                                          "\n";
11909         static const GLchar* gs = "#version 430 core\n"
11910                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11911                                                           "\n"
11912                                                           "layout(points)                           in;\n"
11913                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11914                                                           "\n"
11915                                                           "in  vec4 tes_gs[];\n"
11916                                                           "out vec4 gs_fs;\n"
11917                                                           "\n"
11918                                                           "void main()\n"
11919                                                           "{\n"
11920                                                           "    gs_fs = tes_gs[0];\n"
11921                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11922                                                           "    EmitVertex();\n"
11923                                                           "    gs_fs = tes_gs[0];\n"
11924                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11925                                                           "    EmitVertex();\n"
11926                                                           "    gs_fs = tes_gs[0];\n"
11927                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11928                                                           "    EmitVertex();\n"
11929                                                           "    gs_fs = tes_gs[0];\n"
11930                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11931                                                           "    EmitVertex();\n"
11932                                                           "}\n"
11933                                                           "\n";
11934         static const GLchar* gs_tested = "#version 430 core\n"
11935                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11936                                                                          "\n"
11937                                                                          "layout(points)                           in;\n"
11938                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11939                                                                          "\n"
11940                                                                          "layout (std140) buffer Block {\n"
11941                                                                          "    vec4 boy;\n"
11942                                                                          "    layout (align = ALIGN) TYPE man;\n"
11943                                                                          "} block;\n"
11944                                                                          "\n"
11945                                                                          "in  vec4 tes_gs[];\n"
11946                                                                          "out vec4 gs_fs;\n"
11947                                                                          "\n"
11948                                                                          "void main()\n"
11949                                                                          "{\n"
11950                                                                          "    if (TYPE(0) == block.man)\n"
11951                                                                          "    {\n"
11952                                                                          "        gs_fs = block.boy;\n"
11953                                                                          "    }\n"
11954                                                                          "\n"
11955                                                                          "    gs_fs += tes_gs[0];\n"
11956                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11957                                                                          "    EmitVertex();\n"
11958                                                                          "    gs_fs += tes_gs[0];\n"
11959                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11960                                                                          "    EmitVertex();\n"
11961                                                                          "    gs_fs += tes_gs[0];\n"
11962                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11963                                                                          "    EmitVertex();\n"
11964                                                                          "    gs_fs += tes_gs[0];\n"
11965                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11966                                                                          "    EmitVertex();\n"
11967                                                                          "}\n"
11968                                                                          "\n";
11969         static const GLchar* tcs = "#version 430 core\n"
11970                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11971                                                            "\n"
11972                                                            "layout(vertices = 1) out;\n"
11973                                                            "\n"
11974                                                            "in  vec4 vs_tcs[];\n"
11975                                                            "out vec4 tcs_tes[];\n"
11976                                                            "\n"
11977                                                            "void main()\n"
11978                                                            "{\n"
11979                                                            "\n"
11980                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11981                                                            "\n"
11982                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11983                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11984                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11985                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11986                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11987                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11988                                                            "}\n"
11989                                                            "\n";
11990         static const GLchar* tcs_tested = "#version 430 core\n"
11991                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11992                                                                           "\n"
11993                                                                           "layout(vertices = 1) out;\n"
11994                                                                           "\n"
11995                                                                           "layout (std140) buffer Block {\n"
11996                                                                           "    vec4 boy;\n"
11997                                                                           "    layout (align = ALIGN) TYPE man;\n"
11998                                                                           "} block;\n"
11999                                                                           "\n"
12000                                                                           "in  vec4 vs_tcs[];\n"
12001                                                                           "out vec4 tcs_tes[];\n"
12002                                                                           "\n"
12003                                                                           "void main()\n"
12004                                                                           "{\n"
12005                                                                           "    if (TYPE(0) == block.man)\n"
12006                                                                           "    {\n"
12007                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
12008                                                                           "    }\n"
12009                                                                           "\n"
12010                                                                           "\n"
12011                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
12012                                                                           "\n"
12013                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
12014                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
12015                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
12016                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
12017                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
12018                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
12019                                                                           "}\n"
12020                                                                           "\n";
12021         static const GLchar* tes = "#version 430 core\n"
12022                                                            "#extension GL_ARB_enhanced_layouts : require\n"
12023                                                            "\n"
12024                                                            "layout(isolines, point_mode) in;\n"
12025                                                            "\n"
12026                                                            "in  vec4 tcs_tes[];\n"
12027                                                            "out vec4 tes_gs;\n"
12028                                                            "\n"
12029                                                            "void main()\n"
12030                                                            "{\n"
12031                                                            "    tes_gs = tcs_tes[0];\n"
12032                                                            "}\n"
12033                                                            "\n";
12034         static const GLchar* tes_tested = "#version 430 core\n"
12035                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12036                                                                           "\n"
12037                                                                           "layout(isolines, point_mode) in;\n"
12038                                                                           "\n"
12039                                                                           "layout (std140) buffer Block {\n"
12040                                                                           "    vec4 boy;\n"
12041                                                                           "    layout (align = ALIGN) TYPE man;\n"
12042                                                                           "} block;\n"
12043                                                                           "\n"
12044                                                                           "in  vec4 tcs_tes[];\n"
12045                                                                           "out vec4 tes_gs;\n"
12046                                                                           "\n"
12047                                                                           "void main()\n"
12048                                                                           "{\n"
12049                                                                           "    if (TYPE(0) == block.man)\n"
12050                                                                           "    {\n"
12051                                                                           "        tes_gs = block.boy;\n"
12052                                                                           "    }\n"
12053                                                                           "\n"
12054                                                                           "    tes_gs += tcs_tes[0];\n"
12055                                                                           "}\n"
12056                                                                           "\n";
12057         static const GLchar* vs = "#version 430 core\n"
12058                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12059                                                           "\n"
12060                                                           "in  vec4 in_vs;\n"
12061                                                           "out vec4 vs_tcs;\n"
12062                                                           "\n"
12063                                                           "void main()\n"
12064                                                           "{\n"
12065                                                           "    vs_tcs = in_vs;\n"
12066                                                           "}\n"
12067                                                           "\n";
12068         static const GLchar* vs_tested = "#version 430 core\n"
12069                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12070                                                                          "\n"
12071                                                                          "layout (std140) buffer Block {\n"
12072                                                                          "    vec4 boy;\n"
12073                                                                          "    layout (align = ALIGN) TYPE man;\n"
12074                                                                          "} block;\n"
12075                                                                          "\n"
12076                                                                          "in  vec4 in_vs;\n"
12077                                                                          "out vec4 vs_tcs;\n"
12078                                                                          "\n"
12079                                                                          "void main()\n"
12080                                                                          "{\n"
12081                                                                          "    if (TYPE(0) == block.man)\n"
12082                                                                          "    {\n"
12083                                                                          "        vs_tcs = block.boy;\n"
12084                                                                          "    }\n"
12085                                                                          "\n"
12086                                                                          "    vs_tcs += in_vs;\n"
12087                                                                          "}\n"
12088                                                                          "\n";
12089
12090         std::string source;
12091         testCase&   test_case = m_test_cases[test_case_index];
12092
12093         if (test_case.m_stage == stage)
12094         {
12095                 GLchar                     buffer[16];
12096                 const GLuint       alignment = test_case.m_alignment;
12097                 const Utils::Type& type          = test_case.m_type;
12098                 const GLchar*     type_name = type.GetGLSLTypeName();
12099                 size_t                     position  = 0;
12100
12101                 switch (stage)
12102                 {
12103                 case Utils::Shader::COMPUTE:
12104                         source = cs;
12105                         break;
12106                 case Utils::Shader::FRAGMENT:
12107                         source = fs_tested;
12108                         break;
12109                 case Utils::Shader::GEOMETRY:
12110                         source = gs_tested;
12111                         break;
12112                 case Utils::Shader::TESS_CTRL:
12113                         source = tcs_tested;
12114                         break;
12115                 case Utils::Shader::TESS_EVAL:
12116                         source = tes_tested;
12117                         break;
12118                 case Utils::Shader::VERTEX:
12119                         source = vs_tested;
12120                         break;
12121                 default:
12122                         TCU_FAIL("Invalid enum");
12123                 }
12124
12125                 sprintf(buffer, "%d", alignment);
12126                 Utils::replaceToken("ALIGN", position, buffer, source);
12127                 Utils::replaceToken("TYPE", position, type_name, source);
12128                 Utils::replaceToken("TYPE", position, type_name, source);
12129         }
12130         else
12131         {
12132                 switch (stage)
12133                 {
12134                 case Utils::Shader::FRAGMENT:
12135                         source = fs;
12136                         break;
12137                 case Utils::Shader::GEOMETRY:
12138                         source = gs;
12139                         break;
12140                 case Utils::Shader::TESS_CTRL:
12141                         source = tcs;
12142                         break;
12143                 case Utils::Shader::TESS_EVAL:
12144                         source = tes;
12145                         break;
12146                 case Utils::Shader::VERTEX:
12147                         source = vs;
12148                         break;
12149                 default:
12150                         TCU_FAIL("Invalid enum");
12151                 }
12152         }
12153
12154         return source;
12155 }
12156
12157 /** Checks if stage is supported
12158  *
12159  * @param stage Shader stage
12160  *
12161  * @return true if supported, false otherwise
12162  **/
12163 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12164 {
12165         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12166         GLint                    max_supported_buffers = 0;
12167         GLenum                   pname                             = 0;
12168
12169         switch (stage)
12170         {
12171         case Utils::Shader::COMPUTE:
12172                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12173                 break;
12174         case Utils::Shader::FRAGMENT:
12175                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12176                 break;
12177         case Utils::Shader::GEOMETRY:
12178                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12179                 break;
12180         case Utils::Shader::TESS_CTRL:
12181                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12182                 break;
12183         case Utils::Shader::TESS_EVAL:
12184                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12185                 break;
12186         case Utils::Shader::VERTEX:
12187                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12188                 break;
12189         default:
12190                 TCU_FAIL("Invalid enum");
12191         }
12192
12193         gl.getIntegerv(pname, &max_supported_buffers);
12194         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12195
12196         return 1 <= max_supported_buffers;
12197 }
12198
12199 /** Constructor
12200  *
12201  * @param context Test framework context
12202  **/
12203 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12204         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12205 {
12206 }
12207
12208 /** Get interface of program
12209  *
12210  * @param ignored
12211  * @param program_interface Interface of program
12212  * @param varying_passthrough Collection of connections between in and out variables
12213  **/
12214 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12215                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12216 {
12217         static const Utils::Type vec4 = Utils::Type::vec4;
12218
12219 #if WRKARD_UNIFORMBLOCKALIGNMENT
12220
12221         static const GLuint block_align = 16;
12222
12223 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12224
12225         static const GLuint block_align = 64;
12226
12227 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12228
12229         static const GLuint fifth_align = 16;
12230         static const GLuint vec4_stride = 16;
12231         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12232
12233         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12234         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12235         const GLuint third_offset =
12236                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12237         const GLuint fourth_offset =
12238                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12239         const GLuint fifth_offset =
12240                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12241         const GLuint sixth_offset =
12242                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12243
12244         Utils::Interface* structure = program_interface.Structure("Data");
12245
12246         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12247                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12248
12249         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12250                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12251                                           Utils::Type::vec4.GetSize() /* offset */);
12252
12253         /* Prepare Block */
12254         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12255
12256         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12257                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12258
12259         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12260                                                  0 /* n_array_elements */, data_stride, second_offset);
12261
12262         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12263                                                  2 /* n_array_elements */, data_stride, third_offset);
12264
12265         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12266                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12267
12268         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12269                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12270
12271         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12272                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12273
12274         const GLuint stride = calculateStride(*vs_buf_Block);
12275         m_data.resize(stride);
12276         generateData(*vs_buf_Block, 0, m_data);
12277
12278         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12279
12280 /* Add uniform BLOCK */
12281 #if WRKARD_UNIFORMBLOCKALIGNMENT
12282         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12283                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12284 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12285         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12286                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12287 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12288
12289         program_interface.CloneVertexInterface(varying_passthrough);
12290 }
12291
12292 /** Selects if "draw" stages are relevant for test
12293  *
12294  * @param ignored
12295  *
12296  * @return true if all stages support shader storage buffers, false otherwise
12297  **/
12298 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12299 {
12300         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12301         GLint                    gs_supported_buffers  = 0;
12302         GLint                    tcs_supported_buffers = 0;
12303         GLint                    tes_supported_buffers = 0;
12304         GLint                    vs_supported_buffers  = 0;
12305
12306         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12307         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12308         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12309         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12310
12311         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12312
12313         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12314                         (1 <= vs_supported_buffers));
12315 }
12316
12317 /** Constructor
12318  *
12319  * @param context Test framework context
12320  **/
12321 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12322         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12323 {
12324 }
12325
12326 /** Constructor
12327  *
12328  * @param context          Test context
12329  * @param test_name        Name of test
12330  * @param test_description Description of test
12331  **/
12332 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12333                                                                                    const glw::GLchar* test_description)
12334         : TextureTestBase(context, test_name, test_description)
12335 {
12336 }
12337
12338 /** Get interface of program
12339  *
12340  * @param test_case_index     Test case
12341  * @param program_interface   Interface of program
12342  * @param varying_passthrough Collection of connections between in and out variables
12343  **/
12344 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12345                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12346 {
12347         const Utils::Type type = getType(test_case_index);
12348
12349         m_first_data = type.GenerateDataPacked();
12350         m_last_data  = type.GenerateDataPacked();
12351
12352         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12353         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12354         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12355         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12356         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12357 }
12358
12359 /** Get type name
12360  *
12361  * @param test_case_index Index of test case
12362  *
12363  * @return Name of type test in test_case_index
12364  **/
12365 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12366 {
12367         return getTypeName(test_case_index);
12368 }
12369
12370 /** Returns number of types to test
12371  *
12372  * @return Number of types, 34
12373  **/
12374 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12375 {
12376         return getTypesNumber();
12377 }
12378
12379 /** Selects if "compute" stage is relevant for test
12380  *
12381  * @param ignored
12382  *
12383  * @return false
12384  **/
12385 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12386 {
12387         return false;
12388 }
12389
12390 /**
12391  *
12392  *
12393  **/
12394 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12395 {
12396         GLchar          buffer[16];
12397         std::string globals = "const uint first_input_location  = 0u;\n"
12398                                                   "const uint first_output_location = 0u;\n"
12399                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12400                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12401         size_t position = 100; /* Skip first part */
12402
12403         sprintf(buffer, "%d", last_in_loc);
12404         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12405
12406         sprintf(buffer, "%d", last_out_loc);
12407         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12408
12409         return globals;
12410 }
12411
12412 /**
12413  *
12414  **/
12415 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12416                                                                                           Utils::ProgramInterface&   program_interface,
12417                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12418 {
12419         const GLuint array_length  = 1;
12420         const GLuint first_in_loc  = 0;
12421         const GLuint first_out_loc = 0;
12422         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12423         size_t           position         = 0;
12424
12425         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12426
12427         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12428
12429         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12430         const GLchar* qual_first_out = "layout (location = first_output_location)";
12431         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12432         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12433
12434         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12435         const GLuint                    type_size = type.GetSize();
12436
12437         std::string first_in_name  = "PREFIXfirst";
12438         std::string first_out_name = "PREFIXfirst";
12439         std::string last_in_name   = "PREFIXlast";
12440         std::string last_out_name  = "PREFIXlast";
12441
12442         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12443         position = 0;
12444         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12445         position = 0;
12446         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12447         position = 0;
12448         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12449
12450         if (Utils::Shader::FRAGMENT == stage)
12451         {
12452                 qual_first_in = "layout (location = first_input_location) flat";
12453                 qual_last_in  = "layout (location = last_input_location)  flat";
12454         }
12455         if (Utils::Shader::GEOMETRY == stage)
12456         {
12457                 qual_first_out = "layout (location = first_output_location) flat";
12458                 qual_last_out  = "layout (location = last_output_location)  flat";
12459         }
12460
12461         Utils::Variable* first_in = si.Input(
12462                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12463                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12464                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12465
12466         Utils::Variable* last_in =
12467                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12468                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12469                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12470                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12471
12472         if (Utils::Shader::FRAGMENT != stage)
12473         {
12474                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12475
12476                 Utils::Variable* first_out =
12477                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12478                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12479                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12480                                           m_first_data.size() /* data_size */);
12481
12482                 Utils::Variable* last_out = si.Output(
12483                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12484                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12485                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12486
12487                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12488
12489                 varying_passthrough.Add(stage, first_in, first_out);
12490                 varying_passthrough.Add(stage, last_in, last_out);
12491         }
12492         else
12493         {
12494                 /* No outputs for fragment shader, so last_output_location can be 0 */
12495                 si.m_globals = prepareGlobals(last_in_loc, 0);
12496         }
12497 }
12498
12499 /** This test should be run with separable programs
12500  *
12501  * @param ignored
12502  *
12503  * @return true
12504  **/
12505 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12506 {
12507         return false;
12508 }
12509
12510 /* Constants used by VertexAttribLocationsTest */
12511 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12512 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12513 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12514 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12515 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12516
12517 /** Constructor
12518  *
12519  * @param context Test framework context
12520  **/
12521 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12522         : TextureTestBase(context, "vertex_attrib_locations",
12523                                           "Test verifies that attribute locations are respected by drawing operations")
12524 {
12525 }
12526
12527 /** Execute proper draw command for test case
12528  *
12529  * @param test_case_index Index of test case
12530  **/
12531 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12532 {
12533         const Functions& gl = m_context.getRenderContext().getFunctions();
12534
12535         switch (test_case_index)
12536         {
12537         case DRAWARRAYS:
12538                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12539                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12540                 break;
12541         case DRAWARRAYSINSTANCED:
12542                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12543                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12544                 break;
12545         case DRAWELEMENTS:
12546                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12547                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12548                 break;
12549         case DRAWELEMENTSBASEVERTEX:
12550                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12551                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12552                 break;
12553         case DRAWELEMENTSINSTANCED:
12554                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12555                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12556                 break;
12557         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12558                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12559                                                                                          m_base_instance);
12560                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12561                 break;
12562         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12563                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12564                                                                                    m_base_vertex);
12565                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12566                 break;
12567         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12568                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12569                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12570                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12571                 break;
12572         default:
12573                 TCU_FAIL("Invalid enum");
12574         }
12575 }
12576
12577 /** Get interface of program
12578  *
12579  * @param ignored
12580  * @param program_interface   Interface of program
12581  * @param ignored
12582  **/
12583 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12584                                                                                                         Utils::ProgramInterface& program_interface,
12585                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12586 {
12587         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12588
12589         /* Globals */
12590         si.m_globals = "const uint vertex_index_location   = 2;\n"
12591                                    "const uint instance_index_location = 5;\n";
12592
12593         /* Attributes */
12594         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12595                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12596                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12597                          (GLvoid*)0 /* data */, 0 /* data_size */);
12598         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12599                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12600                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12601                          (GLvoid*)0 /* data */, 0 /* data_size */);
12602 }
12603
12604 /** Get name of test case
12605  *
12606  * @param test_case_index Index of test case
12607  *
12608  * @return Name of test case
12609  **/
12610 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12611 {
12612         std::string result;
12613
12614         switch (test_case_index)
12615         {
12616         case DRAWARRAYS:
12617                 result = "DrawArrays";
12618                 break;
12619         case DRAWARRAYSINSTANCED:
12620                 result = "DrawArraysInstanced";
12621                 break;
12622         case DRAWELEMENTS:
12623                 result = "DrawElements";
12624                 break;
12625         case DRAWELEMENTSBASEVERTEX:
12626                 result = "DrawElementsBaseVertex";
12627                 break;
12628         case DRAWELEMENTSINSTANCED:
12629                 result = "DrawElementsInstanced";
12630                 break;
12631         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12632                 result = "DrawElementsInstancedBaseInstance";
12633                 break;
12634         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12635                 result = "DrawElementsInstancedBaseVertex";
12636                 break;
12637         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12638                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12639                 break;
12640         default:
12641                 TCU_FAIL("Invalid enum");
12642         }
12643
12644         return result;
12645 }
12646
12647 /** Get number of test cases
12648  *
12649  * @return Number of test cases
12650  **/
12651 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12652 {
12653         return TESTCASES_MAX;
12654 }
12655
12656 /** Prepare code snippet that will verify in and uniform variables
12657  *
12658  * @param ignored
12659  * @param ignored
12660  * @param stage   Shader stage
12661  *
12662  * @return Code that verify variables
12663  **/
12664 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12665                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12666                                                                                                                           Utils::Shader::STAGES stage)
12667 {
12668         std::string verification;
12669
12670         if (Utils::Shader::VERTEX == stage)
12671         {
12672
12673 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12674
12675                 verification = "if (gl_InstanceID != instance_index)\n"
12676                                            "    {\n"
12677                                            "        result = 12u;\n"
12678                                            "    }\n"
12679                                            "    else if (gl_VertexID != vertex_index)\n"
12680                                            "    {\n"
12681                                            "        result = 11u;\n"
12682                                            "    }\n";
12683
12684 #else
12685
12686                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12687                                            "        (gl_InstanceID != instance_index) )\n"
12688                                            "    {\n"
12689                                            "        result = 0u;\n"
12690                                            "    }\n";
12691
12692 #endif
12693         }
12694         else
12695         {
12696                 verification = "";
12697         }
12698
12699         return verification;
12700 }
12701
12702 /** Selects if "compute" stage is relevant for test
12703  *
12704  * @param ignored
12705  *
12706  * @return false
12707  **/
12708 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12709 {
12710         return false;
12711 }
12712
12713 /** Prepare attributes, vertex array object and array buffer
12714  *
12715  * @param ignored
12716  * @param ignored Interface of program
12717  * @param buffer  Array buffer
12718  * @param vao     Vertex array object
12719  **/
12720 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12721                                                                                                   Utils::ProgramInterface& /* program_interface */,
12722                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12723 {
12724         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12725         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12726
12727         std::vector<GLuint> buffer_data;
12728         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12729
12730         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12731
12732         /*
12733          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12734          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12735          */
12736         if (test_case_index >= 2)
12737         {
12738                 buffer.m_buffer = Utils::Buffer::Element;
12739         }
12740         vao.Bind();
12741         buffer.Bind();
12742
12743         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12744                                   0 /* stride */, 0 /* offset */);
12745
12746         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12747                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12748         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12749         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12750         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12751                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12752         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12753                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12754
12755         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12756         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12757
12758         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12759 }
12760
12761 /** This test should be run with separable programs
12762  *
12763  * @param ignored
12764  *
12765  * @return true
12766  **/
12767 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12768 {
12769         return false;
12770 }
12771
12772 /** Constructor
12773  *
12774  * @param context Test framework context
12775  **/
12776 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12777         : VaryingLocationsTest(context, "varying_array_locations",
12778                                                    "Test verifies that input and output locations are respected for arrays")
12779 {
12780 }
12781
12782 /**
12783  *
12784  **/
12785 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12786                                                                                                    Utils::ProgramInterface&   program_interface,
12787                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12788 {
12789         const GLuint array_length  = 1u;
12790         const GLuint first_in_loc  = 0;
12791         const GLuint first_out_loc = 0;
12792         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12793         size_t           position         = 0;
12794
12795         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12796
12797         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12798
12799         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12800         const GLchar* qual_first_out = "layout (location = first_output_location)";
12801         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12802         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12803
12804         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12805         const GLuint                    type_size = type.GetSize();
12806
12807         std::string first_in_name  = "PREFIXfirst";
12808         std::string first_out_name = "PREFIXfirst";
12809         std::string last_in_name   = "PREFIXlast";
12810         std::string last_out_name  = "PREFIXlast";
12811
12812         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12813         position = 0;
12814         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12815         position = 0;
12816         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12817         position = 0;
12818         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12819
12820         if (Utils::Shader::FRAGMENT == stage)
12821         {
12822                 qual_first_in = "layout (location = first_input_location) flat";
12823                 qual_last_in  = "layout (location = last_input_location)  flat";
12824         }
12825         if (Utils::Shader::GEOMETRY == stage)
12826         {
12827                 qual_first_out = "layout (location = first_output_location) flat";
12828                 qual_last_out  = "layout (location = last_output_location)  flat";
12829         }
12830
12831         Utils::Variable* first_in =
12832                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12833                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12834                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12835                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12836
12837         Utils::Variable* last_in =
12838                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12839                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12840                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12841                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12842
12843         if (Utils::Shader::FRAGMENT != stage)
12844         {
12845                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12846
12847                 Utils::Variable* first_out =
12848                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12849                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12850                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12851                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12852
12853                 Utils::Variable* last_out =
12854                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12855                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12856                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12857                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12858
12859                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12860
12861                 varying_passthrough.Add(stage, first_in, first_out);
12862                 varying_passthrough.Add(stage, last_in, last_out);
12863         }
12864         else
12865         {
12866                 /* No outputs for fragment shader, so last_output_location can be 0 */
12867                 si.m_globals = prepareGlobals(last_in_loc, 0);
12868         }
12869 }
12870
12871 /** Constructor
12872  *
12873  * @param context Test framework context
12874  **/
12875 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12876         : TextureTestBase(context, "varying_structure_locations",
12877                                           "Test verifies that locations are respected when structures are used as in and out ")
12878 {
12879 }
12880
12881 /** Prepare code snippet that will pass in variables to out variables
12882  *
12883  * @param ignored
12884  * @param varying_passthrough Collection of connections between in and out variables
12885  * @param stage               Shader stage
12886  *
12887  * @return Code that pass in variables to next stage
12888  **/
12889 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12890                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12891                                                                                                                   Utils::Shader::STAGES          stage)
12892 {
12893         std::string result;
12894
12895         if (Utils::Shader::VERTEX != stage)
12896         {
12897                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12898         }
12899         else
12900         {
12901                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12902                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12903         }
12904
12905         return result;
12906 }
12907
12908 /** Get interface of program
12909  *
12910  * @param test_case_index     Test case
12911  * @param program_interface   Interface of program
12912  * @param varying_passthrough Collection of connections between in and out variables
12913  **/
12914 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12915                                                                                                                 Utils::ProgramInterface&   program_interface,
12916                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12917 {
12918         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12919         const Utils::Type               type = getType(test_case_index);
12920
12921         /* Prepare data */
12922         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12923         m_single_data = type.GenerateDataPacked();
12924         m_array_data  = type.GenerateDataPacked();
12925
12926         m_data.resize(m_single_data.size() + m_array_data.size());
12927         GLubyte* ptr = (GLubyte*)&m_data[0];
12928         memcpy(ptr, &m_single_data[0], m_single_data.size());
12929         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12930
12931         Utils::Interface* structure = program_interface.Structure("Data");
12932
12933         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12934                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12935
12936         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12937         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12938                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12939
12940         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12941                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12942                          m_single_data.size() /* data_size */);
12943
12944         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12945                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12946                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12947
12948         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12949                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12950                           m_data.size() /* data_size */);
12951
12952         program_interface.CloneVertexInterface(varying_passthrough);
12953 }
12954
12955 /** Get type name
12956  *
12957  * @param test_case_index Index of test case
12958  *
12959  * @return Name of type test in test_case_index
12960  **/
12961 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12962 {
12963         return getTypeName(test_case_index);
12964 }
12965
12966 /** Returns number of types to test
12967  *
12968  * @return Number of types, 34
12969  **/
12970 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12971 {
12972         return getTypesNumber();
12973 }
12974
12975 /** Selects if "compute" stage is relevant for test
12976  *
12977  * @param ignored
12978  *
12979  * @return false
12980  **/
12981 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12982 {
12983         return false;
12984 }
12985
12986 /** This test should be run with separable programs
12987  *
12988  * @param ignored
12989  *
12990  * @return true
12991  **/
12992 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12993 {
12994         return false;
12995 }
12996
12997 /** Constructor
12998  *
12999  * @param context          Test context
13000  * @param test_name        Name of test
13001  * @param test_description Description of test
13002  **/
13003 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
13004         : NegativeTestBase(context, "varying_structure_member_location",
13005                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
13006 {
13007 }
13008
13009 /** Source for given test case and stage
13010  *
13011  * @param test_case_index Index of test case
13012  * @param stage           Shader stage
13013  *
13014  * @return Shader source
13015  **/
13016 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13017 {
13018         static const GLchar* struct_definition = "struct Data {\n"
13019                                                                                          "    vec4 gohan;\n"
13020                                                                                          "    layout (location = 4) vec4 goten;\n"
13021                                                                                          "};\n";
13022         static const GLchar* input_var  = "in Data data;\n";
13023         static const GLchar* output_var = "out Data data;\n";
13024         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
13025         static const GLchar* output_use = "    data.gohan = result / 2;\n"
13026                                                                           "    data.goten = result / 4 - data.gohan;\n";
13027         static const GLchar* fs = "#version 430 core\n"
13028                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13029                                                           "\n"
13030                                                           "in  vec4 gs_fs;\n"
13031                                                           "out vec4 fs_out;\n"
13032                                                           "\n"
13033                                                           "void main()\n"
13034                                                           "{\n"
13035                                                           "    fs_out = gs_fs;\n"
13036                                                           "}\n"
13037                                                           "\n";
13038         static const GLchar* fs_tested = "#version 430 core\n"
13039                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13040                                                                          "\n"
13041                                                                          "STRUCT_DEFINITION"
13042                                                                          "\n"
13043                                                                          "VARIABLE_DEFINITION"
13044                                                                          "\n"
13045                                                                          "in  vec4 gs_fs;\n"
13046                                                                          "out vec4 fs_out;\n"
13047                                                                          "\n"
13048                                                                          "void main()\n"
13049                                                                          "{\n"
13050                                                                          "    vec4 result = gs_fs;\n"
13051                                                                          "\n"
13052                                                                          "VARIABLE_USE"
13053                                                                          "\n"
13054                                                                          "    fs_out += result;\n"
13055                                                                          "}\n"
13056                                                                          "\n";
13057         static const GLchar* gs = "#version 430 core\n"
13058                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13059                                                           "\n"
13060                                                           "layout(points)                           in;\n"
13061                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13062                                                           "\n"
13063                                                           "in  vec4 tes_gs[];\n"
13064                                                           "out vec4 gs_fs;\n"
13065                                                           "\n"
13066                                                           "void main()\n"
13067                                                           "{\n"
13068                                                           "    gs_fs = tes_gs[0];\n"
13069                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13070                                                           "    EmitVertex();\n"
13071                                                           "    gs_fs = tes_gs[0];\n"
13072                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13073                                                           "    EmitVertex();\n"
13074                                                           "    gs_fs = tes_gs[0];\n"
13075                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13076                                                           "    EmitVertex();\n"
13077                                                           "    gs_fs = tes_gs[0];\n"
13078                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13079                                                           "    EmitVertex();\n"
13080                                                           "}\n"
13081                                                           "\n";
13082         static const GLchar* gs_tested = "#version 430 core\n"
13083                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13084                                                                          "\n"
13085                                                                          "layout(points)                           in;\n"
13086                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13087                                                                          "\n"
13088                                                                          "STRUCT_DEFINITION"
13089                                                                          "\n"
13090                                                                          "VARIABLE_DEFINITION"
13091                                                                          "\n"
13092                                                                          "in  vec4 tes_gs[];\n"
13093                                                                          "out vec4 gs_fs;\n"
13094                                                                          "\n"
13095                                                                          "void main()\n"
13096                                                                          "{\n"
13097                                                                          "    vec4 result = tes_gs[0];\n"
13098                                                                          "\n"
13099                                                                          "VARIABLE_USE"
13100                                                                          "\n"
13101                                                                          "    gs_fs = result;\n"
13102                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13103                                                                          "    EmitVertex();\n"
13104                                                                          "    gs_fs = result;\n"
13105                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13106                                                                          "    EmitVertex();\n"
13107                                                                          "    gs_fs = result;\n"
13108                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13109                                                                          "    EmitVertex();\n"
13110                                                                          "    gs_fs = result;\n"
13111                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13112                                                                          "    EmitVertex();\n"
13113                                                                          "}\n"
13114                                                                          "\n";
13115         static const GLchar* tcs = "#version 430 core\n"
13116                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13117                                                            "\n"
13118                                                            "layout(vertices = 1) out;\n"
13119                                                            "\n"
13120                                                            "in  vec4 vs_tcs[];\n"
13121                                                            "out vec4 tcs_tes[];\n"
13122                                                            "\n"
13123                                                            "void main()\n"
13124                                                            "{\n"
13125                                                            "\n"
13126                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13127                                                            "\n"
13128                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13129                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13130                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13131                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13132                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13133                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13134                                                            "}\n"
13135                                                            "\n";
13136         static const GLchar* tcs_tested = "#version 430 core\n"
13137                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13138                                                                           "\n"
13139                                                                           "layout(vertices = 1) out;\n"
13140                                                                           "\n"
13141                                                                           "STRUCT_DEFINITION"
13142                                                                           "\n"
13143                                                                           "VARIABLE_DEFINITION"
13144                                                                           "\n"
13145                                                                           "in  vec4 vs_tcs[];\n"
13146                                                                           "out vec4 tcs_tes[];\n"
13147                                                                           "\n"
13148                                                                           "void main()\n"
13149                                                                           "{\n"
13150                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13151                                                                           "\n"
13152                                                                           "VARIABLE_USE"
13153                                                                           "\n"
13154                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13155                                                                           "\n"
13156                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13157                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13158                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13159                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13160                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13161                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13162                                                                           "}\n"
13163                                                                           "\n";
13164         static const GLchar* tes = "#version 430 core\n"
13165                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13166                                                            "\n"
13167                                                            "layout(isolines, point_mode) in;\n"
13168                                                            "\n"
13169                                                            "in  vec4 tcs_tes[];\n"
13170                                                            "out vec4 tes_gs;\n"
13171                                                            "\n"
13172                                                            "void main()\n"
13173                                                            "{\n"
13174                                                            "    tes_gs = tcs_tes[0];\n"
13175                                                            "}\n"
13176                                                            "\n";
13177         static const GLchar* tes_tested = "#version 430 core\n"
13178                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13179                                                                           "\n"
13180                                                                           "layout(isolines, point_mode) in;\n"
13181                                                                           "\n"
13182                                                                           "STRUCT_DEFINITION"
13183                                                                           "\n"
13184                                                                           "VARIABLE_DEFINITION"
13185                                                                           "\n"
13186                                                                           "in  vec4 tcs_tes[];\n"
13187                                                                           "out vec4 tes_gs;\n"
13188                                                                           "\n"
13189                                                                           "void main()\n"
13190                                                                           "{\n"
13191                                                                           "    vec4 result = tcs_tes[0];\n"
13192                                                                           "\n"
13193                                                                           "VARIABLE_USE"
13194                                                                           "\n"
13195                                                                           "    tes_gs += result;\n"
13196                                                                           "}\n"
13197                                                                           "\n";
13198         static const GLchar* vs = "#version 430 core\n"
13199                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13200                                                           "\n"
13201                                                           "in  vec4 in_vs;\n"
13202                                                           "out vec4 vs_tcs;\n"
13203                                                           "\n"
13204                                                           "void main()\n"
13205                                                           "{\n"
13206                                                           "    vs_tcs = in_vs;\n"
13207                                                           "}\n"
13208                                                           "\n";
13209         static const GLchar* vs_tested = "#version 430 core\n"
13210                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13211                                                                          "\n"
13212                                                                          "STRUCT_DEFINITION"
13213                                                                          "\n"
13214                                                                          "VARIABLE_DEFINITION"
13215                                                                          "\n"
13216                                                                          "in  vec4 in_vs;\n"
13217                                                                          "out vec4 vs_tcs;\n"
13218                                                                          "\n"
13219                                                                          "void main()\n"
13220                                                                          "{\n"
13221                                                                          "    vec4 result = in_vs;\n"
13222                                                                          "\n"
13223                                                                          "VARIABLE_USE"
13224                                                                          "\n"
13225                                                                          "    vs_tcs += result;\n"
13226                                                                          "}\n"
13227                                                                          "\n";
13228
13229         std::string   source;
13230         testCase&        test_case               = m_test_cases[test_case_index];
13231         const GLchar* var_definition = 0;
13232         const GLchar* var_use            = 0;
13233
13234         if (true == test_case.m_is_input)
13235         {
13236                 var_definition = input_var;
13237                 var_use            = input_use;
13238         }
13239         else
13240         {
13241                 var_definition = output_var;
13242                 var_use            = output_use;
13243         }
13244
13245         if (test_case.m_stage == stage)
13246         {
13247                 size_t position = 0;
13248
13249                 switch (stage)
13250                 {
13251                 case Utils::Shader::FRAGMENT:
13252                         source = fs_tested;
13253                         break;
13254                 case Utils::Shader::GEOMETRY:
13255                         source = gs_tested;
13256                         break;
13257                 case Utils::Shader::TESS_CTRL:
13258                         source = tcs_tested;
13259                         break;
13260                 case Utils::Shader::TESS_EVAL:
13261                         source = tes_tested;
13262                         break;
13263                 case Utils::Shader::VERTEX:
13264                         source = vs_tested;
13265                         break;
13266                 default:
13267                         TCU_FAIL("Invalid enum");
13268                 }
13269
13270                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13271                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13272                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13273         }
13274         else
13275         {
13276                 switch (stage)
13277                 {
13278                 case Utils::Shader::FRAGMENT:
13279                         source = fs;
13280                         break;
13281                 case Utils::Shader::GEOMETRY:
13282                         source = gs;
13283                         break;
13284                 case Utils::Shader::TESS_CTRL:
13285                         source = tcs;
13286                         break;
13287                 case Utils::Shader::TESS_EVAL:
13288                         source = tes;
13289                         break;
13290                 case Utils::Shader::VERTEX:
13291                         source = vs;
13292                         break;
13293                 default:
13294                         TCU_FAIL("Invalid enum");
13295                 }
13296         }
13297
13298         return source;
13299 }
13300
13301 /** Get description of test case
13302  *
13303  * @param test_case_index Index of test case
13304  *
13305  * @return Test case description
13306  **/
13307 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13308 {
13309         std::stringstream stream;
13310         testCase&                 test_case = m_test_cases[test_case_index];
13311
13312         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13313
13314         if (true == test_case.m_is_input)
13315         {
13316                 stream << "input";
13317         }
13318         else
13319         {
13320                 stream << "output";
13321         }
13322
13323         return stream.str();
13324 }
13325
13326 /** Get number of test cases
13327  *
13328  * @return Number of test cases
13329  **/
13330 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13331 {
13332         return static_cast<GLuint>(m_test_cases.size());
13333 }
13334
13335 /** Selects if "compute" stage is relevant for test
13336  *
13337  * @param ignored
13338  *
13339  * @return false
13340  **/
13341 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13342 {
13343         return false;
13344 }
13345
13346 /** Prepare all test cases
13347  *
13348  **/
13349 void VaryingStructureMemberLocationTest::testInit()
13350 {
13351         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13352         {
13353                 if (Utils::Shader::COMPUTE == stage)
13354                 {
13355                         continue;
13356                 }
13357
13358                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13359                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13360
13361                 m_test_cases.push_back(test_case_in);
13362
13363                 if (Utils::Shader::FRAGMENT != stage)
13364                 {
13365                         m_test_cases.push_back(test_case_out);
13366                 }
13367         }
13368 }
13369
13370 /** Constructor
13371  *
13372  * @param context Test framework context
13373  **/
13374 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13375         : TextureTestBase(context, "varying_block_locations",
13376                                           "Test verifies that locations are respected when blocks are used as in and out ")
13377 {
13378 }
13379
13380 /** Prepare code snippet that will pass in variables to out variables
13381  *
13382  * @param ignored
13383  * @param varying_passthrough Collection of connections between in and out variables
13384  * @param stage               Shader stage
13385  *
13386  * @return Code that pass in variables to next stage
13387  **/
13388 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13389                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13390                                                                                                           Utils::Shader::STAGES          stage)
13391 {
13392         std::string result;
13393
13394         if (Utils::Shader::VERTEX != stage)
13395         {
13396                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13397         }
13398         else
13399         {
13400                 result = "vs_tcs_block.third  = vs_in_third;\n"
13401                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13402                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13403         }
13404
13405         return result;
13406 }
13407
13408 /** Get interface of program
13409  *
13410  * @param ignored
13411  * @param program_interface   Interface of program
13412  * @param varying_passthrough Collection of connections between in and out variables
13413  **/
13414 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13415                                                                                                         Utils::ProgramInterface&   program_interface,
13416                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13417 {
13418         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13419         const Utils::Type               vec4 = Utils::Type::vec4;
13420
13421         /* Prepare data */
13422         m_third_data  = vec4.GenerateData();
13423         m_fourth_data = vec4.GenerateData();
13424         m_fifth_data  = vec4.GenerateData();
13425
13426         /* Memory layout is different from location layout */
13427         const GLuint fifth_offset  = 0u;
13428         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13429         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13430
13431         m_data.resize(fourth_offset + m_fourth_data.size());
13432         GLubyte* ptr = (GLubyte*)&m_data[0];
13433         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13434         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13435         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13436
13437         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13438
13439         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13440                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13441
13442         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13443                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13444
13445         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13446                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13447
13448         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13449                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13450                           m_data.size() /* data_size */);
13451
13452         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13453                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13454                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13455
13456         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13457                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13458                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13459
13460         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13461                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13462                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13463
13464         program_interface.CloneVertexInterface(varying_passthrough);
13465 }
13466
13467 /** Selects if "compute" stage is relevant for test
13468  *
13469  * @param ignored
13470  *
13471  * @return false
13472  **/
13473 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13474 {
13475         return false;
13476 }
13477
13478 /** This test should be run with separable programs
13479  *
13480  * @param ignored
13481  *
13482  * @return true
13483  **/
13484 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13485 {
13486         return false;
13487 }
13488
13489 /** Constructor
13490  *
13491  * @param context Test framework context
13492  **/
13493 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13494         : NegativeTestBase(
13495                   context, "varying_block_member_locations",
13496                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13497 {
13498 }
13499
13500 /** Source for given test case and stage
13501  *
13502  * @param test_case_index Index of test case
13503  * @param stage           Shader stage
13504  *
13505  * @return Shader source
13506  **/
13507 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13508 {
13509         static const GLchar* block_definition_all = "Goku {\n"
13510                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13511                                                                                                 "    layout (location = 4) vec4 goten;\n"
13512                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13513                                                                                                 "} gokuARRAY;\n";
13514         static const GLchar* block_definition_default = "Goku {\n"
13515                                                                                                         "    vec4 gohan;\n"
13516                                                                                                         "    vec4 goten;\n"
13517                                                                                                         "    vec4 chichi;\n"
13518                                                                                                         "} gokuARRAY;\n";
13519         static const GLchar* block_definition_one = "Goku {\n"
13520                                                                                                 "    vec4 gohan;\n"
13521                                                                                                 "    layout (location = 4) vec4 goten;\n"
13522                                                                                                 "    vec4 chichi;\n"
13523                                                                                                 "} gokuARRAY;\n";
13524         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13525         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13526                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13527                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13528         static const GLchar* fs = "#version 430 core\n"
13529                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13530                                                           "\n"
13531                                                           "in  vec4 gs_fs;\n"
13532                                                           "out vec4 fs_out;\n"
13533                                                           "\n"
13534                                                           "void main()\n"
13535                                                           "{\n"
13536                                                           "    fs_out = gs_fs;\n"
13537                                                           "}\n"
13538                                                           "\n";
13539         static const GLchar* fs_tested = "#version 430 core\n"
13540                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13541                                                                          "\n"
13542                                                                          "DIRECTION BLOCK_DEFINITION"
13543                                                                          "\n"
13544                                                                          "in  vec4 gs_fs;\n"
13545                                                                          "out vec4 fs_out;\n"
13546                                                                          "\n"
13547                                                                          "void main()\n"
13548                                                                          "{\n"
13549                                                                          "    vec4 result = gs_fs;\n"
13550                                                                          "\n"
13551                                                                          "VARIABLE_USE"
13552                                                                          "\n"
13553                                                                          "    fs_out = result;\n"
13554                                                                          "}\n"
13555                                                                          "\n";
13556         static const GLchar* gs = "#version 430 core\n"
13557                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13558                                                           "\n"
13559                                                           "layout(points)                           in;\n"
13560                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13561                                                           "\n"
13562                                                           "in  vec4 tes_gs[];\n"
13563                                                           "out vec4 gs_fs;\n"
13564                                                           "\n"
13565                                                           "void main()\n"
13566                                                           "{\n"
13567                                                           "    gs_fs = tes_gs[0];\n"
13568                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13569                                                           "    EmitVertex();\n"
13570                                                           "    gs_fs = tes_gs[0];\n"
13571                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13572                                                           "    EmitVertex();\n"
13573                                                           "    gs_fs = tes_gs[0];\n"
13574                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13575                                                           "    EmitVertex();\n"
13576                                                           "    gs_fs = tes_gs[0];\n"
13577                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13578                                                           "    EmitVertex();\n"
13579                                                           "}\n"
13580                                                           "\n";
13581         static const GLchar* gs_tested = "#version 430 core\n"
13582                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13583                                                                          "\n"
13584                                                                          "layout(points)                           in;\n"
13585                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13586                                                                          "\n"
13587                                                                          "DIRECTION BLOCK_DEFINITION"
13588                                                                          "\n"
13589                                                                          "in  vec4 tes_gs[];\n"
13590                                                                          "out vec4 gs_fs;\n"
13591                                                                          "\n"
13592                                                                          "void main()\n"
13593                                                                          "{\n"
13594                                                                          "    vec4 result = tes_gs[0];\n"
13595                                                                          "\n"
13596                                                                          "VARIABLE_USE"
13597                                                                          "\n"
13598                                                                          "    gs_fs = result;\n"
13599                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13600                                                                          "    EmitVertex();\n"
13601                                                                          "    gs_fs = result;\n"
13602                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13603                                                                          "    EmitVertex();\n"
13604                                                                          "    gs_fs = result;\n"
13605                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13606                                                                          "    EmitVertex();\n"
13607                                                                          "    gs_fs = result;\n"
13608                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13609                                                                          "    EmitVertex();\n"
13610                                                                          "}\n"
13611                                                                          "\n";
13612         static const GLchar* tcs = "#version 430 core\n"
13613                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13614                                                            "\n"
13615                                                            "layout(vertices = 1) out;\n"
13616                                                            "\n"
13617                                                            "in  vec4 vs_tcs[];\n"
13618                                                            "out vec4 tcs_tes[];\n"
13619                                                            "\n"
13620                                                            "void main()\n"
13621                                                            "{\n"
13622                                                            "\n"
13623                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13624                                                            "\n"
13625                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13626                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13627                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13628                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13629                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13630                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13631                                                            "}\n"
13632                                                            "\n";
13633         static const GLchar* tcs_tested = "#version 430 core\n"
13634                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13635                                                                           "\n"
13636                                                                           "layout(vertices = 1) out;\n"
13637                                                                           "\n"
13638                                                                           "DIRECTION BLOCK_DEFINITION"
13639                                                                           "\n"
13640                                                                           "in  vec4 vs_tcs[];\n"
13641                                                                           "out vec4 tcs_tes[];\n"
13642                                                                           "\n"
13643                                                                           "void main()\n"
13644                                                                           "{\n"
13645                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13646                                                                           "\n"
13647                                                                           "VARIABLE_USE"
13648                                                                           "\n"
13649                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13650                                                                           "\n"
13651                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13652                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13653                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13654                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13655                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13656                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13657                                                                           "}\n"
13658                                                                           "\n";
13659         static const GLchar* tes = "#version 430 core\n"
13660                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13661                                                            "\n"
13662                                                            "layout(isolines, point_mode) in;\n"
13663                                                            "\n"
13664                                                            "in  vec4 tcs_tes[];\n"
13665                                                            "out vec4 tes_gs;\n"
13666                                                            "\n"
13667                                                            "void main()\n"
13668                                                            "{\n"
13669                                                            "    tes_gs = tcs_tes[0];\n"
13670                                                            "}\n"
13671                                                            "\n";
13672         static const GLchar* tes_tested = "#version 430 core\n"
13673                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13674                                                                           "\n"
13675                                                                           "layout(isolines, point_mode) in;\n"
13676                                                                           "\n"
13677                                                                           "DIRECTION BLOCK_DEFINITION"
13678                                                                           "\n"
13679                                                                           "in  vec4 tcs_tes[];\n"
13680                                                                           "out vec4 tes_gs;\n"
13681                                                                           "\n"
13682                                                                           "void main()\n"
13683                                                                           "{\n"
13684                                                                           "    vec4 result = tcs_tes[0];\n"
13685                                                                           "\n"
13686                                                                           "VARIABLE_USE"
13687                                                                           "\n"
13688                                                                           "    tes_gs = result;\n"
13689                                                                           "}\n"
13690                                                                           "\n";
13691         static const GLchar* vs = "#version 430 core\n"
13692                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13693                                                           "\n"
13694                                                           "in  vec4 in_vs;\n"
13695                                                           "out vec4 vs_tcs;\n"
13696                                                           "\n"
13697                                                           "void main()\n"
13698                                                           "{\n"
13699                                                           "    vs_tcs = in_vs;\n"
13700                                                           "}\n"
13701                                                           "\n";
13702         static const GLchar* vs_tested = "#version 430 core\n"
13703                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13704                                                                          "\n"
13705                                                                          "DIRECTION BLOCK_DEFINITION"
13706                                                                          "\n"
13707                                                                          "in  vec4 in_vs;\n"
13708                                                                          "out vec4 vs_tcs;\n"
13709                                                                          "\n"
13710                                                                          "void main()\n"
13711                                                                          "{\n"
13712                                                                          "    vec4 result = in_vs;\n"
13713                                                                          "\n"
13714                                                                          "VARIABLE_USE"
13715                                                                          "\n"
13716                                                                          "    vs_tcs = result;\n"
13717                                                                          "}\n"
13718                                                                          "\n";
13719
13720         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13721                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13722                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13723                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13724                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13725                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13726
13727         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13728                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13729                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13730                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13731                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13732                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13733
13734         static const bool require_modifications_in[6][6] = {
13735                 /* cs  */ { false, false, false, false, false, false },
13736                 /* vs  */ { false, true, false, false, false, false },
13737                 /* tcs */ { false, true, true, false, false, false },
13738                 /* tes */ { false, false, true, true, false, false },
13739                 /* gs  */ { false, false, false, true, true, false },
13740                 /* fs  */ { false, false, false, false, true, true }
13741         };
13742
13743         static const bool require_modifications_out[6][6] = {
13744                 /* cs  */ { false, false, false, false, false, false },
13745                 /* vs  */ { false, true, true, false, false, false },
13746                 /* tcs */ { false, false, true, true, false, false },
13747                 /* tes */ { false, false, false, true, true, false },
13748                 /* gs  */ { false, false, false, false, true, true },
13749                 /* fs  */ { false, false, false, false, false, false }
13750         };
13751
13752         const GLchar* array                                     = "";
13753         const GLchar* direction                         = "out";
13754         const GLchar* index                                     = "";
13755         bool              require_modifications = false;
13756         std::string   source;
13757         testCase&        test_case = m_test_cases[test_case_index];
13758         const GLchar* var_use   = output_use;
13759
13760         if (true == test_case.m_is_input)
13761         {
13762                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13763                 source                            = shaders_in[test_case.m_stage][stage];
13764
13765                 if (test_case.m_stage == stage)
13766                 {
13767                         direction = "in";
13768                         var_use   = input_use;
13769                 }
13770         }
13771         else
13772         {
13773                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13774                 source                            = shaders_out[test_case.m_stage][stage];
13775
13776                 if (test_case.m_stage != stage)
13777                 {
13778                         direction = "in";
13779                         var_use   = input_use;
13780                 }
13781         }
13782
13783         const GLchar* definition = test_case.m_qualify_all ? block_definition_all
13784                         : block_definition_default;
13785
13786         if (test_case.m_stage == stage)
13787         {
13788                 if (true == test_case.m_qualify_all)
13789                 {
13790                         definition = block_definition_all;
13791                 }
13792                 else
13793                 {
13794                         definition = block_definition_one;
13795                 }
13796         }
13797
13798         // Geometry shader inputs, tessellation control shader inputs and outputs, and tessellation evaluation
13799         // inputs all have an additional level of arrayness relative to other shader inputs and outputs.
13800         switch (stage)
13801         {
13802         case Utils::Shader::FRAGMENT:
13803                 break;
13804         case Utils::Shader::TESS_CTRL:
13805                 array = "[]";
13806                 index = "[gl_InvocationID]";
13807                 break;
13808         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13809         // the GS input block is an array, so the DS output can't be declared as an array
13810         case Utils::Shader::GEOMETRY:
13811         case Utils::Shader::TESS_EVAL:
13812         {
13813                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13814                 {
13815                         array = "[]";
13816                         index = "[0]";
13817                 }
13818                 else // match DS output and GS input
13819                 {
13820                         array = "";
13821                         index = "";
13822                 }
13823         }
13824         break;
13825         case Utils::Shader::VERTEX:
13826                 break;
13827         default:
13828                 TCU_FAIL("Invalid enum");
13829         }
13830
13831         if (true == require_modifications)
13832         {
13833                 size_t position = 0;
13834                 size_t temp;
13835
13836                 Utils::replaceToken("DIRECTION", position, direction, source);
13837                 temp = position;
13838                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13839                 position = temp;
13840                 Utils::replaceToken("ARRAY", position, array, source);
13841                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13842
13843                 Utils::replaceAllTokens("INDEX", index, source);
13844         }
13845         else
13846         {
13847                 switch (stage)
13848                 {
13849                 case Utils::Shader::FRAGMENT:
13850                         source = fs;
13851                         break;
13852                 case Utils::Shader::GEOMETRY:
13853                         source = gs;
13854                         break;
13855                 case Utils::Shader::TESS_CTRL:
13856                         source = tcs;
13857                         break;
13858                 case Utils::Shader::TESS_EVAL:
13859                         source = tes;
13860                         break;
13861                 case Utils::Shader::VERTEX:
13862                         source = vs;
13863                         break;
13864                 default:
13865                         TCU_FAIL("Invalid enum");
13866                 }
13867         }
13868
13869         return source;
13870 }
13871
13872 /** Get description of test case
13873  *
13874  * @param test_case_index Index of test case
13875  *
13876  * @return Test case description
13877  **/
13878 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13879 {
13880         std::stringstream stream;
13881         testCase&                 test_case = m_test_cases[test_case_index];
13882
13883         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13884
13885         if (true == test_case.m_is_input)
13886         {
13887                 stream << "input";
13888         }
13889         else
13890         {
13891                 stream << "output";
13892         }
13893
13894         if (true == test_case.m_qualify_all)
13895         {
13896                 stream << ", all members qualified";
13897         }
13898         else
13899         {
13900                 stream << ", not all members qualified";
13901         }
13902
13903         return stream.str();
13904 }
13905
13906 /** Get number of test cases
13907  *
13908  * @return Number of test cases
13909  **/
13910 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13911 {
13912         return static_cast<GLuint>(m_test_cases.size());
13913 }
13914
13915 /** Selects if "compute" stage is relevant for test
13916  *
13917  * @param ignored
13918  *
13919  * @return false
13920  **/
13921 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13922 {
13923         return false;
13924 }
13925
13926 /** Selects if compilation failure is expected result
13927  *
13928  * @param test_case_index Index of test case
13929  *
13930  * @return false when all members are qualified, true otherwise
13931  **/
13932 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13933 {
13934         return (true != m_test_cases[test_case_index].m_qualify_all);
13935 }
13936
13937 /** Prepare all test cases
13938  *
13939  **/
13940 void VaryingBlockMemberLocationsTest::testInit()
13941 {
13942         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13943         {
13944                 if (Utils::Shader::COMPUTE == stage)
13945                 {
13946                         continue;
13947                 }
13948
13949                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13950                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13951                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13952                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13953
13954                 if (Utils::Shader::VERTEX != stage)
13955                 {
13956                         m_test_cases.push_back(test_case_in_all);
13957                         m_test_cases.push_back(test_case_in_one);
13958                 }
13959
13960                 if (Utils::Shader::FRAGMENT != stage)
13961                 {
13962                         m_test_cases.push_back(test_case_out_all);
13963                         m_test_cases.push_back(test_case_out_one);
13964                 }
13965         }
13966 }
13967
13968 /** Constructor
13969  *
13970  * @param context Test framework context
13971  **/
13972 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13973         : NegativeTestBase(
13974                   context, "varying_block_automatic_member_locations",
13975                   "Test verifies that compiler assigns subsequent locations to block members, even if this causes errors")
13976 {
13977 }
13978
13979 /** Source for given test case and stage
13980  *
13981  * @param test_case_index Index of test case
13982  * @param stage           Shader stage
13983  *
13984  * @return Shader source
13985  **/
13986 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13987                                                                                                                                           Utils::Shader::STAGES stage)
13988 {
13989         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13990                                                                                         "    vec4 goku;\n"
13991                                                                                         "    vec4 gohan[4];\n"
13992                                                                                         "    vec4 goten;\n"
13993                                                                                         "    layout (location = 1) vec4 chichi;\n"
13994                                                                                         "    vec4 pan;\n"
13995                                                                                         "} dbzARRAY;\n";
13996         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13997                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13998                                                                          "dbzINDEX.pan;\n";
13999         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
14000                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
14001                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
14002                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
14003                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
14004                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
14005                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
14006                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
14007                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
14008         static const GLchar* fs = "#version 430 core\n"
14009                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14010                                                           "\n"
14011                                                           "in  vec4 gs_fs;\n"
14012                                                           "out vec4 fs_out;\n"
14013                                                           "\n"
14014                                                           "void main()\n"
14015                                                           "{\n"
14016                                                           "    fs_out = gs_fs;\n"
14017                                                           "}\n"
14018                                                           "\n";
14019         static const GLchar* fs_tested = "#version 430 core\n"
14020                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14021                                                                          "\n"
14022                                                                          "BLOCK_DEFINITION"
14023                                                                          "\n"
14024                                                                          "in  vec4 gs_fs;\n"
14025                                                                          "out vec4 fs_out;\n"
14026                                                                          "\n"
14027                                                                          "void main()\n"
14028                                                                          "{\n"
14029                                                                          "    vec4 result = gs_fs;\n"
14030                                                                          "\n"
14031                                                                          "VARIABLE_USE"
14032                                                                          "\n"
14033                                                                          "    fs_out += result;\n"
14034                                                                          "}\n"
14035                                                                          "\n";
14036         static const GLchar* gs = "#version 430 core\n"
14037                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14038                                                           "\n"
14039                                                           "layout(points)                           in;\n"
14040                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14041                                                           "\n"
14042                                                           "in  vec4 tes_gs[];\n"
14043                                                           "out vec4 gs_fs;\n"
14044                                                           "\n"
14045                                                           "void main()\n"
14046                                                           "{\n"
14047                                                           "    gs_fs = tes_gs[0];\n"
14048                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14049                                                           "    EmitVertex();\n"
14050                                                           "    gs_fs = tes_gs[0];\n"
14051                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14052                                                           "    EmitVertex();\n"
14053                                                           "    gs_fs = tes_gs[0];\n"
14054                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14055                                                           "    EmitVertex();\n"
14056                                                           "    gs_fs = tes_gs[0];\n"
14057                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14058                                                           "    EmitVertex();\n"
14059                                                           "}\n"
14060                                                           "\n";
14061         static const GLchar* gs_tested = "#version 430 core\n"
14062                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14063                                                                          "\n"
14064                                                                          "layout(points)                           in;\n"
14065                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14066                                                                          "\n"
14067                                                                          "BLOCK_DEFINITION"
14068                                                                          "\n"
14069                                                                          "in  vec4 tes_gs[];\n"
14070                                                                          "out vec4 gs_fs;\n"
14071                                                                          "\n"
14072                                                                          "void main()\n"
14073                                                                          "{\n"
14074                                                                          "    vec4 result = tes_gs[0];\n"
14075                                                                          "\n"
14076                                                                          "VARIABLE_USE"
14077                                                                          "\n"
14078                                                                          "    gs_fs = result;\n"
14079                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14080                                                                          "    EmitVertex();\n"
14081                                                                          "    gs_fs = result;\n"
14082                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14083                                                                          "    EmitVertex();\n"
14084                                                                          "    gs_fs = result;\n"
14085                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14086                                                                          "    EmitVertex();\n"
14087                                                                          "    gs_fs = result;\n"
14088                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14089                                                                          "    EmitVertex();\n"
14090                                                                          "}\n"
14091                                                                          "\n";
14092         static const GLchar* tcs = "#version 430 core\n"
14093                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14094                                                            "\n"
14095                                                            "layout(vertices = 1) out;\n"
14096                                                            "\n"
14097                                                            "in  vec4 vs_tcs[];\n"
14098                                                            "out vec4 tcs_tes[];\n"
14099                                                            "\n"
14100                                                            "void main()\n"
14101                                                            "{\n"
14102                                                            "\n"
14103                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14104                                                            "\n"
14105                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14106                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14107                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14108                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14109                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14110                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14111                                                            "}\n"
14112                                                            "\n";
14113         static const GLchar* tcs_tested = "#version 430 core\n"
14114                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14115                                                                           "\n"
14116                                                                           "layout(vertices = 1) out;\n"
14117                                                                           "\n"
14118                                                                           "BLOCK_DEFINITION"
14119                                                                           "\n"
14120                                                                           "in  vec4 vs_tcs[];\n"
14121                                                                           "out vec4 tcs_tes[];\n"
14122                                                                           "\n"
14123                                                                           "void main()\n"
14124                                                                           "{\n"
14125                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14126                                                                           "\n"
14127                                                                           "VARIABLE_USE"
14128                                                                           "\n"
14129                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14130                                                                           "\n"
14131                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14132                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14133                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14134                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14135                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14136                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14137                                                                           "}\n"
14138                                                                           "\n";
14139         static const GLchar* tes = "#version 430 core\n"
14140                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14141                                                            "\n"
14142                                                            "layout(isolines, point_mode) in;\n"
14143                                                            "\n"
14144                                                            "in  vec4 tcs_tes[];\n"
14145                                                            "out vec4 tes_gs;\n"
14146                                                            "\n"
14147                                                            "void main()\n"
14148                                                            "{\n"
14149                                                            "    tes_gs = tcs_tes[0];\n"
14150                                                            "}\n"
14151                                                            "\n";
14152         static const GLchar* tes_tested = "#version 430 core\n"
14153                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14154                                                                           "\n"
14155                                                                           "layout(isolines, point_mode) in;\n"
14156                                                                           "\n"
14157                                                                           "BLOCK_DEFINITION"
14158                                                                           "\n"
14159                                                                           "in  vec4 tcs_tes[];\n"
14160                                                                           "out vec4 tes_gs;\n"
14161                                                                           "\n"
14162                                                                           "void main()\n"
14163                                                                           "{\n"
14164                                                                           "    vec4 result = tcs_tes[0];\n"
14165                                                                           "\n"
14166                                                                           "VARIABLE_USE"
14167                                                                           "\n"
14168                                                                           "    tes_gs += result;\n"
14169                                                                           "}\n"
14170                                                                           "\n";
14171         static const GLchar* vs = "#version 430 core\n"
14172                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14173                                                           "\n"
14174                                                           "in  vec4 in_vs;\n"
14175                                                           "out vec4 vs_tcs;\n"
14176                                                           "\n"
14177                                                           "void main()\n"
14178                                                           "{\n"
14179                                                           "    vs_tcs = in_vs;\n"
14180                                                           "}\n"
14181                                                           "\n";
14182         static const GLchar* vs_tested = "#version 430 core\n"
14183                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14184                                                                          "\n"
14185                                                                          "BLOCK_DEFINITION"
14186                                                                          "\n"
14187                                                                          "in  vec4 in_vs;\n"
14188                                                                          "out vec4 vs_tcs;\n"
14189                                                                          "\n"
14190                                                                          "void main()\n"
14191                                                                          "{\n"
14192                                                                          "    vec4 result = in_vs;\n"
14193                                                                          "\n"
14194                                                                          "VARIABLE_USE"
14195                                                                          "\n"
14196                                                                          "    vs_tcs += result;\n"
14197                                                                          "}\n"
14198                                                                          "\n";
14199
14200         const GLchar* array             = "";
14201         const GLchar* direction = "out";
14202         const GLchar* index             = "";
14203         std::string   source;
14204         testCase&        test_case = m_test_cases[test_case_index];
14205         const GLchar* var_use   = output_use;
14206
14207         if (true == test_case.m_is_input)
14208         {
14209                 direction = "in ";
14210                 var_use   = input_use;
14211         }
14212
14213         if (test_case.m_stage == stage)
14214         {
14215                 size_t position = 0;
14216                 size_t temp;
14217
14218                 switch (stage)
14219                 {
14220                 case Utils::Shader::FRAGMENT:
14221                         source = fs_tested;
14222                         break;
14223                 case Utils::Shader::GEOMETRY:
14224                         source = gs_tested;
14225                         array  = "[]";
14226                         index  = "[0]";
14227                         break;
14228                 case Utils::Shader::TESS_CTRL:
14229                         source = tcs_tested;
14230                         array  = "[]";
14231                         index  = "[gl_InvocationID]";
14232                         break;
14233                 case Utils::Shader::TESS_EVAL:
14234                         source = tes_tested;
14235                         array  = "[]";
14236                         index  = "[0]";
14237                         break;
14238                 case Utils::Shader::VERTEX:
14239                         source = vs_tested;
14240                         break;
14241                 default:
14242                         TCU_FAIL("Invalid enum");
14243                 }
14244
14245                 temp = position;
14246                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14247                 position = temp;
14248                 Utils::replaceToken("DIRECTION", position, direction, source);
14249                 Utils::replaceToken("ARRAY", position, array, source);
14250                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14251
14252                 Utils::replaceAllTokens("INDEX", index, source);
14253         }
14254         else
14255         {
14256                 switch (stage)
14257                 {
14258                 case Utils::Shader::FRAGMENT:
14259                         source = fs;
14260                         break;
14261                 case Utils::Shader::GEOMETRY:
14262                         source = gs;
14263                         break;
14264                 case Utils::Shader::TESS_CTRL:
14265                         source = tcs;
14266                         break;
14267                 case Utils::Shader::TESS_EVAL:
14268                         source = tes;
14269                         break;
14270                 case Utils::Shader::VERTEX:
14271                         source = vs;
14272                         break;
14273                 default:
14274                         TCU_FAIL("Invalid enum");
14275                 }
14276         }
14277
14278         return source;
14279 }
14280
14281 /** Get description of test case
14282  *
14283  * @param test_case_index Index of test case
14284  *
14285  * @return Test case description
14286  **/
14287 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14288 {
14289         std::stringstream stream;
14290         testCase&                 test_case = m_test_cases[test_case_index];
14291
14292         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14293
14294         if (true == test_case.m_is_input)
14295         {
14296                 stream << "input";
14297         }
14298         else
14299         {
14300                 stream << "output";
14301         }
14302
14303         return stream.str();
14304 }
14305
14306 /** Get number of test cases
14307  *
14308  * @return Number of test cases
14309  **/
14310 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14311 {
14312         return static_cast<GLuint>(m_test_cases.size());
14313 }
14314
14315 /** Selects if "compute" stage is relevant for test
14316  *
14317  * @param ignored
14318  *
14319  * @return false
14320  **/
14321 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14322 {
14323         return false;
14324 }
14325
14326 /** Prepare all test cases
14327  *
14328  **/
14329 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14330 {
14331         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14332         {
14333                 if (Utils::Shader::COMPUTE == stage)
14334                 {
14335                         continue;
14336                 }
14337
14338                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14339                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14340
14341                 if (Utils::Shader::VERTEX != stage)
14342                 {
14343                         m_test_cases.push_back(test_case_in);
14344                 }
14345
14346                 if (Utils::Shader::FRAGMENT != stage)
14347                 {
14348                         m_test_cases.push_back(test_case_out);
14349                 }
14350         }
14351 }
14352
14353 /** Constructor
14354  *
14355  * @param context Test framework context
14356  **/
14357 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14358         : NegativeTestBase(context, "varying_location_limit",
14359                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14360 {
14361 }
14362
14363 /** Source for given test case and stage
14364  *
14365  * @param test_case_index Index of test case
14366  * @param stage           Shader stage
14367  *
14368  * @return Shader source
14369  **/
14370 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14371 {
14372         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14373         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14374                                                                          "    {\n"
14375                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14376                                                                          "    }\n";
14377         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14378                                                                           "    if (vec4(0) == result)\n"
14379                                                                           "    {\n"
14380                                                                           "        gokuINDEX = TYPE(1);\n"
14381                                                                           "    }\n";
14382         static const GLchar* fs = "#version 430 core\n"
14383                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14384                                                           "\n"
14385                                                           "in  vec4 gs_fs;\n"
14386                                                           "out vec4 fs_out;\n"
14387                                                           "\n"
14388                                                           "void main()\n"
14389                                                           "{\n"
14390                                                           "    fs_out = gs_fs;\n"
14391                                                           "}\n"
14392                                                           "\n";
14393         static const GLchar* fs_tested = "#version 430 core\n"
14394                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14395                                                                          "\n"
14396                                                                          "VAR_DEFINITION"
14397                                                                          "\n"
14398                                                                          "in  vec4 gs_fs;\n"
14399                                                                          "out vec4 fs_out;\n"
14400                                                                          "\n"
14401                                                                          "void main()\n"
14402                                                                          "{\n"
14403                                                                          "    vec4 result = gs_fs;\n"
14404                                                                          "\n"
14405                                                                          "VARIABLE_USE"
14406                                                                          "\n"
14407                                                                          "    fs_out += result;\n"
14408                                                                          "}\n"
14409                                                                          "\n";
14410         static const GLchar* gs = "#version 430 core\n"
14411                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14412                                                           "\n"
14413                                                           "layout(points)                           in;\n"
14414                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14415                                                           "\n"
14416                                                           "in  vec4 tes_gs[];\n"
14417                                                           "out vec4 gs_fs;\n"
14418                                                           "\n"
14419                                                           "void main()\n"
14420                                                           "{\n"
14421                                                           "    gs_fs = tes_gs[0];\n"
14422                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14423                                                           "    EmitVertex();\n"
14424                                                           "    gs_fs = tes_gs[0];\n"
14425                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14426                                                           "    EmitVertex();\n"
14427                                                           "    gs_fs = tes_gs[0];\n"
14428                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14429                                                           "    EmitVertex();\n"
14430                                                           "    gs_fs = tes_gs[0];\n"
14431                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14432                                                           "    EmitVertex();\n"
14433                                                           "}\n"
14434                                                           "\n";
14435         static const GLchar* gs_tested = "#version 430 core\n"
14436                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14437                                                                          "\n"
14438                                                                          "layout(points)                           in;\n"
14439                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14440                                                                          "\n"
14441                                                                          "VAR_DEFINITION"
14442                                                                          "\n"
14443                                                                          "in  vec4 tes_gs[];\n"
14444                                                                          "out vec4 gs_fs;\n"
14445                                                                          "\n"
14446                                                                          "void main()\n"
14447                                                                          "{\n"
14448                                                                          "    vec4 result = tes_gs[0];\n"
14449                                                                          "\n"
14450                                                                          "VARIABLE_USE"
14451                                                                          "\n"
14452                                                                          "    gs_fs = result;\n"
14453                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14454                                                                          "    EmitVertex();\n"
14455                                                                          "    gs_fs = result;\n"
14456                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14457                                                                          "    EmitVertex();\n"
14458                                                                          "    gs_fs = result;\n"
14459                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14460                                                                          "    EmitVertex();\n"
14461                                                                          "    gs_fs = result;\n"
14462                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14463                                                                          "    EmitVertex();\n"
14464                                                                          "}\n"
14465                                                                          "\n";
14466         static const GLchar* tcs = "#version 430 core\n"
14467                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14468                                                            "\n"
14469                                                            "layout(vertices = 1) out;\n"
14470                                                            "\n"
14471                                                            "in  vec4 vs_tcs[];\n"
14472                                                            "out vec4 tcs_tes[];\n"
14473                                                            "\n"
14474                                                            "void main()\n"
14475                                                            "{\n"
14476                                                            "\n"
14477                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14478                                                            "\n"
14479                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14480                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14481                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14482                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14483                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14484                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14485                                                            "}\n"
14486                                                            "\n";
14487         static const GLchar* tcs_tested = "#version 430 core\n"
14488                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14489                                                                           "\n"
14490                                                                           "layout(vertices = 1) out;\n"
14491                                                                           "\n"
14492                                                                           "VAR_DEFINITION"
14493                                                                           "\n"
14494                                                                           "in  vec4 vs_tcs[];\n"
14495                                                                           "out vec4 tcs_tes[];\n"
14496                                                                           "\n"
14497                                                                           "void main()\n"
14498                                                                           "{\n"
14499                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14500                                                                           "\n"
14501                                                                           "VARIABLE_USE"
14502                                                                           "\n"
14503                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14504                                                                           "\n"
14505                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14506                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14507                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14508                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14509                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14510                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14511                                                                           "}\n"
14512                                                                           "\n";
14513         static const GLchar* tes = "#version 430 core\n"
14514                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14515                                                            "\n"
14516                                                            "layout(isolines, point_mode) in;\n"
14517                                                            "\n"
14518                                                            "in  vec4 tcs_tes[];\n"
14519                                                            "out vec4 tes_gs;\n"
14520                                                            "\n"
14521                                                            "void main()\n"
14522                                                            "{\n"
14523                                                            "    tes_gs = tcs_tes[0];\n"
14524                                                            "}\n"
14525                                                            "\n";
14526         static const GLchar* tes_tested = "#version 430 core\n"
14527                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14528                                                                           "\n"
14529                                                                           "layout(isolines, point_mode) in;\n"
14530                                                                           "\n"
14531                                                                           "VAR_DEFINITION"
14532                                                                           "\n"
14533                                                                           "in  vec4 tcs_tes[];\n"
14534                                                                           "out vec4 tes_gs;\n"
14535                                                                           "\n"
14536                                                                           "void main()\n"
14537                                                                           "{\n"
14538                                                                           "    vec4 result = tcs_tes[0];\n"
14539                                                                           "\n"
14540                                                                           "VARIABLE_USE"
14541                                                                           "\n"
14542                                                                           "    tes_gs += result;\n"
14543                                                                           "}\n"
14544                                                                           "\n";
14545         static const GLchar* vs = "#version 430 core\n"
14546                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14547                                                           "\n"
14548                                                           "in  vec4 in_vs;\n"
14549                                                           "out vec4 vs_tcs;\n"
14550                                                           "\n"
14551                                                           "void main()\n"
14552                                                           "{\n"
14553                                                           "    vs_tcs = in_vs;\n"
14554                                                           "}\n"
14555                                                           "\n";
14556         static const GLchar* vs_tested = "#version 430 core\n"
14557                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14558                                                                          "\n"
14559                                                                          "VAR_DEFINITION"
14560                                                                          "\n"
14561                                                                          "in  vec4 in_vs;\n"
14562                                                                          "out vec4 vs_tcs;\n"
14563                                                                          "\n"
14564                                                                          "void main()\n"
14565                                                                          "{\n"
14566                                                                          "    vec4 result = in_vs;\n"
14567                                                                          "\n"
14568                                                                          "VARIABLE_USE"
14569                                                                          "\n"
14570                                                                          "    vs_tcs += result;\n"
14571                                                                          "}\n"
14572                                                                          "\n";
14573
14574         std::string source;
14575         testCase&   test_case = m_test_cases[test_case_index];
14576
14577         if (test_case.m_stage == stage)
14578         {
14579                 const GLchar*                    array = "";
14580                 GLchar                                   buffer[16];
14581                 const GLchar*                    direction = "in ";
14582                 const GLchar*                    flat     = "";
14583                 const GLchar*                    index   = "";
14584                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14585                 size_t                                   position  = 0;
14586                 size_t                                   temp;
14587                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14588                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14589                 const GLchar*                    var_use   = input_use;
14590
14591                 if (false == test_case.m_is_input)
14592                 {
14593                         direction = "out";
14594                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14595                         storage   = Utils::Variable::VARYING_OUTPUT;
14596                         var_use   = output_use;
14597                 }
14598
14599                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14600                 {
14601                         flat = "flat";
14602                 }
14603
14604                 sprintf(buffer, "%d", last);
14605
14606                 switch (stage)
14607                 {
14608                 case Utils::Shader::FRAGMENT:
14609                         source = fs_tested;
14610                         break;
14611                 case Utils::Shader::GEOMETRY:
14612                         source = gs_tested;
14613                         array  = "[]";
14614                         index  = "[0]";
14615                         break;
14616                 case Utils::Shader::TESS_CTRL:
14617                         source = tcs_tested;
14618                         array  = "[]";
14619                         index  = "[gl_InvocationID]";
14620                         break;
14621                 case Utils::Shader::TESS_EVAL:
14622                         source = tes_tested;
14623                         array  = "[]";
14624                         index  = "[0]";
14625                         break;
14626                 case Utils::Shader::VERTEX:
14627                         source = vs_tested;
14628                         break;
14629                 default:
14630                         TCU_FAIL("Invalid enum");
14631                 }
14632
14633                 temp = position;
14634                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14635                 position = temp;
14636                 Utils::replaceToken("LAST", position, buffer, source);
14637                 Utils::replaceToken("FLAT", position, flat, source);
14638                 Utils::replaceToken("DIRECTION", position, direction, source);
14639                 Utils::replaceToken("ARRAY", position, array, source);
14640                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14641
14642                 Utils::replaceAllTokens("TYPE", type_name, source);
14643                 Utils::replaceAllTokens("INDEX", index, source);
14644         }
14645         else
14646         {
14647                 switch (stage)
14648                 {
14649                 case Utils::Shader::FRAGMENT:
14650                         source = fs;
14651                         break;
14652                 case Utils::Shader::GEOMETRY:
14653                         source = gs;
14654                         break;
14655                 case Utils::Shader::TESS_CTRL:
14656                         source = tcs;
14657                         break;
14658                 case Utils::Shader::TESS_EVAL:
14659                         source = tes;
14660                         break;
14661                 case Utils::Shader::VERTEX:
14662                         source = vs;
14663                         break;
14664                 default:
14665                         TCU_FAIL("Invalid enum");
14666                 }
14667         }
14668
14669         return source;
14670 }
14671
14672 /** Get description of test case
14673  *
14674  * @param test_case_index Index of test case
14675  *
14676  * @return Test case description
14677  **/
14678 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14679 {
14680         std::stringstream stream;
14681         testCase&                 test_case = m_test_cases[test_case_index];
14682
14683         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14684                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14685
14686         if (true == test_case.m_is_input)
14687         {
14688                 stream << "input";
14689         }
14690         else
14691         {
14692                 stream << "output";
14693         }
14694
14695         return stream.str();
14696 }
14697
14698 /** Get number of test cases
14699  *
14700  * @return Number of test cases
14701  **/
14702 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14703 {
14704         return static_cast<GLuint>(m_test_cases.size());
14705 }
14706
14707 /** Selects if "compute" stage is relevant for test
14708  *
14709  * @param ignored
14710  *
14711  * @return false
14712  **/
14713 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14714 {
14715         return false;
14716 }
14717
14718 /** Prepare all test cases
14719  *
14720  **/
14721 void VaryingLocationLimitTest::testInit()
14722 {
14723         const GLuint n_types = getTypesNumber();
14724
14725         for (GLuint i = 0; i < n_types; ++i)
14726         {
14727                 const Utils::Type& type = getType(i);
14728
14729                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14730                 {
14731                         if (Utils::Shader::COMPUTE == stage)
14732                         {
14733                                 continue;
14734                         }
14735
14736                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14737                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14738
14739                         m_test_cases.push_back(test_case_in);
14740
14741                         if (Utils::Shader::FRAGMENT != stage)
14742                         {
14743                                 m_test_cases.push_back(test_case_out);
14744                         }
14745                 }
14746         }
14747 }
14748
14749 /** Constructor
14750  *
14751  * @param context Test framework context
14752  **/
14753 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14754         : VaryingLocationsTest(context, "varying_components",
14755                                                    "Test verifies that input and output components are respected")
14756 {
14757 }
14758
14759 /** Constructor
14760  *
14761  * @param context          Test framework context
14762  * @param test_name        Name of test
14763  * @param test_description Description of test
14764  **/
14765 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14766                                                                                          const glw::GLchar* test_description)
14767         : VaryingLocationsTest(context, test_name, test_description)
14768 {
14769 }
14770
14771 /** Get interface of program
14772  *
14773  * @param test_case_index     Test case
14774  * @param program_interface   Interface of program
14775  * @param varying_passthrough Collection of connections between in and out variables
14776  **/
14777 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14778                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14779 {
14780         GLuint                             array_length = getArrayLength();
14781         const testCase&            test_case    = m_test_cases[test_case_index];
14782         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14783         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14784
14785         /* Zero means no array, however we still need at least 1 slot of data */
14786         if (0 == array_length)
14787         {
14788                 array_length += 1;
14789         }
14790
14791         /* Generate data */
14792         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14793         const size_t                            data_size = data.size();
14794
14795         /* Prepare data for variables */
14796         m_data.resize(array_length * data_size);
14797
14798         GLubyte*           dst = &m_data[0];
14799         const GLubyte* src = &data[0];
14800
14801         for (GLuint i = 0; i < array_length; ++i)
14802         {
14803                 memcpy(dst + data_size * i, src, data_size);
14804         }
14805
14806         /* Prepare interface for each stage */
14807         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14808         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14809         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14810         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14811         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14812 }
14813
14814 /** Get type name
14815  *
14816  * @param test_case_index Index of test case
14817  *
14818  * @return Name of type test in test_case_index
14819  **/
14820 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14821 {
14822         std::string name;
14823
14824         const testCase& test_case = m_test_cases[test_case_index];
14825
14826         name = "Type: ";
14827
14828         switch (test_case.m_type)
14829         {
14830         case Utils::Type::Double:
14831                 name.append(Utils::Type::_double.GetGLSLTypeName());
14832                 break;
14833         case Utils::Type::Float:
14834                 name.append(Utils::Type::_float.GetGLSLTypeName());
14835                 break;
14836         case Utils::Type::Int:
14837                 name.append(Utils::Type::_int.GetGLSLTypeName());
14838                 break;
14839         case Utils::Type::Uint:
14840                 name.append(Utils::Type::uint.GetGLSLTypeName());
14841                 break;
14842         }
14843
14844         name.append(", layout: ");
14845
14846         switch (test_case.m_layout)
14847         {
14848         case GVEC4:
14849                 name.append("GVEC4");
14850                 break;
14851         case SCALAR_GVEC3:
14852                 name.append("SCALAR_GVEC3");
14853                 break;
14854         case GVEC3_SCALAR:
14855                 name.append("GVEC3_SCALAR");
14856                 break;
14857         case GVEC2_GVEC2:
14858                 name.append("GVEC2_GVEC2");
14859                 break;
14860         case GVEC2_SCALAR_SCALAR:
14861                 name.append("GVEC2_SCALAR_SCALAR");
14862                 break;
14863         case SCALAR_GVEC2_SCALAR:
14864                 name.append("SCALAR_GVEC2_SCALAR");
14865                 break;
14866         case SCALAR_SCALAR_GVEC2:
14867                 name.append("SCALAR_SCALAR_GVEC2");
14868                 break;
14869         case SCALAR_SCALAR_SCALAR_SCALAR:
14870                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14871                 break;
14872         }
14873
14874         return name;
14875 }
14876
14877 /** Returns number of types to test
14878  *
14879  * @return Number of types, 34
14880  **/
14881 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14882 {
14883         return static_cast<GLuint>(m_test_cases.size());
14884 }
14885
14886 /* Prepare test cases */
14887 void VaryingComponentsTest::testInit()
14888 {
14889         // FIXME: add tests for doubles, which have specific rules
14890
14891         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14892         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14893         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14894         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14895         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14896         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14897         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14898         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14899
14900         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14901         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14902         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14903         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14904         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14905         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14906         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14907         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14908
14909         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14910         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14911         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14912         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14913         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14914         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14915         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14916         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14917 }
14918
14919 /** Inform that test use components
14920  *
14921  * @param ignored
14922  *
14923  * @return true
14924  **/
14925 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14926 {
14927         return true;
14928 }
14929
14930 /** Get length of arrays that should be used during test
14931  *
14932  * @return 0u - no array at all
14933  **/
14934 GLuint VaryingComponentsTest::getArrayLength()
14935 {
14936         return 0;
14937 }
14938
14939 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14940 {
14941         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14942
14943         globals.append("const uint comp_x = 0u;\n"
14944                                    "const uint comp_y = 1u;\n"
14945                                    "const uint comp_z = 2u;\n"
14946                                    "const uint comp_w = 3u;\n");
14947
14948         return globals;
14949 }
14950
14951 /**
14952  *
14953  **/
14954 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14955                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14956 {
14957         GLchar            buffer[16];
14958         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14959         size_t            position = 0;
14960         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14961
14962         Utils::replaceToken("PREFIX", position, prefix, result);
14963         Utils::replaceToken("NAME", position, name, result);
14964
14965         sprintf(buffer, "%d", location);
14966         Utils::replaceToken("LOCATION", position, buffer, result);
14967
14968         sprintf(buffer, "%d", component);
14969         Utils::replaceToken("COMPONENT", position, buffer, result);
14970
14971         return result;
14972 }
14973
14974 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14975                                                                                                          const glw::GLchar* interpolation)
14976 {
14977         size_t          position   = 0;
14978         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14979
14980         Utils::replaceToken("LOCATION", position, location, qualifiers);
14981         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14982         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14983
14984         return qualifiers;
14985 }
14986
14987 /**
14988  *
14989  **/
14990 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14991                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14992                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14993 {
14994         const GLuint                    array_length = getArrayLength();
14995         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14996         descriptor                              desc_in[8];
14997         descriptor                              desc_out[8];
14998         const GLuint                    first_in_loc  = 0;
14999         const GLuint                    first_out_loc = 0;
15000         const GLchar*                   interpolation = "";
15001         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
15002         GLuint                                  last_out_loc  = 0;
15003         GLuint                                  n_desc            = 0;
15004         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
15005
15006         /* Select interpolation */
15007         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
15008         {
15009                 interpolation = " flat";
15010         }
15011
15012         if (Utils::Shader::FRAGMENT != stage)
15013         {
15014                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
15015         }
15016
15017         switch (test_case.m_layout)
15018         {
15019         case GVEC4:
15020                 n_desc = 2;
15021                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
15022                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
15023
15024                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
15025                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
15026                 break;
15027         case SCALAR_GVEC3:
15028                 n_desc = 4;
15029                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15030                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15031                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
15032                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
15033
15034                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15035                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15036                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
15037                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
15038                 break;
15039         case GVEC3_SCALAR:
15040                 n_desc = 4;
15041                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
15042                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
15043                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15044                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15045
15046                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
15047                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
15048                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15049                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15050                 break;
15051         case GVEC2_GVEC2:
15052                 n_desc = 4;
15053                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
15054                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
15055                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
15056                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
15057
15058                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
15059                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
15060                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15061                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15062                 break;
15063         case GVEC2_SCALAR_SCALAR:
15064                 n_desc = 6;
15065                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
15066                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
15067                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15068                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15069                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15070                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15071
15072                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
15073                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
15074                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15075                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15076                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15077                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15078                 break;
15079         case SCALAR_GVEC2_SCALAR:
15080                 n_desc = 6;
15081                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15082                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15083                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
15084                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
15085                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15086                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15087
15088                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15089                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15090                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
15091                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
15092                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15093                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15094                 break;
15095         case SCALAR_SCALAR_GVEC2:
15096                 n_desc = 6;
15097                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15098                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15099                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15100                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15101                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
15102                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
15103
15104                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15105                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15106                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15107                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15108                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15109                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15110                 break;
15111         case SCALAR_SCALAR_SCALAR_SCALAR:
15112                 n_desc = 8;
15113                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15114                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15115                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15116                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15117                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15118                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15119                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15120                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15121
15122                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15123                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15124                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15125                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15126                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15127                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15128                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15129                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15130                 break;
15131         }
15132
15133         for (GLuint i = 0; i < n_desc; ++i)
15134         {
15135                 const descriptor& in_desc = desc_in[i];
15136
15137                 Utils::Variable* in =
15138                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15139
15140                 if (Utils::Shader::FRAGMENT != stage)
15141                 {
15142                         const descriptor& out_desc = desc_out[i];
15143
15144                         Utils::Variable* out =
15145                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15146
15147                         varying_passthrough.Add(stage, in, out);
15148                 }
15149         }
15150
15151         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15152 }
15153
15154 /**
15155  *
15156  **/
15157 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15158                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15159                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15160 {
15161         const GLuint       array_length   = getArrayLength();
15162         const GLuint       component_size = basic_type.GetSize();
15163         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15164         const GLuint       offset                 = desc.m_component * component_size;
15165         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15166         const GLuint       size                   = desc.m_n_rows * component_size;
15167         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15168         Utils::Variable*   var                    = 0;
15169
15170         if (Utils::Variable::VARYING_INPUT == storage)
15171         {
15172                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15173                                            desc.m_location /* expected_location */, type, /* built_in_type */
15174                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15175                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15176         }
15177         else
15178         {
15179                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15180                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15181                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15182                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15183         }
15184
15185         return var;
15186 }
15187
15188 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15189                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15190                                                                                            const glw::GLchar* name)
15191 {
15192         m_component             = component;
15193         m_component_str = component_str;
15194         m_location              = location;
15195         m_location_str  = location_str;
15196         m_n_rows                = n_rows;
15197         m_name                  = name;
15198 }
15199
15200 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15201         : m_layout(layout), m_type(type)
15202 {
15203 }
15204
15205 /** Constructor
15206  *
15207  * @param context Test framework context
15208  **/
15209 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15210         : VaryingComponentsTest(context, "varying_array_components",
15211                                                         "Test verifies that input and output components are respected for arrays")
15212 {
15213 }
15214
15215 /** Get length of arrays that should be used during test
15216  *
15217  * @return 4u
15218  **/
15219 GLuint VaryingArrayComponentsTest::getArrayLength()
15220 {
15221         return 4u;
15222 }
15223
15224 /** Constructor
15225  *
15226  * @param context Test framework context
15227  **/
15228 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15229         : NegativeTestBase(context, "varying_exceeding_components",
15230                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15231 {
15232 }
15233
15234 /** Source for given test case and stage
15235  *
15236  * @param test_case_index Index of test case
15237  * @param stage           Shader stage
15238  *
15239  * @return Shader source
15240  **/
15241 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15242 {
15243         static const GLchar* var_definition_arr =
15244                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15245         static const GLchar* var_definition_one =
15246                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15247         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15248                                                                                  "    {\n"
15249                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15250                                                                                  "    }\n";
15251         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15252                                                                                  "    {\n"
15253                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15254                                                                                  "    }\n";
15255         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15256                                                                                   "    if (vec4(0) == result)\n"
15257                                                                                   "    {\n"
15258                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15259                                                                                   "    }\n";
15260         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15261                                                                                   "    if (vec4(0) == result)\n"
15262                                                                                   "    {\n"
15263                                                                                   "        gokuINDEX = TYPE(1);\n"
15264                                                                                   "    }\n";
15265         static const GLchar* fs = "#version 430 core\n"
15266                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15267                                                           "\n"
15268                                                           "in  vec4 gs_fs;\n"
15269                                                           "out vec4 fs_out;\n"
15270                                                           "\n"
15271                                                           "void main()\n"
15272                                                           "{\n"
15273                                                           "    fs_out = gs_fs;\n"
15274                                                           "}\n"
15275                                                           "\n";
15276         static const GLchar* fs_tested = "#version 430 core\n"
15277                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15278                                                                          "\n"
15279                                                                          "VAR_DEFINITION"
15280                                                                          "\n"
15281                                                                          "in  vec4 gs_fs;\n"
15282                                                                          "out vec4 fs_out;\n"
15283                                                                          "\n"
15284                                                                          "void main()\n"
15285                                                                          "{\n"
15286                                                                          "    vec4 result = gs_fs;\n"
15287                                                                          "\n"
15288                                                                          "VARIABLE_USE"
15289                                                                          "\n"
15290                                                                          "    fs_out += result;\n"
15291                                                                          "}\n"
15292                                                                          "\n";
15293         static const GLchar* gs = "#version 430 core\n"
15294                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15295                                                           "\n"
15296                                                           "layout(points)                           in;\n"
15297                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15298                                                           "\n"
15299                                                           "in  vec4 tes_gs[];\n"
15300                                                           "out vec4 gs_fs;\n"
15301                                                           "\n"
15302                                                           "void main()\n"
15303                                                           "{\n"
15304                                                           "    gs_fs = tes_gs[0];\n"
15305                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15306                                                           "    EmitVertex();\n"
15307                                                           "    gs_fs = tes_gs[0];\n"
15308                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15309                                                           "    EmitVertex();\n"
15310                                                           "    gs_fs = tes_gs[0];\n"
15311                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15312                                                           "    EmitVertex();\n"
15313                                                           "    gs_fs = tes_gs[0];\n"
15314                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15315                                                           "    EmitVertex();\n"
15316                                                           "}\n"
15317                                                           "\n";
15318         static const GLchar* gs_tested = "#version 430 core\n"
15319                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15320                                                                          "\n"
15321                                                                          "layout(points)                           in;\n"
15322                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15323                                                                          "\n"
15324                                                                          "VAR_DEFINITION"
15325                                                                          "\n"
15326                                                                          "in  vec4 tes_gs[];\n"
15327                                                                          "out vec4 gs_fs;\n"
15328                                                                          "\n"
15329                                                                          "void main()\n"
15330                                                                          "{\n"
15331                                                                          "    vec4 result = tes_gs[0];\n"
15332                                                                          "\n"
15333                                                                          "VARIABLE_USE"
15334                                                                          "\n"
15335                                                                          "    gs_fs = result;\n"
15336                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15337                                                                          "    EmitVertex();\n"
15338                                                                          "    gs_fs = result;\n"
15339                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15340                                                                          "    EmitVertex();\n"
15341                                                                          "    gs_fs = result;\n"
15342                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15343                                                                          "    EmitVertex();\n"
15344                                                                          "    gs_fs = result;\n"
15345                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15346                                                                          "    EmitVertex();\n"
15347                                                                          "}\n"
15348                                                                          "\n";
15349         static const GLchar* tcs = "#version 430 core\n"
15350                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15351                                                            "\n"
15352                                                            "layout(vertices = 1) out;\n"
15353                                                            "\n"
15354                                                            "in  vec4 vs_tcs[];\n"
15355                                                            "out vec4 tcs_tes[];\n"
15356                                                            "\n"
15357                                                            "void main()\n"
15358                                                            "{\n"
15359                                                            "\n"
15360                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15361                                                            "\n"
15362                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15363                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15364                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15365                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15366                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15367                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15368                                                            "}\n"
15369                                                            "\n";
15370         static const GLchar* tcs_tested = "#version 430 core\n"
15371                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15372                                                                           "\n"
15373                                                                           "layout(vertices = 1) out;\n"
15374                                                                           "\n"
15375                                                                           "VAR_DEFINITION"
15376                                                                           "\n"
15377                                                                           "in  vec4 vs_tcs[];\n"
15378                                                                           "out vec4 tcs_tes[];\n"
15379                                                                           "\n"
15380                                                                           "void main()\n"
15381                                                                           "{\n"
15382                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15383                                                                           "\n"
15384                                                                           "VARIABLE_USE"
15385                                                                           "\n"
15386                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15387                                                                           "\n"
15388                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15389                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15390                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15391                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15392                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15393                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15394                                                                           "}\n"
15395                                                                           "\n";
15396         static const GLchar* tes = "#version 430 core\n"
15397                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15398                                                            "\n"
15399                                                            "layout(isolines, point_mode) in;\n"
15400                                                            "\n"
15401                                                            "in  vec4 tcs_tes[];\n"
15402                                                            "out vec4 tes_gs;\n"
15403                                                            "\n"
15404                                                            "void main()\n"
15405                                                            "{\n"
15406                                                            "    tes_gs = tcs_tes[0];\n"
15407                                                            "}\n"
15408                                                            "\n";
15409         static const GLchar* tes_tested = "#version 430 core\n"
15410                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15411                                                                           "\n"
15412                                                                           "layout(isolines, point_mode) in;\n"
15413                                                                           "\n"
15414                                                                           "VAR_DEFINITION"
15415                                                                           "\n"
15416                                                                           "in  vec4 tcs_tes[];\n"
15417                                                                           "out vec4 tes_gs;\n"
15418                                                                           "\n"
15419                                                                           "void main()\n"
15420                                                                           "{\n"
15421                                                                           "    vec4 result = tcs_tes[0];\n"
15422                                                                           "\n"
15423                                                                           "VARIABLE_USE"
15424                                                                           "\n"
15425                                                                           "    tes_gs += result;\n"
15426                                                                           "}\n"
15427                                                                           "\n";
15428         static const GLchar* vs = "#version 430 core\n"
15429                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15430                                                           "\n"
15431                                                           "in  vec4 in_vs;\n"
15432                                                           "out vec4 vs_tcs;\n"
15433                                                           "\n"
15434                                                           "void main()\n"
15435                                                           "{\n"
15436                                                           "    vs_tcs = in_vs;\n"
15437                                                           "}\n"
15438                                                           "\n";
15439         static const GLchar* vs_tested = "#version 430 core\n"
15440                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15441                                                                          "\n"
15442                                                                          "VAR_DEFINITION"
15443                                                                          "\n"
15444                                                                          "in  vec4 in_vs;\n"
15445                                                                          "out vec4 vs_tcs;\n"
15446                                                                          "\n"
15447                                                                          "void main()\n"
15448                                                                          "{\n"
15449                                                                          "    vec4 result = in_vs;\n"
15450                                                                          "\n"
15451                                                                          "VARIABLE_USE"
15452                                                                          "\n"
15453                                                                          "    vs_tcs += result;\n"
15454                                                                          "}\n"
15455                                                                          "\n";
15456
15457         std::string source;
15458         testCase&   test_case = m_test_cases[test_case_index];
15459
15460         if (test_case.m_stage == stage)
15461         {
15462                 const GLchar* array = "";
15463                 GLchar            buffer[16];
15464                 const GLchar* var_definition = 0;
15465                 const GLchar* direction          = "in ";
15466                 const GLchar* index                      = "";
15467                 size_t            position               = 0;
15468                 size_t            temp;
15469                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15470                 const GLchar* var_use   = 0;
15471
15472                 if (false == test_case.m_is_input)
15473                 {
15474                         direction = "out";
15475
15476                         if (false == test_case.m_is_array)
15477                         {
15478                                 var_definition = var_definition_one;
15479                                 var_use            = output_use_one;
15480                         }
15481                         else
15482                         {
15483                                 var_definition = var_definition_arr;
15484                                 var_use            = output_use_arr;
15485                         }
15486                 }
15487                 else
15488                 {
15489                         if (false == test_case.m_is_array)
15490                         {
15491                                 var_definition = var_definition_one;
15492                                 var_use            = input_use_one;
15493                         }
15494                         else
15495                         {
15496                                 var_definition = var_definition_arr;
15497                                 var_use            = input_use_arr;
15498                         }
15499                 }
15500
15501                 sprintf(buffer, "%d", test_case.m_component);
15502
15503                 switch (stage)
15504                 {
15505                 case Utils::Shader::FRAGMENT:
15506                         source = fs_tested;
15507                         break;
15508                 case Utils::Shader::GEOMETRY:
15509                         source = gs_tested;
15510                         array  = "[]";
15511                         index  = "[0]";
15512                         break;
15513                 case Utils::Shader::TESS_CTRL:
15514                         source = tcs_tested;
15515                         array  = "[]";
15516                         index  = "[gl_InvocationID]";
15517                         break;
15518                 case Utils::Shader::TESS_EVAL:
15519                         source = tes_tested;
15520                         array  = "[]";
15521                         index  = "[0]";
15522                         break;
15523                 case Utils::Shader::VERTEX:
15524                         source = vs_tested;
15525                         break;
15526                 default:
15527                         TCU_FAIL("Invalid enum");
15528                 }
15529
15530                 temp = position;
15531                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15532                 position = temp;
15533                 Utils::replaceToken("COMPONENT", position, buffer, source);
15534                 Utils::replaceToken("DIRECTION", position, direction, source);
15535                 Utils::replaceToken("ARRAY", position, array, source);
15536                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15537
15538                 Utils::replaceAllTokens("TYPE", type_name, source);
15539                 Utils::replaceAllTokens("INDEX", index, source);
15540         }
15541         else
15542         {
15543                 switch (stage)
15544                 {
15545                 case Utils::Shader::FRAGMENT:
15546                         source = fs;
15547                         break;
15548                 case Utils::Shader::GEOMETRY:
15549                         source = gs;
15550                         break;
15551                 case Utils::Shader::TESS_CTRL:
15552                         source = tcs;
15553                         break;
15554                 case Utils::Shader::TESS_EVAL:
15555                         source = tes;
15556                         break;
15557                 case Utils::Shader::VERTEX:
15558                         source = vs;
15559                         break;
15560                 default:
15561                         TCU_FAIL("Invalid enum");
15562                 }
15563         }
15564
15565         return source;
15566 }
15567
15568 /** Get description of test case
15569  *
15570  * @param test_case_index Index of test case
15571  *
15572  * @return Test case description
15573  **/
15574 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15575 {
15576         std::stringstream stream;
15577         testCase&                 test_case = m_test_cases[test_case_index];
15578
15579         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15580                    << " type: " << test_case.m_type.GetGLSLTypeName();
15581
15582         if (true == test_case.m_is_array)
15583         {
15584                 stream << "[1]";
15585         }
15586
15587         stream << ", direction: ";
15588
15589         if (true == test_case.m_is_input)
15590         {
15591                 stream << "input";
15592         }
15593         else
15594         {
15595                 stream << "output";
15596         }
15597
15598         stream << ", component: " << test_case.m_component;
15599
15600         return stream.str();
15601 }
15602
15603 /** Get number of test cases
15604  *
15605  * @return Number of test cases
15606  **/
15607 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15608 {
15609         return static_cast<GLuint>(m_test_cases.size());
15610 }
15611
15612 /** Selects if "compute" stage is relevant for test
15613  *
15614  * @param ignored
15615  *
15616  * @return false
15617  **/
15618 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15619 {
15620         return false;
15621 }
15622
15623 /** Prepare all test cases
15624  *
15625  **/
15626 void VaryingExceedingComponentsTest::testInit()
15627 {
15628         static const GLuint n_components_per_location = 4;
15629         const GLuint            n_types                                   = getTypesNumber();
15630
15631         for (GLuint i = 0; i < n_types; ++i)
15632         {
15633                 const Utils::Type& type                          = getType(i);
15634                 const GLuint       n_req_components  = type.m_n_rows;
15635                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15636                 const GLuint       invalid_component = valid_component + 1;
15637
15638                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15639                 {
15640                         if (Utils::Shader::COMPUTE == stage)
15641                         {
15642                                 continue;
15643                         }
15644
15645                         /* Component cannot be used for matrices */
15646                         if (1 != type.m_n_columns)
15647                         {
15648                                 continue;
15649                         }
15650
15651                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15652                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15653                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15654                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15655
15656                         m_test_cases.push_back(test_case_in_arr);
15657                         m_test_cases.push_back(test_case_in_one);
15658
15659                         if (Utils::Shader::FRAGMENT != stage)
15660                         {
15661                                 m_test_cases.push_back(test_case_out_arr);
15662                                 m_test_cases.push_back(test_case_out_one);
15663                         }
15664                 }
15665         }
15666 }
15667
15668 /** Constructor
15669  *
15670  * @param context Test framework context
15671  **/
15672 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15673         : NegativeTestBase(context, "varying_component_without_location",
15674                                            "Test verifies that compiler reports error when component qualifier is used without location")
15675 {
15676 }
15677
15678 /** Source for given test case and stage
15679  *
15680  * @param test_case_index Index of test case
15681  * @param stage           Shader stage
15682  *
15683  * @return Shader source
15684  **/
15685 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15686 {
15687         static const GLchar* var_definition = "layout (component = COMPONENT) FLAT DIRECTION TYPE gokuARRAY;\n";
15688         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15689                                                                          "    {\n"
15690                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15691                                                                          "    }\n";
15692         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15693                                                                           "    if (vec4(0) == result)\n"
15694                                                                           "    {\n"
15695                                                                           "        gokuINDEX = TYPE(1);\n"
15696                                                                           "    }\n";
15697         static const GLchar* fs = "#version 430 core\n"
15698                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15699                                                           "\n"
15700                                                           "in  vec4 gs_fs;\n"
15701                                                           "out vec4 fs_out;\n"
15702                                                           "\n"
15703                                                           "void main()\n"
15704                                                           "{\n"
15705                                                           "    fs_out = gs_fs;\n"
15706                                                           "}\n"
15707                                                           "\n";
15708         static const GLchar* fs_tested = "#version 430 core\n"
15709                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15710                                                                          "\n"
15711                                                                          "VAR_DEFINITION"
15712                                                                          "\n"
15713                                                                          "in  vec4 gs_fs;\n"
15714                                                                          "out vec4 fs_out;\n"
15715                                                                          "\n"
15716                                                                          "void main()\n"
15717                                                                          "{\n"
15718                                                                          "    vec4 result = gs_fs;\n"
15719                                                                          "\n"
15720                                                                          "VARIABLE_USE"
15721                                                                          "\n"
15722                                                                          "    fs_out = result;\n"
15723                                                                          "}\n"
15724                                                                          "\n";
15725         static const GLchar* gs = "#version 430 core\n"
15726                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15727                                                           "\n"
15728                                                           "layout(points)                           in;\n"
15729                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15730                                                           "\n"
15731                                                           "in  vec4 tes_gs[];\n"
15732                                                           "out vec4 gs_fs;\n"
15733                                                           "\n"
15734                                                           "void main()\n"
15735                                                           "{\n"
15736                                                           "    gs_fs = tes_gs[0];\n"
15737                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15738                                                           "    EmitVertex();\n"
15739                                                           "    gs_fs = tes_gs[0];\n"
15740                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15741                                                           "    EmitVertex();\n"
15742                                                           "    gs_fs = tes_gs[0];\n"
15743                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15744                                                           "    EmitVertex();\n"
15745                                                           "    gs_fs = tes_gs[0];\n"
15746                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15747                                                           "    EmitVertex();\n"
15748                                                           "}\n"
15749                                                           "\n";
15750         static const GLchar* gs_tested = "#version 430 core\n"
15751                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15752                                                                          "\n"
15753                                                                          "layout(points)                           in;\n"
15754                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15755                                                                          "\n"
15756                                                                          "VAR_DEFINITION"
15757                                                                          "\n"
15758                                                                          "in  vec4 tes_gs[];\n"
15759                                                                          "out vec4 gs_fs;\n"
15760                                                                          "\n"
15761                                                                          "void main()\n"
15762                                                                          "{\n"
15763                                                                          "    vec4 result = tes_gs[0];\n"
15764                                                                          "\n"
15765                                                                          "VARIABLE_USE"
15766                                                                          "\n"
15767                                                                          "    gs_fs = result;\n"
15768                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15769                                                                          "    EmitVertex();\n"
15770                                                                          "    gs_fs = result;\n"
15771                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15772                                                                          "    EmitVertex();\n"
15773                                                                          "    gs_fs = result;\n"
15774                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15775                                                                          "    EmitVertex();\n"
15776                                                                          "    gs_fs = result;\n"
15777                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15778                                                                          "    EmitVertex();\n"
15779                                                                          "}\n"
15780                                                                          "\n";
15781         static const GLchar* tcs = "#version 430 core\n"
15782                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15783                                                            "\n"
15784                                                            "layout(vertices = 1) out;\n"
15785                                                            "\n"
15786                                                            "in  vec4 vs_tcs[];\n"
15787                                                            "out vec4 tcs_tes[];\n"
15788                                                            "\n"
15789                                                            "void main()\n"
15790                                                            "{\n"
15791                                                            "\n"
15792                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15793                                                            "\n"
15794                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15795                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15796                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15797                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15798                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15799                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15800                                                            "}\n"
15801                                                            "\n";
15802         static const GLchar* tcs_tested = "#version 430 core\n"
15803                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15804                                                                           "\n"
15805                                                                           "layout(vertices = 1) out;\n"
15806                                                                           "\n"
15807                                                                           "VAR_DEFINITION"
15808                                                                           "\n"
15809                                                                           "in  vec4 vs_tcs[];\n"
15810                                                                           "out vec4 tcs_tes[];\n"
15811                                                                           "\n"
15812                                                                           "void main()\n"
15813                                                                           "{\n"
15814                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15815                                                                           "\n"
15816                                                                           "VARIABLE_USE"
15817                                                                           "\n"
15818                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15819                                                                           "\n"
15820                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15821                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15822                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15823                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15824                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15825                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15826                                                                           "}\n"
15827                                                                           "\n";
15828         static const GLchar* tes = "#version 430 core\n"
15829                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15830                                                            "\n"
15831                                                            "layout(isolines, point_mode) in;\n"
15832                                                            "\n"
15833                                                            "in  vec4 tcs_tes[];\n"
15834                                                            "out vec4 tes_gs;\n"
15835                                                            "\n"
15836                                                            "void main()\n"
15837                                                            "{\n"
15838                                                            "    tes_gs = tcs_tes[0];\n"
15839                                                            "}\n"
15840                                                            "\n";
15841         static const GLchar* tes_tested = "#version 430 core\n"
15842                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15843                                                                           "\n"
15844                                                                           "layout(isolines, point_mode) in;\n"
15845                                                                           "\n"
15846                                                                           "VAR_DEFINITION"
15847                                                                           "\n"
15848                                                                           "in  vec4 tcs_tes[];\n"
15849                                                                           "out vec4 tes_gs;\n"
15850                                                                           "\n"
15851                                                                           "void main()\n"
15852                                                                           "{\n"
15853                                                                           "    vec4 result = tcs_tes[0];\n"
15854                                                                           "\n"
15855                                                                           "VARIABLE_USE"
15856                                                                           "\n"
15857                                                                           "    tes_gs = result;\n"
15858                                                                           "}\n"
15859                                                                           "\n";
15860         static const GLchar* vs = "#version 430 core\n"
15861                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15862                                                           "\n"
15863                                                           "in  vec4 in_vs;\n"
15864                                                           "out vec4 vs_tcs;\n"
15865                                                           "\n"
15866                                                           "void main()\n"
15867                                                           "{\n"
15868                                                           "    vs_tcs = in_vs;\n"
15869                                                           "}\n"
15870                                                           "\n";
15871         static const GLchar* vs_tested = "#version 430 core\n"
15872                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15873                                                                          "\n"
15874                                                                          "VAR_DEFINITION"
15875                                                                          "\n"
15876                                                                          "in  vec4 in_vs;\n"
15877                                                                          "out vec4 vs_tcs;\n"
15878                                                                          "\n"
15879                                                                          "void main()\n"
15880                                                                          "{\n"
15881                                                                          "    vec4 result = in_vs;\n"
15882                                                                          "\n"
15883                                                                          "VARIABLE_USE"
15884                                                                          "\n"
15885                                                                          "    vs_tcs = result;\n"
15886                                                                          "}\n"
15887                                                                          "\n";
15888
15889         std::string source;
15890         testCase&   test_case = m_test_cases[test_case_index];
15891
15892         if (test_case.m_stage == stage)
15893         {
15894                 const GLchar* array = "";
15895                 GLchar            buffer[16];
15896                 const GLchar* direction = "in ";
15897                 const GLchar* index             = "";
15898                 size_t            position  = 0;
15899                 size_t            temp;
15900                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15901                 const GLchar* var_use   = input_use;
15902                 const GLchar* flat              = "flat";
15903
15904                 if (false == test_case.m_is_input)
15905                 {
15906                         direction = "out";
15907                         var_use   = output_use;
15908                 }
15909
15910                 sprintf(buffer, "%d", test_case.m_component);
15911
15912                 switch (stage)
15913                 {
15914                 case Utils::Shader::FRAGMENT:
15915                         source = fs_tested;
15916                         break;
15917                 case Utils::Shader::GEOMETRY:
15918                         source = gs_tested;
15919                         array  = "[]";
15920                         index  = "[0]";
15921                         break;
15922                 case Utils::Shader::TESS_CTRL:
15923                         source = tcs_tested;
15924                         array  = "[]";
15925                         index  = "[gl_InvocationID]";
15926                         break;
15927                 case Utils::Shader::TESS_EVAL:
15928                         source = tes_tested;
15929                         array  = "[]";
15930                         index  = "[0]";
15931                         break;
15932                 case Utils::Shader::VERTEX:
15933                         source = vs_tested;
15934                         flat   = "";
15935                         break;
15936                 default:
15937                         TCU_FAIL("Invalid enum");
15938                 }
15939
15940                 temp = position;
15941                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15942                 position = temp;
15943                 Utils::replaceToken("COMPONENT", position, buffer, source);
15944                 Utils::replaceToken("FLAT", position, flat, source);
15945                 Utils::replaceToken("DIRECTION", position, direction, source);
15946                 Utils::replaceToken("ARRAY", position, array, source);
15947                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15948
15949                 Utils::replaceAllTokens("TYPE", type_name, source);
15950                 Utils::replaceAllTokens("INDEX", index, source);
15951         }
15952         else
15953         {
15954                 switch (stage)
15955                 {
15956                 case Utils::Shader::FRAGMENT:
15957                         source = fs;
15958                         break;
15959                 case Utils::Shader::GEOMETRY:
15960                         source = gs;
15961                         break;
15962                 case Utils::Shader::TESS_CTRL:
15963                         source = tcs;
15964                         break;
15965                 case Utils::Shader::TESS_EVAL:
15966                         source = tes;
15967                         break;
15968                 case Utils::Shader::VERTEX:
15969                         source = vs;
15970                         break;
15971                 default:
15972                         TCU_FAIL("Invalid enum");
15973                 }
15974         }
15975
15976         return source;
15977 }
15978
15979 /** Get description of test case
15980  *
15981  * @param test_case_index Index of test case
15982  *
15983  * @return Test case description
15984  **/
15985 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15986 {
15987         std::stringstream stream;
15988         testCase&                 test_case = m_test_cases[test_case_index];
15989
15990         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15991                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15992
15993         if (true == test_case.m_is_input)
15994         {
15995                 stream << "input";
15996         }
15997         else
15998         {
15999                 stream << "output";
16000         }
16001
16002         stream << ", component: " << test_case.m_component;
16003
16004         return stream.str();
16005 }
16006
16007 /** Get number of test cases
16008  *
16009  * @return Number of test cases
16010  **/
16011 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
16012 {
16013         return static_cast<GLuint>(m_test_cases.size());
16014 }
16015
16016 /** Selects if "compute" stage is relevant for test
16017  *
16018  * @param ignored
16019  *
16020  * @return false
16021  **/
16022 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
16023 {
16024         return false;
16025 }
16026
16027 /** Prepare all test cases
16028  *
16029  **/
16030 void VaryingComponentWithoutLocationTest::testInit()
16031 {
16032         static const GLuint n_components_per_location = 4;
16033         const GLuint            n_types                                   = getTypesNumber();
16034
16035         for (GLuint i = 0; i < n_types; ++i)
16036         {
16037                 const Utils::Type& type                         = getType(i);
16038                 const GLuint       n_req_components = type.m_n_rows;
16039                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16040
16041                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16042                 {
16043                         if (Utils::Shader::COMPUTE == stage)
16044                         {
16045                                 continue;
16046                         }
16047
16048                         /* Component cannot be used for matrices */
16049                         if (1 != type.m_n_columns)
16050                         {
16051                                 continue;
16052                         }
16053
16054                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
16055                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
16056
16057                         m_test_cases.push_back(test_case_in);
16058
16059                         if (Utils::Shader::FRAGMENT != stage)
16060                         {
16061                                 m_test_cases.push_back(test_case_out);
16062                         }
16063                 }
16064         }
16065 }
16066
16067 /** Constructor
16068  *
16069  * @param context Test framework context
16070  **/
16071 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
16072         : NegativeTestBase(context, "varying_component_of_invalid_type",
16073                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
16074 {
16075 }
16076
16077 /** Source for given test case and stage
16078  *
16079  * @param test_case_index Index of test case
16080  * @param stage           Shader stage
16081  *
16082  * @return Shader source
16083  **/
16084 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16085 {
16086         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
16087                                                                                                 "    TYPE member;\n"
16088                                                                                                 "} gokuARRAY[1];\n";
16089         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
16090                                                                                                 "    TYPE member;\n"
16091                                                                                                 "} gokuARRAY;\n";
16092         static const GLchar* matrix_definition_arr =
16093                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
16094         static const GLchar* matrix_definition_one =
16095                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
16096         static const GLchar* struct_definition_arr =
16097                 "struct Goku {\n"
16098                 "    TYPE member;\n"
16099                 "};\n"
16100                 "\n"
16101                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
16102         static const GLchar* struct_definition_one =
16103                 "struct Goku {\n"
16104                 "    TYPE member;\n"
16105                 "};\n"
16106                 "\n"
16107                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
16108         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
16109                                                                                                 "    {\n"
16110                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16111                                                                                                 "    }\n";
16112         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
16113                                                                                                 "    {\n"
16114                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16115                                                                                                 "    }\n";
16116         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
16117                                                                                                  "    if (vec4(0) == result)\n"
16118                                                                                                  "    {\n"
16119                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
16120                                                                                                  "    }\n";
16121         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16122                                                                                                  "    if (vec4(0) == result)\n"
16123                                                                                                  "    {\n"
16124                                                                                                  "        gokuINDEX = TYPE(1);\n"
16125                                                                                                  "    }\n";
16126         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16127                                                                                                 "    {\n"
16128                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16129                                                                                                 "    }\n";
16130         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16131                                                                                                 "    {\n"
16132                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16133                                                                                                 "    }\n";
16134         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16135                                                                                                  "    if (vec4(0) == result)\n"
16136                                                                                                  "    {\n"
16137                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16138                                                                                                  "    }\n";
16139         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16140                                                                                                  "    if (vec4(0) == result)\n"
16141                                                                                                  "    {\n"
16142                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16143                                                                                                  "    }\n";
16144         static const GLchar* fs = "#version 430 core\n"
16145                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16146                                                           "\n"
16147                                                           "in  vec4 gs_fs;\n"
16148                                                           "out vec4 fs_out;\n"
16149                                                           "\n"
16150                                                           "void main()\n"
16151                                                           "{\n"
16152                                                           "    fs_out = gs_fs;\n"
16153                                                           "}\n"
16154                                                           "\n";
16155         static const GLchar* fs_tested = "#version 430 core\n"
16156                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16157                                                                          "\n"
16158                                                                          "VAR_DEFINITION"
16159                                                                          "\n"
16160                                                                          "in  vec4 gs_fs;\n"
16161                                                                          "out vec4 fs_out;\n"
16162                                                                          "\n"
16163                                                                          "void main()\n"
16164                                                                          "{\n"
16165                                                                          "    vec4 result = gs_fs;\n"
16166                                                                          "\n"
16167                                                                          "VARIABLE_USE"
16168                                                                          "\n"
16169                                                                          "    fs_out += result;\n"
16170                                                                          "}\n"
16171                                                                          "\n";
16172         static const GLchar* gs = "#version 430 core\n"
16173                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16174                                                           "\n"
16175                                                           "layout(points)                           in;\n"
16176                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16177                                                           "\n"
16178                                                           "in  vec4 tes_gs[];\n"
16179                                                           "out vec4 gs_fs;\n"
16180                                                           "\n"
16181                                                           "void main()\n"
16182                                                           "{\n"
16183                                                           "    gs_fs = tes_gs[0];\n"
16184                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16185                                                           "    EmitVertex();\n"
16186                                                           "    gs_fs = tes_gs[0];\n"
16187                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16188                                                           "    EmitVertex();\n"
16189                                                           "    gs_fs = tes_gs[0];\n"
16190                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16191                                                           "    EmitVertex();\n"
16192                                                           "    gs_fs = tes_gs[0];\n"
16193                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16194                                                           "    EmitVertex();\n"
16195                                                           "}\n"
16196                                                           "\n";
16197         static const GLchar* gs_tested = "#version 430 core\n"
16198                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16199                                                                          "\n"
16200                                                                          "layout(points)                           in;\n"
16201                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16202                                                                          "\n"
16203                                                                          "VAR_DEFINITION"
16204                                                                          "\n"
16205                                                                          "in  vec4 tes_gs[];\n"
16206                                                                          "out vec4 gs_fs;\n"
16207                                                                          "\n"
16208                                                                          "void main()\n"
16209                                                                          "{\n"
16210                                                                          "    vec4 result = tes_gs[0];\n"
16211                                                                          "\n"
16212                                                                          "VARIABLE_USE"
16213                                                                          "\n"
16214                                                                          "    gs_fs = result;\n"
16215                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16216                                                                          "    EmitVertex();\n"
16217                                                                          "    gs_fs = result;\n"
16218                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16219                                                                          "    EmitVertex();\n"
16220                                                                          "    gs_fs = result;\n"
16221                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16222                                                                          "    EmitVertex();\n"
16223                                                                          "    gs_fs = result;\n"
16224                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16225                                                                          "    EmitVertex();\n"
16226                                                                          "}\n"
16227                                                                          "\n";
16228         static const GLchar* tcs = "#version 430 core\n"
16229                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16230                                                            "\n"
16231                                                            "layout(vertices = 1) out;\n"
16232                                                            "\n"
16233                                                            "in  vec4 vs_tcs[];\n"
16234                                                            "out vec4 tcs_tes[];\n"
16235                                                            "\n"
16236                                                            "void main()\n"
16237                                                            "{\n"
16238                                                            "\n"
16239                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16240                                                            "\n"
16241                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16242                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16243                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16244                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16245                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16246                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16247                                                            "}\n"
16248                                                            "\n";
16249         static const GLchar* tcs_tested = "#version 430 core\n"
16250                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16251                                                                           "\n"
16252                                                                           "layout(vertices = 1) out;\n"
16253                                                                           "\n"
16254                                                                           "VAR_DEFINITION"
16255                                                                           "\n"
16256                                                                           "in  vec4 vs_tcs[];\n"
16257                                                                           "out vec4 tcs_tes[];\n"
16258                                                                           "\n"
16259                                                                           "void main()\n"
16260                                                                           "{\n"
16261                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16262                                                                           "\n"
16263                                                                           "VARIABLE_USE"
16264                                                                           "\n"
16265                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16266                                                                           "\n"
16267                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16268                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16269                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16270                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16271                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16272                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16273                                                                           "}\n"
16274                                                                           "\n";
16275         static const GLchar* tes = "#version 430 core\n"
16276                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16277                                                            "\n"
16278                                                            "layout(isolines, point_mode) in;\n"
16279                                                            "\n"
16280                                                            "in  vec4 tcs_tes[];\n"
16281                                                            "out vec4 tes_gs;\n"
16282                                                            "\n"
16283                                                            "void main()\n"
16284                                                            "{\n"
16285                                                            "    tes_gs = tcs_tes[0];\n"
16286                                                            "}\n"
16287                                                            "\n";
16288         static const GLchar* tes_tested = "#version 430 core\n"
16289                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16290                                                                           "\n"
16291                                                                           "layout(isolines, point_mode) in;\n"
16292                                                                           "\n"
16293                                                                           "VAR_DEFINITION"
16294                                                                           "\n"
16295                                                                           "in  vec4 tcs_tes[];\n"
16296                                                                           "out vec4 tes_gs;\n"
16297                                                                           "\n"
16298                                                                           "void main()\n"
16299                                                                           "{\n"
16300                                                                           "    vec4 result = tcs_tes[0];\n"
16301                                                                           "\n"
16302                                                                           "VARIABLE_USE"
16303                                                                           "\n"
16304                                                                           "    tes_gs += result;\n"
16305                                                                           "}\n"
16306                                                                           "\n";
16307         static const GLchar* vs = "#version 430 core\n"
16308                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16309                                                           "\n"
16310                                                           "in  vec4 in_vs;\n"
16311                                                           "out vec4 vs_tcs;\n"
16312                                                           "\n"
16313                                                           "void main()\n"
16314                                                           "{\n"
16315                                                           "    vs_tcs = in_vs;\n"
16316                                                           "}\n"
16317                                                           "\n";
16318         static const GLchar* vs_tested = "#version 430 core\n"
16319                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16320                                                                          "\n"
16321                                                                          "VAR_DEFINITION"
16322                                                                          "\n"
16323                                                                          "in  vec4 in_vs;\n"
16324                                                                          "out vec4 vs_tcs;\n"
16325                                                                          "\n"
16326                                                                          "void main()\n"
16327                                                                          "{\n"
16328                                                                          "    vec4 result = in_vs;\n"
16329                                                                          "\n"
16330                                                                          "VARIABLE_USE"
16331                                                                          "\n"
16332                                                                          "    vs_tcs += result;\n"
16333                                                                          "}\n"
16334                                                                          "\n";
16335
16336         std::string source;
16337         testCase&   test_case = m_test_cases[test_case_index];
16338
16339         if (test_case.m_stage == stage)
16340         {
16341                 const GLchar* array = "";
16342                 GLchar            buffer[16];
16343                 const GLchar* var_definition = 0;
16344                 const GLchar* direction          = "in ";
16345                 const GLchar* index                      = "";
16346                 size_t            position               = 0;
16347                 size_t            temp;
16348                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16349                 const GLchar* var_use   = 0;
16350
16351                 if (false == test_case.m_is_input)
16352                 {
16353                         direction = "out";
16354
16355                         if (false == test_case.m_is_array)
16356                         {
16357                                 switch (test_case.m_case)
16358                                 {
16359                                 case BLOCK:
16360                                         var_definition = block_definition_one;
16361                                         var_use            = member_output_use_one;
16362                                         break;
16363                                 case MATRIX:
16364                                         var_definition = matrix_definition_one;
16365                                         var_use            = matrix_output_use_one;
16366                                         break;
16367                                 case STRUCT:
16368                                         var_definition = struct_definition_one;
16369                                         var_use            = member_output_use_one;
16370                                         break;
16371                                 default:
16372                                         TCU_FAIL("Invalid enum");
16373                                 }
16374                         }
16375                         else
16376                         {
16377                                 switch (test_case.m_case)
16378                                 {
16379                                 case BLOCK:
16380                                         var_definition = block_definition_arr;
16381                                         var_use            = member_output_use_arr;
16382                                         break;
16383                                 case MATRIX:
16384                                         var_definition = matrix_definition_arr;
16385                                         var_use            = matrix_output_use_arr;
16386                                         break;
16387                                 case STRUCT:
16388                                         var_definition = struct_definition_arr;
16389                                         var_use            = member_output_use_arr;
16390                                         break;
16391                                 default:
16392                                         TCU_FAIL("Invalid enum");
16393                                 }
16394                         }
16395                 }
16396                 else
16397                 {
16398                         if (false == test_case.m_is_array)
16399                         {
16400                                 switch (test_case.m_case)
16401                                 {
16402                                 case BLOCK:
16403                                         var_definition = block_definition_one;
16404                                         var_use            = member_input_use_one;
16405                                         break;
16406                                 case MATRIX:
16407                                         var_definition = matrix_definition_one;
16408                                         var_use            = matrix_input_use_one;
16409                                         break;
16410                                 case STRUCT:
16411                                         var_definition = struct_definition_one;
16412                                         var_use            = member_input_use_one;
16413                                         break;
16414                                 default:
16415                                         TCU_FAIL("Invalid enum");
16416                                 }
16417                         }
16418                         else
16419                         {
16420                                 switch (test_case.m_case)
16421                                 {
16422                                 case BLOCK:
16423                                         var_definition = block_definition_arr;
16424                                         var_use            = member_input_use_arr;
16425                                         break;
16426                                 case MATRIX:
16427                                         var_definition = matrix_definition_arr;
16428                                         var_use            = matrix_input_use_arr;
16429                                         break;
16430                                 case STRUCT:
16431                                         var_definition = struct_definition_arr;
16432                                         var_use            = member_input_use_arr;
16433                                         break;
16434                                 default:
16435                                         TCU_FAIL("Invalid enum");
16436                                 }
16437                         }
16438                 }
16439
16440                 sprintf(buffer, "%d", test_case.m_component);
16441
16442                 switch (stage)
16443                 {
16444                 case Utils::Shader::FRAGMENT:
16445                         source = fs_tested;
16446                         break;
16447                 case Utils::Shader::GEOMETRY:
16448                         source = gs_tested;
16449                         array  = "[]";
16450                         index  = "[0]";
16451                         break;
16452                 case Utils::Shader::TESS_CTRL:
16453                         source = tcs_tested;
16454                         array  = "[]";
16455                         index  = "[gl_InvocationID]";
16456                         break;
16457                 case Utils::Shader::TESS_EVAL:
16458                         source = tes_tested;
16459                         array  = "[]";
16460                         index  = "[0]";
16461                         break;
16462                 case Utils::Shader::VERTEX:
16463                         source = vs_tested;
16464                         break;
16465                 default:
16466                         TCU_FAIL("Invalid enum");
16467                 }
16468
16469                 temp = position;
16470                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16471                 position = temp;
16472                 Utils::replaceToken("COMPONENT", position, buffer, source);
16473                 Utils::replaceToken("DIRECTION", position, direction, source);
16474                 Utils::replaceToken("ARRAY", position, array, source);
16475                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16476
16477                 Utils::replaceAllTokens("TYPE", type_name, source);
16478                 Utils::replaceAllTokens("INDEX", index, source);
16479         }
16480         else
16481         {
16482                 switch (stage)
16483                 {
16484                 case Utils::Shader::FRAGMENT:
16485                         source = fs;
16486                         break;
16487                 case Utils::Shader::GEOMETRY:
16488                         source = gs;
16489                         break;
16490                 case Utils::Shader::TESS_CTRL:
16491                         source = tcs;
16492                         break;
16493                 case Utils::Shader::TESS_EVAL:
16494                         source = tes;
16495                         break;
16496                 case Utils::Shader::VERTEX:
16497                         source = vs;
16498                         break;
16499                 default:
16500                         TCU_FAIL("Invalid enum");
16501                 }
16502         }
16503
16504         return source;
16505 }
16506
16507 /** Get description of test case
16508  *
16509  * @param test_case_index Index of test case
16510  *
16511  * @return Test case description
16512  **/
16513 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16514 {
16515         std::stringstream stream;
16516         testCase&                 test_case = m_test_cases[test_case_index];
16517
16518         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16519                    << " type: " << test_case.m_type.GetGLSLTypeName();
16520
16521         if (true == test_case.m_is_array)
16522         {
16523                 stream << "[1]";
16524         }
16525
16526         stream << ", direction: ";
16527
16528         if (true == test_case.m_is_input)
16529         {
16530                 stream << "input";
16531         }
16532         else
16533         {
16534                 stream << "output";
16535         }
16536
16537         stream << ", component: " << test_case.m_component;
16538
16539         return stream.str();
16540 }
16541
16542 /** Get number of test cases
16543  *
16544  * @return Number of test cases
16545  **/
16546 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16547 {
16548         return static_cast<GLuint>(m_test_cases.size());
16549 }
16550
16551 /** Selects if "compute" stage is relevant for test
16552  *
16553  * @param ignored
16554  *
16555  * @return false
16556  **/
16557 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16558 {
16559         return false;
16560 }
16561
16562 /** Prepare all test cases
16563  *
16564  **/
16565 void VaryingComponentOfInvalidTypeTest::testInit()
16566 {
16567         static const GLuint n_components_per_location = 4;
16568         const GLuint            n_types                                   = getTypesNumber();
16569
16570         for (GLuint i = 0; i < n_types; ++i)
16571         {
16572                 const Utils::Type& type                         = getType(i);
16573                 const GLuint       n_req_components = type.m_n_rows;
16574                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16575
16576                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16577                 {
16578                         if (Utils::Shader::COMPUTE == stage)
16579                         {
16580                                 continue;
16581                         }
16582
16583                         /* Use different CASE for matrices */
16584                         if (1 != type.m_n_columns)
16585                         {
16586                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16587                                 testCase test_case_in_one = {
16588                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16589                                 };
16590                                 testCase test_case_out_arr = {
16591                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16592                                 };
16593                                 testCase test_case_out_one = {
16594                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16595                                 };
16596
16597                                 m_test_cases.push_back(test_case_in_arr);
16598                                 m_test_cases.push_back(test_case_in_one);
16599
16600                                 if (Utils::Shader::FRAGMENT != stage)
16601                                 {
16602                                         m_test_cases.push_back(test_case_out_arr);
16603                                         m_test_cases.push_back(test_case_out_one);
16604                                 }
16605                         }
16606                         else
16607                         {
16608                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16609                                 {
16610                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16611                                                                                                   type };
16612                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16613                                                                                                   type };
16614                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16615                                                                                                    type };
16616                                         testCase test_case_out_one = {
16617                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16618                                         };
16619
16620                                         if (Utils::Shader::VERTEX != stage)
16621                                         {
16622                                                 m_test_cases.push_back(test_case_in_arr);
16623                                                 m_test_cases.push_back(test_case_in_one);
16624                                         }
16625
16626                                         if (Utils::Shader::FRAGMENT != stage)
16627                                         {
16628                                                 m_test_cases.push_back(test_case_out_arr);
16629                                                 m_test_cases.push_back(test_case_out_one);
16630                                         }
16631                                 }
16632                         }
16633                 }
16634         }
16635 }
16636
16637 /** Constructor
16638  *
16639  * @param context Test framework context
16640  **/
16641 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16642         : NegativeTestBase(context, "input_component_aliasing",
16643                                            "Test verifies that compiler reports component aliasing as error")
16644 {
16645 }
16646
16647 /** Source for given test case and stage
16648  *
16649  * @param test_case_index Index of test case
16650  * @param stage           Shader stage
16651  *
16652  * @return Shader source
16653  **/
16654 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16655 {
16656         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16657                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16658         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16659                                                                         "    {\n"
16660                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16661                                                                         "    }\n";
16662         static const GLchar* fs = "#version 430 core\n"
16663                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16664                                                           "\n"
16665                                                           "in  vec4 gs_fs;\n"
16666                                                           "out vec4 fs_out;\n"
16667                                                           "\n"
16668                                                           "void main()\n"
16669                                                           "{\n"
16670                                                           "    fs_out = gs_fs;\n"
16671                                                           "}\n"
16672                                                           "\n";
16673         static const GLchar* fs_tested = "#version 430 core\n"
16674                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16675                                                                          "\n"
16676                                                                          "VAR_DEFINITION"
16677                                                                          "\n"
16678                                                                          "in  vec4 gs_fs;\n"
16679                                                                          "out vec4 fs_out;\n"
16680                                                                          "\n"
16681                                                                          "void main()\n"
16682                                                                          "{\n"
16683                                                                          "    vec4 result = gs_fs;\n"
16684                                                                          "\n"
16685                                                                          "VARIABLE_USE"
16686                                                                          "\n"
16687                                                                          "    fs_out += result;\n"
16688                                                                          "}\n"
16689                                                                          "\n";
16690         static const GLchar* gs = "#version 430 core\n"
16691                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16692                                                           "\n"
16693                                                           "layout(points)                           in;\n"
16694                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16695                                                           "\n"
16696                                                           "in  vec4 tes_gs[];\n"
16697                                                           "out vec4 gs_fs;\n"
16698                                                           "\n"
16699                                                           "void main()\n"
16700                                                           "{\n"
16701                                                           "    gs_fs = tes_gs[0];\n"
16702                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16703                                                           "    EmitVertex();\n"
16704                                                           "    gs_fs = tes_gs[0];\n"
16705                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16706                                                           "    EmitVertex();\n"
16707                                                           "    gs_fs = tes_gs[0];\n"
16708                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16709                                                           "    EmitVertex();\n"
16710                                                           "    gs_fs = tes_gs[0];\n"
16711                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16712                                                           "    EmitVertex();\n"
16713                                                           "}\n"
16714                                                           "\n";
16715         static const GLchar* gs_tested = "#version 430 core\n"
16716                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16717                                                                          "\n"
16718                                                                          "layout(points)                           in;\n"
16719                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16720                                                                          "\n"
16721                                                                          "VAR_DEFINITION"
16722                                                                          "\n"
16723                                                                          "in  vec4 tes_gs[];\n"
16724                                                                          "out vec4 gs_fs;\n"
16725                                                                          "\n"
16726                                                                          "void main()\n"
16727                                                                          "{\n"
16728                                                                          "    vec4 result = tes_gs[0];\n"
16729                                                                          "\n"
16730                                                                          "VARIABLE_USE"
16731                                                                          "\n"
16732                                                                          "    gs_fs = result;\n"
16733                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16734                                                                          "    EmitVertex();\n"
16735                                                                          "    gs_fs = result;\n"
16736                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16737                                                                          "    EmitVertex();\n"
16738                                                                          "    gs_fs = result;\n"
16739                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16740                                                                          "    EmitVertex();\n"
16741                                                                          "    gs_fs = result;\n"
16742                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16743                                                                          "    EmitVertex();\n"
16744                                                                          "}\n"
16745                                                                          "\n";
16746         static const GLchar* tcs = "#version 430 core\n"
16747                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16748                                                            "\n"
16749                                                            "layout(vertices = 1) out;\n"
16750                                                            "\n"
16751                                                            "in  vec4 vs_tcs[];\n"
16752                                                            "out vec4 tcs_tes[];\n"
16753                                                            "\n"
16754                                                            "void main()\n"
16755                                                            "{\n"
16756                                                            "\n"
16757                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16758                                                            "\n"
16759                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16760                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16761                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16762                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16763                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16764                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16765                                                            "}\n"
16766                                                            "\n";
16767         static const GLchar* tcs_tested = "#version 430 core\n"
16768                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16769                                                                           "\n"
16770                                                                           "layout(vertices = 1) out;\n"
16771                                                                           "\n"
16772                                                                           "VAR_DEFINITION"
16773                                                                           "\n"
16774                                                                           "in  vec4 vs_tcs[];\n"
16775                                                                           "out vec4 tcs_tes[];\n"
16776                                                                           "\n"
16777                                                                           "void main()\n"
16778                                                                           "{\n"
16779                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16780                                                                           "\n"
16781                                                                           "VARIABLE_USE"
16782                                                                           "\n"
16783                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16784                                                                           "\n"
16785                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16786                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16787                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16788                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16789                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16790                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16791                                                                           "}\n"
16792                                                                           "\n";
16793         static const GLchar* tes = "#version 430 core\n"
16794                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16795                                                            "\n"
16796                                                            "layout(isolines, point_mode) in;\n"
16797                                                            "\n"
16798                                                            "in  vec4 tcs_tes[];\n"
16799                                                            "out vec4 tes_gs;\n"
16800                                                            "\n"
16801                                                            "void main()\n"
16802                                                            "{\n"
16803                                                            "    tes_gs = tcs_tes[0];\n"
16804                                                            "}\n"
16805                                                            "\n";
16806         static const GLchar* tes_tested = "#version 430 core\n"
16807                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16808                                                                           "\n"
16809                                                                           "layout(isolines, point_mode) in;\n"
16810                                                                           "\n"
16811                                                                           "VAR_DEFINITION"
16812                                                                           "\n"
16813                                                                           "in  vec4 tcs_tes[];\n"
16814                                                                           "out vec4 tes_gs;\n"
16815                                                                           "\n"
16816                                                                           "void main()\n"
16817                                                                           "{\n"
16818                                                                           "    vec4 result = tcs_tes[0];\n"
16819                                                                           "\n"
16820                                                                           "VARIABLE_USE"
16821                                                                           "\n"
16822                                                                           "    tes_gs += result;\n"
16823                                                                           "}\n"
16824                                                                           "\n";
16825         static const GLchar* vs = "#version 430 core\n"
16826                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16827                                                           "\n"
16828                                                           "in  vec4 in_vs;\n"
16829                                                           "out vec4 vs_tcs;\n"
16830                                                           "\n"
16831                                                           "void main()\n"
16832                                                           "{\n"
16833                                                           "    vs_tcs = in_vs;\n"
16834                                                           "}\n"
16835                                                           "\n";
16836         static const GLchar* vs_tested = "#version 430 core\n"
16837                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16838                                                                          "\n"
16839                                                                          "VAR_DEFINITION"
16840                                                                          "\n"
16841                                                                          "in  vec4 in_vs;\n"
16842                                                                          "out vec4 vs_tcs;\n"
16843                                                                          "\n"
16844                                                                          "void main()\n"
16845                                                                          "{\n"
16846                                                                          "    vec4 result = in_vs;\n"
16847                                                                          "\n"
16848                                                                          "VARIABLE_USE"
16849                                                                          "\n"
16850                                                                          "    vs_tcs += result;\n"
16851                                                                          "}\n"
16852                                                                          "\n";
16853
16854         std::string source;
16855         testCase&   test_case = m_test_cases[test_case_index];
16856
16857         if (test_case.m_stage == stage)
16858         {
16859                 const GLchar* array = "";
16860                 GLchar            buffer_gohan[16];
16861                 GLchar            buffer_goten[16];
16862                 const GLchar* flat                = "";
16863                 const GLchar* index               = "";
16864                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16865                 size_t            position      = 0;
16866                 size_t            temp;
16867                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16868                 const GLchar* var_use   = test_one;
16869
16870                 if (true == is_flat_req)
16871                 {
16872                         flat = "flat";
16873                 }
16874
16875                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16876                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16877
16878                 switch (stage)
16879                 {
16880                 case Utils::Shader::FRAGMENT:
16881                         source = fs_tested;
16882                         break;
16883                 case Utils::Shader::GEOMETRY:
16884                         source = gs_tested;
16885                         array  = "[]";
16886                         index  = "[0]";
16887                         break;
16888                 case Utils::Shader::TESS_CTRL:
16889                         source = tcs_tested;
16890                         array  = "[]";
16891                         index  = "[gl_InvocationID]";
16892                         break;
16893                 case Utils::Shader::TESS_EVAL:
16894                         source = tes_tested;
16895                         array  = "[]";
16896                         index  = "[0]";
16897                         break;
16898                 case Utils::Shader::VERTEX:
16899                         source = vs_tested;
16900                         break;
16901                 default:
16902                         TCU_FAIL("Invalid enum");
16903                 }
16904
16905                 temp = position;
16906                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16907                 position = temp;
16908                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16909                 Utils::replaceToken("ARRAY", position, array, source);
16910                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16911                 Utils::replaceToken("ARRAY", position, array, source);
16912                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16913
16914                 Utils::replaceAllTokens("FLAT", flat, source);
16915                 Utils::replaceAllTokens("TYPE", type_name, source);
16916                 Utils::replaceAllTokens("INDEX", index, source);
16917         }
16918         else
16919         {
16920                 switch (stage)
16921                 {
16922                 case Utils::Shader::FRAGMENT:
16923                         source = fs;
16924                         break;
16925                 case Utils::Shader::GEOMETRY:
16926                         source = gs;
16927                         break;
16928                 case Utils::Shader::TESS_CTRL:
16929                         source = tcs;
16930                         break;
16931                 case Utils::Shader::TESS_EVAL:
16932                         source = tes;
16933                         break;
16934                 case Utils::Shader::VERTEX:
16935                         source = vs;
16936                         break;
16937                 default:
16938                         TCU_FAIL("Invalid enum");
16939                 }
16940         }
16941
16942         return source;
16943 }
16944
16945 /** Get description of test case
16946  *
16947  * @param test_case_index Index of test case
16948  *
16949  * @return Test case description
16950  **/
16951 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16952 {
16953         std::stringstream stream;
16954         testCase&                 test_case = m_test_cases[test_case_index];
16955
16956         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16957                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16958                    << " & " << test_case.m_component_goten;
16959
16960         return stream.str();
16961 }
16962
16963 /** Get number of test cases
16964  *
16965  * @return Number of test cases
16966  **/
16967 GLuint InputComponentAliasingTest::getTestCaseNumber()
16968 {
16969         return static_cast<GLuint>(m_test_cases.size());
16970 }
16971
16972 /** Selects if "compute" stage is relevant for test
16973  *
16974  * @param ignored
16975  *
16976  * @return false
16977  **/
16978 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16979 {
16980         return false;
16981 }
16982
16983 /** Selects if compilation failure is expected result
16984  *
16985  * @param test_case_index Index of test case
16986  *
16987  * @return false for VS that use only single variable, true otherwise
16988  **/
16989 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16990 {
16991         testCase& test_case = m_test_cases[test_case_index];
16992
16993         return (Utils::Shader::VERTEX != test_case.m_stage);
16994 }
16995
16996 /** Prepare all test cases
16997  *
16998  **/
16999 void InputComponentAliasingTest::testInit()
17000 {
17001         const GLuint            n_types                                   = getTypesNumber();
17002
17003         for (GLuint i = 0; i < n_types; ++i)
17004         {
17005                 const Utils::Type& type                                          = getType(i);
17006                 const bool                 use_double                            = (Utils::Type::Double == type.m_basic_type);
17007                 const GLuint       n_components_per_location = use_double ? 2 : 4;
17008                 const GLuint       n_req_components                      = type.m_n_rows;
17009                 const GLint                valid_component                       = (GLint)n_components_per_location - (GLint)n_req_components;
17010                 const GLuint       component_size                        = use_double ? 2 : 1;
17011                 /* Skip matrices */
17012                 if (1 != type.m_n_columns)
17013                 {
17014                         continue;
17015                 }
17016                 /* Skip dvec3/dvec4 which doesn't support the component qualifier */
17017                 if (valid_component < 0)
17018                 {
17019                         continue;
17020                 }
17021
17022                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17023                 {
17024                         if (Utils::Shader::COMPUTE == stage)
17025                         {
17026                                 continue;
17027                         }
17028
17029                         for (GLuint gohan = 0; gohan <= (GLuint)valid_component; ++gohan)
17030                         {
17031                                 const GLint first_aliasing = gohan - n_req_components + 1;
17032                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17033
17034                                 const GLuint goten_start = std::max(0, first_aliasing);
17035                                 const GLuint goten_stop  = std::min(valid_component, last_aliasing);
17036
17037                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17038                                 {
17039                                         testCase test_case = { gohan * component_size, goten * component_size, (Utils::Shader::STAGES)stage,
17040                                                                                    type };
17041
17042                                         m_test_cases.push_back(test_case);
17043                                 }
17044                         }
17045                 }
17046         }
17047 }
17048
17049 /** Constructor
17050  *
17051  * @param context Test framework context
17052  **/
17053 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
17054         : NegativeTestBase(context, "output_component_aliasing",
17055                                            "Test verifies that compiler reports component aliasing as error")
17056 {
17057 }
17058
17059 /** Source for given test case and stage
17060  *
17061  * @param test_case_index Index of test case
17062  * @param stage           Shader stage
17063  *
17064  * @return Shader source
17065  **/
17066 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
17067 {
17068         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
17069                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
17070         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
17071                                                                   "    gotenINDEX = TYPE(0);\n";
17072         static const GLchar* fs = "#version 430 core\n"
17073                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17074                                                           "\n"
17075                                                           "in  vec4 gs_fs;\n"
17076                                                           "out vec4 fs_out;\n"
17077                                                           "\n"
17078                                                           "void main()\n"
17079                                                           "{\n"
17080                                                           "    fs_out = gs_fs;\n"
17081                                                           "}\n"
17082                                                           "\n";
17083         static const GLchar* fs_tested = "#version 430 core\n"
17084                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17085                                                                          "\n"
17086                                                                          "VAR_DEFINITION"
17087                                                                          "\n"
17088                                                                          "in  vec4 gs_fs;\n"
17089                                                                          "out vec4 fs_out;\n"
17090                                                                          "\n"
17091                                                                          "void main()\n"
17092                                                                          "{\n"
17093                                                                          "    vec4 result = gs_fs;\n"
17094                                                                          "\n"
17095                                                                          "VARIABLE_USE"
17096                                                                          "\n"
17097                                                                          "    fs_out += result;\n"
17098                                                                          "}\n"
17099                                                                          "\n";
17100         static const GLchar* gs = "#version 430 core\n"
17101                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17102                                                           "\n"
17103                                                           "layout(points)                           in;\n"
17104                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17105                                                           "\n"
17106                                                           "in  vec4 tes_gs[];\n"
17107                                                           "out vec4 gs_fs;\n"
17108                                                           "\n"
17109                                                           "void main()\n"
17110                                                           "{\n"
17111                                                           "    gs_fs = tes_gs[0];\n"
17112                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17113                                                           "    EmitVertex();\n"
17114                                                           "    gs_fs = tes_gs[0];\n"
17115                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17116                                                           "    EmitVertex();\n"
17117                                                           "    gs_fs = tes_gs[0];\n"
17118                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17119                                                           "    EmitVertex();\n"
17120                                                           "    gs_fs = tes_gs[0];\n"
17121                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17122                                                           "    EmitVertex();\n"
17123                                                           "}\n"
17124                                                           "\n";
17125         static const GLchar* gs_tested = "#version 430 core\n"
17126                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17127                                                                          "\n"
17128                                                                          "layout(points)                           in;\n"
17129                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17130                                                                          "\n"
17131                                                                          "VAR_DEFINITION"
17132                                                                          "\n"
17133                                                                          "in  vec4 tes_gs[];\n"
17134                                                                          "out vec4 gs_fs;\n"
17135                                                                          "\n"
17136                                                                          "void main()\n"
17137                                                                          "{\n"
17138                                                                          "    vec4 result = tes_gs[0];\n"
17139                                                                          "\n"
17140                                                                          "VARIABLE_USE"
17141                                                                          "\n"
17142                                                                          "    gs_fs = result;\n"
17143                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17144                                                                          "    EmitVertex();\n"
17145                                                                          "    gs_fs = result;\n"
17146                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17147                                                                          "    EmitVertex();\n"
17148                                                                          "    gs_fs = result;\n"
17149                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17150                                                                          "    EmitVertex();\n"
17151                                                                          "    gs_fs = result;\n"
17152                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17153                                                                          "    EmitVertex();\n"
17154                                                                          "}\n"
17155                                                                          "\n";
17156         static const GLchar* tcs = "#version 430 core\n"
17157                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17158                                                            "\n"
17159                                                            "layout(vertices = 1) out;\n"
17160                                                            "\n"
17161                                                            "in  vec4 vs_tcs[];\n"
17162                                                            "out vec4 tcs_tes[];\n"
17163                                                            "\n"
17164                                                            "void main()\n"
17165                                                            "{\n"
17166                                                            "\n"
17167                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17168                                                            "\n"
17169                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17170                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17171                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17172                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17173                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17174                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17175                                                            "}\n"
17176                                                            "\n";
17177         static const GLchar* tcs_tested = "#version 430 core\n"
17178                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17179                                                                           "\n"
17180                                                                           "layout(vertices = 1) out;\n"
17181                                                                           "\n"
17182                                                                           "VAR_DEFINITION"
17183                                                                           "\n"
17184                                                                           "in  vec4 vs_tcs[];\n"
17185                                                                           "out vec4 tcs_tes[];\n"
17186                                                                           "\n"
17187                                                                           "void main()\n"
17188                                                                           "{\n"
17189                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17190                                                                           "\n"
17191                                                                           "VARIABLE_USE"
17192                                                                           "\n"
17193                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17194                                                                           "\n"
17195                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17196                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17197                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17198                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17199                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17200                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17201                                                                           "}\n"
17202                                                                           "\n";
17203         static const GLchar* tes = "#version 430 core\n"
17204                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17205                                                            "\n"
17206                                                            "layout(isolines, point_mode) in;\n"
17207                                                            "\n"
17208                                                            "in  vec4 tcs_tes[];\n"
17209                                                            "out vec4 tes_gs;\n"
17210                                                            "\n"
17211                                                            "void main()\n"
17212                                                            "{\n"
17213                                                            "    tes_gs = tcs_tes[0];\n"
17214                                                            "}\n"
17215                                                            "\n";
17216         static const GLchar* tes_tested = "#version 430 core\n"
17217                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17218                                                                           "\n"
17219                                                                           "layout(isolines, point_mode) in;\n"
17220                                                                           "\n"
17221                                                                           "VAR_DEFINITION"
17222                                                                           "\n"
17223                                                                           "in  vec4 tcs_tes[];\n"
17224                                                                           "out vec4 tes_gs;\n"
17225                                                                           "\n"
17226                                                                           "void main()\n"
17227                                                                           "{\n"
17228                                                                           "    vec4 result = tcs_tes[0];\n"
17229                                                                           "\n"
17230                                                                           "VARIABLE_USE"
17231                                                                           "\n"
17232                                                                           "    tes_gs += result;\n"
17233                                                                           "}\n"
17234                                                                           "\n";
17235         static const GLchar* vs = "#version 430 core\n"
17236                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17237                                                           "\n"
17238                                                           "in  vec4 in_vs;\n"
17239                                                           "out vec4 vs_tcs;\n"
17240                                                           "\n"
17241                                                           "void main()\n"
17242                                                           "{\n"
17243                                                           "    vs_tcs = in_vs;\n"
17244                                                           "}\n"
17245                                                           "\n";
17246         static const GLchar* vs_tested = "#version 430 core\n"
17247                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17248                                                                          "\n"
17249                                                                          "VAR_DEFINITION"
17250                                                                          "\n"
17251                                                                          "in  vec4 in_vs;\n"
17252                                                                          "out vec4 vs_tcs;\n"
17253                                                                          "\n"
17254                                                                          "void main()\n"
17255                                                                          "{\n"
17256                                                                          "    vec4 result = in_vs;\n"
17257                                                                          "\n"
17258                                                                          "VARIABLE_USE"
17259                                                                          "\n"
17260                                                                          "    vs_tcs += result;\n"
17261                                                                          "}\n"
17262                                                                          "\n";
17263
17264         std::string source;
17265         testCase&   test_case = m_test_cases[test_case_index];
17266
17267         if (test_case.m_stage == stage)
17268         {
17269                 const GLchar* array = "";
17270                 GLchar            buffer_gohan[16];
17271                 GLchar            buffer_goten[16];
17272                 const GLchar* index     = "";
17273                 size_t            position = 0;
17274                 size_t            temp;
17275                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17276
17277                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17278                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17279
17280                 switch (stage)
17281                 {
17282                 case Utils::Shader::FRAGMENT:
17283                         source = fs_tested;
17284                         break;
17285                 case Utils::Shader::GEOMETRY:
17286                         source = gs_tested;
17287                         array  = "[]";
17288                         index  = "[0]";
17289                         break;
17290                 case Utils::Shader::TESS_CTRL:
17291                         source = tcs_tested;
17292                         array  = "[]";
17293                         index  = "[gl_InvocationID]";
17294                         break;
17295                 case Utils::Shader::TESS_EVAL:
17296                         source = tes_tested;
17297                         array  = "[]";
17298                         index  = "[0]";
17299                         break;
17300                 case Utils::Shader::VERTEX:
17301                         source = vs_tested;
17302                         break;
17303                 default:
17304                         TCU_FAIL("Invalid enum");
17305                 }
17306
17307                 temp = position;
17308                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17309                 position = temp;
17310                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17311                 Utils::replaceToken("ARRAY", position, array, source);
17312                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17313                 Utils::replaceToken("ARRAY", position, array, source);
17314                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17315
17316                 Utils::replaceAllTokens("TYPE", type_name, source);
17317                 Utils::replaceAllTokens("INDEX", index, source);
17318         }
17319         else
17320         {
17321                 switch (stage)
17322                 {
17323                 case Utils::Shader::FRAGMENT:
17324                         source = fs;
17325                         break;
17326                 case Utils::Shader::GEOMETRY:
17327                         source = gs;
17328                         break;
17329                 case Utils::Shader::TESS_CTRL:
17330                         source = tcs;
17331                         break;
17332                 case Utils::Shader::TESS_EVAL:
17333                         source = tes;
17334                         break;
17335                 case Utils::Shader::VERTEX:
17336                         source = vs;
17337                         break;
17338                 default:
17339                         TCU_FAIL("Invalid enum");
17340                 }
17341         }
17342
17343         return source;
17344 }
17345
17346 /** Get description of test case
17347  *
17348  * @param test_case_index Index of test case
17349  *
17350  * @return Test case description
17351  **/
17352 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17353 {
17354         std::stringstream stream;
17355         testCase&                 test_case = m_test_cases[test_case_index];
17356
17357         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17358                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17359                    << " & " << test_case.m_component_goten;
17360
17361         return stream.str();
17362 }
17363
17364 /** Get number of test cases
17365  *
17366  * @return Number of test cases
17367  **/
17368 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17369 {
17370         return static_cast<GLuint>(m_test_cases.size());
17371 }
17372
17373 /** Selects if "compute" stage is relevant for test
17374  *
17375  * @param ignored
17376  *
17377  * @return false
17378  **/
17379 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17380 {
17381         return false;
17382 }
17383
17384 /** Prepare all test cases
17385  *
17386  **/
17387 void OutputComponentAliasingTest::testInit()
17388 {
17389         static const GLuint n_components_per_location = 4;
17390         const GLuint            n_types                                   = getTypesNumber();
17391
17392         for (GLuint i = 0; i < n_types; ++i)
17393         {
17394                 const Utils::Type& type                         = getType(i);
17395                 const GLuint       n_req_components = type.m_n_rows;
17396                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17397
17398                 /* Skip matrices */
17399                 if (1 != type.m_n_columns)
17400                 {
17401                         continue;
17402                 }
17403
17404                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17405                 {
17406                         if (Utils::Shader::COMPUTE == stage)
17407                         {
17408                                 continue;
17409                         }
17410
17411                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17412                         {
17413                                 continue;
17414                         }
17415
17416                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17417                         {
17418                                 const GLint first_aliasing = gohan - n_req_components + 1;
17419                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17420
17421                                 const GLuint goten_start = std::max(0, first_aliasing);
17422                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17423
17424                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17425                                 {
17426                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17427
17428                                         m_test_cases.push_back(test_case);
17429                                 }
17430                         }
17431                 }
17432         }
17433 }
17434
17435 /** Constructor
17436  *
17437  * @param context Test framework context
17438  **/
17439 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17440         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17441                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17442 {
17443 }
17444
17445 /** Source for given test case and stage
17446  *
17447  * @param test_case_index Index of test case
17448  * @param stage           Shader stage
17449  *
17450  * @return Shader source
17451  **/
17452 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17453                                                                                                                                            Utils::Shader::STAGES stage)
17454 {
17455         static const GLchar* var_definition =
17456                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17457                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17458         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17459                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17460                                                                          "    {\n"
17461                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17462                                                                          "    }\n";
17463         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17464                                                                           "    gotenINDEX = TYPE(1);\n"
17465                                                                           "    if (vec4(0) == result)\n"
17466                                                                           "    {\n"
17467                                                                           "        gohanINDEX = TYPE(1);\n"
17468                                                                           "        gotenINDEX = TYPE(0);\n"
17469                                                                           "    }\n";
17470         static const GLchar* fs = "#version 430 core\n"
17471                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17472                                                           "\n"
17473                                                           "in  vec4 gs_fs;\n"
17474                                                           "out vec4 fs_out;\n"
17475                                                           "\n"
17476                                                           "void main()\n"
17477                                                           "{\n"
17478                                                           "    fs_out = gs_fs;\n"
17479                                                           "}\n"
17480                                                           "\n";
17481         static const GLchar* fs_tested = "#version 430 core\n"
17482                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17483                                                                          "\n"
17484                                                                          "VAR_DEFINITION"
17485                                                                          "\n"
17486                                                                          "in  vec4 gs_fs;\n"
17487                                                                          "out vec4 fs_out;\n"
17488                                                                          "\n"
17489                                                                          "void main()\n"
17490                                                                          "{\n"
17491                                                                          "    vec4 result = gs_fs;\n"
17492                                                                          "\n"
17493                                                                          "VARIABLE_USE"
17494                                                                          "\n"
17495                                                                          "    fs_out += result;\n"
17496                                                                          "}\n"
17497                                                                          "\n";
17498         static const GLchar* gs = "#version 430 core\n"
17499                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17500                                                           "\n"
17501                                                           "layout(points)                           in;\n"
17502                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17503                                                           "\n"
17504                                                           "in  vec4 tes_gs[];\n"
17505                                                           "out vec4 gs_fs;\n"
17506                                                           "\n"
17507                                                           "void main()\n"
17508                                                           "{\n"
17509                                                           "    gs_fs = tes_gs[0];\n"
17510                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17511                                                           "    EmitVertex();\n"
17512                                                           "    gs_fs = tes_gs[0];\n"
17513                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17514                                                           "    EmitVertex();\n"
17515                                                           "    gs_fs = tes_gs[0];\n"
17516                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17517                                                           "    EmitVertex();\n"
17518                                                           "    gs_fs = tes_gs[0];\n"
17519                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17520                                                           "    EmitVertex();\n"
17521                                                           "}\n"
17522                                                           "\n";
17523         static const GLchar* gs_tested = "#version 430 core\n"
17524                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17525                                                                          "\n"
17526                                                                          "layout(points)                           in;\n"
17527                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17528                                                                          "\n"
17529                                                                          "VAR_DEFINITION"
17530                                                                          "\n"
17531                                                                          "in  vec4 tes_gs[];\n"
17532                                                                          "out vec4 gs_fs;\n"
17533                                                                          "\n"
17534                                                                          "void main()\n"
17535                                                                          "{\n"
17536                                                                          "    vec4 result = tes_gs[0];\n"
17537                                                                          "\n"
17538                                                                          "VARIABLE_USE"
17539                                                                          "\n"
17540                                                                          "    gs_fs = result;\n"
17541                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17542                                                                          "    EmitVertex();\n"
17543                                                                          "    gs_fs = result;\n"
17544                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17545                                                                          "    EmitVertex();\n"
17546                                                                          "    gs_fs = result;\n"
17547                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17548                                                                          "    EmitVertex();\n"
17549                                                                          "    gs_fs = result;\n"
17550                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17551                                                                          "    EmitVertex();\n"
17552                                                                          "}\n"
17553                                                                          "\n";
17554         static const GLchar* tcs = "#version 430 core\n"
17555                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17556                                                            "\n"
17557                                                            "layout(vertices = 1) out;\n"
17558                                                            "\n"
17559                                                            "in  vec4 vs_tcs[];\n"
17560                                                            "out vec4 tcs_tes[];\n"
17561                                                            "\n"
17562                                                            "void main()\n"
17563                                                            "{\n"
17564                                                            "\n"
17565                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17566                                                            "\n"
17567                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17568                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17569                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17570                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17571                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17572                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17573                                                            "}\n"
17574                                                            "\n";
17575         static const GLchar* tcs_tested = "#version 430 core\n"
17576                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17577                                                                           "\n"
17578                                                                           "layout(vertices = 1) out;\n"
17579                                                                           "\n"
17580                                                                           "VAR_DEFINITION"
17581                                                                           "\n"
17582                                                                           "in  vec4 vs_tcs[];\n"
17583                                                                           "out vec4 tcs_tes[];\n"
17584                                                                           "\n"
17585                                                                           "void main()\n"
17586                                                                           "{\n"
17587                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17588                                                                           "\n"
17589                                                                           "VARIABLE_USE"
17590                                                                           "\n"
17591                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17592                                                                           "\n"
17593                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17594                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17595                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17596                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17597                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17598                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17599                                                                           "}\n"
17600                                                                           "\n";
17601         static const GLchar* tes = "#version 430 core\n"
17602                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17603                                                            "\n"
17604                                                            "layout(isolines, point_mode) in;\n"
17605                                                            "\n"
17606                                                            "in  vec4 tcs_tes[];\n"
17607                                                            "out vec4 tes_gs;\n"
17608                                                            "\n"
17609                                                            "void main()\n"
17610                                                            "{\n"
17611                                                            "    tes_gs = tcs_tes[0];\n"
17612                                                            "}\n"
17613                                                            "\n";
17614         static const GLchar* tes_tested = "#version 430 core\n"
17615                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17616                                                                           "\n"
17617                                                                           "layout(isolines, point_mode) in;\n"
17618                                                                           "\n"
17619                                                                           "VAR_DEFINITION"
17620                                                                           "\n"
17621                                                                           "in  vec4 tcs_tes[];\n"
17622                                                                           "out vec4 tes_gs;\n"
17623                                                                           "\n"
17624                                                                           "void main()\n"
17625                                                                           "{\n"
17626                                                                           "    vec4 result = tcs_tes[0];\n"
17627                                                                           "\n"
17628                                                                           "VARIABLE_USE"
17629                                                                           "\n"
17630                                                                           "    tes_gs += result;\n"
17631                                                                           "}\n"
17632                                                                           "\n";
17633         static const GLchar* vs = "#version 430 core\n"
17634                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17635                                                           "\n"
17636                                                           "in  vec4 in_vs;\n"
17637                                                           "out vec4 vs_tcs;\n"
17638                                                           "\n"
17639                                                           "void main()\n"
17640                                                           "{\n"
17641                                                           "    vs_tcs = in_vs;\n"
17642                                                           "}\n"
17643                                                           "\n";
17644         static const GLchar* vs_tested = "#version 430 core\n"
17645                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17646                                                                          "\n"
17647                                                                          "VAR_DEFINITION"
17648                                                                          "\n"
17649                                                                          "in  vec4 in_vs;\n"
17650                                                                          "out vec4 vs_tcs;\n"
17651                                                                          "\n"
17652                                                                          "void main()\n"
17653                                                                          "{\n"
17654                                                                          "    vec4 result = in_vs;\n"
17655                                                                          "\n"
17656                                                                          "VARIABLE_USE"
17657                                                                          "\n"
17658                                                                          "    vs_tcs += result;\n"
17659                                                                          "}\n"
17660                                                                          "\n";
17661
17662         std::string source;
17663         testCase&   test_case = m_test_cases[test_case_index];
17664
17665         if (test_case.m_stage == stage)
17666         {
17667                 const GLchar*                    array = "";
17668                 GLchar                                   buffer_gohan[16];
17669                 GLchar                                   buffer_goten[16];
17670                 const GLchar*                    direction  = "in ";
17671                 const GLchar*                    flat_gohan = "";
17672                 const GLchar*                    flat_goten = "";
17673                 const GLchar*                    index          = "";
17674                 size_t                                   position   = 0;
17675                 size_t                                   temp;
17676                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17677                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17678                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17679                 const GLchar*                    var_use                 = input_use;
17680
17681                 if (false == test_case.m_is_input)
17682                 {
17683                         direction = "out";
17684                         storage   = Utils::Variable::VARYING_OUTPUT;
17685                         var_use   = output_use;
17686                 }
17687
17688                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17689                 {
17690                         flat_gohan = "flat";
17691                 }
17692
17693                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17694                 {
17695                         flat_goten = "flat";
17696                 }
17697
17698                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17699                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17700
17701                 switch (stage)
17702                 {
17703                 case Utils::Shader::FRAGMENT:
17704                         source = fs_tested;
17705                         break;
17706                 case Utils::Shader::GEOMETRY:
17707                         source = gs_tested;
17708                         array  = "[]";
17709                         index  = "[0]";
17710                         break;
17711                 case Utils::Shader::TESS_CTRL:
17712                         source = tcs_tested;
17713                         array  = "[]";
17714                         index  = "[gl_InvocationID]";
17715                         break;
17716                 case Utils::Shader::TESS_EVAL:
17717                         source = tes_tested;
17718                         array  = "[]";
17719                         index  = "[0]";
17720                         break;
17721                 case Utils::Shader::VERTEX:
17722                         source = vs_tested;
17723                         break;
17724                 default:
17725                         TCU_FAIL("Invalid enum");
17726                 }
17727
17728                 temp = position;
17729                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17730                 position = temp;
17731                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17732                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17733                 Utils::replaceToken("DIRECTION", position, direction, source);
17734                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17735                 Utils::replaceToken("ARRAY", position, array, source);
17736                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17737                 Utils::replaceToken("FLAT", position, flat_goten, source);
17738                 Utils::replaceToken("DIRECTION", position, direction, source);
17739                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17740                 Utils::replaceToken("ARRAY", position, array, source);
17741
17742                 temp = position;
17743                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17744                 position = temp;
17745                 if (true == test_case.m_is_input)
17746                 {
17747                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17748                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17749                 }
17750                 else
17751                 {
17752                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17753                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17754                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17755                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17756                 }
17757
17758                 Utils::replaceAllTokens("INDEX", index, source);
17759         }
17760         else
17761         {
17762                 switch (stage)
17763                 {
17764                 case Utils::Shader::FRAGMENT:
17765                         source = fs;
17766                         break;
17767                 case Utils::Shader::GEOMETRY:
17768                         source = gs;
17769                         break;
17770                 case Utils::Shader::TESS_CTRL:
17771                         source = tcs;
17772                         break;
17773                 case Utils::Shader::TESS_EVAL:
17774                         source = tes;
17775                         break;
17776                 case Utils::Shader::VERTEX:
17777                         source = vs;
17778                         break;
17779                 default:
17780                         TCU_FAIL("Invalid enum");
17781                 }
17782         }
17783
17784         return source;
17785 }
17786
17787 /** Get description of test case
17788  *
17789  * @param test_case_index Index of test case
17790  *
17791  * @return Test case description
17792  **/
17793 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17794 {
17795         std::stringstream stream;
17796         testCase&                 test_case = m_test_cases[test_case_index];
17797
17798         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17799                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17800                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17801
17802         if (true == test_case.m_is_input)
17803         {
17804                 stream << "input";
17805         }
17806         else
17807         {
17808                 stream << "output";
17809         }
17810
17811         return stream.str();
17812 }
17813
17814 /** Get number of test cases
17815  *
17816  * @return Number of test cases
17817  **/
17818 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17819 {
17820         return static_cast<GLuint>(m_test_cases.size());
17821 }
17822
17823 /** Selects if "compute" stage is relevant for test
17824  *
17825  * @param ignored
17826  *
17827  * @return false
17828  **/
17829 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17830 {
17831         return false;
17832 }
17833
17834 /** Prepare all test cases
17835  *
17836  **/
17837 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17838 {
17839         static const GLuint n_components_per_location = 4;
17840         const GLuint            n_types                                   = getTypesNumber();
17841
17842         for (GLuint i = 0; i < n_types; ++i)
17843         {
17844                 const Utils::Type& type_gohan              = getType(i);
17845                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17846
17847                 /* Skip matrices */
17848                 if (1 != type_gohan.m_n_columns)
17849                 {
17850                         continue;
17851                 }
17852
17853                 for (GLuint j = 0; j < n_types; ++j)
17854                 {
17855                         const Utils::Type& type_goten              = getType(j);
17856                         const bool                 is_float_type_goten = isFloatType(type_goten);
17857
17858                         /* Skip matrices */
17859                         if (1 != type_goten.m_n_columns)
17860                         {
17861                                 continue;
17862                         }
17863
17864                         /* Skip valid combinations */
17865                         if (is_float_type_gohan == is_float_type_goten)
17866                         {
17867                                 continue;
17868                         }
17869
17870                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17871                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17872                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17873                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17874
17875                         /* Skip pairs that cannot fit into one location */
17876                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17877                         {
17878                                 continue;
17879                         }
17880
17881                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17882                         {
17883                                 /* Skip compute shader */
17884                                 if (Utils::Shader::COMPUTE == stage)
17885                                 {
17886                                         continue;
17887                                 }
17888
17889                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17890                                 {
17891                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17892                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17893
17894                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17895                                         const GLuint goten_upper_limit = last_aliasing + 1;
17896
17897                                         /* Compoennets before gohan */
17898                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17899                                         {
17900                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17901                                                                                                   type_gohan, type_goten };
17902                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17903                                                                                                    type_gohan, type_goten };
17904
17905                                                 if (Utils::Shader::VERTEX != stage)
17906                                                         m_test_cases.push_back(test_case_in);
17907
17908                                                 /* Skip double outputs in fragment shader */
17909                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17910                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17911                                                 {
17912                                                         m_test_cases.push_back(test_case_out);
17913                                                 }
17914                                         }
17915
17916                                         /* Components after gohan */
17917                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17918                                         {
17919                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17920                                                                                                   type_gohan, type_goten };
17921                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17922                                                                                                    type_gohan, type_goten };
17923
17924                                                 if (Utils::Shader::VERTEX != stage)
17925                                                         m_test_cases.push_back(test_case_in);
17926
17927                                                 /* Skip double outputs in fragment shader */
17928                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17929                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17930                                                 {
17931                                                         m_test_cases.push_back(test_case_out);
17932                                                 }
17933                                         }
17934                                 }
17935                         }
17936                 }
17937         }
17938 }
17939
17940 /** Check if given type is float
17941  *
17942  * @param type Type in question
17943  *
17944  * @return true if tpye is float, false otherwise
17945  **/
17946 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17947 {
17948         bool is_float = false;
17949
17950         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17951         {
17952                 is_float = true;
17953         }
17954
17955         return is_float;
17956 }
17957
17958 /** Constructor
17959  *
17960  * @param context Test framework context
17961  **/
17962 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17963         deqp::Context& context)
17964         : NegativeTestBase(
17965                   context, "varying_location_aliasing_with_mixed_interpolation",
17966                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17967 {
17968 }
17969
17970 /** Source for given test case and stage
17971  *
17972  * @param test_case_index Index of test case
17973  * @param stage           Shader stage
17974  *
17975  * @return Shader source
17976  **/
17977 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17978                                                                                                                                                            Utils::Shader::STAGES stage)
17979 {
17980         static const GLchar* var_definition =
17981                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17982                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17983         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17984                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17985                                                                          "    {\n"
17986                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17987                                                                          "    }\n";
17988         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17989                                                                           "    gotenINDEX = TYPE(1);\n"
17990                                                                           "    if (vec4(0) == result)\n"
17991                                                                           "    {\n"
17992                                                                           "        gohanINDEX = TYPE(1);\n"
17993                                                                           "        gotenINDEX = TYPE(0);\n"
17994                                                                           "    }\n";
17995         static const GLchar* fs = "#version 430 core\n"
17996                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17997                                                           "\n"
17998                                                           "in  vec4 gs_fs;\n"
17999                                                           "out vec4 fs_out;\n"
18000                                                           "\n"
18001                                                           "void main()\n"
18002                                                           "{\n"
18003                                                           "    fs_out = gs_fs;\n"
18004                                                           "}\n"
18005                                                           "\n";
18006         static const GLchar* fs_tested = "#version 430 core\n"
18007                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18008                                                                          "\n"
18009                                                                          "VAR_DEFINITION"
18010                                                                          "\n"
18011                                                                          "in  vec4 gs_fs;\n"
18012                                                                          "out vec4 fs_out;\n"
18013                                                                          "\n"
18014                                                                          "void main()\n"
18015                                                                          "{\n"
18016                                                                          "    vec4 result = gs_fs;\n"
18017                                                                          "\n"
18018                                                                          "VARIABLE_USE"
18019                                                                          "\n"
18020                                                                          "    fs_out = result;\n"
18021                                                                          "}\n"
18022                                                                          "\n";
18023         static const GLchar* gs = "#version 430 core\n"
18024                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18025                                                           "\n"
18026                                                           "layout(points)                           in;\n"
18027                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18028                                                           "\n"
18029                                                           "in  vec4 tes_gs[];\n"
18030                                                           "out vec4 gs_fs;\n"
18031                                                           "\n"
18032                                                           "void main()\n"
18033                                                           "{\n"
18034                                                           "    gs_fs = tes_gs[0];\n"
18035                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18036                                                           "    EmitVertex();\n"
18037                                                           "    gs_fs = tes_gs[0];\n"
18038                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18039                                                           "    EmitVertex();\n"
18040                                                           "    gs_fs = tes_gs[0];\n"
18041                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18042                                                           "    EmitVertex();\n"
18043                                                           "    gs_fs = tes_gs[0];\n"
18044                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18045                                                           "    EmitVertex();\n"
18046                                                           "}\n"
18047                                                           "\n";
18048         static const GLchar* gs_tested = "#version 430 core\n"
18049                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18050                                                                          "\n"
18051                                                                          "layout(points)                           in;\n"
18052                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18053                                                                          "\n"
18054                                                                          "VAR_DEFINITION"
18055                                                                          "\n"
18056                                                                          "in  vec4 tes_gs[];\n"
18057                                                                          "out vec4 gs_fs;\n"
18058                                                                          "\n"
18059                                                                          "void main()\n"
18060                                                                          "{\n"
18061                                                                          "    vec4 result = tes_gs[0];\n"
18062                                                                          "\n"
18063                                                                          "VARIABLE_USE"
18064                                                                          "\n"
18065                                                                          "    gs_fs = result;\n"
18066                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18067                                                                          "    EmitVertex();\n"
18068                                                                          "    gs_fs = result;\n"
18069                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18070                                                                          "    EmitVertex();\n"
18071                                                                          "    gs_fs = result;\n"
18072                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18073                                                                          "    EmitVertex();\n"
18074                                                                          "    gs_fs = result;\n"
18075                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18076                                                                          "    EmitVertex();\n"
18077                                                                          "}\n"
18078                                                                          "\n";
18079         static const GLchar* tcs = "#version 430 core\n"
18080                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18081                                                            "\n"
18082                                                            "layout(vertices = 1) out;\n"
18083                                                            "\n"
18084                                                            "in  vec4 vs_tcs[];\n"
18085                                                            "out vec4 tcs_tes[];\n"
18086                                                            "\n"
18087                                                            "void main()\n"
18088                                                            "{\n"
18089                                                            "\n"
18090                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18091                                                            "\n"
18092                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18093                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18094                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18095                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18096                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18097                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18098                                                            "}\n"
18099                                                            "\n";
18100         static const GLchar* tcs_tested = "#version 430 core\n"
18101                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18102                                                                           "\n"
18103                                                                           "layout(vertices = 1) out;\n"
18104                                                                           "\n"
18105                                                                           "VAR_DEFINITION"
18106                                                                           "\n"
18107                                                                           "in  vec4 vs_tcs[];\n"
18108                                                                           "out vec4 tcs_tes[];\n"
18109                                                                           "\n"
18110                                                                           "void main()\n"
18111                                                                           "{\n"
18112                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18113                                                                           "\n"
18114                                                                           "VARIABLE_USE"
18115                                                                           "\n"
18116                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18117                                                                           "\n"
18118                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18119                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18120                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18121                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18122                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18123                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18124                                                                           "}\n"
18125                                                                           "\n";
18126         static const GLchar* tes = "#version 430 core\n"
18127                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18128                                                            "\n"
18129                                                            "layout(isolines, point_mode) in;\n"
18130                                                            "\n"
18131                                                            "in  vec4 tcs_tes[];\n"
18132                                                            "out vec4 tes_gs;\n"
18133                                                            "\n"
18134                                                            "void main()\n"
18135                                                            "{\n"
18136                                                            "    tes_gs = tcs_tes[0];\n"
18137                                                            "}\n"
18138                                                            "\n";
18139         static const GLchar* tes_tested = "#version 430 core\n"
18140                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18141                                                                           "\n"
18142                                                                           "layout(isolines, point_mode) in;\n"
18143                                                                           "\n"
18144                                                                           "VAR_DEFINITION"
18145                                                                           "\n"
18146                                                                           "in  vec4 tcs_tes[];\n"
18147                                                                           "out vec4 tes_gs;\n"
18148                                                                           "\n"
18149                                                                           "void main()\n"
18150                                                                           "{\n"
18151                                                                           "    vec4 result = tcs_tes[0];\n"
18152                                                                           "\n"
18153                                                                           "VARIABLE_USE"
18154                                                                           "\n"
18155                                                                           "    tes_gs += result;\n"
18156                                                                           "}\n"
18157                                                                           "\n";
18158         static const GLchar* vs = "#version 430 core\n"
18159                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18160                                                           "\n"
18161                                                           "in  vec4 in_vs;\n"
18162                                                           "out vec4 vs_tcs;\n"
18163                                                           "\n"
18164                                                           "void main()\n"
18165                                                           "{\n"
18166                                                           "    vs_tcs = in_vs;\n"
18167                                                           "}\n"
18168                                                           "\n";
18169         static const GLchar* vs_tested = "#version 430 core\n"
18170                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18171                                                                          "\n"
18172                                                                          "VAR_DEFINITION"
18173                                                                          "\n"
18174                                                                          "in  vec4 in_vs;\n"
18175                                                                          "out vec4 vs_tcs;\n"
18176                                                                          "\n"
18177                                                                          "void main()\n"
18178                                                                          "{\n"
18179                                                                          "    vec4 result = in_vs;\n"
18180                                                                          "\n"
18181                                                                          "VARIABLE_USE"
18182                                                                          "\n"
18183                                                                          "    vs_tcs += result;\n"
18184                                                                          "}\n"
18185                                                                          "\n";
18186
18187         std::string source;
18188         testCase&   test_case = m_test_cases[test_case_index];
18189
18190         if (test_case.m_stage == stage)
18191         {
18192                 const GLchar* array = "";
18193                 GLchar            buffer_gohan[16];
18194                 GLchar            buffer_goten[16];
18195                 const GLchar* direction = "in ";
18196                 const GLchar* index             = "";
18197                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18198                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18199                 size_t            position  = 0;
18200                 size_t            temp;
18201                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18202                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18203                 const GLchar* var_use             = input_use;
18204
18205                 if (false == test_case.m_is_input)
18206                 {
18207                         direction = "out";
18208
18209                         var_use = output_use;
18210                 }
18211
18212                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18213                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18214
18215                 switch (stage)
18216                 {
18217                 case Utils::Shader::FRAGMENT:
18218                         source = fs_tested;
18219                         break;
18220                 case Utils::Shader::GEOMETRY:
18221                         source = gs_tested;
18222                         array  = "[]";
18223                         index  = "[0]";
18224                         break;
18225                 case Utils::Shader::TESS_CTRL:
18226                         source = tcs_tested;
18227                         array  = "[]";
18228                         index  = "[gl_InvocationID]";
18229                         break;
18230                 case Utils::Shader::TESS_EVAL:
18231                         source = tes_tested;
18232                         array  = "[]";
18233                         index  = "[0]";
18234                         break;
18235                 case Utils::Shader::VERTEX:
18236                         source = vs_tested;
18237                         break;
18238                 default:
18239                         TCU_FAIL("Invalid enum");
18240                 }
18241
18242                 temp = position;
18243                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18244                 position = temp;
18245                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18246                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18247                 Utils::replaceToken("DIRECTION", position, direction, source);
18248                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18249                 Utils::replaceToken("ARRAY", position, array, source);
18250                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18251                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18252                 Utils::replaceToken("DIRECTION", position, direction, source);
18253                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18254                 Utils::replaceToken("ARRAY", position, array, source);
18255
18256                 temp = position;
18257                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18258                 position = temp;
18259                 if (true == test_case.m_is_input)
18260                 {
18261                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18262                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18263                 }
18264                 else
18265                 {
18266                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18267                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18268                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18269                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18270                 }
18271
18272                 Utils::replaceAllTokens("INDEX", index, source);
18273         }
18274         else
18275         {
18276                 switch (stage)
18277                 {
18278                 case Utils::Shader::FRAGMENT:
18279                         source = fs;
18280                         break;
18281                 case Utils::Shader::GEOMETRY:
18282                         source = gs;
18283                         break;
18284                 case Utils::Shader::TESS_CTRL:
18285                         source = tcs;
18286                         break;
18287                 case Utils::Shader::TESS_EVAL:
18288                         source = tes;
18289                         break;
18290                 case Utils::Shader::VERTEX:
18291                         source = vs;
18292                         break;
18293                 default:
18294                         TCU_FAIL("Invalid enum");
18295                 }
18296         }
18297
18298         return source;
18299 }
18300
18301 /** Get description of test case
18302  *
18303  * @param test_case_index Index of test case
18304  *
18305  * @return Test case description
18306  **/
18307 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18308 {
18309         std::stringstream stream;
18310         testCase&                 test_case = m_test_cases[test_case_index];
18311
18312         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18313                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18314                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18315                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18316                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18317
18318         if (true == test_case.m_is_input)
18319         {
18320                 stream << "input";
18321         }
18322         else
18323         {
18324                 stream << "output";
18325         }
18326
18327         return stream.str();
18328 }
18329
18330 /** Get number of test cases
18331  *
18332  * @return Number of test cases
18333  **/
18334 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18335 {
18336         return static_cast<GLuint>(m_test_cases.size());
18337 }
18338
18339 /** Selects if "compute" stage is relevant for test
18340  *
18341  * @param ignored
18342  *
18343  * @return false
18344  **/
18345 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18346 {
18347         return false;
18348 }
18349
18350 /** Prepare all test cases
18351  *
18352  **/
18353 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18354 {
18355         static const GLuint n_components_per_location = 4;
18356         const GLuint            n_types                                   = getTypesNumber();
18357
18358         for (GLuint i = 0; i < n_types; ++i)
18359         {
18360                 const Utils::Type& type_gohan              = getType(i);
18361                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18362
18363                 /* Skip matrices */
18364                 if (1 != type_gohan.m_n_columns)
18365                 {
18366                         continue;
18367                 }
18368
18369                 for (GLuint j = 0; j < n_types; ++j)
18370                 {
18371                         const Utils::Type& type_goten              = getType(j);
18372                         const bool                 is_float_type_goten = isFloatType(type_goten);
18373
18374                         /* Skip matrices */
18375                         if (1 != type_goten.m_n_columns)
18376                         {
18377                                 continue;
18378                         }
18379
18380                         /* Skip invalid combinations */
18381                         if (is_float_type_gohan != is_float_type_goten)
18382                         {
18383                                 continue;
18384                         }
18385
18386                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18387                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18388
18389                         /* Skip pairs that cannot fit into one location */
18390                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18391                         {
18392                                 continue;
18393                         }
18394
18395                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18396                         {
18397                                 /* Skip compute shader */
18398                                 if (Utils::Shader::COMPUTE == stage)
18399                                 {
18400                                         continue;
18401                                 }
18402
18403                                 const GLuint gohan = 0;
18404                                 const GLuint goten = gohan + n_req_components_gohan;
18405
18406                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18407                                 {
18408                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18409                                         {
18410                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18411                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18412                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18413                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18414                                                 const bool is_gohan_accepted_as_fs_in =
18415                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18416                                                 const bool is_goten_accepted_as_fs_in =
18417                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18418                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18419
18420                                                 /* Skip when both are the same */
18421                                                 if (int_gohan == int_goten)
18422                                                 {
18423                                                         continue;
18424                                                 }
18425
18426                                                 testCase test_case_in = { gohan,
18427                                                                                                   goten,
18428                                                                                                   (INTERPOLATIONS)int_gohan,
18429                                                                                                   (INTERPOLATIONS)int_goten,
18430                                                                                                   true,
18431                                                                                                   (Utils::Shader::STAGES)stage,
18432                                                                                                   type_gohan,
18433                                                                                                   type_goten };
18434
18435                                                 testCase test_case_out = { gohan,
18436                                                                                                    goten,
18437                                                                                                    (INTERPOLATIONS)int_gohan,
18438                                                                                                    (INTERPOLATIONS)int_goten,
18439                                                                                                    false,
18440                                                                                                    (Utils::Shader::STAGES)stage,
18441                                                                                                    type_gohan,
18442                                                                                                    type_goten };
18443
18444                                                 /* Skip inputs in:
18445                                                  * vertex shader,
18446                                                  * fragment shader when not flat double is used
18447                                                  */
18448                                                 if ((Utils::Shader::VERTEX != stage) &&
18449                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18450                                                 {
18451                                                         m_test_cases.push_back(test_case_in);
18452                                                 }
18453
18454                                                 /* Skip outputs in fragment shader */
18455                                                 if (Utils::Shader::FRAGMENT != stage)
18456                                                 {
18457                                                         m_test_cases.push_back(test_case_out);
18458                                                 }
18459                                         }
18460                                 }
18461                         }
18462                 }
18463         }
18464 }
18465
18466 /** Get interpolation qualifier
18467  *
18468  * @param interpolation Enumeration
18469  *
18470  * @return GLSL qualifier
18471  **/
18472 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18473 {
18474         const GLchar* result = 0;
18475
18476         switch (interpolation)
18477         {
18478         case SMOOTH:
18479                 result = "smooth";
18480                 break;
18481         case FLAT:
18482                 result = "flat";
18483                 break;
18484         case NO_PERSPECTIVE:
18485                 result = "noperspective";
18486                 break;
18487         default:
18488                 TCU_FAIL("Invalid enum");
18489         }
18490
18491         return result;
18492 }
18493
18494 /** Check if given type is float
18495  *
18496  * @param type Type in question
18497  *
18498  * @return true if tpye is float, false otherwise
18499  **/
18500 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18501 {
18502         bool is_float = false;
18503
18504         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18505         {
18506                 is_float = true;
18507         }
18508
18509         return is_float;
18510 }
18511
18512 /** Constructor
18513  *
18514  * @param context Test framework context
18515  **/
18516 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18517         deqp::Context& context)
18518         : NegativeTestBase(
18519                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18520                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18521 {
18522 }
18523
18524 /** Source for given test case and stage
18525  *
18526  * @param test_case_index Index of test case
18527  * @param stage           Shader stage
18528  *
18529  * @return Shader source
18530  **/
18531 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18532                                                                                                                                                                   Utils::Shader::STAGES stage)
18533 {
18534         static const GLchar* var_definition =
18535                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18536                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18537         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18538                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18539                                                                          "    {\n"
18540                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18541                                                                          "    }\n";
18542         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18543                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18544                                                                           "    if (vec4(0) == result)\n"
18545                                                                           "    {\n"
18546                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18547                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18548                                                                           "    }\n";
18549         static const GLchar* fs = "#version 430 core\n"
18550                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18551                                                           "\n"
18552                                                           "in  vec4 gs_fs;\n"
18553                                                           "out vec4 fs_out;\n"
18554                                                           "\n"
18555                                                           "void main()\n"
18556                                                           "{\n"
18557                                                           "    fs_out = gs_fs;\n"
18558                                                           "}\n"
18559                                                           "\n";
18560         static const GLchar* fs_tested = "#version 430 core\n"
18561                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18562                                                                          "\n"
18563                                                                          "VAR_DEFINITION"
18564                                                                          "\n"
18565                                                                          "in  vec4 gs_fs;\n"
18566                                                                          "out vec4 fs_out;\n"
18567                                                                          "\n"
18568                                                                          "void main()\n"
18569                                                                          "{\n"
18570                                                                          "    vec4 result = gs_fs;\n"
18571                                                                          "\n"
18572                                                                          "VARIABLE_USE"
18573                                                                          "\n"
18574                                                                          "    fs_out = result;\n"
18575                                                                          "}\n"
18576                                                                          "\n";
18577         static const GLchar* gs = "#version 430 core\n"
18578                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18579                                                           "\n"
18580                                                           "layout(points)                           in;\n"
18581                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18582                                                           "\n"
18583                                                           "in  vec4 tes_gs[];\n"
18584                                                           "out vec4 gs_fs;\n"
18585                                                           "\n"
18586                                                           "void main()\n"
18587                                                           "{\n"
18588                                                           "    gs_fs = tes_gs[0];\n"
18589                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18590                                                           "    EmitVertex();\n"
18591                                                           "    gs_fs = tes_gs[0];\n"
18592                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18593                                                           "    EmitVertex();\n"
18594                                                           "    gs_fs = tes_gs[0];\n"
18595                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18596                                                           "    EmitVertex();\n"
18597                                                           "    gs_fs = tes_gs[0];\n"
18598                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18599                                                           "    EmitVertex();\n"
18600                                                           "}\n"
18601                                                           "\n";
18602         static const GLchar* gs_tested = "#version 430 core\n"
18603                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18604                                                                          "\n"
18605                                                                          "layout(points)                           in;\n"
18606                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18607                                                                          "\n"
18608                                                                          "VAR_DEFINITION"
18609                                                                          "\n"
18610                                                                          "in  vec4 tes_gs[];\n"
18611                                                                          "out vec4 gs_fs;\n"
18612                                                                          "\n"
18613                                                                          "void main()\n"
18614                                                                          "{\n"
18615                                                                          "    vec4 result = tes_gs[0];\n"
18616                                                                          "\n"
18617                                                                          "VARIABLE_USE"
18618                                                                          "\n"
18619                                                                          "    gs_fs = result;\n"
18620                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18621                                                                          "    EmitVertex();\n"
18622                                                                          "    gs_fs = result;\n"
18623                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18624                                                                          "    EmitVertex();\n"
18625                                                                          "    gs_fs = result;\n"
18626                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18627                                                                          "    EmitVertex();\n"
18628                                                                          "    gs_fs = result;\n"
18629                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18630                                                                          "    EmitVertex();\n"
18631                                                                          "}\n"
18632                                                                          "\n";
18633         static const GLchar* tcs = "#version 430 core\n"
18634                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18635                                                            "\n"
18636                                                            "layout(vertices = 1) out;\n"
18637                                                            "\n"
18638                                                            "in  vec4 vs_tcs[];\n"
18639                                                            "out vec4 tcs_tes[];\n"
18640                                                            "\n"
18641                                                            "void main()\n"
18642                                                            "{\n"
18643                                                            "\n"
18644                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18645                                                            "\n"
18646                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18647                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18648                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18649                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18650                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18651                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18652                                                            "}\n"
18653                                                            "\n";
18654         static const GLchar* tcs_tested = "#version 430 core\n"
18655                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18656                                                                           "\n"
18657                                                                           "layout(vertices = 1) out;\n"
18658                                                                           "\n"
18659                                                                           "VAR_DEFINITION"
18660                                                                           "\n"
18661                                                                           "in  vec4 vs_tcs[];\n"
18662                                                                           "out vec4 tcs_tes[];\n"
18663                                                                           "\n"
18664                                                                           "void main()\n"
18665                                                                           "{\n"
18666                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18667                                                                           "\n"
18668                                                                           "VARIABLE_USE"
18669                                                                           "\n"
18670                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18671                                                                           "\n"
18672                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18673                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18674                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18675                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18676                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18677                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18678                                                                           "}\n"
18679                                                                           "\n";
18680         static const GLchar* tes = "#version 430 core\n"
18681                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18682                                                            "\n"
18683                                                            "layout(isolines, point_mode) in;\n"
18684                                                            "\n"
18685                                                            "in  vec4 tcs_tes[];\n"
18686                                                            "out vec4 tes_gs;\n"
18687                                                            "\n"
18688                                                            "void main()\n"
18689                                                            "{\n"
18690                                                            "    tes_gs = tcs_tes[0];\n"
18691                                                            "}\n"
18692                                                            "\n";
18693         static const GLchar* tes_tested = "#version 430 core\n"
18694                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18695                                                                           "\n"
18696                                                                           "layout(isolines, point_mode) in;\n"
18697                                                                           "\n"
18698                                                                           "VAR_DEFINITION"
18699                                                                           "\n"
18700                                                                           "in  vec4 tcs_tes[];\n"
18701                                                                           "out vec4 tes_gs;\n"
18702                                                                           "\n"
18703                                                                           "void main()\n"
18704                                                                           "{\n"
18705                                                                           "    vec4 result = tcs_tes[0];\n"
18706                                                                           "\n"
18707                                                                           "VARIABLE_USE"
18708                                                                           "\n"
18709                                                                           "    tes_gs += result;\n"
18710                                                                           "}\n"
18711                                                                           "\n";
18712         static const GLchar* vs = "#version 430 core\n"
18713                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18714                                                           "\n"
18715                                                           "in  vec4 in_vs;\n"
18716                                                           "out vec4 vs_tcs;\n"
18717                                                           "\n"
18718                                                           "void main()\n"
18719                                                           "{\n"
18720                                                           "    vs_tcs = in_vs;\n"
18721                                                           "}\n"
18722                                                           "\n";
18723         static const GLchar* vs_tested = "#version 430 core\n"
18724                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18725                                                                          "\n"
18726                                                                          "VAR_DEFINITION"
18727                                                                          "\n"
18728                                                                          "in  vec4 in_vs;\n"
18729                                                                          "out vec4 vs_tcs;\n"
18730                                                                          "\n"
18731                                                                          "void main()\n"
18732                                                                          "{\n"
18733                                                                          "    vec4 result = in_vs;\n"
18734                                                                          "\n"
18735                                                                          "VARIABLE_USE"
18736                                                                          "\n"
18737                                                                          "    vs_tcs += result;\n"
18738                                                                          "}\n"
18739                                                                          "\n";
18740
18741         std::string source;
18742         testCase&   test_case = m_test_cases[test_case_index];
18743
18744         if (test_case.m_stage == stage)
18745         {
18746                 const GLchar* array_gohan = "";
18747                 const GLchar* array_goten = "";
18748                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18749                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18750                 GLchar            buffer_gohan[16];
18751                 GLchar            buffer_goten[16];
18752                 const GLchar* direction   = "in ";
18753                 const GLchar* index_gohan = "";
18754                 const GLchar* index_goten = "";
18755                 const GLchar* int_gohan   = test_case.m_int_gohan;
18756                 const GLchar* int_goten   = test_case.m_int_goten;
18757                 size_t            position      = 0;
18758                 size_t            temp;
18759                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18760                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18761                 const GLchar* var_use             = input_use;
18762
18763                 if (false == test_case.m_is_input)
18764                 {
18765                         direction = "out";
18766
18767                         var_use = output_use;
18768                 }
18769
18770                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18771                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18772
18773                 switch (stage)
18774                 {
18775                 case Utils::Shader::FRAGMENT:
18776                         source = fs_tested;
18777                         break;
18778                 case Utils::Shader::GEOMETRY:
18779                         source          = gs_tested;
18780                         array_gohan = "[]";
18781                         index_gohan = "[0]";
18782                         array_goten = "[]";
18783                         index_goten = "[0]";
18784                         break;
18785                 case Utils::Shader::TESS_CTRL:
18786                         source = tcs_tested;
18787                         if (PATCH != test_case.m_aux_gohan)
18788                         {
18789                                 array_gohan = "[]";
18790                                 index_gohan = "[gl_InvocationID]";
18791                         }
18792                         if (PATCH != test_case.m_aux_goten)
18793                         {
18794                                 array_goten = "[]";
18795                                 index_goten = "[gl_InvocationID]";
18796                         }
18797                         break;
18798                 case Utils::Shader::TESS_EVAL:
18799                         source          = tes_tested;
18800                         array_gohan = "[]";
18801                         index_gohan = "[0]";
18802                         array_goten = "[]";
18803                         index_goten = "[0]";
18804                         break;
18805                 case Utils::Shader::VERTEX:
18806                         source = vs_tested;
18807                         break;
18808                 default:
18809                         TCU_FAIL("Invalid enum");
18810                 }
18811
18812                 temp = position;
18813                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18814                 position = temp;
18815                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18816                 Utils::replaceToken("AUX", position, aux_gohan, source);
18817                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18818                 Utils::replaceToken("DIRECTION", position, direction, source);
18819                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18820                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18821                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18822                 Utils::replaceToken("AUX", position, aux_goten, source);
18823                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18824                 Utils::replaceToken("DIRECTION", position, direction, source);
18825                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18826                 Utils::replaceToken("ARRAY", position, array_goten, source);
18827
18828                 temp = position;
18829                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18830                 position = temp;
18831                 if (true == test_case.m_is_input)
18832                 {
18833                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18834                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18835                 }
18836                 else
18837                 {
18838                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18839                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18840                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18841                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18842                 }
18843
18844                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18845                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18846         }
18847         else
18848         {
18849                 switch (stage)
18850                 {
18851                 case Utils::Shader::FRAGMENT:
18852                         source = fs;
18853                         break;
18854                 case Utils::Shader::GEOMETRY:
18855                         source = gs;
18856                         break;
18857                 case Utils::Shader::TESS_CTRL:
18858                         source = tcs;
18859                         break;
18860                 case Utils::Shader::TESS_EVAL:
18861                         source = tes;
18862                         break;
18863                 case Utils::Shader::VERTEX:
18864                         source = vs;
18865                         break;
18866                 default:
18867                         TCU_FAIL("Invalid enum");
18868                 }
18869         }
18870
18871         return source;
18872 }
18873
18874 /** Get description of test case
18875  *
18876  * @param test_case_index Index of test case
18877  *
18878  * @return Test case description
18879  **/
18880 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18881 {
18882         std::stringstream stream;
18883         testCase&                 test_case = m_test_cases[test_case_index];
18884
18885         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18886                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18887                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18888                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18889
18890         if (true == test_case.m_is_input)
18891         {
18892                 stream << "input";
18893         }
18894         else
18895         {
18896                 stream << "output";
18897         }
18898
18899         return stream.str();
18900 }
18901
18902 /** Get number of test cases
18903  *
18904  * @return Number of test cases
18905  **/
18906 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18907 {
18908         return static_cast<GLuint>(m_test_cases.size());
18909 }
18910
18911 /** Selects if "compute" stage is relevant for test
18912  *
18913  * @param ignored
18914  *
18915  * @return false
18916  **/
18917 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18918 {
18919         return false;
18920 }
18921
18922 /** Prepare all test cases
18923  *
18924  **/
18925 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18926 {
18927         static const GLuint n_components_per_location = 4;
18928         const GLuint            n_types                                   = getTypesNumber();
18929
18930         for (GLuint i = 0; i < n_types; ++i)
18931         {
18932                 const Utils::Type& type_gohan              = getType(i);
18933                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18934
18935                 /* Skip matrices */
18936                 if (1 != type_gohan.m_n_columns)
18937                 {
18938                         continue;
18939                 }
18940
18941                 for (GLuint j = 0; j < n_types; ++j)
18942                 {
18943                         const Utils::Type& type_goten              = getType(j);
18944                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18945                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18946                         const bool                 is_float_type_goten = isFloatType(type_goten);
18947
18948                         /* Skip matrices */
18949                         if (1 != type_goten.m_n_columns)
18950                         {
18951                                 continue;
18952                         }
18953
18954                         /* Skip invalid combinations */
18955                         if (is_float_type_gohan != is_float_type_goten)
18956                         {
18957                                 continue;
18958                         }
18959
18960                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18961                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18962
18963                         /* Skip pairs that cannot fit into one location */
18964                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18965                         {
18966                                 continue;
18967                         }
18968
18969                         const GLuint gohan = 0;
18970                         const GLuint goten = gohan + n_req_components_gohan;
18971
18972                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18973                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18974
18975                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18976                                                                                   type_gohan, type_goten };
18977
18978                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18979                                                                                   type_gohan, type_goten };
18980
18981                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18982                                                                                   type_gohan, type_goten };
18983
18984                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18985                                                                                   type_gohan, type_goten };
18986
18987                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18988                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18989                                                                                  type_gohan,   type_goten };
18990
18991                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18992                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18993                                                                                  type_gohan,   type_goten };
18994
18995                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18996                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18997                                                                                  type_gohan,   type_goten };
18998
18999                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
19000                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
19001                                                                                  type_gohan,   type_goten };
19002
19003                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
19004                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
19005                                                                                  type_gohan,   type_goten };
19006
19007                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
19008                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
19009                                                                                  type_gohan,   type_goten };
19010
19011                         m_test_cases.push_back(test_case_tcs_np);
19012                         m_test_cases.push_back(test_case_tcs_pn);
19013                         m_test_cases.push_back(test_case_tes_np);
19014                         m_test_cases.push_back(test_case_tes_pn);
19015                         m_test_cases.push_back(test_case_fs_nc);
19016                         m_test_cases.push_back(test_case_fs_cn);
19017                         m_test_cases.push_back(test_case_fs_ns);
19018                         m_test_cases.push_back(test_case_fs_sn);
19019                         m_test_cases.push_back(test_case_fs_cs);
19020                         m_test_cases.push_back(test_case_fs_sc);
19021                 }
19022         }
19023 }
19024
19025 /** Get auxiliary storage qualifier
19026  *
19027  * @param aux Enumeration
19028  *
19029  * @return GLSL qualifier
19030  **/
19031 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
19032 {
19033         const GLchar* result = 0;
19034
19035         switch (aux)
19036         {
19037         case NONE:
19038                 result = "";
19039                 break;
19040         case PATCH:
19041                 result = "patch";
19042                 break;
19043         case CENTROID:
19044                 result = "centroid";
19045                 break;
19046         case SAMPLE:
19047                 result = "sample";
19048                 break;
19049         default:
19050                 TCU_FAIL("Invalid enum");
19051         }
19052
19053         return result;
19054 }
19055
19056 /** Check if given type is float
19057  *
19058  * @param type Type in question
19059  *
19060  * @return true if tpye is float, false otherwise
19061  **/
19062 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
19063 {
19064         bool is_float = false;
19065
19066         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
19067         {
19068                 is_float = true;
19069         }
19070
19071         return is_float;
19072 }
19073
19074 /* Constants used by VertexAttribLocationAPITest */
19075 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
19076
19077 /** Constructor
19078  *
19079  * @param context Test framework context
19080  **/
19081 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
19082         : TextureTestBase(context, "vertex_attrib_location_api",
19083                                           "Test verifies that attribute locations API works as expected")
19084 {
19085 }
19086
19087 /** Does BindAttribLocation for "goten" and relink program
19088  *
19089  * @param program           Program object
19090  * @param program_interface Interface of program
19091  **/
19092 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
19093                                                                                                                 Utils::ProgramInterface& program_interface)
19094 {
19095         const Functions& gl = m_context.getRenderContext().getFunctions();
19096
19097         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
19098         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
19099
19100         program.Link(gl, program.m_id);
19101
19102         /* We still need to get locations for gohan and chichi */
19103         TextureTestBase::prepareAttribLocation(program, program_interface);
19104 }
19105
19106 /** Get interface of program
19107  *
19108  * @param ignored
19109  * @param program_interface   Interface of program
19110  * @param ignored
19111  **/
19112 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19113                                                                                                           Utils::ProgramInterface& program_interface,
19114                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19115 {
19116         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19117         const Utils::Type&              type      = Utils::Type::vec4;
19118         const GLuint                    type_size = type.GetSize();
19119
19120         /* Offsets */
19121         const GLuint chichi_offset = 0;
19122         const GLuint goten_offset  = chichi_offset + type_size;
19123         const GLuint gohan_offset  = goten_offset + type_size;
19124         const GLuint goku_offset   = gohan_offset + type_size;
19125
19126         /* Locations */
19127         const GLuint goku_location  = 2;
19128         const GLuint goten_location = m_goten_location;
19129
19130         /* Generate data */
19131         m_goku_data   = type.GenerateDataPacked();
19132         m_gohan_data  = type.GenerateDataPacked();
19133         m_goten_data  = type.GenerateDataPacked();
19134         m_chichi_data = type.GenerateDataPacked();
19135
19136         /* Globals */
19137         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19138
19139         /* Attributes */
19140         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19141                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19142                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19143                          m_goku_data.size() /* data_size */);
19144
19145         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19146                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19147                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19148                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19149
19150         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19151                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19152                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19153                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19154
19155         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19156                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19157                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19158                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19159 }
19160
19161 /** Selects if "compute" stage is relevant for test
19162  *
19163  * @param ignored
19164  *
19165  * @return false
19166  **/
19167 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19168 {
19169         return false;
19170 }
19171
19172 /* Constants used by FragmentDataLocationAPITest */
19173 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19174
19175 /** Constructor
19176  *
19177  * @param context Test framework context
19178  **/
19179 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19180         : TextureTestBase(context, "fragment_data_location_api",
19181                                           "Test verifies that fragment data locations API works as expected")
19182         , m_goku(context)
19183         , m_gohan(context)
19184         , m_goten(context)
19185         , m_chichi(context)
19186 {
19187 }
19188
19189 /** Verifies contents of drawn images
19190  *
19191  * @param ignored
19192  * @param ignored
19193  *
19194  * @return true if images are filled with expected values, false otherwise
19195  **/
19196 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19197 {
19198         static const GLuint size                        = m_width * m_height;
19199         static const GLuint expected_goku   = 0xff000000;
19200         static const GLuint expected_gohan  = 0xff0000ff;
19201         static const GLuint expected_goten  = 0xff00ff00;
19202         static const GLuint expected_chichi = 0xffff0000;
19203
19204         std::vector<GLuint> data;
19205         data.resize(size);
19206
19207         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19208
19209         for (GLuint i = 0; i < size; ++i)
19210         {
19211                 const GLuint color = data[i];
19212
19213                 if (expected_goku != color)
19214                 {
19215                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19216                                                                                                 << tcu::TestLog::EndMessage;
19217                         return false;
19218                 }
19219         }
19220
19221         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19222
19223         for (GLuint i = 0; i < size; ++i)
19224         {
19225                 const GLuint color = data[i];
19226
19227                 if (expected_gohan != color)
19228                 {
19229                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19230                                                                                                 << tcu::TestLog::EndMessage;
19231                         return false;
19232                 }
19233         }
19234
19235         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19236
19237         for (GLuint i = 0; i < size; ++i)
19238         {
19239                 const GLuint color = data[i];
19240
19241                 if (expected_goten != color)
19242                 {
19243                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19244                                                                                                 << tcu::TestLog::EndMessage;
19245                         return false;
19246                 }
19247         }
19248
19249         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19250
19251         for (GLuint i = 0; i < size; ++i)
19252         {
19253                 const GLuint color = data[i];
19254
19255                 if (expected_chichi != color)
19256                 {
19257                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19258                                                                                                 << tcu::TestLog::EndMessage;
19259                         return false;
19260                 }
19261         }
19262
19263         return true;
19264 }
19265
19266 /** Prepare code snippet that will set out variables
19267  *
19268  * @param ignored
19269  * @param ignored
19270  * @param stage               Shader stage
19271  *
19272  * @return Code that pass in variables to next stage
19273  **/
19274 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19275                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19276                                                                                                                 Utils::Shader::STAGES stage)
19277 {
19278         std::string result;
19279
19280         /* Skip for compute shader */
19281         if (Utils::Shader::FRAGMENT != stage)
19282         {
19283                 result = "";
19284         }
19285         else
19286         {
19287                 result = "chichi = vec4(0, 0, 1, 1);\n"
19288                                  "    goku   = vec4(0, 0, 0, 1);\n"
19289                                  "    goten  = vec4(0, 1, 0, 1);\n"
19290                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19291         }
19292
19293         return result;
19294 }
19295
19296 /** Get interface of program
19297  *
19298  * @param ignored
19299  * @param program_interface Interface of program
19300  * @param ignored
19301  **/
19302 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19303                                                                                                           Utils::ProgramInterface& program_interface,
19304                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19305 {
19306         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19307         const Utils::Type&              type = Utils::Type::vec4;
19308
19309         /* Locations */
19310         m_goku_location = 2;
19311
19312         /* Globals */
19313         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19314
19315         /* Attributes */
19316         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19317                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19318                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19319
19320         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19321                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19322                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19323
19324         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19325                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19326                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19327
19328         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19329                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19330                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19331 }
19332
19333 /** Selects if "compute" stage is relevant for test
19334  *
19335  * @param ignored
19336  *
19337  * @return false
19338  **/
19339 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19340 {
19341         return false;
19342 }
19343
19344 /** Get locations for all outputs with automatic_location
19345  *
19346  * @param program           Program object
19347  * @param program_interface Interface of program
19348  **/
19349 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19350                                                                                                                  Utils::ProgramInterface& program_interface)
19351 {
19352         /* Bind location of goten */
19353         const Functions& gl = m_context.getRenderContext().getFunctions();
19354
19355         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19356         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19357
19358         program.Link(gl, program.m_id);
19359
19360         /* Prepare locations for gohan and chichi */
19361         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19362
19363         /* Get all locations */
19364         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19365
19366         Utils::Variable::PtrVector& outputs = si.m_outputs;
19367
19368         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19369         {
19370                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19371
19372                 if (0 == desc.m_name.compare("gohan"))
19373                 {
19374                         m_gohan_location = desc.m_expected_location;
19375                 }
19376                 else if (0 == desc.m_name.compare("chichi"))
19377                 {
19378                         m_chichi_location = desc.m_expected_location;
19379                 }
19380
19381                 /* Locations of goku and goten are fixed */
19382         }
19383 }
19384
19385 /** Prepare framebuffer with single texture as color attachment
19386  *
19387  * @param framebuffer     Framebuffer
19388  * @param color_0_texture Texture that will used as color attachment
19389  **/
19390 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19391 {
19392         /* Let parent prepare its stuff */
19393         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19394
19395         /* Prepare data */
19396         std::vector<GLuint> texture_data;
19397         texture_data.resize(m_width * m_height);
19398
19399         for (GLuint i = 0; i < texture_data.size(); ++i)
19400         {
19401                 texture_data[i] = 0x20406080;
19402         }
19403
19404         /* Prepare textures */
19405         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19406
19407         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19408
19409         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19410
19411         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19412
19413         /* Attach textures to framebuffer */
19414         framebuffer.Bind();
19415         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19416         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19417         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19418         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19419
19420         /* Set up drawbuffers */
19421         const Functions& gl = m_context.getRenderContext().getFunctions();
19422         // The fragment shader can have more than 4 color outputs, but it only care about 4 (goku, gohan, goten, chichi).
19423         // We will first initialize all draw buffers to NONE and then set the real value for the 4 outputs we care about
19424         GLint maxDrawBuffers = 0;
19425         gl.getIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
19426
19427         std::vector<GLenum> buffers(maxDrawBuffers, GL_NONE);
19428         buffers[m_chichi_location] = GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location);
19429         buffers[m_goten_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location);
19430         buffers[m_goku_location]   = GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location);
19431         buffers[m_gohan_location]  = GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location);
19432
19433         gl.drawBuffers(maxDrawBuffers, buffers.data());
19434         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19435 }
19436
19437 /** Constructor
19438  *
19439  * @param context Test framework context
19440  **/
19441 XFBInputTest::XFBInputTest(deqp::Context& context)
19442         : NegativeTestBase(context, "xfb_input",
19443                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19444 {
19445 }
19446
19447 /** Source for given test case and stage
19448  *
19449  * @param test_case_index Index of test case
19450  * @param stage           Shader stage
19451  *
19452  * @return Shader source
19453  **/
19454 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19455 {
19456         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19457         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19458         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19459         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19460         static const GLchar* fs                                    = "#version 430 core\n"
19461                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19462                                                           "\n"
19463                                                           "in  vec4 gs_fs;\n"
19464                                                           "out vec4 fs_out;\n"
19465                                                           "\n"
19466                                                           "void main()\n"
19467                                                           "{\n"
19468                                                           "    fs_out = gs_fs;\n"
19469                                                           "}\n"
19470                                                           "\n";
19471         static const GLchar* fs_tested = "#version 430 core\n"
19472                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19473                                                                          "\n"
19474                                                                          "VAR_DEFINITION"
19475                                                                          "\n"
19476                                                                          "in  vec4 gs_fs;\n"
19477                                                                          "out vec4 fs_out;\n"
19478                                                                          "\n"
19479                                                                          "void main()\n"
19480                                                                          "{\n"
19481                                                                          "    vec4 result = gs_fs;\n"
19482                                                                          "\n"
19483                                                                          "VARIABLE_USE"
19484                                                                          "\n"
19485                                                                          "    fs_out = result;\n"
19486                                                                          "}\n"
19487                                                                          "\n";
19488         static const GLchar* gs = "#version 430 core\n"
19489                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19490                                                           "\n"
19491                                                           "layout(points)                           in;\n"
19492                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19493                                                           "\n"
19494                                                           "in  vec4 tes_gs[];\n"
19495                                                           "out vec4 gs_fs;\n"
19496                                                           "\n"
19497                                                           "void main()\n"
19498                                                           "{\n"
19499                                                           "    gs_fs = tes_gs[0];\n"
19500                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19501                                                           "    EmitVertex();\n"
19502                                                           "    gs_fs = tes_gs[0];\n"
19503                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19504                                                           "    EmitVertex();\n"
19505                                                           "    gs_fs = tes_gs[0];\n"
19506                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19507                                                           "    EmitVertex();\n"
19508                                                           "    gs_fs = tes_gs[0];\n"
19509                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19510                                                           "    EmitVertex();\n"
19511                                                           "}\n"
19512                                                           "\n";
19513         static const GLchar* gs_tested = "#version 430 core\n"
19514                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19515                                                                          "\n"
19516                                                                          "layout(points)                           in;\n"
19517                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19518                                                                          "\n"
19519                                                                          "VAR_DEFINITION"
19520                                                                          "\n"
19521                                                                          "in  vec4 tes_gs[];\n"
19522                                                                          "out vec4 gs_fs;\n"
19523                                                                          "\n"
19524                                                                          "void main()\n"
19525                                                                          "{\n"
19526                                                                          "    vec4 result = tes_gs[0];\n"
19527                                                                          "\n"
19528                                                                          "VARIABLE_USE"
19529                                                                          "\n"
19530                                                                          "    gs_fs = result;\n"
19531                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19532                                                                          "    EmitVertex();\n"
19533                                                                          "    gs_fs = result;\n"
19534                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19535                                                                          "    EmitVertex();\n"
19536                                                                          "    gs_fs = result;\n"
19537                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19538                                                                          "    EmitVertex();\n"
19539                                                                          "    gs_fs = result;\n"
19540                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19541                                                                          "    EmitVertex();\n"
19542                                                                          "}\n"
19543                                                                          "\n";
19544         static const GLchar* tcs = "#version 430 core\n"
19545                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19546                                                            "\n"
19547                                                            "layout(vertices = 1) out;\n"
19548                                                            "\n"
19549                                                            "in  vec4 vs_tcs[];\n"
19550                                                            "out vec4 tcs_tes[];\n"
19551                                                            "\n"
19552                                                            "void main()\n"
19553                                                            "{\n"
19554                                                            "\n"
19555                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19556                                                            "\n"
19557                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19558                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19559                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19560                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19561                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19562                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19563                                                            "}\n"
19564                                                            "\n";
19565         static const GLchar* tcs_tested = "#version 430 core\n"
19566                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19567                                                                           "\n"
19568                                                                           "layout(vertices = 1) out;\n"
19569                                                                           "\n"
19570                                                                           "VAR_DEFINITION"
19571                                                                           "\n"
19572                                                                           "in  vec4 vs_tcs[];\n"
19573                                                                           "out vec4 tcs_tes[];\n"
19574                                                                           "\n"
19575                                                                           "void main()\n"
19576                                                                           "{\n"
19577                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19578                                                                           "\n"
19579                                                                           "VARIABLE_USE"
19580                                                                           "\n"
19581                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19582                                                                           "\n"
19583                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19584                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19585                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19586                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19587                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19588                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19589                                                                           "}\n"
19590                                                                           "\n";
19591         static const GLchar* tes = "#version 430 core\n"
19592                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19593                                                            "\n"
19594                                                            "layout(isolines, point_mode) in;\n"
19595                                                            "\n"
19596                                                            "in  vec4 tcs_tes[];\n"
19597                                                            "out vec4 tes_gs;\n"
19598                                                            "\n"
19599                                                            "void main()\n"
19600                                                            "{\n"
19601                                                            "    tes_gs = tcs_tes[0];\n"
19602                                                            "}\n"
19603                                                            "\n";
19604         static const GLchar* tes_tested = "#version 430 core\n"
19605                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19606                                                                           "\n"
19607                                                                           "layout(isolines, point_mode) in;\n"
19608                                                                           "\n"
19609                                                                           "VAR_DEFINITION"
19610                                                                           "\n"
19611                                                                           "in  vec4 tcs_tes[];\n"
19612                                                                           "out vec4 tes_gs;\n"
19613                                                                           "\n"
19614                                                                           "void main()\n"
19615                                                                           "{\n"
19616                                                                           "    vec4 result = tcs_tes[0];\n"
19617                                                                           "\n"
19618                                                                           "VARIABLE_USE"
19619                                                                           "\n"
19620                                                                           "    tes_gs += result;\n"
19621                                                                           "}\n"
19622                                                                           "\n";
19623         static const GLchar* vs = "#version 430 core\n"
19624                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19625                                                           "\n"
19626                                                           "in  vec4 in_vs;\n"
19627                                                           "out vec4 vs_tcs;\n"
19628                                                           "\n"
19629                                                           "void main()\n"
19630                                                           "{\n"
19631                                                           "    vs_tcs = in_vs;\n"
19632                                                           "}\n"
19633                                                           "\n";
19634         static const GLchar* vs_tested = "#version 430 core\n"
19635                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19636                                                                          "\n"
19637                                                                          "VAR_DEFINITION"
19638                                                                          "\n"
19639                                                                          "in  vec4 in_vs;\n"
19640                                                                          "out vec4 vs_tcs;\n"
19641                                                                          "\n"
19642                                                                          "void main()\n"
19643                                                                          "{\n"
19644                                                                          "    vec4 result = in_vs;\n"
19645                                                                          "\n"
19646                                                                          "VARIABLE_USE"
19647                                                                          "\n"
19648                                                                          "    vs_tcs += result;\n"
19649                                                                          "}\n"
19650                                                                          "\n";
19651
19652         std::string source;
19653         testCase&   test_case = m_test_cases[test_case_index];
19654
19655         if (test_case.m_stage == stage)
19656         {
19657                 const GLchar* array     = "";
19658                 const GLchar* index     = "";
19659                 size_t            position = 0;
19660                 size_t            temp;
19661                 const GLchar* var_definition = 0;
19662                 const GLchar* var_use            = input_use;
19663
19664                 switch (test_case.m_qualifier)
19665                 {
19666                 case BUFFER:
19667                         var_definition = buffer_var_definition;
19668                         break;
19669                 case OFFSET:
19670                         var_definition = offset_var_definition;
19671                         break;
19672                 case STRIDE:
19673                         var_definition = stride_var_definition;
19674                         break;
19675                 default:
19676                         TCU_FAIL("Invalid enum");
19677                 }
19678
19679                 switch (stage)
19680                 {
19681                 case Utils::Shader::FRAGMENT:
19682                         source = fs_tested;
19683                         break;
19684                 case Utils::Shader::GEOMETRY:
19685                         source = gs_tested;
19686                         array  = "[]";
19687                         index  = "[0]";
19688                         break;
19689                 case Utils::Shader::TESS_CTRL:
19690                         source = tcs_tested;
19691                         array  = "[]";
19692                         index  = "[gl_InvocationID]";
19693                         break;
19694                 case Utils::Shader::TESS_EVAL:
19695                         source = tes_tested;
19696                         array  = "[]";
19697                         index  = "[0]";
19698                         break;
19699                 case Utils::Shader::VERTEX:
19700                         source = vs_tested;
19701                         break;
19702                 default:
19703                         TCU_FAIL("Invalid enum");
19704                 }
19705
19706                 temp = position;
19707                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19708                 position = temp;
19709                 Utils::replaceToken("ARRAY", position, array, source);
19710                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19711
19712                 Utils::replaceAllTokens("INDEX", index, source);
19713         }
19714         else
19715         {
19716                 switch (stage)
19717                 {
19718                 case Utils::Shader::FRAGMENT:
19719                         source = fs;
19720                         break;
19721                 case Utils::Shader::GEOMETRY:
19722                         source = gs;
19723                         break;
19724                 case Utils::Shader::TESS_CTRL:
19725                         source = tcs;
19726                         break;
19727                 case Utils::Shader::TESS_EVAL:
19728                         source = tes;
19729                         break;
19730                 case Utils::Shader::VERTEX:
19731                         source = vs;
19732                         break;
19733                 default:
19734                         TCU_FAIL("Invalid enum");
19735                 }
19736         }
19737
19738         return source;
19739 }
19740
19741 /** Get description of test case
19742  *
19743  * @param test_case_index Index of test case
19744  *
19745  * @return Test case description
19746  **/
19747 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19748 {
19749         std::stringstream stream;
19750         testCase&                 test_case = m_test_cases[test_case_index];
19751
19752         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19753
19754         switch (test_case.m_qualifier)
19755         {
19756         case BUFFER:
19757                 stream << "xfb_buffer";
19758                 break;
19759         case OFFSET:
19760                 stream << "xfb_offset";
19761                 break;
19762         case STRIDE:
19763                 stream << "xfb_stride";
19764                 break;
19765         default:
19766                 TCU_FAIL("Invalid enum");
19767         }
19768
19769         return stream.str();
19770 }
19771
19772 /** Get number of test cases
19773  *
19774  * @return Number of test cases
19775  **/
19776 GLuint XFBInputTest::getTestCaseNumber()
19777 {
19778         return static_cast<GLuint>(m_test_cases.size());
19779 }
19780
19781 /** Selects if "compute" stage is relevant for test
19782  *
19783  * @param ignored
19784  *
19785  * @return false
19786  **/
19787 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19788 {
19789         return false;
19790 }
19791
19792 /** Prepare all test cases
19793  *
19794  **/
19795 void XFBInputTest::testInit()
19796 {
19797         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19798         {
19799                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19800                 {
19801                         if (Utils::Shader::COMPUTE == stage)
19802                         {
19803                                 continue;
19804                         }
19805
19806                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19807
19808                         m_test_cases.push_back(test_case);
19809                 }
19810         }
19811 }
19812
19813 /* Constants used by XFBAllStagesTest */
19814 const GLuint XFBAllStagesTest::m_gs_index = 3;
19815
19816 /** Constructor
19817  *
19818  * @param context Test context
19819  **/
19820 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19821         : BufferTestBase(context, "xfb_all_stages",
19822                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19823 {
19824         /* Nothing to be done here */
19825 }
19826
19827 /** Get descriptors of buffers necessary for test
19828  *
19829  * @param ignored
19830  * @param out_descriptors Descriptors of buffers used by test
19831  **/
19832 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19833                                                                                         bufferDescriptor::Vector& out_descriptors)
19834 {
19835         static const GLuint n_stages = 4;
19836         const Utils::Type&  vec4         = Utils::Type::vec4;
19837
19838         /* Data */
19839         tcu::Vec4 sum;
19840
19841         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19842         out_descriptors.resize(n_stages * 2 + 1);
19843
19844         /* */
19845         for (GLuint i = 0; i < n_stages; ++i)
19846         {
19847                 /* Get references */
19848                 bufferDescriptor& uniform = out_descriptors[i + 0];
19849                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19850
19851                 /* Index */
19852                 uniform.m_index = i;
19853                 xfb.m_index             = i;
19854
19855                 /* Target */
19856                 uniform.m_target = Utils::Buffer::Uniform;
19857                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19858
19859                 /* Data */
19860                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19861
19862                 sum += var;
19863
19864                 uniform.m_initial_data.resize(vec4.GetSize());
19865                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19866
19867                 xfb.m_initial_data = vec4.GenerateDataPacked();
19868
19869                 if (m_gs_index != i)
19870                 {
19871                         xfb.m_expected_data = xfb.m_initial_data;
19872                 }
19873                 else
19874                 {
19875                         xfb.m_expected_data.resize(vec4.GetSize());
19876                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19877                 }
19878         }
19879
19880         /* FS */
19881         {
19882                 /* Get reference */
19883                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19884
19885                 /* Index */
19886                 uniform.m_index = n_stages;
19887
19888                 /* Target */
19889                 uniform.m_target = Utils::Buffer::Uniform;
19890
19891                 /* Data */
19892                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19893
19894                 uniform.m_initial_data.resize(vec4.GetSize());
19895                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19896         }
19897 }
19898
19899 /** Get body of main function for given shader stage
19900  *
19901  * @param ignored
19902  * @param stage            Shader stage
19903  * @param out_assignments  Set to empty
19904  * @param out_calculations Set to empty
19905  **/
19906 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19907                                                                          std::string& out_assignments, std::string& out_calculations)
19908 {
19909         out_calculations = "";
19910
19911         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19912         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19913         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19914         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19915         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19916
19917         const GLchar* assignments = 0;
19918         switch (stage)
19919         {
19920         case Utils::Shader::FRAGMENT:
19921                 assignments = fs;
19922                 break;
19923         case Utils::Shader::GEOMETRY:
19924                 assignments = gs;
19925                 break;
19926         case Utils::Shader::TESS_CTRL:
19927                 assignments = tcs;
19928                 break;
19929         case Utils::Shader::TESS_EVAL:
19930                 assignments = tes;
19931                 break;
19932         case Utils::Shader::VERTEX:
19933                 assignments = vs;
19934                 break;
19935         default:
19936                 TCU_FAIL("Invalid enum");
19937         }
19938
19939         out_assignments = assignments;
19940 }
19941
19942 /** Get interface of shader
19943  *
19944  * @param ignored
19945  * @param stage         Shader stage
19946  * @param out_interface Set to ""
19947  **/
19948 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19949                                                                                   std::string& out_interface)
19950 {
19951         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19952                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19953                                                           "    vec4 uni_vs;\n"
19954                                                           "};\n";
19955         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19956                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19957                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19958                                                            "    vec4 uni_tcs;\n"
19959                                                            "};\n";
19960         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19961                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19962                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19963                                                            "    vec4 uni_tes;\n"
19964                                                            "};\n";
19965         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19966                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19967                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19968                                                           "    vec4 uni_gs;\n"
19969                                                           "};\n";
19970         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19971                                                           "                       out     vec4 fs_out;\n"
19972                                                           "layout(binding    = 4) uniform fs_block {\n"
19973                                                           "    vec4 uni_fs;\n"
19974                                                           "};\n";
19975
19976         const GLchar* interface = 0;
19977         switch (stage)
19978         {
19979         case Utils::Shader::FRAGMENT:
19980                 interface = fs;
19981                 break;
19982         case Utils::Shader::GEOMETRY:
19983                 interface = gs;
19984                 break;
19985         case Utils::Shader::TESS_CTRL:
19986                 interface = tcs;
19987                 break;
19988         case Utils::Shader::TESS_EVAL:
19989                 interface = tes;
19990                 break;
19991         case Utils::Shader::VERTEX:
19992                 interface = vs;
19993                 break;
19994         default:
19995                 TCU_FAIL("Invalid enum");
19996         }
19997
19998         out_interface = interface;
19999 }
20000
20001 /* Constants used by XFBStrideOfEmptyListTest */
20002 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
20003
20004 /** Constructor
20005  *
20006  * @param context Test context
20007  **/
20008 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
20009         : BufferTestBase(
20010                   context, "xfb_stride_of_empty_list",
20011                   "Test verifies correct behavior when xfb_stride qualifier is specified but no xfb_offset is specified")
20012 {
20013         /* Nothing to be done here */
20014 }
20015
20016 /** Execute drawArrays for single vertex
20017  *
20018  * @param test_case_index Index of test case
20019  *
20020  * @return true if proper error is reported
20021  **/
20022 bool XFBStrideOfEmptyListTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20023 {
20024         const Functions& gl             = m_context.getRenderContext().getFunctions();
20025         bool                     result = true;
20026
20027         /* Draw */
20028         gl.disable(GL_RASTERIZER_DISCARD);
20029         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20030
20031         gl.beginTransformFeedback(GL_POINTS);
20032         GLenum error = gl.getError();
20033         switch (test_case_index)
20034         {
20035         case VALID:
20036                 if (GL_NO_ERROR != error)
20037                 {
20038                         gl.endTransformFeedback();
20039                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20040                 }
20041
20042                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20043                 error = gl.getError();
20044
20045                 gl.endTransformFeedback();
20046                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20047                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20048
20049                 break;
20050
20051         case FIRST_MISSING:
20052                 if (GL_NO_ERROR == error)
20053                 {
20054                         gl.endTransformFeedback();
20055                 }
20056
20057                 if (GL_INVALID_OPERATION != error)
20058                 {
20059                         m_context.getTestContext().getLog()
20060                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
20061                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20062                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20063
20064                         result = false;
20065                 }
20066
20067                 break;
20068
20069         case SECOND_MISSING:
20070                 if (GL_NO_ERROR != error)
20071                 {
20072                         gl.endTransformFeedback();
20073                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20074                 }
20075
20076                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20077                 error = gl.getError();
20078
20079                 gl.endTransformFeedback();
20080                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20081                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20082
20083                 break;
20084         }
20085
20086         /* Done */
20087         return result;
20088 }
20089
20090 /** Get descriptors of buffers necessary for test
20091  *
20092  * @param test_case_index Index of test case
20093  * @param out_descriptors Descriptors of buffers used by test
20094  **/
20095 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
20096                                                                                                         bufferDescriptor::Vector& out_descriptors)
20097 {
20098         switch (test_case_index)
20099         {
20100         case VALID:
20101         {
20102                 /* Test needs single uniform and two xfbs */
20103                 out_descriptors.resize(3);
20104
20105                 /* Get references */
20106                 bufferDescriptor& uniform = out_descriptors[0];
20107                 bufferDescriptor& xfb_0   = out_descriptors[1];
20108                 bufferDescriptor& xfb_1   = out_descriptors[2];
20109
20110                 /* Index */
20111                 uniform.m_index = 0;
20112                 xfb_0.m_index   = 0;
20113                 xfb_1.m_index   = 1;
20114
20115                 /* Target */
20116                 uniform.m_target = Utils::Buffer::Uniform;
20117                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20118                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20119
20120                 /* Data */
20121                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20122
20123                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20124                 xfb_0.m_expected_data = uniform.m_initial_data;
20125
20126                 /* Data, contents are the same as no modification is expected */
20127                 xfb_1.m_initial_data.resize(m_stride);
20128                 xfb_1.m_expected_data.resize(m_stride);
20129
20130                 for (GLuint i = 0; i < m_stride; ++i)
20131                 {
20132                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20133                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20134                 }
20135         }
20136
20137         break;
20138
20139         case FIRST_MISSING:
20140         {
20141                 /* Test needs single uniform and two xfbs */
20142                 out_descriptors.resize(2);
20143
20144                 /* Get references */
20145                 bufferDescriptor& uniform = out_descriptors[0];
20146                 bufferDescriptor& xfb_1   = out_descriptors[1];
20147
20148                 /* Index */
20149                 uniform.m_index = 0;
20150                 xfb_1.m_index   = 1;
20151
20152                 /* Target */
20153                 uniform.m_target = Utils::Buffer::Uniform;
20154                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20155
20156                 /* Data */
20157                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20158
20159                 /* Draw call will not be executed, contents does not matter */
20160                 xfb_1.m_initial_data.resize(m_stride);
20161         }
20162
20163         break;
20164
20165         case SECOND_MISSING:
20166         {
20167                 /* Test needs single uniform and two xfbs */
20168                 out_descriptors.resize(2);
20169
20170                 /* Get references */
20171                 bufferDescriptor& uniform = out_descriptors[0];
20172                 bufferDescriptor& xfb_0   = out_descriptors[1];
20173
20174                 /* Index */
20175                 uniform.m_index = 0;
20176                 xfb_0.m_index   = 0;
20177
20178                 /* Target */
20179                 uniform.m_target = Utils::Buffer::Uniform;
20180                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20181
20182                 /* Data */
20183                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20184
20185                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20186                 xfb_0.m_expected_data = uniform.m_initial_data;
20187         }
20188
20189         break;
20190         }
20191 }
20192
20193 /** Get body of main function for given shader stage
20194  *
20195  * @param ignored
20196  * @param stage            Shader stage
20197  * @param out_assignments  Set to empty
20198  * @param out_calculations Set to empty
20199  **/
20200 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20201                                                                                          std::string& out_assignments, std::string& out_calculations)
20202 {
20203         out_calculations = "";
20204
20205         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20206         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20207
20208         const GLchar* assignments = "";
20209         switch (stage)
20210         {
20211         case Utils::Shader::FRAGMENT:
20212                 assignments = fs;
20213                 break;
20214         case Utils::Shader::GEOMETRY:
20215                 assignments = gs;
20216                 break;
20217         default:
20218                 break;
20219         }
20220
20221         out_assignments = assignments;
20222 }
20223
20224 /** Get interface of shader
20225  *
20226  * @param ignored
20227  * @param stage            Shader stage
20228  * @param out_interface    Set to ""
20229  **/
20230 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20231                                                                                                   std::string& out_interface)
20232 {
20233         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20234                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20235                                                           "\n"
20236                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20237                                                           "    vec4 uni_gs;\n"
20238                                                           "};\n";
20239         static const GLchar* fs = "in  vec4 gs_fs;\n"
20240                                                           "out vec4 fs_out;\n";
20241
20242         switch (stage)
20243         {
20244         case Utils::Shader::FRAGMENT:
20245                 out_interface = fs;
20246                 break;
20247         case Utils::Shader::GEOMETRY:
20248                 out_interface = gs;
20249                 break;
20250         default:
20251                 out_interface = "";
20252                 return;
20253         }
20254 }
20255
20256 /** Returns buffer details in human readable form.
20257  *
20258  * @param test_case_index Index of test case
20259  *
20260  * @return Case description
20261  **/
20262 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20263 {
20264         std::string result;
20265
20266         switch (test_case_index)
20267         {
20268         case VALID:
20269                 result = "Valid case";
20270                 break;
20271         case FIRST_MISSING:
20272                 result = "Missing xfb at index 0";
20273                 break;
20274         case SECOND_MISSING:
20275                 result = "Missing xfb at index 1";
20276                 break;
20277         default:
20278                 TCU_FAIL("Invalid enum");
20279         }
20280
20281         return result;
20282 }
20283
20284 /** Get number of test cases
20285  *
20286  * @return 3
20287  **/
20288 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20289 {
20290         return 3;
20291 }
20292
20293 /* Constants used by XFBStrideOfEmptyListTest */
20294 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20295
20296 /** Constructor
20297  *
20298  * @param context Test context
20299  **/
20300 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20301         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20302                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20303 {
20304         /* Nothing to be done here */
20305 }
20306
20307 /** Execute drawArrays for single vertex
20308  *
20309  * @param test_case_index Index of test case
20310  *
20311  * @return true if proper error is reported
20312  **/
20313 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20314 {
20315         const Functions& gl             = m_context.getRenderContext().getFunctions();
20316         bool                     result = true;
20317
20318         /* Draw */
20319         gl.disable(GL_RASTERIZER_DISCARD);
20320         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20321
20322         gl.beginTransformFeedback(GL_POINTS);
20323         GLenum error = gl.getError();
20324         switch (test_case_index)
20325         {
20326         case VALID:
20327                 if (GL_NO_ERROR != error)
20328                 {
20329                         gl.endTransformFeedback();
20330                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20331                 }
20332
20333                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20334                 error = gl.getError();
20335
20336                 gl.endTransformFeedback();
20337                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20338                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20339
20340                 break;
20341
20342         case FIRST_MISSING:
20343                 if (GL_NO_ERROR != error)
20344                 {
20345                         gl.endTransformFeedback();
20346                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20347                 }
20348
20349                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20350                 error = gl.getError();
20351
20352                 gl.endTransformFeedback();
20353                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20354                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20355
20356                 break;
20357
20358         case SECOND_MISSING:
20359                 if (GL_NO_ERROR == error)
20360                 {
20361                         gl.endTransformFeedback();
20362                 }
20363
20364                 if (GL_INVALID_OPERATION != error)
20365                 {
20366                         m_context.getTestContext().getLog()
20367                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
20368                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20369                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20370
20371                         result = false;
20372                 }
20373
20374                 break;
20375         }
20376
20377         /* Done */
20378         return result;
20379 }
20380
20381 /** Get descriptors of buffers necessary for test
20382  *
20383  * @param test_case_index Index of test case
20384  * @param out_descriptors Descriptors of buffers used by test
20385  **/
20386 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20387                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20388 {
20389         switch (test_case_index)
20390         {
20391         case VALID:
20392         {
20393                 /* Test needs single uniform and two xfbs */
20394                 out_descriptors.resize(3);
20395
20396                 /* Get references */
20397                 bufferDescriptor& uniform = out_descriptors[0];
20398                 bufferDescriptor& xfb_0   = out_descriptors[1];
20399                 bufferDescriptor& xfb_1   = out_descriptors[2];
20400
20401                 /* Index */
20402                 uniform.m_index = 0;
20403                 xfb_0.m_index   = 0;
20404                 xfb_1.m_index   = 1;
20405
20406                 /* Target */
20407                 uniform.m_target = Utils::Buffer::Uniform;
20408                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20409                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20410
20411                 /* Data */
20412                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20413
20414                 /* Data, contents are the same as no modification is expected */
20415                 xfb_0.m_initial_data.resize(m_stride);
20416                 xfb_0.m_expected_data.resize(m_stride);
20417
20418                 for (GLuint i = 0; i < m_stride; ++i)
20419                 {
20420                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20421                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20422                 }
20423
20424                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20425                 xfb_1.m_expected_data = uniform.m_initial_data;
20426         }
20427
20428         break;
20429
20430         case FIRST_MISSING:
20431         {
20432                 /* Test needs single uniform and two xfbs */
20433                 out_descriptors.resize(2);
20434
20435                 /* Get references */
20436                 bufferDescriptor& uniform = out_descriptors[0];
20437                 bufferDescriptor& xfb_1   = out_descriptors[1];
20438
20439                 /* Index */
20440                 uniform.m_index = 0;
20441                 xfb_1.m_index   = 1;
20442
20443                 /* Target */
20444                 uniform.m_target = Utils::Buffer::Uniform;
20445                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20446
20447                 /* Data */
20448                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20449
20450                 /* Data, contents are the same as no modification is expected */
20451                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20452                 xfb_1.m_expected_data = uniform.m_initial_data;
20453         }
20454
20455         break;
20456
20457         case SECOND_MISSING:
20458         {
20459                 /* Test needs single uniform and two xfbs */
20460                 out_descriptors.resize(2);
20461
20462                 /* Get references */
20463                 bufferDescriptor& uniform = out_descriptors[0];
20464                 bufferDescriptor& xfb_0   = out_descriptors[1];
20465
20466                 /* Index */
20467                 uniform.m_index = 0;
20468                 xfb_0.m_index   = 0;
20469
20470                 /* Target */
20471                 uniform.m_target = Utils::Buffer::Uniform;
20472                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20473
20474                 /* Data */
20475                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20476
20477                 /* Draw call will not be executed, contents does not matter */
20478                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20479         }
20480
20481         break;
20482         }
20483 }
20484
20485 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20486  *
20487  * @param ignored
20488  * @param captured_varyings Vector of varying names to be captured
20489  **/
20490 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20491                                                                                                                  Utils::Program::NameVector& captured_varyings,
20492                                                                                                                  GLint* xfb_components)
20493 {
20494         captured_varyings.push_back("gs_fs1");
20495         captured_varyings.push_back("gs_fs2");
20496         *xfb_components = 4;
20497 }
20498
20499 /** Get body of main function for given shader stage
20500  *
20501  * @param ignored
20502  * @param stage            Shader stage
20503  * @param out_assignments  Set to empty
20504  * @param out_calculations Set to empty
20505  **/
20506 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20507                                                                                                    std::string& out_assignments, std::string& out_calculations)
20508 {
20509         out_calculations = "";
20510
20511         static const GLchar* gs = "    gs_fs1 = -uni_gs;\n"
20512                                                           "    gs_fs2 = uni_gs;\n";
20513         static const GLchar* fs = "    fs_out = vec4(gs_fs2);\n";
20514
20515         const GLchar* assignments = "";
20516         switch (stage)
20517         {
20518         case Utils::Shader::FRAGMENT:
20519                 assignments = fs;
20520                 break;
20521         case Utils::Shader::GEOMETRY:
20522                 assignments = gs;
20523                 break;
20524         default:
20525                 break;
20526         }
20527
20528         out_assignments = assignments;
20529 }
20530
20531 /** Get interface of shader
20532  *
20533  * @param ignored
20534  * @param stage            Shader stage
20535  * @param out_interface    Set to ""
20536  **/
20537 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20538                                                                                                                 std::string& out_interface)
20539 {
20540         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out vec4 gs_fs1;\n"
20541                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs2;\n"
20542                                                           "\n"
20543                                                           "layout(binding    = 0) uniform gs_block {\n"
20544                                                           "    vec4 uni_gs;\n"
20545                                                           "};\n";
20546         static const GLchar* fs = "in  vec4 gs_fs2;\n"
20547                                                           "out vec4 fs_out;\n";
20548
20549         switch (stage)
20550         {
20551         case Utils::Shader::FRAGMENT:
20552                 out_interface = fs;
20553                 break;
20554         case Utils::Shader::GEOMETRY:
20555                 out_interface = gs;
20556                 break;
20557         default:
20558                 out_interface = "";
20559                 return;
20560         }
20561 }
20562
20563 /** Returns buffer details in human readable form.
20564  *
20565  * @param test_case_index Index of test case
20566  *
20567  * @return Case description
20568  **/
20569 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20570 {
20571         std::string result;
20572
20573         switch (test_case_index)
20574         {
20575         case VALID:
20576                 result = "Valid case";
20577                 break;
20578         case FIRST_MISSING:
20579                 result = "Missing xfb at index 0";
20580                 break;
20581         case SECOND_MISSING:
20582                 result = "Missing xfb at index 1";
20583                 break;
20584         default:
20585                 TCU_FAIL("Invalid enum");
20586         }
20587
20588         return result;
20589 }
20590
20591 /** Get number of test cases
20592  *
20593  * @return 2
20594  **/
20595 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20596 {
20597         return 3;
20598 }
20599
20600 /** Constructor
20601  *
20602  * @param context Test framework context
20603  **/
20604 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20605         : NegativeTestBase(context, "xfb_too_small_stride",
20606                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20607 {
20608 }
20609
20610 /** Source for given test case and stage
20611  *
20612  * @param test_case_index Index of test case
20613  * @param stage           Shader stage
20614  *
20615  * @return Shader source
20616  **/
20617 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20618 {
20619         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20620                                                                                                 "\n"
20621                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20622         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20623                                                                                                 "\n"
20624                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20625                                                                                                 "    vec4 gohan;\n"
20626                                                                                                 "    vec4 goten;\n"
20627                                                                                                 "    vec4 chichi;\n"
20628                                                                                                 "} gokuARRAY;\n";
20629         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20630                                                                                                  "\n"
20631                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20632         // 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;"
20633         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20634         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20635                                                                                                  "\n"
20636                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20637         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20638                                                                          "    gohanINDEX[1] = result / 4;\n"
20639                                                                          "    gohanINDEX[2] = result / 6;\n"
20640                                                                          "    gohanINDEX[3] = result / 8;\n";
20641         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20642                                                                          "    gokuINDEX.goten  = result / 4;\n"
20643                                                                          "    gokuINDEX.chichi = result / 6;\n";
20644         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20645         static const GLchar* fs                 = "#version 430 core\n"
20646                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20647                                                           "\n"
20648                                                           "in  vec4 gs_fs;\n"
20649                                                           "out vec4 fs_out;\n"
20650                                                           "\n"
20651                                                           "void main()\n"
20652                                                           "{\n"
20653                                                           "    fs_out = gs_fs;\n"
20654                                                           "}\n"
20655                                                           "\n";
20656         static const GLchar* gs_tested = "#version 430 core\n"
20657                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20658                                                                          "\n"
20659                                                                          "layout(points)                           in;\n"
20660                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20661                                                                          "\n"
20662                                                                          "VAR_DEFINITION"
20663                                                                          "\n"
20664                                                                          "in  vec4 tes_gs[];\n"
20665                                                                          "out vec4 gs_fs;\n"
20666                                                                          "\n"
20667                                                                          "void main()\n"
20668                                                                          "{\n"
20669                                                                          "    vec4 result = tes_gs[0];\n"
20670                                                                          "\n"
20671                                                                          "VARIABLE_USE"
20672                                                                          "\n"
20673                                                                          "    gs_fs = result;\n"
20674                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20675                                                                          "    EmitVertex();\n"
20676                                                                          "    gs_fs = result;\n"
20677                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20678                                                                          "    EmitVertex();\n"
20679                                                                          "    gs_fs = result;\n"
20680                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20681                                                                          "    EmitVertex();\n"
20682                                                                          "    gs_fs = result;\n"
20683                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20684                                                                          "    EmitVertex();\n"
20685                                                                          "}\n"
20686                                                                          "\n";
20687         static const GLchar* tcs = "#version 430 core\n"
20688                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20689                                                            "\n"
20690                                                            "layout(vertices = 1) out;\n"
20691                                                            "\n"
20692                                                            "in  vec4 vs_tcs[];\n"
20693                                                            "out vec4 tcs_tes[];\n"
20694                                                            "\n"
20695                                                            "void main()\n"
20696                                                            "{\n"
20697                                                            "\n"
20698                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20699                                                            "\n"
20700                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20701                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20702                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20703                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20704                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20705                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20706                                                            "}\n"
20707                                                            "\n";
20708         static const GLchar* tcs_tested = "#version 430 core\n"
20709                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20710                                                                           "\n"
20711                                                                           "layout(vertices = 1) out;\n"
20712                                                                           "\n"
20713                                                                           "VAR_DEFINITION"
20714                                                                           "\n"
20715                                                                           "in  vec4 vs_tcs[];\n"
20716                                                                           "out vec4 tcs_tes[];\n"
20717                                                                           "\n"
20718                                                                           "void main()\n"
20719                                                                           "{\n"
20720                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20721                                                                           "\n"
20722                                                                           "VARIABLE_USE"
20723                                                                           "\n"
20724                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20725                                                                           "\n"
20726                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20727                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20728                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20729                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20730                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20731                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20732                                                                           "}\n"
20733                                                                           "\n";
20734         static const GLchar* tes_tested = "#version 430 core\n"
20735                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20736                                                                           "\n"
20737                                                                           "layout(isolines, point_mode) in;\n"
20738                                                                           "\n"
20739                                                                           "VAR_DEFINITION"
20740                                                                           "\n"
20741                                                                           "in  vec4 tcs_tes[];\n"
20742                                                                           "out vec4 tes_gs;\n"
20743                                                                           "\n"
20744                                                                           "void main()\n"
20745                                                                           "{\n"
20746                                                                           "    vec4 result = tcs_tes[0];\n"
20747                                                                           "\n"
20748                                                                           "VARIABLE_USE"
20749                                                                           "\n"
20750                                                                           "    tes_gs += result;\n"
20751                                                                           "}\n"
20752                                                                           "\n";
20753         static const GLchar* vs = "#version 430 core\n"
20754                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20755                                                           "\n"
20756                                                           "in  vec4 in_vs;\n"
20757                                                           "out vec4 vs_tcs;\n"
20758                                                           "\n"
20759                                                           "void main()\n"
20760                                                           "{\n"
20761                                                           "    vs_tcs = in_vs;\n"
20762                                                           "}\n"
20763                                                           "\n";
20764         static const GLchar* vs_tested = "#version 430 core\n"
20765                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20766                                                                          "\n"
20767                                                                          "VAR_DEFINITION"
20768                                                                          "\n"
20769                                                                          "in  vec4 in_vs;\n"
20770                                                                          "out vec4 vs_tcs;\n"
20771                                                                          "\n"
20772                                                                          "void main()\n"
20773                                                                          "{\n"
20774                                                                          "    vec4 result = in_vs;\n"
20775                                                                          "\n"
20776                                                                          "VARIABLE_USE"
20777                                                                          "\n"
20778                                                                          "    vs_tcs += result;\n"
20779                                                                          "}\n"
20780                                                                          "\n";
20781
20782         std::string source;
20783         testCase&   test_case = m_test_cases[test_case_index];
20784
20785         if (test_case.m_stage == stage)
20786         {
20787                 const GLchar* array     = "";
20788                 const GLchar* index     = "";
20789                 size_t            position = 0;
20790                 size_t            temp;
20791                 const GLchar* var_definition = 0;
20792                 const GLchar* var_use            = 0;
20793
20794                 switch (test_case.m_case)
20795                 {
20796                 case OFFSET:
20797                         var_definition = offset_var_definition;
20798                         var_use            = output_use;
20799                         break;
20800                 case STRIDE:
20801                         var_definition = stride_var_definition;
20802                         var_use            = output_use;
20803                         break;
20804                 case BLOCK:
20805                         var_definition = block_var_definition;
20806                         var_use            = block_use;
20807                         break;
20808                 case ARRAY:
20809                         var_definition = array_var_definition;
20810                         var_use            = array_use;
20811                         break;
20812                 default:
20813                         TCU_FAIL("Invalid enum");
20814                 }
20815
20816                 switch (stage)
20817                 {
20818                 case Utils::Shader::GEOMETRY:
20819                         source = gs_tested;
20820                         array  = "[]";
20821                         index  = "[0]";
20822                         break;
20823                 case Utils::Shader::TESS_CTRL:
20824                         source = tcs_tested;
20825                         array  = "[]";
20826                         index  = "[gl_InvocationID]";
20827                         break;
20828                 case Utils::Shader::TESS_EVAL:
20829                         source = tes_tested;
20830                         array  = "[]";
20831                         index  = "[0]";
20832                         break;
20833                 case Utils::Shader::VERTEX:
20834                         source = vs_tested;
20835                         break;
20836                 default:
20837                         TCU_FAIL("Invalid enum");
20838                 }
20839
20840                 temp = position;
20841                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20842                 position = temp;
20843                 Utils::replaceToken("ARRAY", position, array, source);
20844                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20845
20846                 Utils::replaceAllTokens("INDEX", index, source);
20847         }
20848         else
20849         {
20850                 switch (test_case.m_stage)
20851                 {
20852                 case Utils::Shader::GEOMETRY:
20853                         switch (stage)
20854                         {
20855                         case Utils::Shader::FRAGMENT:
20856                                 source = fs;
20857                                 break;
20858                         case Utils::Shader::VERTEX:
20859                                 source = vs;
20860                                 break;
20861                         default:
20862                                 source = "";
20863                         }
20864                         break;
20865                 case Utils::Shader::TESS_CTRL:
20866                         switch (stage)
20867                         {
20868                         case Utils::Shader::FRAGMENT:
20869                                 source = fs;
20870                                 break;
20871                         case Utils::Shader::VERTEX:
20872                                 source = vs;
20873                                 break;
20874                         default:
20875                                 source = "";
20876                         }
20877                         break;
20878                 case Utils::Shader::TESS_EVAL:
20879                         switch (stage)
20880                         {
20881                         case Utils::Shader::FRAGMENT:
20882                                 source = fs;
20883                                 break;
20884                         case Utils::Shader::TESS_CTRL:
20885                                 source = tcs;
20886                                 break;
20887                         case Utils::Shader::VERTEX:
20888                                 source = vs;
20889                                 break;
20890                         default:
20891                                 source = "";
20892                         }
20893                         break;
20894                 case Utils::Shader::VERTEX:
20895                         switch (stage)
20896                         {
20897                         case Utils::Shader::FRAGMENT:
20898                                 source = fs;
20899                                 break;
20900                         default:
20901                                 source = "";
20902                         }
20903                         break;
20904                 default:
20905                         TCU_FAIL("Invalid enum");
20906                         break;
20907                 }
20908         }
20909
20910         return source;
20911 }
20912
20913 /** Get description of test case
20914  *
20915  * @param test_case_index Index of test case
20916  *
20917  * @return Test case description
20918  **/
20919 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20920 {
20921         std::stringstream stream;
20922         testCase&                 test_case = m_test_cases[test_case_index];
20923
20924         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20925
20926         switch (test_case.m_case)
20927         {
20928         case OFFSET:
20929                 stream << "buffer stride: 40, vec4 offset: 32";
20930                 break;
20931         case STRIDE:
20932                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20933                 break;
20934         case BLOCK:
20935                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20936                 break;
20937         case ARRAY:
20938                 stream << "buffer stride: 32, vec4[4] offset 16";
20939                 break;
20940         default:
20941                 TCU_FAIL("Invalid enum");
20942         }
20943
20944         return stream.str();
20945 }
20946
20947 /** Get number of test cases
20948  *
20949  * @return Number of test cases
20950  **/
20951 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20952 {
20953         return static_cast<GLuint>(m_test_cases.size());
20954 }
20955
20956 /** Selects if "compute" stage is relevant for test
20957  *
20958  * @param ignored
20959  *
20960  * @return false
20961  **/
20962 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20963 {
20964         return false;
20965 }
20966
20967 /** Prepare all test cases
20968  *
20969  **/
20970 void XFBTooSmallStrideTest::testInit()
20971 {
20972         for (GLuint c = 0; c < CASE_MAX; ++c)
20973         {
20974                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20975                 {
20976                         /*
20977                          It is invalid to define transform feedback output in TCS, according to spec:
20978                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20979                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20980                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20981                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20982                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20983                          each primitive processed by the vertex shader.
20984                          */
20985                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20986                                 (Utils::Shader::FRAGMENT == stage))
20987                         {
20988                                 continue;
20989                         }
20990
20991                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20992
20993                         m_test_cases.push_back(test_case);
20994                 }
20995         }
20996 }
20997
20998 /** Constructor
20999  *
21000  * @param context Test framework context
21001  **/
21002 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
21003         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
21004 {
21005 }
21006
21007 /** Source for given test case and stage
21008  *
21009  * @param test_case_index Index of test case
21010  * @param stage           Shader stage
21011  *
21012  * @return Shader source
21013  **/
21014 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21015 {
21016         static const GLchar* invalid_var_definition =
21017                 "const uint type_size = SIZE;\n"
21018                 "\n"
21019                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
21020                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
21021         static const GLchar* valid_var_definition =
21022                 "const uint type_size = SIZE;\n"
21023                 "\n"
21024                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
21025         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
21026                                                                            "    vegetaINDEX = TYPE(0);\n"
21027                                                                            "    if (vec4(0) == result)\n"
21028                                                                            "    {\n"
21029                                                                            "        gokuINDEX   = TYPE(0);\n"
21030                                                                            "        vegetaINDEX = TYPE(1);\n"
21031                                                                            "    }\n";
21032         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
21033                                                                          "    if (vec4(0) == result)\n"
21034                                                                          "    {\n"
21035                                                                          "        gokuINDEX   = TYPE(0);\n"
21036                                                                          "    }\n";
21037         static const GLchar* fs = "#version 430 core\n"
21038                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21039                                                           "\n"
21040                                                           "in  vec4 any_fs;\n"
21041                                                           "out vec4 fs_out;\n"
21042                                                           "\n"
21043                                                           "void main()\n"
21044                                                           "{\n"
21045                                                           "    fs_out = any_fs;\n"
21046                                                           "}\n"
21047                                                           "\n";
21048         static const GLchar* gs_tested = "#version 430 core\n"
21049                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21050                                                                          "\n"
21051                                                                          "layout(points)                           in;\n"
21052                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21053                                                                          "\n"
21054                                                                          "VAR_DEFINITION"
21055                                                                          "\n"
21056                                                                          "in  vec4 vs_any[];\n"
21057                                                                          "out vec4 any_fs;\n"
21058                                                                          "\n"
21059                                                                          "void main()\n"
21060                                                                          "{\n"
21061                                                                          "    vec4 result = vs_any[0];\n"
21062                                                                          "\n"
21063                                                                          "VARIABLE_USE"
21064                                                                          "\n"
21065                                                                          "    any_fs = result;\n"
21066                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21067                                                                          "    EmitVertex();\n"
21068                                                                          "    any_fs = result;\n"
21069                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21070                                                                          "    EmitVertex();\n"
21071                                                                          "    any_fs = result;\n"
21072                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21073                                                                          "    EmitVertex();\n"
21074                                                                          "    any_fs = result;\n"
21075                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21076                                                                          "    EmitVertex();\n"
21077                                                                          "}\n"
21078                                                                          "\n";
21079         static const GLchar* tcs = "#version 430 core\n"
21080                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21081                                                            "\n"
21082                                                            "layout(vertices = 1) out;\n"
21083                                                            "\n"
21084                                                            "in  vec4 vs_any[];\n"
21085                                                            "out vec4 tcs_tes[];\n"
21086                                                            "\n"
21087                                                            "void main()\n"
21088                                                            "{\n"
21089                                                            "\n"
21090                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21091                                                            "\n"
21092                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21093                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21094                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21095                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21096                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21097                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21098                                                            "}\n"
21099                                                            "\n";
21100         static const GLchar* tcs_tested = "#version 430 core\n"
21101                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21102                                                                           "\n"
21103                                                                           "layout(vertices = 1) out;\n"
21104                                                                           "\n"
21105                                                                           "VAR_DEFINITION"
21106                                                                           "\n"
21107                                                                           "in  vec4 vs_any[];\n"
21108                                                                           "out vec4 any_fs[];\n"
21109                                                                           "\n"
21110                                                                           "void main()\n"
21111                                                                           "{\n"
21112                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21113                                                                           "\n"
21114                                                                           "VARIABLE_USE"
21115                                                                           "\n"
21116                                                                           "    any_fs[gl_InvocationID] = result;\n"
21117                                                                           "\n"
21118                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21119                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21120                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21121                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21122                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21123                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21124                                                                           "}\n"
21125                                                                           "\n";
21126         static const GLchar* tes_tested = "#version 430 core\n"
21127                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21128                                                                           "\n"
21129                                                                           "layout(isolines, point_mode) in;\n"
21130                                                                           "\n"
21131                                                                           "VAR_DEFINITION"
21132                                                                           "\n"
21133                                                                           "in  vec4 tcs_tes[];\n"
21134                                                                           "out vec4 any_fs;\n"
21135                                                                           "\n"
21136                                                                           "void main()\n"
21137                                                                           "{\n"
21138                                                                           "    vec4 result = tcs_tes[0];\n"
21139                                                                           "\n"
21140                                                                           "VARIABLE_USE"
21141                                                                           "\n"
21142                                                                           "    any_fs = result;\n"
21143                                                                           "}\n"
21144                                                                           "\n";
21145         static const GLchar* vs = "#version 430 core\n"
21146                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21147                                                           "\n"
21148                                                           "in  vec4 in_vs;\n"
21149                                                           "out vec4 vs_any;\n"
21150                                                           "\n"
21151                                                           "void main()\n"
21152                                                           "{\n"
21153                                                           "    vs_any = in_vs;\n"
21154                                                           "}\n"
21155                                                           "\n";
21156         static const GLchar* vs_tested = "#version 430 core\n"
21157                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21158                                                                          "\n"
21159                                                                          "VAR_DEFINITION"
21160                                                                          "\n"
21161                                                                          "in  vec4 in_vs;\n"
21162                                                                          "out vec4 any_fs;\n"
21163                                                                          "\n"
21164                                                                          "void main()\n"
21165                                                                          "{\n"
21166                                                                          "    vec4 result = in_vs;\n"
21167                                                                          "\n"
21168                                                                          "VARIABLE_USE"
21169                                                                          "\n"
21170                                                                          "    any_fs = result;\n"
21171                                                                          "}\n"
21172                                                                          "\n";
21173
21174         std::string source;
21175         testCase&   test_case = m_test_cases[test_case_index];
21176
21177         if (test_case.m_stage == stage)
21178         {
21179                 const GLchar* array = "";
21180                 GLchar            buffer[16];
21181                 const GLchar* index     = "";
21182                 size_t            position = 0;
21183                 size_t            temp;
21184                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21185                 const GLchar* var_definition = 0;
21186                 const GLchar* var_use            = 0;
21187
21188                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21189
21190                 switch (test_case.m_case)
21191                 {
21192                 case VALID:
21193                         var_definition = valid_var_definition;
21194                         var_use            = valid_use;
21195                         break;
21196                 case INVALID:
21197                         var_definition = invalid_var_definition;
21198                         var_use            = invalid_use;
21199                         break;
21200                 default:
21201                         TCU_FAIL("Invalid enum");
21202                 }
21203
21204                 switch (stage)
21205                 {
21206                 case Utils::Shader::GEOMETRY:
21207                         source = gs_tested;
21208                         array  = "[1]";
21209                         index  = "[0]";
21210                         break;
21211                 case Utils::Shader::TESS_CTRL:
21212                         source = tcs_tested;
21213                         array  = "[1]";
21214                         index  = "[gl_InvocationID]";
21215                         break;
21216                 case Utils::Shader::TESS_EVAL:
21217                         source = tes_tested;
21218                         array  = "[1]";
21219                         index  = "[0]";
21220                         break;
21221                 case Utils::Shader::VERTEX:
21222                         source = vs_tested;
21223                         break;
21224                 default:
21225                         TCU_FAIL("Invalid enum");
21226                 }
21227
21228                 temp = position;
21229                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21230                 position = temp;
21231                 Utils::replaceToken("SIZE", position, buffer, source);
21232                 Utils::replaceToken("ARRAY", position, array, source);
21233                 if (INVALID == test_case.m_case)
21234                 {
21235                         Utils::replaceToken("ARRAY", position, array, source);
21236                 }
21237                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21238
21239                 Utils::replaceAllTokens("TYPE", type_name, source);
21240                 Utils::replaceAllTokens("INDEX", index, source);
21241         }
21242         else
21243         {
21244                 switch (test_case.m_stage)
21245                 {
21246                 case Utils::Shader::GEOMETRY:
21247                         switch (stage)
21248                         {
21249                         case Utils::Shader::FRAGMENT:
21250                                 source = fs;
21251                                 break;
21252                         case Utils::Shader::VERTEX:
21253                                 source = vs;
21254                                 break;
21255                         default:
21256                                 source = "";
21257                         }
21258                         break;
21259                 case Utils::Shader::TESS_CTRL:
21260                         switch (stage)
21261                         {
21262                         case Utils::Shader::FRAGMENT:
21263                                 source = fs;
21264                                 break;
21265                         case Utils::Shader::VERTEX:
21266                                 source = vs;
21267                                 break;
21268                         default:
21269                                 source = "";
21270                         }
21271                         break;
21272                 case Utils::Shader::TESS_EVAL:
21273                         switch (stage)
21274                         {
21275                         case Utils::Shader::FRAGMENT:
21276                                 source = fs;
21277                                 break;
21278                         case Utils::Shader::TESS_CTRL:
21279                                 source = tcs;
21280                                 break;
21281                         case Utils::Shader::VERTEX:
21282                                 source = vs;
21283                                 break;
21284                         default:
21285                                 source = "";
21286                         }
21287                         break;
21288                 case Utils::Shader::VERTEX:
21289                         switch (stage)
21290                         {
21291                         case Utils::Shader::FRAGMENT:
21292                                 source = fs;
21293                                 break;
21294                         default:
21295                                 source = "";
21296                         }
21297                         break;
21298                 default:
21299                         TCU_FAIL("Invalid enum");
21300                         break;
21301                 }
21302         }
21303
21304         return source;
21305 }
21306
21307 /** Get description of test case
21308  *
21309  * @param test_case_index Index of test case
21310  *
21311  * @return Test case description
21312  **/
21313 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21314 {
21315         std::stringstream stream;
21316         testCase&                 test_case = m_test_cases[test_case_index];
21317
21318         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21319                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21320
21321         switch (test_case.m_case)
21322         {
21323         case VALID:
21324                 stream << "valid";
21325                 break;
21326         case INVALID:
21327                 stream << "invalid";
21328                 break;
21329         default:
21330                 TCU_FAIL("Invalid enum");
21331         }
21332
21333         return stream.str();
21334 }
21335
21336 /** Get number of test cases
21337  *
21338  * @return Number of test cases
21339  **/
21340 GLuint XFBVariableStrideTest::getTestCaseNumber()
21341 {
21342         return static_cast<GLuint>(m_test_cases.size());
21343 }
21344
21345 /** Selects if "compute" stage is relevant for test
21346  *
21347  * @param ignored
21348  *
21349  * @return false
21350  **/
21351 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21352 {
21353         return false;
21354 }
21355
21356 /** Selects if compilation failure is expected result
21357  *
21358  * @param test_case_index Index of test case
21359  *
21360  * @return true
21361  **/
21362 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21363 {
21364         testCase& test_case = m_test_cases[test_case_index];
21365
21366         return (INVALID == test_case.m_case);
21367 }
21368
21369 /** Prepare all test cases
21370  *
21371  **/
21372 void XFBVariableStrideTest::testInit()
21373 {
21374         const GLuint n_types = getTypesNumber();
21375
21376         for (GLuint i = 0; i < n_types; ++i)
21377         {
21378                 const Utils::Type& type = getType(i);
21379
21380                 /*
21381                  Some of the cases are declared as following are considered as invalid,
21382                  but accoring to spec, the following declaration is valid: shaders in the
21383                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21384                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21385                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21386                  the stride.
21387
21388                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21389                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21390                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21391                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21392
21393                  int type_size = 8;
21394                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21395                  layout (xfb_offset = type_size)                     out double vegeta;
21396                  */
21397                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21398                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21399                 {
21400                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21401                         {
21402                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21403                                         (Utils::Shader::FRAGMENT == stage))
21404                                 {
21405                                         continue;
21406                                 }
21407
21408                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21409
21410                                 m_test_cases.push_back(test_case);
21411                         }
21412                 }
21413         }
21414 }
21415
21416 /** Constructor
21417  *
21418  * @param context Test framework context
21419  **/
21420 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21421         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21422 {
21423 }
21424
21425 /** Source for given test case and stage
21426  *
21427  * @param test_case_index Index of test case
21428  * @param stage           Shader stage
21429  *
21430  * @return Shader source
21431  **/
21432 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21433 {
21434         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21435                                                                                   "    vec4 gohan;\n"
21436                                                                                   "    vec4 goten;\n"
21437                                                                                   "    vec4 chichi;\n"
21438                                                                                   "} gokuARRAY;\n";
21439         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21440                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21441                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21442                                                                    "    if (vec4(0) == result)\n"
21443                                                                    "    {\n"
21444                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21445                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21446                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21447                                                                    "    }\n";
21448         static const GLchar* gs_tested =
21449                 "#version 430 core\n"
21450                 "#extension GL_ARB_enhanced_layouts : require\n"
21451                 "\n"
21452                 "layout(points)                           in;\n"
21453                 "layout(triangle_strip, max_vertices = 4) out;\n"
21454                 "\n"
21455                 "VAR_DEFINITION"
21456                 "\n"
21457                 "out gl_PerVertex \n"
21458                 "{ \n"
21459                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21460                 "}; \n"
21461                 "in  vec4 tes_gs[];\n"
21462                 "out vec4 gs_fs;\n"
21463                 "\n"
21464                 "void main()\n"
21465                 "{\n"
21466                 "    vec4 result = tes_gs[0];\n"
21467                 "\n"
21468                 "VARIABLE_USE"
21469                 "\n"
21470                 "    gs_fs = result;\n"
21471                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21472                 "    EmitVertex();\n"
21473                 "    gs_fs = result;\n"
21474                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21475                 "    EmitVertex();\n"
21476                 "    gs_fs = result;\n"
21477                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21478                 "    EmitVertex();\n"
21479                 "    gs_fs = result;\n"
21480                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21481                 "    EmitVertex();\n"
21482                 "}\n"
21483                 "\n";
21484         static const GLchar* tcs = "#version 430 core\n"
21485                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21486                                                            "\n"
21487                                                            "layout(vertices = 1) out;\n"
21488                                                            "\n"
21489                                                            "in  vec4 vs_tcs[];\n"
21490                                                            "out vec4 tcs_tes[];\n"
21491                                                            "\n"
21492                                                            "void main()\n"
21493                                                            "{\n"
21494                                                            "\n"
21495                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21496                                                            "\n"
21497                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21498                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21499                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21500                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21501                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21502                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21503                                                            "}\n"
21504                                                            "\n";
21505 #if 0
21506         static const GLchar* tcs_tested =
21507                 "#version 430 core\n"
21508                 "#extension GL_ARB_enhanced_layouts : require\n"
21509                 "\n"
21510                 "layout(vertices = 1) out;\n"
21511                 "\n"
21512                 "VAR_DEFINITION"
21513                 "\n"
21514                 "in  vec4 vs_tcs[];\n"
21515                 "out vec4 tcs_tes[];\n"
21516                 "\n"
21517                 "void main()\n"
21518                 "{\n"
21519                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21520                 "\n"
21521                 "VARIABLE_USE"
21522                 "\n"
21523                 "    tcs_tes[gl_InvocationID] = result;\n"
21524                 "\n"
21525                 "    gl_TessLevelOuter[0] = 1.0;\n"
21526                 "    gl_TessLevelOuter[1] = 1.0;\n"
21527                 "    gl_TessLevelOuter[2] = 1.0;\n"
21528                 "    gl_TessLevelOuter[3] = 1.0;\n"
21529                 "    gl_TessLevelInner[0] = 1.0;\n"
21530                 "    gl_TessLevelInner[1] = 1.0;\n"
21531                 "}\n"
21532                 "\n";
21533 #endif
21534         static const GLchar* tes_tested = "#version 430 core\n"
21535                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21536                                                                           "\n"
21537                                                                           "layout(isolines, point_mode) in;\n"
21538                                                                           "\n"
21539                                                                           "VAR_DEFINITION"
21540                                                                           "\n"
21541                                                                           "in  vec4 tcs_tes[];\n"
21542                                                                           "out vec4 tes_gs;\n"
21543                                                                           "\n"
21544                                                                           "void main()\n"
21545                                                                           "{\n"
21546                                                                           "    vec4 result = tcs_tes[0];\n"
21547                                                                           "\n"
21548                                                                           "VARIABLE_USE"
21549                                                                           "\n"
21550                                                                           "    tes_gs += result;\n"
21551                                                                           "}\n"
21552                                                                           "\n";
21553         static const GLchar* vs = "#version 430 core\n"
21554                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21555                                                           "\n"
21556                                                           "in  vec4 in_vs;\n"
21557                                                           "out vec4 vs_tcs;\n"
21558                                                           "\n"
21559                                                           "void main()\n"
21560                                                           "{\n"
21561                                                           "    vs_tcs = in_vs;\n"
21562                                                           "}\n"
21563                                                           "\n";
21564         static const GLchar* vs_tested = "#version 430 core\n"
21565                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21566                                                                          "\n"
21567                                                                          "VAR_DEFINITION"
21568                                                                          "\n"
21569                                                                          "in  vec4 in_vs;\n"
21570                                                                          "out vec4 vs_tcs;\n"
21571                                                                          "\n"
21572                                                                          "void main()\n"
21573                                                                          "{\n"
21574                                                                          "    vec4 result = in_vs;\n"
21575                                                                          "\n"
21576                                                                          "VARIABLE_USE"
21577                                                                          "\n"
21578                                                                          "    vs_tcs += result;\n"
21579                                                                          "}\n"
21580                                                                          "\n";
21581
21582         std::string                       source;
21583         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21584
21585         if (test_case == stage)
21586         {
21587                 const GLchar* array     = "";
21588                 const GLchar* index     = "";
21589                 size_t            position = 0;
21590                 size_t            temp;
21591                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21592                 // change array = "[]" to "[1]"
21593                 switch (stage)
21594                 {
21595                 case Utils::Shader::GEOMETRY:
21596                         source = gs_tested;
21597                         array  = "[1]";
21598                         index  = "[0]";
21599                         break;
21600 /*
21601                          It is invalid to define transform feedback output in HS
21602                          */
21603 #if 0
21604                         case Utils::Shader::TESS_CTRL:
21605                         source = tcs_tested;
21606                         array = "[]";
21607                         index = "[gl_InvocationID]";
21608                         break;
21609 #endif
21610                 case Utils::Shader::TESS_EVAL:
21611                         source = tes_tested;
21612                         array  = "[1]";
21613                         index  = "[0]";
21614                         break;
21615                 case Utils::Shader::VERTEX:
21616                         source = vs_tested;
21617                         break;
21618                 default:
21619                         TCU_FAIL("Invalid enum");
21620                 }
21621
21622                 temp = position;
21623                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21624                 position = temp;
21625                 Utils::replaceToken("ARRAY", position, array, source);
21626                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21627
21628                 Utils::replaceAllTokens("INDEX", index, source);
21629         }
21630         else
21631         {
21632                 switch (test_case)
21633                 {
21634                 case Utils::Shader::GEOMETRY:
21635                         switch (stage)
21636                         {
21637                         case Utils::Shader::VERTEX:
21638                                 source = vs;
21639                                 break;
21640                         default:
21641                                 source = "";
21642                         }
21643                         break;
21644                 case Utils::Shader::TESS_CTRL:
21645                         switch (stage)
21646                         {
21647                         case Utils::Shader::VERTEX:
21648                                 source = vs;
21649                                 break;
21650                         default:
21651                                 source = "";
21652                         }
21653                         break;
21654                 case Utils::Shader::TESS_EVAL:
21655                         switch (stage)
21656                         {
21657                         case Utils::Shader::TESS_CTRL:
21658                                 source = tcs;
21659                                 break;
21660                         case Utils::Shader::VERTEX:
21661                                 source = vs;
21662                                 break;
21663                         default:
21664                                 source = "";
21665                         }
21666                         break;
21667                 case Utils::Shader::VERTEX:
21668                         source = "";
21669                         break;
21670                 default:
21671                         TCU_FAIL("Invalid enum");
21672                         break;
21673                 }
21674         }
21675
21676         return source;
21677 }
21678
21679 /** Get description of test case
21680  *
21681  * @param test_case_index Index of test case
21682  *
21683  * @return Test case description
21684  **/
21685 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21686 {
21687         std::stringstream stream;
21688
21689         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21690
21691         return stream.str();
21692 }
21693
21694 /** Get number of test cases
21695  *
21696  * @return Number of test cases
21697  **/
21698 GLuint XFBBlockStrideTest::getTestCaseNumber()
21699 {
21700         return static_cast<GLuint>(m_test_cases.size());
21701 }
21702
21703 /** Inspects program for xfb stride
21704  *
21705  * @param program Program to query
21706  *
21707  * @return true if query results match expected values, false otherwise
21708  **/
21709 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21710 {
21711         GLint stride = 0;
21712
21713         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21714                                                 1 /* buf_size */, &stride);
21715
21716         return (128 == stride);
21717 }
21718
21719 /** Runs test case
21720  *
21721  * @param test_case_index Id of test case
21722  *
21723  * @return true if test case pass, false otherwise
21724  **/
21725 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21726 {
21727         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21728         Utils::Program   program(m_context);
21729         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21730         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21731         bool                       test_case_result = true;
21732         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21733
21734         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21735
21736         test_case_result = inspectProgram(program);
21737
21738         return test_case_result;
21739 }
21740
21741 /** Prepare all test cases
21742  *
21743  **/
21744 void XFBBlockStrideTest::testInit()
21745 {
21746         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21747         {
21748                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21749                         (Utils::Shader::FRAGMENT == stage))
21750                 {
21751                         continue;
21752                 }
21753
21754                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21755         }
21756 }
21757
21758 /** Constructor
21759  *
21760  * @param context Test context
21761  **/
21762 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21763         : BufferTestBase(context, "xfb_block_member_stride",
21764                                          "Test verifies that xfb_stride qualifier is respected for block member")
21765 {
21766         /* Nothing to be done here */
21767 }
21768
21769 /** Get descriptors of buffers necessary for test
21770  *
21771  * @param ignored
21772  * @param out_descriptors Descriptors of buffers used by test
21773  **/
21774 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21775                                                                                                         bufferDescriptor::Vector& out_descriptors)
21776 {
21777         const Utils::Type& vec4 = Utils::Type::vec4;
21778
21779         /* Test needs single uniform and xfb */
21780         out_descriptors.resize(2);
21781
21782         /* Get references */
21783         bufferDescriptor& uniform = out_descriptors[0];
21784         bufferDescriptor& xfb    = out_descriptors[1];
21785
21786         /* Index */
21787         uniform.m_index = 0;
21788         xfb.m_index             = 0;
21789
21790         /* Target */
21791         uniform.m_target = Utils::Buffer::Uniform;
21792         xfb.m_target     = Utils::Buffer::Transform_feedback;
21793
21794         /* Data */
21795         static const GLuint                     vec4_size   = 16;
21796         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21797         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21798         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21799
21800         /* Uniform data */
21801         uniform.m_initial_data.resize(3 * vec4_size);
21802         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21803         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21804         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21805
21806         /* XFB data */
21807         xfb.m_initial_data.resize(4 * vec4_size);
21808         xfb.m_expected_data.resize(4 * vec4_size);
21809
21810         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21811         {
21812                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21813                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21814         }
21815
21816         // the xfb_offset of "chichi" should be 32
21817         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21818         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21819         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21820 }
21821
21822 /** Get body of main function for given shader stage
21823  *
21824  * @param ignored
21825  * @param stage            Shader stage
21826  * @param out_assignments  Set to empty
21827  * @param out_calculations Set to empty
21828  **/
21829 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21830                                                                                          std::string& out_assignments, std::string& out_calculations)
21831 {
21832         out_calculations = "";
21833
21834         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21835                                                           "    goten  = uni_goten;\n"
21836                                                           "    chichi = uni_chichi;\n";
21837         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21838
21839         const GLchar* assignments = "";
21840         switch (stage)
21841         {
21842         case Utils::Shader::FRAGMENT:
21843                 assignments = fs;
21844                 break;
21845         case Utils::Shader::GEOMETRY:
21846                 assignments = gs;
21847                 break;
21848         default:
21849                 break;
21850         }
21851
21852         out_assignments = assignments;
21853 }
21854
21855 /** Get interface of shader
21856  *
21857  * @param ignored
21858  * @param stage            Shader stage
21859  * @param out_interface    Set to ""
21860  **/
21861 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21862                                                                                                   std::string& out_interface)
21863 {
21864         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21865                                                           "                             vec4 gohan;\n"
21866                                                           "    layout (xfb_stride = 48) vec4 goten;\n"
21867                                                           "                             vec4 chichi;\n"
21868                                                           "};\n"
21869                                                           "layout(binding = 0) uniform gs_block {\n"
21870                                                           "    vec4 uni_gohan;\n"
21871                                                           "    vec4 uni_goten;\n"
21872                                                           "    vec4 uni_chichi;\n"
21873                                                           "};\n";
21874         static const GLchar* fs = "in Goku {\n"
21875                                                           "    vec4 gohan;\n"
21876                                                           "    vec4 goten;\n"
21877                                                           "    vec4 chichi;\n"
21878                                                           "};\n"
21879                                                           "out vec4 fs_out;\n";
21880
21881         switch (stage)
21882         {
21883         case Utils::Shader::FRAGMENT:
21884                 out_interface = fs;
21885                 break;
21886         case Utils::Shader::GEOMETRY:
21887                 out_interface = gs;
21888                 break;
21889         default:
21890                 out_interface = "";
21891                 return;
21892         }
21893 }
21894
21895 /** Inspects program to check if all resources are as expected
21896  *
21897  * @param ignored
21898  * @param program    Program instance
21899  * @param out_stream Error message
21900  *
21901  * @return true if everything is ok, false otherwise
21902  **/
21903 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21904                                                                                           std::stringstream& out_stream)
21905 {
21906         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21907         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21908         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21909
21910         GLint gohan_offset  = 0;
21911         GLint goten_offset  = 0;
21912         GLint chichi_offset = 0;
21913
21914         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21915         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21916         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21917
21918         // the xfb_offset of "chichi" should be 32
21919         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21920         {
21921                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21922                                    << "] expected: [0, 16, 32]";
21923                 return false;
21924         }
21925
21926         return true;
21927 }
21928
21929 /** Constructor
21930  *
21931  * @param context Test framework context
21932  **/
21933 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21934         : NegativeTestBase(context, "xfb_duplicated_stride",
21935                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21936 {
21937 }
21938
21939 /** Source for given test case and stage
21940  *
21941  * @param test_case_index Index of test case
21942  * @param stage           Shader stage
21943  *
21944  * @return Shader source
21945  **/
21946 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21947 {
21948         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21949                                                                                                   "const uint conflicting_stride = 128;\n"
21950                                                                                                   "\n"
21951                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21952                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21953         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21954                                                                                                 "\n"
21955                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21956                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21957         static const GLchar* fs = "#version 430 core\n"
21958                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21959                                                           "\n"
21960                                                           "in  vec4 any_fs;\n"
21961                                                           "out vec4 fs_out;\n"
21962                                                           "\n"
21963                                                           "void main()\n"
21964                                                           "{\n"
21965                                                           "    fs_out = any_fs;\n"
21966                                                           "}\n"
21967                                                           "\n";
21968         static const GLchar* gs_tested = "#version 430 core\n"
21969                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21970                                                                          "\n"
21971                                                                          "layout(points)                           in;\n"
21972                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21973                                                                          "\n"
21974                                                                          "VAR_DEFINITION"
21975                                                                          "\n"
21976                                                                          "in  vec4 vs_any[];\n"
21977                                                                          "out vec4 any_fs;\n"
21978                                                                          "\n"
21979                                                                          "void main()\n"
21980                                                                          "{\n"
21981                                                                          "    vec4 result = vs_any[0];\n"
21982                                                                          "\n"
21983                                                                          "VARIABLE_USE"
21984                                                                          "\n"
21985                                                                          "    any_fs = result;\n"
21986                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21987                                                                          "    EmitVertex();\n"
21988                                                                          "    any_fs = result;\n"
21989                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21990                                                                          "    EmitVertex();\n"
21991                                                                          "    any_fs = result;\n"
21992                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21993                                                                          "    EmitVertex();\n"
21994                                                                          "    any_fs = result;\n"
21995                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21996                                                                          "    EmitVertex();\n"
21997                                                                          "}\n"
21998                                                                          "\n";
21999         static const GLchar* tcs = "#version 430 core\n"
22000                                                            "#extension GL_ARB_enhanced_layouts : require\n"
22001                                                            "\n"
22002                                                            "layout(vertices = 1) out;\n"
22003                                                            "\n"
22004                                                            "in  vec4 vs_any[];\n"
22005                                                            "out vec4 tcs_tes[];\n"
22006                                                            "\n"
22007                                                            "void main()\n"
22008                                                            "{\n"
22009                                                            "\n"
22010                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
22011                                                            "\n"
22012                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
22013                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
22014                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
22015                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
22016                                                            "    gl_TessLevelInner[0] = 1.0;\n"
22017                                                            "    gl_TessLevelInner[1] = 1.0;\n"
22018                                                            "}\n"
22019                                                            "\n";
22020         static const GLchar* tcs_tested = "#version 430 core\n"
22021                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22022                                                                           "\n"
22023                                                                           "layout(vertices = 1) out;\n"
22024                                                                           "\n"
22025                                                                           "VAR_DEFINITION"
22026                                                                           "\n"
22027                                                                           "in  vec4 vs_any[];\n"
22028                                                                           "out vec4 any_fs[];\n"
22029                                                                           "\n"
22030                                                                           "void main()\n"
22031                                                                           "{\n"
22032                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
22033                                                                           "\n"
22034                                                                           "VARIABLE_USE"
22035                                                                           "\n"
22036                                                                           "    any_fs[gl_InvocationID] = result;\n"
22037                                                                           "\n"
22038                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
22039                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
22040                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
22041                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
22042                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
22043                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
22044                                                                           "}\n"
22045                                                                           "\n";
22046         static const GLchar* tes_tested = "#version 430 core\n"
22047                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22048                                                                           "\n"
22049                                                                           "layout(isolines, point_mode) in;\n"
22050                                                                           "\n"
22051                                                                           "VAR_DEFINITION"
22052                                                                           "\n"
22053                                                                           "in  vec4 tcs_tes[];\n"
22054                                                                           "out vec4 any_fs;\n"
22055                                                                           "\n"
22056                                                                           "void main()\n"
22057                                                                           "{\n"
22058                                                                           "    vec4 result = tcs_tes[0];\n"
22059                                                                           "\n"
22060                                                                           "VARIABLE_USE"
22061                                                                           "\n"
22062                                                                           "    any_fs = result;\n"
22063                                                                           "}\n"
22064                                                                           "\n";
22065         static const GLchar* vs = "#version 430 core\n"
22066                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22067                                                           "\n"
22068                                                           "in  vec4 in_vs;\n"
22069                                                           "out vec4 vs_any;\n"
22070                                                           "\n"
22071                                                           "void main()\n"
22072                                                           "{\n"
22073                                                           "    vs_any = in_vs;\n"
22074                                                           "}\n"
22075                                                           "\n";
22076         static const GLchar* vs_tested = "#version 430 core\n"
22077                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22078                                                                          "\n"
22079                                                                          "VAR_DEFINITION"
22080                                                                          "\n"
22081                                                                          "in  vec4 in_vs;\n"
22082                                                                          "out vec4 any_fs;\n"
22083                                                                          "\n"
22084                                                                          "void main()\n"
22085                                                                          "{\n"
22086                                                                          "    vec4 result = in_vs;\n"
22087                                                                          "\n"
22088                                                                          "VARIABLE_USE"
22089                                                                          "\n"
22090                                                                          "    any_fs += result;\n"
22091                                                                          "}\n"
22092                                                                          "\n";
22093
22094         std::string source;
22095         testCase&   test_case = m_test_cases[test_case_index];
22096
22097         if (test_case.m_stage == stage)
22098         {
22099                 size_t            position               = 0;
22100                 const GLchar* var_definition = 0;
22101                 const GLchar* var_use            = "";
22102
22103                 switch (test_case.m_case)
22104                 {
22105                 case VALID:
22106                         var_definition = valid_var_definition;
22107                         break;
22108                 case INVALID:
22109                         var_definition = invalid_var_definition;
22110                         break;
22111                 default:
22112                         TCU_FAIL("Invalid enum");
22113                 }
22114
22115                 switch (stage)
22116                 {
22117                 case Utils::Shader::GEOMETRY:
22118                         source = gs_tested;
22119                         break;
22120                 case Utils::Shader::TESS_CTRL:
22121                         source = tcs_tested;
22122                         break;
22123                 case Utils::Shader::TESS_EVAL:
22124                         source = tes_tested;
22125                         break;
22126                 case Utils::Shader::VERTEX:
22127                         source = vs_tested;
22128                         break;
22129                 default:
22130                         TCU_FAIL("Invalid enum");
22131                 }
22132
22133                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22134                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22135         }
22136         else
22137         {
22138                 switch (test_case.m_stage)
22139                 {
22140                 case Utils::Shader::GEOMETRY:
22141                         switch (stage)
22142                         {
22143                         case Utils::Shader::FRAGMENT:
22144                                 source = fs;
22145                                 break;
22146                         case Utils::Shader::VERTEX:
22147                                 source = vs;
22148                                 break;
22149                         default:
22150                                 source = "";
22151                         }
22152                         break;
22153                 case Utils::Shader::TESS_CTRL:
22154                         switch (stage)
22155                         {
22156                         case Utils::Shader::FRAGMENT:
22157                                 source = fs;
22158                                 break;
22159                         case Utils::Shader::VERTEX:
22160                                 source = vs;
22161                                 break;
22162                         default:
22163                                 source = "";
22164                         }
22165                         break;
22166                 case Utils::Shader::TESS_EVAL:
22167                         switch (stage)
22168                         {
22169                         case Utils::Shader::FRAGMENT:
22170                                 source = fs;
22171                                 break;
22172                         case Utils::Shader::TESS_CTRL:
22173                                 source = tcs;
22174                                 break;
22175                         case Utils::Shader::VERTEX:
22176                                 source = vs;
22177                                 break;
22178                         default:
22179                                 source = "";
22180                         }
22181                         break;
22182                 case Utils::Shader::VERTEX:
22183                         switch (stage)
22184                         {
22185                         case Utils::Shader::FRAGMENT:
22186                                 source = fs;
22187                                 break;
22188                         default:
22189                                 source = "";
22190                         }
22191                         break;
22192                 default:
22193                         TCU_FAIL("Invalid enum");
22194                         break;
22195                 }
22196         }
22197
22198         return source;
22199 }
22200
22201 /** Get description of test case
22202  *
22203  * @param test_case_index Index of test case
22204  *
22205  * @return Test case description
22206  **/
22207 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22208 {
22209         std::stringstream stream;
22210         testCase&                 test_case = m_test_cases[test_case_index];
22211
22212         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22213
22214         switch (test_case.m_case)
22215         {
22216         case VALID:
22217                 stream << "valid";
22218                 break;
22219         case INVALID:
22220                 stream << "invalid";
22221                 break;
22222         default:
22223                 TCU_FAIL("Invalid enum");
22224         }
22225
22226         return stream.str();
22227 }
22228
22229 /** Get number of test cases
22230  *
22231  * @return Number of test cases
22232  **/
22233 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22234 {
22235         return static_cast<GLuint>(m_test_cases.size());
22236 }
22237
22238 /** Selects if "compute" stage is relevant for test
22239  *
22240  * @param ignored
22241  *
22242  * @return false
22243  **/
22244 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22245 {
22246         return false;
22247 }
22248
22249 /** Selects if compilation failure is expected result
22250  *
22251  * @param test_case_index Index of test case
22252  *
22253  * @return true
22254  **/
22255 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22256 {
22257         testCase& test_case = m_test_cases[test_case_index];
22258
22259         return (INVALID == test_case.m_case);
22260 }
22261
22262 /** Prepare all test cases
22263  *
22264  **/
22265 void XFBDuplicatedStrideTest::testInit()
22266 {
22267         for (GLuint c = 0; c < CASE_MAX; ++c)
22268         {
22269                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22270                 {
22271                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22272                                 (Utils::Shader::FRAGMENT == stage))
22273                         {
22274                                 continue;
22275                         }
22276
22277                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22278
22279                         m_test_cases.push_back(test_case);
22280                 }
22281         }
22282 }
22283
22284 /** Constructor
22285  *
22286  * @param context Test framework context
22287  **/
22288 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22289         : TestBase(context, "xfb_get_program_resource_api",
22290                            "Test verifies that get program resource reports correct results for XFB")
22291 {
22292 }
22293
22294 /** Source for given test case and stage
22295  *
22296  * @param test_case_index Index of test case
22297  * @param stage           Shader stage
22298  *
22299  * @return Shader source
22300  **/
22301 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22302 {
22303         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22304                                                                                           "out TYPE b1_v1ARRAY;\n"
22305                                                                                           "out TYPE b0_v3ARRAY;\n"
22306                                                                                           "out TYPE b0_v0ARRAY;\n";
22307         static const GLchar* xfb_var_definition =
22308                 "const uint type_size = SIZE;\n"
22309                 "\n"
22310                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22311                 "\n"
22312                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22313                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22314                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22315                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22316         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22317                                                                    "    b1_v1INDEX = TYPE(1);\n"
22318                                                                    "    b0_v3INDEX = TYPE(0);\n"
22319                                                                    "    b0_v0INDEX = TYPE(1);\n"
22320                                                                    "    if (vec4(0) == result)\n"
22321                                                                    "    {\n"
22322                                                                    "        b0_v1INDEX = TYPE(1);\n"
22323                                                                    "        b1_v1INDEX = TYPE(0);\n"
22324                                                                    "        b0_v3INDEX = TYPE(1);\n"
22325                                                                    "        b0_v0INDEX = TYPE(0);\n"
22326                                                                    "    }\n";
22327         static const GLchar* gs_tested =
22328                 "#version 430 core\n"
22329                 "#extension GL_ARB_enhanced_layouts : require\n"
22330                 "\n"
22331                 "layout(points)                           in;\n"
22332                 "layout(triangle_strip, max_vertices = 4) out;\n"
22333                 "\n"
22334                 "VAR_DEFINITION"
22335                 "\n"
22336                 "out gl_PerVertex \n"
22337                 "{ \n"
22338                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22339                 "}; \n"
22340                 "in  vec4 tes_gs[];\n"
22341                 "out vec4 gs_fs;\n"
22342                 "\n"
22343                 "void main()\n"
22344                 "{\n"
22345                 "    vec4 result = tes_gs[0];\n"
22346                 "\n"
22347                 "VARIABLE_USE"
22348                 "\n"
22349                 "    gs_fs = result;\n"
22350                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22351                 "    EmitVertex();\n"
22352                 "    gs_fs = result;\n"
22353                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22354                 "    EmitVertex();\n"
22355                 "    gs_fs = result;\n"
22356                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22357                 "    EmitVertex();\n"
22358                 "    gs_fs = result;\n"
22359                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22360                 "    EmitVertex();\n"
22361                 "}\n"
22362                 "\n";
22363 #if 0
22364         static const GLchar* tcs_tested =
22365                 "#version 430 core\n"
22366                 "#extension GL_ARB_enhanced_layouts : require\n"
22367                 "\n"
22368                 "layout(vertices = 1) out;\n"
22369                 "\n"
22370                 "VAR_DEFINITION"
22371                 "\n"
22372                 "in  vec4 vs_tcs[];\n"
22373                 "out vec4 tcs_tes[];\n"
22374                 "\n"
22375                 "void main()\n"
22376                 "{\n"
22377                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22378                 "\n"
22379                 "VARIABLE_USE"
22380                 "\n"
22381                 "    tcs_tes[gl_InvocationID] = result;\n"
22382                 "\n"
22383                 "    gl_TessLevelOuter[0] = 1.0;\n"
22384                 "    gl_TessLevelOuter[1] = 1.0;\n"
22385                 "    gl_TessLevelOuter[2] = 1.0;\n"
22386                 "    gl_TessLevelOuter[3] = 1.0;\n"
22387                 "    gl_TessLevelInner[0] = 1.0;\n"
22388                 "    gl_TessLevelInner[1] = 1.0;\n"
22389                 "}\n"
22390                 "\n";
22391 #endif
22392         static const GLchar* tes_tested = "#version 430 core\n"
22393                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22394                                                                           "\n"
22395                                                                           "layout(isolines, point_mode) in;\n"
22396                                                                           "\n"
22397                                                                           "VAR_DEFINITION"
22398                                                                           "\n"
22399                                                                           "in  vec4 tcs_tes[];\n"
22400                                                                           "out vec4 tes_gs;\n"
22401                                                                           "\n"
22402                                                                           "void main()\n"
22403                                                                           "{\n"
22404                                                                           "    vec4 result = tcs_tes[0];\n"
22405                                                                           "\n"
22406                                                                           "VARIABLE_USE"
22407                                                                           "\n"
22408                                                                           "    tes_gs = result;\n"
22409                                                                           "}\n"
22410                                                                           "\n";
22411         static const GLchar* vs_tested = "#version 430 core\n"
22412                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22413                                                                          "\n"
22414                                                                          "VAR_DEFINITION"
22415                                                                          "\n"
22416                                                                          "in  vec4 in_vs;\n"
22417                                                                          "out vec4 vs_tcs;\n"
22418                                                                          "\n"
22419                                                                          "void main()\n"
22420                                                                          "{\n"
22421                                                                          "    vec4 result = in_vs;\n"
22422                                                                          "\n"
22423                                                                          "VARIABLE_USE"
22424                                                                          "\n"
22425                                                                          "    vs_tcs = result;\n"
22426                                                                          "}\n"
22427                                                                          "\n";
22428
22429         std::string              source;
22430         const test_Case& test_case = m_test_cases[test_case_index];
22431
22432         if (test_case.m_stage == stage)
22433         {
22434                 const GLchar* array = "";
22435                 GLchar            buffer[16];
22436                 const GLchar* index     = "";
22437                 size_t            position = 0;
22438                 size_t            temp;
22439                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22440                 const GLchar* var_definition = 0;
22441
22442                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22443
22444                 if (XFB == test_case.m_case)
22445                 {
22446                         var_definition = xfb_var_definition;
22447                 }
22448                 else
22449                 {
22450                         var_definition = api_var_definition;
22451                 }
22452
22453                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22454                 // change array = "[]" to "[1]"
22455                 switch (stage)
22456                 {
22457                 case Utils::Shader::GEOMETRY:
22458                         source = gs_tested;
22459                         array  = "[1]";
22460                         index  = "[0]";
22461                         break;
22462 // It is invalid to output transform feedback varyings in tessellation control shader
22463 #if 0
22464                 case Utils::Shader::TESS_CTRL:
22465                         source = tcs_tested;
22466                         array = "[]";
22467                         index = "[gl_InvocationID]";
22468                         break;
22469 #endif
22470                 case Utils::Shader::TESS_EVAL:
22471                         source = tes_tested;
22472                         array  = "[1]";
22473                         index  = "[0]";
22474                         break;
22475                 case Utils::Shader::VERTEX:
22476                         source = vs_tested;
22477                         break;
22478                 default:
22479                         TCU_FAIL("Invalid enum");
22480                 }
22481
22482                 temp = position;
22483                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22484                 if (XFB == test_case.m_case)
22485                 {
22486                         position = temp;
22487                         Utils::replaceToken("SIZE", position, buffer, source);
22488                 }
22489                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22490
22491                 Utils::replaceAllTokens("ARRAY", array, source);
22492                 Utils::replaceAllTokens("INDEX", index, source);
22493                 Utils::replaceAllTokens("TYPE", type_name, source);
22494         }
22495         else
22496         {
22497                 source = "";
22498         }
22499
22500         return source;
22501 }
22502
22503 /** Get description of test case
22504  *
22505  * @param test_case_index Index of test case
22506  *
22507  * @return Test case description
22508  **/
22509 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22510 {
22511         std::stringstream stream;
22512         const test_Case&  test_case = m_test_cases[test_case_index];
22513
22514         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22515                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22516
22517         switch (test_case.m_case)
22518         {
22519         case INTERLEAVED:
22520                 stream << "interleaved";
22521                 break;
22522         case SEPARATED:
22523                 stream << "separated";
22524                 break;
22525         case XFB:
22526                 stream << "xfb";
22527                 break;
22528         default:
22529                 TCU_FAIL("Invalid enum");
22530         }
22531
22532         return stream.str();
22533 }
22534
22535 /** Get number of test cases
22536  *
22537  * @return Number of test cases
22538  **/
22539 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22540 {
22541         return static_cast<GLuint>(m_test_cases.size());
22542 }
22543
22544 /** Inspects program for offset, buffer index, buffer stride and type
22545  *
22546  * @param test_case_index Index of test case
22547  * @param program         Program to query
22548  *
22549  * @return true if query results match expected values, false otherwise
22550  **/
22551 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22552 {
22553         GLint                    b0_stride      = 0;
22554         GLint                    b1_stride      = 0;
22555         GLint                    b0_v0_buf      = 0;
22556         GLint                    b0_v0_offset = 0;
22557         GLint                    b0_v0_type   = 0;
22558         GLint                    b0_v1_buf      = 0;
22559         GLint                    b0_v1_offset = 0;
22560         GLint                    b0_v1_type   = 0;
22561         GLint                    b0_v3_buf      = 0;
22562         GLint                    b0_v3_offset = 0;
22563         GLint                    b0_v3_type   = 0;
22564         GLint                    b1_v1_buf      = 0;
22565         GLint                    b1_v1_offset = 0;
22566         GLint                    b1_v1_type   = 0;
22567         const test_Case& test_case      = m_test_cases[test_case_index];
22568         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22569         const GLint              type_size      = test_case.m_type.GetSize();
22570
22571         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22572         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22573         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22574         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22575
22576         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22577         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22578         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22579         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22580
22581         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22582         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22583         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22584         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22585
22586         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22587                                                 1 /* buf_size */, &b0_v0_buf);
22588         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22589                                                 1 /* buf_size */, &b0_v1_buf);
22590         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22591                                                 1 /* buf_size */, &b0_v3_buf);
22592         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22593                                                 1 /* buf_size */, &b1_v1_buf);
22594
22595         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22596                                                 &b0_stride);
22597         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22598                                                 &b1_stride);
22599
22600         if (SEPARATED != test_case.m_case)
22601         {
22602                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22603                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22604                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22605                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22606                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22607                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22608                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22609         }
22610         else
22611         {
22612                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22613                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22614                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22615                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22616                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22617         }
22618 }
22619
22620 /** Insert gl_SkipComponents
22621  *
22622  * @param num_components How many gl_SkipComponents1 need to be inserted
22623  * @param varyings The transform feedback varyings string vector
22624  *
22625  **/
22626 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22627 {
22628         int num_component_4 = num_components / 4;
22629         int num_component_1 = num_components % 4;
22630         for (int i = 0; i < num_component_4; i++)
22631         {
22632                 varyings.push_back("gl_SkipComponents4");
22633         }
22634         switch (num_component_1)
22635         {
22636         case 1:
22637                 varyings.push_back("gl_SkipComponents1");
22638                 break;
22639         case 2:
22640                 varyings.push_back("gl_SkipComponents2");
22641                 break;
22642         case 3:
22643                 varyings.push_back("gl_SkipComponents3");
22644                 break;
22645         default:
22646                 break;
22647         }
22648 }
22649
22650 /** Runs test case
22651  *
22652  * @param test_case_index Id of test case
22653  *
22654  * @return true if test case pass, false otherwise
22655  **/
22656 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22657 {
22658         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22659         Utils::Program   program(m_context);
22660         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22661         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22662         const test_Case&   test_case            = m_test_cases[test_case_index];
22663         bool                       test_case_result = true;
22664         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22665
22666         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22667         // 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.
22668
22669         if (INTERLEAVED == test_case.m_case)
22670         {
22671                 /*
22672                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22673                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22674                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22675                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22676
22677                  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,
22678                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22679                  */
22680                 Utils::Program::NameVector captured_varyings;
22681                 captured_varyings.push_back("b0_v0");
22682                 captured_varyings.push_back("b0_v1");
22683                 // Compute how many gl_SkipComponents to be inserted
22684                 int numComponents = test_case.m_type.GetSize() / 4;
22685                 insertSkipComponents(numComponents, captured_varyings);
22686                 captured_varyings.push_back("b0_v3");
22687                 captured_varyings.push_back("gl_NextBuffer");
22688                 insertSkipComponents(numComponents, captured_varyings);
22689                 captured_varyings.push_back("b1_v1");
22690                 insertSkipComponents(numComponents * 2, captured_varyings);
22691
22692                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22693                                          true /* separable */);
22694         }
22695         else if (SEPARATED == test_case.m_case)
22696         {
22697                 Utils::Program::NameVector captured_varyings;
22698
22699                 captured_varyings.push_back("b0_v0");
22700                 captured_varyings.push_back("b0_v1");
22701                 captured_varyings.push_back("b0_v3");
22702                 captured_varyings.push_back("b1_v1");
22703
22704                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22705                                          true /* separable */);
22706         }
22707         else
22708         {
22709
22710                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22711         }
22712
22713         test_case_result = inspectProgram(test_case_index, program);
22714
22715         return test_case_result;
22716 }
22717
22718 /** Prepare all test cases
22719  *
22720  **/
22721 void XFBGetProgramResourceAPITest::testInit()
22722 {
22723         const Functions& gl              = m_context.getRenderContext().getFunctions();
22724         const GLuint     n_types = getTypesNumber();
22725         GLint                    max_xfb_int;
22726         GLint                    max_xfb_sep;
22727
22728         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22729         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22730
22731         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22732         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22733
22734         GLint max_varyings;
22735         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22736
22737         for (GLuint i = 0; i < n_types; ++i)
22738         {
22739                 // 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,
22740                 // 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
22741                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22742                 // to guarantee the number of varying not exceeded.
22743                 /*
22744                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22745                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22746                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22747                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22748                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22749                  in  vec4 in_vs;
22750                  out vec4 vs_tcs;
22751                  */
22752                 if (i == 7 || i == 9)
22753                         continue;
22754                 const Utils::Type& type = getType(i);
22755                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22756                 {
22757                         continue;
22758                 }
22759                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22760                 {
22761                         /*
22762                          It is invalid to define transform feedback output in HS
22763                          */
22764                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22765                                 (Utils::Shader::FRAGMENT == stage))
22766                         {
22767                                 continue;
22768                         }
22769
22770                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22771                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22772                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22773
22774                         if ((int)type.GetSize() <= max_xfb_int)
22775                         {
22776                                 m_test_cases.push_back(test_case_xfb);
22777                                 m_test_cases.push_back(test_case_int);
22778                         }
22779
22780                         if ((int)type.GetSize() <= max_xfb_sep)
22781                         {
22782                                 m_test_cases.push_back(test_case_sep);
22783                         }
22784                 }
22785         }
22786 }
22787
22788 /** Constructor
22789  *
22790  * @param context Test context
22791  **/
22792 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22793         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22794                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22795 {
22796         /* Nothing to be done here */
22797 }
22798
22799 /** Get descriptors of buffers necessary for test
22800  *
22801  * @param test_case_index Index of test case
22802  * @param out_descriptors Descriptors of buffers used by test
22803  **/
22804 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22805                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22806 {
22807         const Utils::Type& type = getType(test_case_index);
22808
22809         /* Test needs single uniform and xfb */
22810         out_descriptors.resize(2);
22811
22812         /* Get references */
22813         bufferDescriptor& uniform = out_descriptors[0];
22814         bufferDescriptor& xfb    = out_descriptors[1];
22815
22816         /* Index */
22817         uniform.m_index = 0;
22818         xfb.m_index             = 0;
22819
22820         /* Target */
22821         uniform.m_target = Utils::Buffer::Uniform;
22822         xfb.m_target     = Utils::Buffer::Transform_feedback;
22823
22824         /* Data */
22825         const GLuint                            gen_start   = Utils::s_rand;
22826         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22827         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22828         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22829
22830         Utils::s_rand                                                           = gen_start;
22831         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22832         type.GenerateDataPacked(); // generate the data for trunks
22833         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22834
22835         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22836         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22837
22838         /* Uniform data */
22839         uniform.m_initial_data.resize(3 * type_size);
22840         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22841         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22842         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22843
22844         /* XFB data */
22845         xfb.m_initial_data.resize(3 * type_size_pck);
22846         xfb.m_expected_data.resize(3 * type_size_pck);
22847
22848         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
22849         {
22850                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22851                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22852         }
22853
22854         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22855         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22856 }
22857
22858 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22859  *
22860  * @param ignored
22861  * @param captured_varyings List of names
22862  **/
22863 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint test_case_index,
22864                                                                                                                    Utils::Program::NameVector& captured_varyings,
22865                                                                                                                    GLint* xfb_components)
22866 {
22867         captured_varyings.resize(1);
22868
22869         captured_varyings[0] = "trunks";
22870
22871         /* The test captures 3 varyings of type 'type' */
22872         Utils::Type     type            = getType(test_case_index);
22873         GLint           type_size       = type.GetSize(false);
22874         *xfb_components                 = 3 * type_size / 4;
22875 }
22876
22877 /** Get body of main function for given shader stage
22878  *
22879  * @param test_case_index  Index of test case
22880  * @param stage            Shader stage
22881  * @param out_assignments  Set to empty
22882  * @param out_calculations Set to empty
22883  **/
22884 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22885                                                                                                          std::string& out_assignments, std::string& out_calculations)
22886 {
22887         out_calculations = "";
22888
22889         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22890                                                           "    trunks = uni_trunks;\n"
22891                                                           "    goku   = uni_goku;\n";
22892         static const GLchar* fs = "    fs_out = vec4(0);\n"
22893                                                           "    if (TYPE(1) == goku + trunks + vegeta)\n"
22894                                                           "    {\n"
22895                                                           "        fs_out = vec4(1);\n"
22896                                                           "    }\n";
22897
22898         const GLchar* assignments = "";
22899         switch (stage)
22900         {
22901         case Utils::Shader::FRAGMENT:
22902                 assignments = fs;
22903                 break;
22904         case Utils::Shader::GEOMETRY:
22905                 assignments = gs;
22906                 break;
22907         default:
22908                 break;
22909         }
22910
22911         out_assignments = assignments;
22912
22913         if (Utils::Shader::FRAGMENT == stage)
22914         {
22915                 const Utils::Type& type = getType(test_case_index);
22916
22917                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22918         }
22919 }
22920
22921 /** Get interface of shader
22922  *
22923  * @param test_case_index  Index of test case
22924  * @param stage            Shader stage
22925  * @param out_interface    Set to ""
22926  **/
22927 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22928                                                                                                                   std::string& out_interface)
22929 {
22930         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22931                                                           "\n"
22932                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22933                                                           "                                      flat out TYPE trunks;\n"
22934                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22935                                                           "\n"
22936                                                           /*
22937                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22938                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22939                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22940                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22941                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22942                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22943                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22944                  */
22945                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22946                                                           "    TYPE uni_vegeta;\n"
22947                                                           "    TYPE uni_trunks;\n"
22948                                                           "    TYPE uni_goku;\n"
22949                                                           "};\n";
22950         static const GLchar* fs = "flat in TYPE vegeta;\n"
22951                                                           "flat in TYPE trunks;\n"
22952                                                           "flat in TYPE goku;\n"
22953                                                           "\n"
22954                                                           "out vec4 fs_out;\n";
22955
22956         const Utils::Type& type = getType(test_case_index);
22957
22958         switch (stage)
22959         {
22960         case Utils::Shader::FRAGMENT:
22961                 out_interface = fs;
22962                 break;
22963         case Utils::Shader::GEOMETRY:
22964                 out_interface = gs;
22965                 break;
22966         default:
22967                 out_interface = "";
22968                 return;
22969         }
22970
22971         if (Utils::Shader::GEOMETRY == stage)
22972         {
22973                 GLchar           buffer[16];
22974                 size_t           position  = 0;
22975                 const GLuint type_size = type.GetSize();
22976
22977                 sprintf(buffer, "%d", type_size);
22978
22979                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22980         }
22981
22982         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22983 }
22984
22985 /** Get type name
22986  *
22987  * @param test_case_index Index of test case
22988  *
22989  * @return Name of type test in test_case_index
22990  **/
22991 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22992 {
22993         return getTypeName(test_case_index);
22994 }
22995
22996 /** Returns number of types to test
22997  *
22998  * @return Number of types, 34
22999  **/
23000 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
23001 {
23002         return getTypesNumber();
23003 }
23004
23005 /** Inspects program to check if all resources are as expected
23006  *
23007  * @param test_case_index Index of test case
23008  * @param program         Program instance
23009  * @param out_stream      Error message
23010  *
23011  * @return true if everything is ok, false otherwise
23012  **/
23013 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
23014                                                                                                           std::stringstream& out_stream)
23015 {
23016         GLint                      stride       = 0;
23017         const Utils::Type& type          = getType(test_case_index);
23018         const GLuint       type_size = type.GetSize(false);
23019
23020         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
23021                                                 1 /* buf_size */, &stride);
23022
23023         if ((GLint)(3 * type_size) != stride)
23024         {
23025                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
23026
23027                 return false;
23028         }
23029
23030         return true;
23031 }
23032
23033 /** Constructor
23034  *
23035  * @param context Test context
23036  **/
23037 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
23038         : BufferTestBase(context, "xfb_vertex_streams",
23039                                          "Test verifies that xfb qualifier works with multiple output streams")
23040 {
23041         /* Nothing to be done here */
23042 }
23043
23044 /** Get descriptors of buffers necessary for test
23045  *
23046  * @param ignored
23047  * @param out_descriptors Descriptors of buffers used by test
23048  **/
23049 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
23050                                                                                                 bufferDescriptor::Vector& out_descriptors)
23051 {
23052         const Utils::Type& type = Utils::Type::vec4;
23053
23054         /* Test needs single uniform and three xfbs */
23055         out_descriptors.resize(4);
23056
23057         /* Get references */
23058         bufferDescriptor& uniform = out_descriptors[0];
23059         bufferDescriptor& xfb_1   = out_descriptors[1];
23060         bufferDescriptor& xfb_2   = out_descriptors[2];
23061         bufferDescriptor& xfb_3   = out_descriptors[3];
23062
23063         /* Index */
23064         uniform.m_index = 0;
23065         xfb_1.m_index   = 1;
23066         xfb_2.m_index   = 2;
23067         xfb_3.m_index   = 3;
23068
23069         /* Target */
23070         uniform.m_target = Utils::Buffer::Uniform;
23071         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
23072         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
23073         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
23074
23075         /* Data */
23076         const std::vector<GLubyte>& goku_data   = type.GenerateData();
23077         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
23078         const std::vector<GLubyte>& goten_data  = type.GenerateData();
23079         const std::vector<GLubyte>& picolo_data = type.GenerateData();
23080         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
23081         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
23082
23083         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
23084
23085         /* Uniform data */
23086         uniform.m_initial_data.resize(6 * type_size);
23087         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
23088         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
23089         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
23090         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
23091         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
23092         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
23093
23094         /* XFB data */
23095         static const GLuint xfb_stride = 64;
23096         xfb_1.m_initial_data.resize(xfb_stride);
23097         xfb_1.m_expected_data.resize(xfb_stride);
23098         xfb_2.m_initial_data.resize(xfb_stride);
23099         xfb_2.m_expected_data.resize(xfb_stride);
23100         xfb_3.m_initial_data.resize(xfb_stride);
23101         xfb_3.m_expected_data.resize(xfb_stride);
23102
23103         for (GLuint i = 0; i < xfb_stride; ++i)
23104         {
23105                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
23106                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
23107                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
23108                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
23109                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
23110                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
23111         }
23112
23113         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23114         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23115         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23116         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23117         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23118         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23119 }
23120
23121 /** Get body of main function for given shader stage
23122  *
23123  * @param ignored
23124  * @param stage            Shader stage
23125  * @param out_assignments  Set to empty
23126  * @param out_calculations Set to empty
23127  **/
23128 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23129                                                                                  std::string& out_assignments, std::string& out_calculations)
23130 {
23131         out_calculations = "";
23132
23133         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23134         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23135         // by the GS is assigned to specific stream.
23136         static const GLchar* gs = "    goku   = uni_goku;\n"
23137                                                           "    gohan  = uni_gohan;\n"
23138                                                           "    goten  = uni_goten;\n"
23139                                                           "    EmitStreamVertex(0);\n"
23140                                                           "    EndStreamPrimitive(0);\n"
23141                                                           "    picolo = uni_picolo;\n"
23142                                                           "    vegeta = uni_vegeta;\n"
23143                                                           "    EmitStreamVertex(1);\n"
23144                                                           "    EndStreamPrimitive(1);\n"
23145                                                           "    bulma  = uni_bulma;\n"
23146                                                           "    EmitStreamVertex(2);\n"
23147                                                           "    EndStreamPrimitive(2);\n";
23148
23149         static const GLchar* fs = "    fs_out = gohan + goku + goten;\n";
23150
23151         const GLchar* assignments = "";
23152         switch (stage)
23153         {
23154         case Utils::Shader::FRAGMENT:
23155                 assignments = fs;
23156                 break;
23157         case Utils::Shader::GEOMETRY:
23158                 assignments = gs;
23159                 break;
23160         default:
23161                 break;
23162         }
23163
23164         out_assignments = assignments;
23165 }
23166
23167 /** Get interface of shader
23168  *
23169  * @param ignored
23170  * @param stage            Shader stage
23171  * @param out_interface    Set to ""
23172  **/
23173 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23174                                                                                           std::string& out_interface)
23175 {
23176         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23177                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23178                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23179                                                           "\n"
23180                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23181                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23182                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23183                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23184                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23185                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23186                                                           "\n"
23187                                                           "layout(binding = 0) uniform gs_block {\n"
23188                                                           "    vec4 uni_goku;\n"
23189                                                           "    vec4 uni_gohan;\n"
23190                                                           "    vec4 uni_goten;\n"
23191                                                           "    vec4 uni_picolo;\n"
23192                                                           "    vec4 uni_vegeta;\n"
23193                                                           "    vec4 uni_bulma;\n"
23194                                                           "};\n";
23195         /*
23196          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23197          */
23198         static const GLchar* fs = "in vec4 goku;\n"
23199                                                           "in vec4 gohan;\n"
23200                                                           "in vec4 goten;\n"
23201                                                           "\n"
23202                                                           "out vec4 fs_out;\n";
23203
23204         switch (stage)
23205         {
23206         case Utils::Shader::FRAGMENT:
23207                 out_interface = fs;
23208                 break;
23209         case Utils::Shader::GEOMETRY:
23210                 out_interface = gs;
23211                 break;
23212         default:
23213                 out_interface = "";
23214                 return;
23215         }
23216 }
23217
23218 /** Constructor
23219  *
23220  * @param context Test framework context
23221  **/
23222 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23223         : NegativeTestBase(
23224                   context, "xfb_multiple_vertex_streams",
23225                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23226 {
23227 }
23228
23229 /** Source for given test case and stage
23230  *
23231  * @param ignored
23232  * @param stage           Shader stage
23233  *
23234  * @return Shader source
23235  **/
23236 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23237 {
23238         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23239                                                                                   "\n"
23240                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23241                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23242                                                                                   "\n"
23243                                                                                   "\n"
23244                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23245                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23246                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23247         static const GLchar* var_use = "    goku  = result / 2;\n"
23248                                                                    "    gohan = result / 4;\n"
23249                                                                    "    goten = result / 6;\n";
23250         static const GLchar* fs = "#version 430 core\n"
23251                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23252                                                           "\n"
23253                                                           "in  vec4 gs_fs;\n"
23254                                                           "in  vec4 goku;\n"
23255                                                           "out vec4 fs_out;\n"
23256                                                           "\n"
23257                                                           "void main()\n"
23258                                                           "{\n"
23259                                                           "    fs_out = gs_fs + goku;\n"
23260                                                           "}\n"
23261                                                           "\n";
23262         static const GLchar* gs = "#version 430 core\n"
23263                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23264                                                           "\n"
23265                                                           "layout(points)                           in;\n"
23266                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23267                                                           "\n"
23268                                                           "VAR_DEFINITION"
23269                                                           "\n"
23270                                                           "in  vec4 tes_gs[];\n"
23271                                                           "out vec4 gs_fs;\n"
23272                                                           "\n"
23273                                                           "void main()\n"
23274                                                           "{\n"
23275                                                           "    vec4 result = tes_gs[0];\n"
23276                                                           "\n"
23277                                                           "VARIABLE_USE"
23278                                                           "\n"
23279                                                           "    gs_fs = result;\n"
23280                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23281                                                           "    EmitVertex();\n"
23282                                                           "    gs_fs = result;\n"
23283                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23284                                                           "    EmitVertex();\n"
23285                                                           "    gs_fs = result;\n"
23286                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23287                                                           "    EmitVertex();\n"
23288                                                           "    gs_fs = result;\n"
23289                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23290                                                           "    EmitVertex();\n"
23291                                                           "}\n"
23292                                                           "\n";
23293         static const GLchar* vs = "#version 430 core\n"
23294                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23295                                                           "\n"
23296                                                           "in  vec4 in_vs;\n"
23297                                                           "out vec4 vs_tcs;\n"
23298                                                           "\n"
23299                                                           "void main()\n"
23300                                                           "{\n"
23301                                                           "    vs_tcs = in_vs;\n"
23302                                                           "}\n"
23303                                                           "\n";
23304
23305         std::string source;
23306
23307         if (Utils::Shader::GEOMETRY == stage)
23308         {
23309                 size_t position = 0;
23310
23311                 source = gs;
23312
23313                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23314                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23315         }
23316         else
23317         {
23318                 switch (stage)
23319                 {
23320                 case Utils::Shader::FRAGMENT:
23321                         source = fs;
23322                         break;
23323                 case Utils::Shader::VERTEX:
23324                         source = vs;
23325                         break;
23326                 default:
23327                         source = "";
23328                 }
23329         }
23330
23331         return source;
23332 }
23333
23334 /** Selects if "compute" stage is relevant for test
23335  *
23336  * @param ignored
23337  *
23338  * @return false
23339  **/
23340 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23341 {
23342         return false;
23343 }
23344
23345 /** Constructor
23346  *
23347  * @param context Test framework context
23348  **/
23349 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23350         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23351                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23352 {
23353 }
23354
23355 /** Source for given test case and stage
23356  *
23357  * @param test_case_index Index of test case
23358  * @param stage           Shader stage
23359  *
23360  * @return Shader source
23361  **/
23362 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23363 {
23364         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23365                                                                                                 "\n"
23366                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23367                                                                                                 "    vec4 member;\n"
23368                                                                                                 "} gokuARRAY;\n";
23369         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23370                                                                                                  "\n"
23371                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23372         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23373                                                                                                  "\n"
23374                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23375         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23376         static const GLchar* global_use = "";
23377         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23378         static const GLchar* fs                 = "#version 430 core\n"
23379                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23380                                                           "\n"
23381                                                           "in  vec4 gs_fs;\n"
23382                                                           "out vec4 fs_out;\n"
23383                                                           "\n"
23384                                                           "void main()\n"
23385                                                           "{\n"
23386                                                           "    fs_out = gs_fs;\n"
23387                                                           "}\n"
23388                                                           "\n";
23389         static const GLchar* gs_tested = "#version 430 core\n"
23390                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23391                                                                          "\n"
23392                                                                          "layout(points)                           in;\n"
23393                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23394                                                                          "\n"
23395                                                                          "VAR_DEFINITION"
23396                                                                          "\n"
23397                                                                          "in  vec4 tes_gs[];\n"
23398                                                                          "out vec4 gs_fs;\n"
23399                                                                          "\n"
23400                                                                          "void main()\n"
23401                                                                          "{\n"
23402                                                                          "    vec4 result = tes_gs[0];\n"
23403                                                                          "\n"
23404                                                                          "VARIABLE_USE"
23405                                                                          "\n"
23406                                                                          "    gs_fs = result;\n"
23407                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23408                                                                          "    EmitVertex();\n"
23409                                                                          "    gs_fs = result;\n"
23410                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23411                                                                          "    EmitVertex();\n"
23412                                                                          "    gs_fs = result;\n"
23413                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23414                                                                          "    EmitVertex();\n"
23415                                                                          "    gs_fs = result;\n"
23416                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23417                                                                          "    EmitVertex();\n"
23418                                                                          "}\n"
23419                                                                          "\n";
23420         static const GLchar* tcs = "#version 430 core\n"
23421                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23422                                                            "\n"
23423                                                            "layout(vertices = 1) out;\n"
23424                                                            "\n"
23425                                                            "in  vec4 vs_tcs[];\n"
23426                                                            "out vec4 tcs_tes[];\n"
23427                                                            "\n"
23428                                                            "void main()\n"
23429                                                            "{\n"
23430                                                            "\n"
23431                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23432                                                            "\n"
23433                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23434                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23435                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23436                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23437                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23438                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23439                                                            "}\n"
23440                                                            "\n";
23441         static const GLchar* tcs_tested = "#version 430 core\n"
23442                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23443                                                                           "\n"
23444                                                                           "layout(vertices = 1) out;\n"
23445                                                                           "\n"
23446                                                                           "VAR_DEFINITION"
23447                                                                           "\n"
23448                                                                           "in  vec4 vs_tcs[];\n"
23449                                                                           "out vec4 tcs_tes[];\n"
23450                                                                           "\n"
23451                                                                           "void main()\n"
23452                                                                           "{\n"
23453                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23454                                                                           "\n"
23455                                                                           "VARIABLE_USE"
23456                                                                           "\n"
23457                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23458                                                                           "\n"
23459                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23460                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23461                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23462                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23463                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23464                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23465                                                                           "}\n"
23466                                                                           "\n";
23467         static const GLchar* tes_tested = "#version 430 core\n"
23468                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23469                                                                           "\n"
23470                                                                           "layout(isolines, point_mode) in;\n"
23471                                                                           "\n"
23472                                                                           "VAR_DEFINITION"
23473                                                                           "\n"
23474                                                                           "in  vec4 tcs_tes[];\n"
23475                                                                           "out vec4 tes_gs;\n"
23476                                                                           "\n"
23477                                                                           "void main()\n"
23478                                                                           "{\n"
23479                                                                           "    vec4 result = tcs_tes[0];\n"
23480                                                                           "\n"
23481                                                                           "VARIABLE_USE"
23482                                                                           "\n"
23483                                                                           "    tes_gs += result;\n"
23484                                                                           "}\n"
23485                                                                           "\n";
23486         static const GLchar* vs = "#version 430 core\n"
23487                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23488                                                           "\n"
23489                                                           "in  vec4 in_vs;\n"
23490                                                           "out vec4 vs_tcs;\n"
23491                                                           "\n"
23492                                                           "void main()\n"
23493                                                           "{\n"
23494                                                           "    vs_tcs = in_vs;\n"
23495                                                           "}\n"
23496                                                           "\n";
23497         static const GLchar* vs_tested = "#version 430 core\n"
23498                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23499                                                                          "\n"
23500                                                                          "VAR_DEFINITION"
23501                                                                          "\n"
23502                                                                          "in  vec4 in_vs;\n"
23503                                                                          "out vec4 vs_tcs;\n"
23504                                                                          "\n"
23505                                                                          "void main()\n"
23506                                                                          "{\n"
23507                                                                          "    vec4 result = in_vs;\n"
23508                                                                          "\n"
23509                                                                          "VARIABLE_USE"
23510                                                                          "\n"
23511                                                                          "    vs_tcs = result;\n"
23512                                                                          "}\n"
23513                                                                          "\n";
23514
23515         std::string source;
23516         testCase&   test_case = m_test_cases[test_case_index];
23517
23518         if (test_case.m_stage == stage)
23519         {
23520                 const GLchar*   array = "";
23521                 GLchar                   buffer[16];
23522                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23523                 const GLchar*   index    = "";
23524                 GLint                    max_n_xfb = 0;
23525                 size_t                   position  = 0;
23526                 size_t                   temp;
23527                 const GLchar*   var_definition = 0;
23528                 const GLchar*   var_use         = 0;
23529
23530                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23531                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23532
23533                 sprintf(buffer, "%d", max_n_xfb);
23534
23535                 switch (test_case.m_case)
23536                 {
23537                 case BLOCK:
23538                         var_definition = block_var_definition;
23539                         var_use            = block_use;
23540                         break;
23541                 case GLOBAL:
23542                         var_definition = global_var_definition;
23543                         var_use            = global_use;
23544                         break;
23545                 case VECTOR:
23546                         var_definition = vector_var_definition;
23547                         var_use            = vector_use;
23548                         break;
23549                 default:
23550                         TCU_FAIL("Invalid enum");
23551                 }
23552
23553                 switch (stage)
23554                 {
23555                 case Utils::Shader::GEOMETRY:
23556                         source = gs_tested;
23557                         array  = "[]";
23558                         index  = "[0]";
23559                         break;
23560                 case Utils::Shader::TESS_CTRL:
23561                         source = tcs_tested;
23562                         array  = "[]";
23563                         index  = "[gl_InvocationID]";
23564                         break;
23565                 case Utils::Shader::TESS_EVAL:
23566                         source = tes_tested;
23567                         array  = "[]";
23568                         index  = "[0]";
23569                         break;
23570                 case Utils::Shader::VERTEX:
23571                         source = vs_tested;
23572                         break;
23573                 default:
23574                         TCU_FAIL("Invalid enum");
23575                 }
23576
23577                 temp = position;
23578                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23579                 position = temp;
23580                 Utils::replaceToken("BUFFER", position, buffer, source);
23581                 if (GLOBAL != test_case.m_case)
23582                 {
23583                         Utils::replaceToken("ARRAY", position, array, source);
23584                 }
23585                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23586
23587                 Utils::replaceAllTokens("INDEX", index, source);
23588         }
23589         else
23590         {
23591                 switch (test_case.m_stage)
23592                 {
23593                 case Utils::Shader::GEOMETRY:
23594                         switch (stage)
23595                         {
23596                         case Utils::Shader::FRAGMENT:
23597                                 source = fs;
23598                                 break;
23599                         case Utils::Shader::VERTEX:
23600                                 source = vs;
23601                                 break;
23602                         default:
23603                                 source = "";
23604                         }
23605                         break;
23606                 case Utils::Shader::TESS_CTRL:
23607                         switch (stage)
23608                         {
23609                         case Utils::Shader::FRAGMENT:
23610                                 source = fs;
23611                                 break;
23612                         case Utils::Shader::VERTEX:
23613                                 source = vs;
23614                                 break;
23615                         default:
23616                                 source = "";
23617                         }
23618                         break;
23619                 case Utils::Shader::TESS_EVAL:
23620                         switch (stage)
23621                         {
23622                         case Utils::Shader::FRAGMENT:
23623                                 source = fs;
23624                                 break;
23625                         case Utils::Shader::TESS_CTRL:
23626                                 source = tcs;
23627                                 break;
23628                         case Utils::Shader::VERTEX:
23629                                 source = vs;
23630                                 break;
23631                         default:
23632                                 source = "";
23633                         }
23634                         break;
23635                 case Utils::Shader::VERTEX:
23636                         switch (stage)
23637                         {
23638                         case Utils::Shader::FRAGMENT:
23639                                 source = fs;
23640                                 break;
23641                         default:
23642                                 source = "";
23643                         }
23644                         break;
23645                 default:
23646                         TCU_FAIL("Invalid enum");
23647                         break;
23648                 }
23649         }
23650
23651         return source;
23652 }
23653
23654 /** Get description of test case
23655  *
23656  * @param test_case_index Index of test case
23657  *
23658  * @return Test case description
23659  **/
23660 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23661 {
23662         std::stringstream stream;
23663         testCase&                 test_case = m_test_cases[test_case_index];
23664
23665         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23666
23667         switch (test_case.m_case)
23668         {
23669         case BLOCK:
23670                 stream << "BLOCK";
23671                 break;
23672         case GLOBAL:
23673                 stream << "GLOBAL";
23674                 break;
23675         case VECTOR:
23676                 stream << "VECTOR";
23677                 break;
23678         default:
23679                 TCU_FAIL("Invalid enum");
23680         }
23681
23682         return stream.str();
23683 }
23684
23685 /** Get number of test cases
23686  *
23687  * @return Number of test cases
23688  **/
23689 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23690 {
23691         return static_cast<GLuint>(m_test_cases.size());
23692 }
23693
23694 /** Selects if "compute" stage is relevant for test
23695  *
23696  * @param ignored
23697  *
23698  * @return false
23699  **/
23700 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23701 {
23702         return false;
23703 }
23704
23705 /** Prepare all test cases
23706  *
23707  **/
23708 void XFBExceedBufferLimitTest::testInit()
23709 {
23710         for (GLuint c = 0; c < CASE_MAX; ++c)
23711         {
23712                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23713                 {
23714                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23715                                 (Utils::Shader::FRAGMENT == stage))
23716                         {
23717                                 continue;
23718                         }
23719
23720                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23721
23722                         m_test_cases.push_back(test_case);
23723                 }
23724         }
23725 }
23726
23727 /** Constructor
23728  *
23729  * @param context Test framework context
23730  **/
23731 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23732         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23733                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23734 {
23735 }
23736
23737 /** Source for given test case and stage
23738  *
23739  * @param test_case_index Index of test case
23740  * @param stage           Shader stage
23741  *
23742  * @return Shader source
23743  **/
23744 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23745 {
23746         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23747                                                                                                 "\n"
23748                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23749                                                                                                 "    vec4 member;\n"
23750                                                                                                 "} gokuARRAY;\n";
23751         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23752                                                                                                  "\n"
23753                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23754         static const GLchar* vector_var_definition =
23755                 "const uint max_size = SIZE;\n"
23756                 "\n"
23757                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23758         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23759         static const GLchar* global_use = "";
23760         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23761         static const GLchar* fs                 = "#version 430 core\n"
23762                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23763                                                           "\n"
23764                                                           "in  vec4 gs_fs;\n"
23765                                                           "out vec4 fs_out;\n"
23766                                                           "\n"
23767                                                           "void main()\n"
23768                                                           "{\n"
23769                                                           "    fs_out = gs_fs;\n"
23770                                                           "}\n"
23771                                                           "\n";
23772         static const GLchar* gs_tested = "#version 430 core\n"
23773                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23774                                                                          "\n"
23775                                                                          "layout(points)                           in;\n"
23776                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23777                                                                          "\n"
23778                                                                          "VAR_DEFINITION"
23779                                                                          "\n"
23780                                                                          "in  vec4 tes_gs[];\n"
23781                                                                          "out vec4 gs_fs;\n"
23782                                                                          "\n"
23783                                                                          "void main()\n"
23784                                                                          "{\n"
23785                                                                          "    vec4 result = tes_gs[0];\n"
23786                                                                          "\n"
23787                                                                          "VARIABLE_USE"
23788                                                                          "\n"
23789                                                                          "    gs_fs = result;\n"
23790                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23791                                                                          "    EmitVertex();\n"
23792                                                                          "    gs_fs = result;\n"
23793                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23794                                                                          "    EmitVertex();\n"
23795                                                                          "    gs_fs = result;\n"
23796                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23797                                                                          "    EmitVertex();\n"
23798                                                                          "    gs_fs = result;\n"
23799                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23800                                                                          "    EmitVertex();\n"
23801                                                                          "}\n"
23802                                                                          "\n";
23803         static const GLchar* tcs = "#version 430 core\n"
23804                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23805                                                            "\n"
23806                                                            "layout(vertices = 1) out;\n"
23807                                                            "\n"
23808                                                            "in  vec4 vs_tcs[];\n"
23809                                                            "out vec4 tcs_tes[];\n"
23810                                                            "\n"
23811                                                            "void main()\n"
23812                                                            "{\n"
23813                                                            "\n"
23814                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23815                                                            "\n"
23816                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23817                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23818                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23819                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23820                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23821                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23822                                                            "}\n"
23823                                                            "\n";
23824         static const GLchar* tcs_tested = "#version 430 core\n"
23825                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23826                                                                           "\n"
23827                                                                           "layout(vertices = 1) out;\n"
23828                                                                           "\n"
23829                                                                           "VAR_DEFINITION"
23830                                                                           "\n"
23831                                                                           "in  vec4 vs_tcs[];\n"
23832                                                                           "out vec4 tcs_tes[];\n"
23833                                                                           "\n"
23834                                                                           "void main()\n"
23835                                                                           "{\n"
23836                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23837                                                                           "\n"
23838                                                                           "VARIABLE_USE"
23839                                                                           "\n"
23840                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23841                                                                           "\n"
23842                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23843                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23844                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23845                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23846                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23847                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23848                                                                           "}\n"
23849                                                                           "\n";
23850         static const GLchar* tes_tested = "#version 430 core\n"
23851                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23852                                                                           "\n"
23853                                                                           "layout(isolines, point_mode) in;\n"
23854                                                                           "\n"
23855                                                                           "VAR_DEFINITION"
23856                                                                           "\n"
23857                                                                           "in  vec4 tcs_tes[];\n"
23858                                                                           "out vec4 tes_gs;\n"
23859                                                                           "\n"
23860                                                                           "void main()\n"
23861                                                                           "{\n"
23862                                                                           "    vec4 result = tcs_tes[0];\n"
23863                                                                           "\n"
23864                                                                           "VARIABLE_USE"
23865                                                                           "\n"
23866                                                                           "    tes_gs += result;\n"
23867                                                                           "}\n"
23868                                                                           "\n";
23869         static const GLchar* vs = "#version 430 core\n"
23870                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23871                                                           "\n"
23872                                                           "in  vec4 in_vs;\n"
23873                                                           "out vec4 vs_tcs;\n"
23874                                                           "\n"
23875                                                           "void main()\n"
23876                                                           "{\n"
23877                                                           "    vs_tcs = in_vs;\n"
23878                                                           "}\n"
23879                                                           "\n";
23880         static const GLchar* vs_tested = "#version 430 core\n"
23881                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23882                                                                          "\n"
23883                                                                          "VAR_DEFINITION"
23884                                                                          "\n"
23885                                                                          "in  vec4 in_vs;\n"
23886                                                                          "out vec4 vs_tcs;\n"
23887                                                                          "\n"
23888                                                                          "void main()\n"
23889                                                                          "{\n"
23890                                                                          "    vec4 result = in_vs;\n"
23891                                                                          "\n"
23892                                                                          "VARIABLE_USE"
23893                                                                          "\n"
23894                                                                          "    vs_tcs = result;\n"
23895                                                                          "}\n"
23896                                                                          "\n";
23897
23898         std::string source;
23899         testCase&   test_case = m_test_cases[test_case_index];
23900
23901         if (test_case.m_stage == stage)
23902         {
23903                 const GLchar*   array = "";
23904                 GLchar                   buffer[16];
23905                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23906                 const GLchar*   index                    = "";
23907                 GLint                    max_n_xfb_comp  = 0;
23908                 GLint                    max_n_xfb_bytes = 0;
23909                 size_t                   position                = 0;
23910                 size_t                   temp;
23911                 const GLchar*   var_definition = 0;
23912                 const GLchar*   var_use         = 0;
23913
23914                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23915                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23916
23917                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23918
23919                 sprintf(buffer, "%d", max_n_xfb_bytes);
23920
23921                 switch (test_case.m_case)
23922                 {
23923                 case BLOCK:
23924                         var_definition = block_var_definition;
23925                         var_use            = block_use;
23926                         break;
23927                 case GLOBAL:
23928                         var_definition = global_var_definition;
23929                         var_use            = global_use;
23930                         break;
23931                 case VECTOR:
23932                         var_definition = vector_var_definition;
23933                         var_use            = vector_use;
23934                         break;
23935                 default:
23936                         TCU_FAIL("Invalid enum");
23937                 }
23938                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23939                 // change array = "[]" to "[1]"
23940                 switch (stage)
23941                 {
23942                 case Utils::Shader::GEOMETRY:
23943                         source = gs_tested;
23944                         array  = "[1]";
23945                         index  = "[0]";
23946                         break;
23947                 case Utils::Shader::TESS_CTRL:
23948                         source = tcs_tested;
23949                         array  = "[1]";
23950                         index  = "[gl_InvocationID]";
23951                         break;
23952                 case Utils::Shader::TESS_EVAL:
23953                         source = tes_tested;
23954                         array  = "[1]";
23955                         index  = "[0]";
23956                         break;
23957                 case Utils::Shader::VERTEX:
23958                         source = vs_tested;
23959                         break;
23960                 default:
23961                         TCU_FAIL("Invalid enum");
23962                 }
23963
23964                 temp = position;
23965                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23966                 position = temp;
23967                 Utils::replaceToken("SIZE", position, buffer, source);
23968                 if (GLOBAL != test_case.m_case)
23969                 {
23970                         Utils::replaceToken("ARRAY", position, array, source);
23971                 }
23972                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23973
23974                 Utils::replaceAllTokens("INDEX", index, source);
23975         }
23976         else
23977         {
23978                 switch (test_case.m_stage)
23979                 {
23980                 case Utils::Shader::GEOMETRY:
23981                         switch (stage)
23982                         {
23983                         case Utils::Shader::FRAGMENT:
23984                                 source = fs;
23985                                 break;
23986                         case Utils::Shader::VERTEX:
23987                                 source = vs;
23988                                 break;
23989                         default:
23990                                 source = "";
23991                         }
23992                         break;
23993                 case Utils::Shader::TESS_CTRL:
23994                         switch (stage)
23995                         {
23996                         case Utils::Shader::FRAGMENT:
23997                                 source = fs;
23998                                 break;
23999                         case Utils::Shader::VERTEX:
24000                                 source = vs;
24001                                 break;
24002                         default:
24003                                 source = "";
24004                         }
24005                         break;
24006                 case Utils::Shader::TESS_EVAL:
24007                         switch (stage)
24008                         {
24009                         case Utils::Shader::FRAGMENT:
24010                                 source = fs;
24011                                 break;
24012                         case Utils::Shader::TESS_CTRL:
24013                                 source = tcs;
24014                                 break;
24015                         case Utils::Shader::VERTEX:
24016                                 source = vs;
24017                                 break;
24018                         default:
24019                                 source = "";
24020                         }
24021                         break;
24022                 case Utils::Shader::VERTEX:
24023                         switch (stage)
24024                         {
24025                         case Utils::Shader::FRAGMENT:
24026                                 source = fs;
24027                                 break;
24028                         default:
24029                                 source = "";
24030                         }
24031                         break;
24032                 default:
24033                         TCU_FAIL("Invalid enum");
24034                         break;
24035                 }
24036         }
24037
24038         return source;
24039 }
24040
24041 /** Get description of test case
24042  *
24043  * @param test_case_index Index of test case
24044  *
24045  * @return Test case description
24046  **/
24047 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
24048 {
24049         std::stringstream stream;
24050         testCase&                 test_case = m_test_cases[test_case_index];
24051
24052         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
24053
24054         switch (test_case.m_case)
24055         {
24056         case BLOCK:
24057                 stream << "BLOCK";
24058                 break;
24059         case GLOBAL:
24060                 stream << "GLOBAL";
24061                 break;
24062         case VECTOR:
24063                 stream << "VECTOR";
24064                 break;
24065         default:
24066                 TCU_FAIL("Invalid enum");
24067         }
24068
24069         return stream.str();
24070 }
24071
24072 /** Get number of test cases
24073  *
24074  * @return Number of test cases
24075  **/
24076 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
24077 {
24078         return static_cast<GLuint>(m_test_cases.size());
24079 }
24080
24081 /** Selects if "compute" stage is relevant for test
24082  *
24083  * @param ignored
24084  *
24085  * @return false
24086  **/
24087 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
24088 {
24089         return false;
24090 }
24091
24092 /** Prepare all test cases
24093  *
24094  **/
24095 void XFBExceedOffsetLimitTest::testInit()
24096 {
24097         for (GLuint c = 0; c < CASE_MAX; ++c)
24098         {
24099                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24100                 {
24101                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
24102                                 (Utils::Shader::FRAGMENT == stage))
24103                         {
24104                                 continue;
24105                         }
24106
24107                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
24108
24109                         m_test_cases.push_back(test_case);
24110                 }
24111         }
24112 }
24113
24114 /** Constructor
24115  *
24116  * @param context Test context
24117  **/
24118 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24119         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24120 {
24121         /* Nothing to be done here */
24122 }
24123
24124 /** Get descriptors of buffers necessary for test
24125  *
24126  * @param test_case_index Index of test case
24127  * @param out_descriptors Descriptors of buffers used by test
24128  **/
24129 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24130 {
24131         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24132         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24133
24134         /* Test needs single uniform and two xfbs */
24135         out_descriptors.resize(3);
24136
24137         /* Get references */
24138         bufferDescriptor& uniform = out_descriptors[0];
24139         bufferDescriptor& xfb_1   = out_descriptors[1];
24140         bufferDescriptor& xfb_3   = out_descriptors[2];
24141
24142         /* Index */
24143         uniform.m_index = 0;
24144         xfb_1.m_index   = 1;
24145         xfb_3.m_index   = 3;
24146
24147         /* Target */
24148         uniform.m_target = Utils::Buffer::Uniform;
24149         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24150         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24151
24152         /* Data */
24153         const GLuint                            gen_start   = Utils::s_rand;
24154         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24155         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24156         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24157         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24158         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24159         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24160
24161         Utils::s_rand                                                           = gen_start;
24162         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24163         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24164         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24165         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24166         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24167         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24168
24169         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24170         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24171
24172         /* Uniform data */
24173         uniform.m_initial_data.resize(6 * type_size);
24174         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24175         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24176         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24177         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24178         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24179         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24180
24181         /* XFB data */
24182         xfb_1.m_initial_data.resize(3 * type_size_pck);
24183         xfb_1.m_expected_data.resize(3 * type_size_pck);
24184         xfb_3.m_initial_data.resize(3 * type_size_pck);
24185         xfb_3.m_expected_data.resize(3 * type_size_pck);
24186
24187         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24188         {
24189                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24190                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24191                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24192                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24193         }
24194
24195         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24196         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24197         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24198         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24199         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24200         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24201 }
24202
24203 /** Source for given test case and stage
24204  *
24205  * @param test_case_index Index of test case
24206  * @param stage           Shader stage
24207  *
24208  * @return Shader source
24209  **/
24210 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24211 {
24212         static const GLchar* fs =
24213                 "#version 430 core\n"
24214                 "#extension GL_ARB_enhanced_layouts : require\n"
24215                 "\n"
24216                 "flat in TYPE chichi;\n"
24217                 "flat in TYPE bulma;\n"
24218                 "in Vegeta {\n"
24219                 "    flat TYPE trunk;\n"
24220                 "    flat TYPE bra;\n"
24221                 "} vegeta;\n"
24222                 "in Goku {\n"
24223                 "    flat TYPE gohan;\n"
24224                 "    flat TYPE goten;\n"
24225                 "} goku;\n"
24226                 "\n"
24227                 "out vec4 fs_out;\n"
24228                 "\n"
24229                 "void main()\n"
24230                 "{\n"
24231                 "    fs_out = vec4(1);\n"
24232                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24233                 "    {\n"
24234                 "        fs_out = vec4(0);\n"
24235                 "    }\n"
24236                 "}\n"
24237                 "\n";
24238
24239         static const GLchar* gs = "#version 430 core\n"
24240                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24241                                                           "\n"
24242                                                           "layout(points)                   in;\n"
24243                                                           "layout(points, max_vertices = 1) out;\n"
24244                                                           "\n"
24245                                                           "INTERFACE"
24246                                                           "\n"
24247                                                           "void main()\n"
24248                                                           "{\n"
24249                                                           "ASSIGNMENTS"
24250                                                           "    EmitVertex();\n"
24251                                                           "}\n"
24252                                                           "\n";
24253
24254         static const GLchar* tcs = "#version 430 core\n"
24255                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24256                                                            "\n"
24257                                                            "layout(vertices = 1) out;\n"
24258                                                            "\n"
24259                                                            "\n"
24260                                                            "void main()\n"
24261                                                            "{\n"
24262                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24263                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24264                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24265                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24266                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24267                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24268                                                            "}\n"
24269                                                            "\n";
24270
24271         static const GLchar* tes = "#version 430 core\n"
24272                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24273                                                            "\n"
24274                                                            "layout(isolines, point_mode) in;\n"
24275                                                            "\n"
24276                                                            "INTERFACE"
24277                                                            "\n"
24278                                                            "void main()\n"
24279                                                            "{\n"
24280                                                            "ASSIGNMENTS"
24281                                                            "}\n"
24282                                                            "\n";
24283
24284         static const GLchar* vs = "#version 430 core\n"
24285                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24286                                                           "\n"
24287                                                           "void main()\n"
24288                                                           "{\n"
24289                                                           "}\n"
24290                                                           "\n";
24291
24292         static const GLchar* vs_tested = "#version 430 core\n"
24293                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24294                                                                          "\n"
24295                                                                          "INTERFACE"
24296                                                                          "\n"
24297                                                                          "void main()\n"
24298                                                                          "{\n"
24299                                                                          "ASSIGNMENTS"
24300                                                                          "}\n"
24301                                                                          "\n";
24302
24303         std::string              source;
24304         const _testCase& test_case = m_test_cases[test_case_index];
24305         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24306
24307         if (test_case.m_stage == stage)
24308         {
24309                 std::string assignments = "    chichi       = uni_chichi;\n"
24310                                                                   "    bulma        = uni_bulma;\n"
24311                                                                   "    vegeta.trunk = uni_trunk;\n"
24312                                                                   "    vegeta.bra   = uni_bra;\n"
24313                                                                   "    goku.gohan   = uni_gohan;\n"
24314                                                                   "    goku.goten   = uni_goten;\n";
24315
24316                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24317                                                                 "\n"
24318                                                                 "const uint type_size = SIZE;\n"
24319                                                                 "\n"
24320                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24321                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24322                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24323                                                                 "    flat TYPE trunk;\n"
24324                                                                 "    flat TYPE bra;\n"
24325                                                                 "} vegeta;\n"
24326                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24327                                                                 "    flat TYPE gohan;\n"
24328                                                                 "    flat TYPE goten;\n"
24329                                                                 "} goku;\n"
24330                                                                 "\n"
24331                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24332                                                                 "layout(binding = 0, std140) uniform block {\n"
24333                                                                 "    TYPE uni_chichi;\n"
24334                                                                 "    TYPE uni_bulma;\n"
24335                                                                 "    TYPE uni_trunk;\n"
24336                                                                 "    TYPE uni_bra;\n"
24337                                                                 "    TYPE uni_gohan;\n"
24338                                                                 "    TYPE uni_goten;\n"
24339                                                                 "};\n";
24340
24341                 /* Prepare interface string */
24342                 {
24343                         GLchar           buffer[16];
24344                         size_t           position  = 0;
24345                         const GLuint type_size = test_case.m_type.GetSize();
24346
24347                         sprintf(buffer, "%d", type_size);
24348
24349                         Utils::replaceToken("SIZE", position, buffer, interface);
24350                         Utils::replaceAllTokens("TYPE", type_name, interface);
24351                 }
24352
24353                 switch (stage)
24354                 {
24355                 case Utils::Shader::GEOMETRY:
24356                         source = gs;
24357                         break;
24358                 case Utils::Shader::TESS_EVAL:
24359                         source = tes;
24360                         break;
24361                 case Utils::Shader::VERTEX:
24362                         source = vs_tested;
24363                         break;
24364                 default:
24365                         TCU_FAIL("Invalid enum");
24366                 }
24367
24368                 /* Replace tokens */
24369                 {
24370                         size_t position = 0;
24371
24372                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24373                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24374                 }
24375         }
24376         else
24377         {
24378                 switch (test_case.m_stage)
24379                 {
24380                 case Utils::Shader::GEOMETRY:
24381                         switch (stage)
24382                         {
24383                         case Utils::Shader::FRAGMENT:
24384                                 source = fs;
24385                                 Utils::replaceAllTokens("TYPE", type_name, source);
24386                                 break;
24387                         case Utils::Shader::VERTEX:
24388                                 source = vs;
24389                                 break;
24390                         default:
24391                                 source = "";
24392                         }
24393                         break;
24394                 case Utils::Shader::TESS_EVAL:
24395                         switch (stage)
24396                         {
24397                         case Utils::Shader::FRAGMENT:
24398                                 source = fs;
24399                                 Utils::replaceAllTokens("TYPE", type_name, source);
24400                                 break;
24401                         case Utils::Shader::TESS_CTRL:
24402                                 source = tcs;
24403                                 break;
24404                         case Utils::Shader::VERTEX:
24405                                 source = vs;
24406                                 break;
24407                         default:
24408                                 source = "";
24409                         }
24410                         break;
24411                 case Utils::Shader::VERTEX:
24412                         switch (stage)
24413                         {
24414                         case Utils::Shader::FRAGMENT:
24415                                 source = fs;
24416                                 Utils::replaceAllTokens("TYPE", type_name, source);
24417                                 break;
24418                         default:
24419                                 source = "";
24420                         }
24421                         break;
24422                 default:
24423                         TCU_FAIL("Invalid enum");
24424                         break;
24425                 }
24426         }
24427
24428         return source;
24429 }
24430
24431 /** Get name of test case
24432  *
24433  * @param test_case_index Index of test case
24434  *
24435  * @return Name of case
24436  **/
24437 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24438 {
24439         std::string              name;
24440         const _testCase& test_case = m_test_cases[test_case_index];
24441
24442         name = "Tested stage: ";
24443         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24444         name.append(". Tested type: ");
24445         name.append(test_case.m_type.GetGLSLTypeName());
24446
24447         return name;
24448 }
24449
24450 /** Get number of cases
24451  *
24452  * @return Number of test cases
24453  **/
24454 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24455 {
24456         return static_cast<GLuint>(m_test_cases.size());
24457 }
24458
24459 /** Prepare set of test cases
24460  *
24461  **/
24462 void XFBGlobalBufferTest::testInit()
24463 {
24464         GLuint n_types = getTypesNumber();
24465
24466         for (GLuint i = 0; i < n_types; ++i)
24467         {
24468                 const Utils::Type& type = getType(i);
24469                 /*
24470                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24471                  cause a link time error.
24472                  */
24473                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24474                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24475                 {
24476                         continue;
24477                 }
24478                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24479                                                                                  { Utils::Shader::GEOMETRY, type },
24480                                                                                  { Utils::Shader::TESS_EVAL, type } };
24481
24482                 m_test_cases.push_back(test_cases[0]);
24483                 m_test_cases.push_back(test_cases[1]);
24484                 m_test_cases.push_back(test_cases[2]);
24485         }
24486 }
24487
24488 /** Constructor
24489  *
24490  * @param context Test context
24491  **/
24492 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24493         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24494 {
24495         /* Nothing to be done here */
24496 }
24497
24498 /** Execute drawArrays for single vertex
24499  *
24500  * @param test_case_index
24501  *
24502  * @return true
24503  **/
24504 bool XFBStrideTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
24505 {
24506         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24507         GLenum                   primitive_type = GL_PATCHES;
24508         const testCase&  test_case              = m_test_cases[test_case_index];
24509
24510         if (Utils::Shader::VERTEX == test_case.m_stage)
24511         {
24512                 primitive_type = GL_POINTS;
24513         }
24514
24515         gl.disable(GL_RASTERIZER_DISCARD);
24516         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24517
24518         gl.beginTransformFeedback(GL_POINTS);
24519         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24520
24521         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24522         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24523
24524         gl.endTransformFeedback();
24525         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24526
24527         return true;
24528 }
24529
24530 /** Get descriptors of buffers necessary for test
24531  *
24532  * @param test_case_index Index of test case
24533  * @param out_descriptors Descriptors of buffers used by test
24534  **/
24535 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24536 {
24537         const testCase& test_case = m_test_cases[test_case_index];
24538         const Utils::Type& type          = test_case.m_type;
24539
24540         /* Test needs single uniform and xfb */
24541         out_descriptors.resize(2);
24542
24543         /* Get references */
24544         bufferDescriptor& uniform = out_descriptors[0];
24545         bufferDescriptor& xfb    = out_descriptors[1];
24546
24547         /* Index */
24548         uniform.m_index = 0;
24549         xfb.m_index             = 0;
24550
24551         /* Target */
24552         uniform.m_target = Utils::Buffer::Uniform;
24553         xfb.m_target     = Utils::Buffer::Transform_feedback;
24554
24555         /* Data */
24556         const GLuint                            rand_start   = Utils::s_rand;
24557         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24558
24559         Utils::s_rand                                            = rand_start;
24560         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24561
24562         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24563         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24564         /*
24565          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24566          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24567          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24568          only one valid data should be initialized in xfb.m_expected_data
24569          */
24570         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24571         /* Uniform data */
24572         uniform.m_initial_data.resize(uni_type_size);
24573         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24574
24575         /* XFB data */
24576         xfb.m_initial_data.resize(xfb_data_size);
24577         xfb.m_expected_data.resize(xfb_data_size);
24578
24579         for (GLuint i = 0; i < xfb_data_size; ++i)
24580         {
24581                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24582                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24583         }
24584
24585         if (test_case.m_stage == Utils::Shader::VERTEX)
24586         {
24587                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24588         }
24589         else
24590         {
24591                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24592                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24593         }
24594 }
24595
24596 /** Get body of main function for given shader stage
24597  *
24598  * @param test_case_index  Index of test case
24599  * @param stage            Shader stage
24600  * @param out_assignments  Set to empty
24601  * @param out_calculations Set to empty
24602  **/
24603 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24604                                                                   std::string& out_calculations)
24605 {
24606         const testCase& test_case = m_test_cases[test_case_index];
24607
24608         out_calculations = "";
24609
24610         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24611         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24612                                                           "    if (TYPE(0) == goku)\n"
24613                                                           "    {\n"
24614                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24615                                                           "    }\n";
24616
24617         const GLchar* assignments = "";
24618
24619         if (test_case.m_stage == stage)
24620         {
24621                 switch (stage)
24622                 {
24623                 case Utils::Shader::GEOMETRY:
24624                         assignments = vs_tes_gs;
24625                         break;
24626                 case Utils::Shader::TESS_EVAL:
24627                         assignments = vs_tes_gs;
24628                         break;
24629                 case Utils::Shader::VERTEX:
24630                         assignments = vs_tes_gs;
24631                         break;
24632                 default:
24633                         TCU_FAIL("Invalid enum");
24634                 }
24635         }
24636         else
24637         {
24638                 switch (stage)
24639                 {
24640                 case Utils::Shader::FRAGMENT:
24641                         assignments = fs;
24642                         break;
24643                 case Utils::Shader::GEOMETRY:
24644                 case Utils::Shader::TESS_CTRL:
24645                 case Utils::Shader::TESS_EVAL:
24646                 case Utils::Shader::VERTEX:
24647                         break;
24648                 default:
24649                         TCU_FAIL("Invalid enum");
24650                 }
24651         }
24652
24653         out_assignments = assignments;
24654
24655         if (Utils::Shader::FRAGMENT == stage)
24656         {
24657                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24658         }
24659 }
24660
24661 /** Get interface of shader
24662  *
24663  * @param test_case_index  Index of test case
24664  * @param stage            Shader stage
24665  * @param out_interface    Set to ""
24666  **/
24667 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24668 {
24669         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24670                                                                          "\n"
24671                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24672                                                                          "    TYPE uni_goku;\n"
24673                                                                          "};\n";
24674         static const GLchar* fs = "FLAT in TYPE goku;\n"
24675                                                           "\n"
24676                                                           "out vec4 fs_out;\n";
24677
24678         const testCase& test_case = m_test_cases[test_case_index];
24679         const GLchar*   interface = "";
24680         const GLchar*   flat      = "";
24681
24682         if (test_case.m_stage == stage)
24683         {
24684                 switch (stage)
24685                 {
24686                 case Utils::Shader::GEOMETRY:
24687                         interface = vs_tes_gs;
24688                         break;
24689                 case Utils::Shader::TESS_EVAL:
24690                         interface = vs_tes_gs;
24691                         break;
24692                 case Utils::Shader::VERTEX:
24693                         interface = vs_tes_gs;
24694                         break;
24695                 default:
24696                         TCU_FAIL("Invalid enum");
24697                 }
24698         }
24699         else
24700         {
24701                 switch (stage)
24702                 {
24703                 case Utils::Shader::FRAGMENT:
24704                         interface = fs;
24705                         break;
24706                 case Utils::Shader::GEOMETRY:
24707                 case Utils::Shader::TESS_CTRL:
24708                 case Utils::Shader::TESS_EVAL:
24709                 case Utils::Shader::VERTEX:
24710                         break;
24711                 default:
24712                         TCU_FAIL("Invalid enum");
24713                 }
24714         }
24715
24716         out_interface = interface;
24717
24718         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24719         {
24720                 flat = "flat";
24721         }
24722
24723         Utils::replaceAllTokens("FLAT", flat, out_interface);
24724         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24725 }
24726
24727 /** Get source code of shader
24728  *
24729  * @param test_case_index Index of test case
24730  * @param stage           Shader stage
24731  *
24732  * @return Source
24733  **/
24734 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24735 {
24736         std::string             source;
24737         const testCase& test_case = m_test_cases[test_case_index];
24738
24739         switch (test_case.m_stage)
24740         {
24741         case Utils::Shader::VERTEX:
24742                 switch (stage)
24743                 {
24744                 case Utils::Shader::FRAGMENT:
24745                 case Utils::Shader::VERTEX:
24746                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24747                         break;
24748                 default:
24749                         break;
24750                 }
24751                 break;
24752
24753         case Utils::Shader::TESS_EVAL:
24754                 switch (stage)
24755                 {
24756                 case Utils::Shader::FRAGMENT:
24757                 case Utils::Shader::TESS_CTRL:
24758                 case Utils::Shader::TESS_EVAL:
24759                 case Utils::Shader::VERTEX:
24760                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24761                         break;
24762                 default:
24763                         break;
24764                 }
24765                 break;
24766
24767         case Utils::Shader::GEOMETRY:
24768                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24769                 break;
24770
24771         default:
24772                 TCU_FAIL("Invalid enum");
24773                 break;
24774         }
24775
24776         /* */
24777         return source;
24778 }
24779
24780 /** Get name of test case
24781  *
24782  * @param test_case_index Index of test case
24783  *
24784  * @return Name of tested stage
24785  **/
24786 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24787 {
24788         std::stringstream stream;
24789         const testCase&   test_case = m_test_cases[test_case_index];
24790
24791         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24792                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24793
24794         return stream.str();
24795 }
24796
24797 /** Returns number of test cases
24798  *
24799  * @return TEST_MAX
24800  **/
24801 glw::GLuint XFBStrideTest::getTestCaseNumber()
24802 {
24803         return static_cast<GLuint>(m_test_cases.size());
24804 }
24805
24806 /** Prepare all test cases
24807  *
24808  **/
24809 void XFBStrideTest::testInit()
24810 {
24811         const GLuint n_types = getTypesNumber();
24812
24813         for (GLuint i = 0; i < n_types; ++i)
24814         {
24815                 const Utils::Type& type = getType(i);
24816
24817                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24818                 {
24819                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24820                                 (Utils::Shader::TESS_CTRL == stage))
24821                         {
24822                                 continue;
24823                         }
24824
24825                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24826
24827                         m_test_cases.push_back(test_case);
24828                 }
24829         }
24830 }
24831
24832 /** Constructor
24833  *
24834  * @param context Test framework context
24835  **/
24836 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24837         : NegativeTestBase(
24838                   context, "xfb_block_member_buffer",
24839                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24840 {
24841 }
24842
24843 /** Source for given test case and stage
24844  *
24845  * @param test_case_index Index of test case
24846  * @param stage           Shader stage
24847  *
24848  * @return Shader source
24849  **/
24850 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24851 {
24852         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24853                                                                                   "                            vec4 gohan;\n"
24854                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24855                                                                                   "} gokuARRAY;\n";
24856         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24857                                                                    "    gokuINDEX.goten = result / 4;\n";
24858         static const GLchar* fs = "#version 430 core\n"
24859                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24860                                                           "\n"
24861                                                           "in  vec4 gs_fs;\n"
24862                                                           "out vec4 fs_out;\n"
24863                                                           "\n"
24864                                                           "void main()\n"
24865                                                           "{\n"
24866                                                           "    fs_out = gs_fs;\n"
24867                                                           "}\n"
24868                                                           "\n";
24869         static const GLchar* gs_tested = "#version 430 core\n"
24870                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24871                                                                          "\n"
24872                                                                          "layout(points)                           in;\n"
24873                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24874                                                                          "\n"
24875                                                                          "VAR_DEFINITION"
24876                                                                          "\n"
24877                                                                          "in  vec4 tes_gs[];\n"
24878                                                                          "out vec4 gs_fs;\n"
24879                                                                          "\n"
24880                                                                          "void main()\n"
24881                                                                          "{\n"
24882                                                                          "    vec4 result = tes_gs[0];\n"
24883                                                                          "\n"
24884                                                                          "VARIABLE_USE"
24885                                                                          "\n"
24886                                                                          "    gs_fs = result;\n"
24887                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24888                                                                          "    EmitVertex();\n"
24889                                                                          "    gs_fs = result;\n"
24890                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24891                                                                          "    EmitVertex();\n"
24892                                                                          "    gs_fs = result;\n"
24893                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24894                                                                          "    EmitVertex();\n"
24895                                                                          "    gs_fs = result;\n"
24896                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24897                                                                          "    EmitVertex();\n"
24898                                                                          "}\n"
24899                                                                          "\n";
24900         static const GLchar* tcs = "#version 430 core\n"
24901                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24902                                                            "\n"
24903                                                            "layout(vertices = 1) out;\n"
24904                                                            "\n"
24905                                                            "in  vec4 vs_tcs[];\n"
24906                                                            "out vec4 tcs_tes[];\n"
24907                                                            "\n"
24908                                                            "void main()\n"
24909                                                            "{\n"
24910                                                            "\n"
24911                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24912                                                            "\n"
24913                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24914                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24915                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24916                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24917                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24918                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24919                                                            "}\n"
24920                                                            "\n";
24921         static const GLchar* tcs_tested = "#version 430 core\n"
24922                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24923                                                                           "\n"
24924                                                                           "layout(vertices = 1) out;\n"
24925                                                                           "\n"
24926                                                                           "VAR_DEFINITION"
24927                                                                           "\n"
24928                                                                           "in  vec4 vs_tcs[];\n"
24929                                                                           "out vec4 tcs_tes[];\n"
24930                                                                           "\n"
24931                                                                           "void main()\n"
24932                                                                           "{\n"
24933                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24934                                                                           "\n"
24935                                                                           "VARIABLE_USE"
24936                                                                           "\n"
24937                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24938                                                                           "\n"
24939                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24940                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24941                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24942                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24943                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24944                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24945                                                                           "}\n"
24946                                                                           "\n";
24947         static const GLchar* tes_tested = "#version 430 core\n"
24948                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24949                                                                           "\n"
24950                                                                           "layout(isolines, point_mode) in;\n"
24951                                                                           "\n"
24952                                                                           "VAR_DEFINITION"
24953                                                                           "\n"
24954                                                                           "in  vec4 tcs_tes[];\n"
24955                                                                           "out vec4 tes_gs;\n"
24956                                                                           "\n"
24957                                                                           "void main()\n"
24958                                                                           "{\n"
24959                                                                           "    vec4 result = tcs_tes[0];\n"
24960                                                                           "\n"
24961                                                                           "VARIABLE_USE"
24962                                                                           "\n"
24963                                                                           "    tes_gs += result;\n"
24964                                                                           "}\n"
24965                                                                           "\n";
24966         static const GLchar* vs = "#version 430 core\n"
24967                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24968                                                           "\n"
24969                                                           "in  vec4 in_vs;\n"
24970                                                           "out vec4 vs_tcs;\n"
24971                                                           "\n"
24972                                                           "void main()\n"
24973                                                           "{\n"
24974                                                           "    vs_tcs = in_vs;\n"
24975                                                           "}\n"
24976                                                           "\n";
24977         static const GLchar* vs_tested = "#version 430 core\n"
24978                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24979                                                                          "\n"
24980                                                                          "VAR_DEFINITION"
24981                                                                          "\n"
24982                                                                          "in  vec4 in_vs;\n"
24983                                                                          "out vec4 vs_tcs;\n"
24984                                                                          "\n"
24985                                                                          "void main()\n"
24986                                                                          "{\n"
24987                                                                          "    vec4 result = in_vs;\n"
24988                                                                          "\n"
24989                                                                          "VARIABLE_USE"
24990                                                                          "\n"
24991                                                                          "    vs_tcs = result;\n"
24992                                                                          "}\n"
24993                                                                          "\n";
24994
24995         std::string source;
24996         testCase&   test_case = m_test_cases[test_case_index];
24997
24998         if (test_case.m_stage == stage)
24999         {
25000                 const GLchar* array     = "";
25001                 const GLchar* index     = "";
25002                 size_t            position = 0;
25003
25004                 switch (stage)
25005                 {
25006                 case Utils::Shader::GEOMETRY:
25007                         source = gs_tested;
25008                         array  = "[]";
25009                         index  = "[0]";
25010                         break;
25011                 case Utils::Shader::TESS_CTRL:
25012                         source = tcs_tested;
25013                         array  = "[]";
25014                         index  = "[gl_InvocationID]";
25015                         break;
25016                 case Utils::Shader::TESS_EVAL:
25017                         source = tes_tested;
25018                         array  = "[]";
25019                         index  = "[0]";
25020                         break;
25021                 case Utils::Shader::VERTEX:
25022                         source = vs_tested;
25023                         break;
25024                 default:
25025                         TCU_FAIL("Invalid enum");
25026                 }
25027
25028                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25029                 position = 0;
25030                 Utils::replaceToken("ARRAY", position, array, source);
25031                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25032
25033                 Utils::replaceAllTokens("INDEX", index, source);
25034         }
25035         else
25036         {
25037                 switch (test_case.m_stage)
25038                 {
25039                 case Utils::Shader::GEOMETRY:
25040                         switch (stage)
25041                         {
25042                         case Utils::Shader::FRAGMENT:
25043                                 source = fs;
25044                                 break;
25045                         case Utils::Shader::VERTEX:
25046                                 source = vs;
25047                                 break;
25048                         default:
25049                                 source = "";
25050                         }
25051                         break;
25052                 case Utils::Shader::TESS_CTRL:
25053                         switch (stage)
25054                         {
25055                         case Utils::Shader::FRAGMENT:
25056                                 source = fs;
25057                                 break;
25058                         case Utils::Shader::VERTEX:
25059                                 source = vs;
25060                                 break;
25061                         default:
25062                                 source = "";
25063                         }
25064                         break;
25065                 case Utils::Shader::TESS_EVAL:
25066                         switch (stage)
25067                         {
25068                         case Utils::Shader::FRAGMENT:
25069                                 source = fs;
25070                                 break;
25071                         case Utils::Shader::TESS_CTRL:
25072                                 source = tcs;
25073                                 break;
25074                         case Utils::Shader::VERTEX:
25075                                 source = vs;
25076                                 break;
25077                         default:
25078                                 source = "";
25079                         }
25080                         break;
25081                 case Utils::Shader::VERTEX:
25082                         switch (stage)
25083                         {
25084                         case Utils::Shader::FRAGMENT:
25085                                 source = fs;
25086                                 break;
25087                         default:
25088                                 source = "";
25089                         }
25090                         break;
25091                 default:
25092                         TCU_FAIL("Invalid enum");
25093                         break;
25094                 }
25095         }
25096
25097         return source;
25098 }
25099
25100 /** Get description of test case
25101  *
25102  * @param test_case_index Index of test case
25103  *
25104  * @return Test case description
25105  **/
25106 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
25107 {
25108         std::stringstream stream;
25109         testCase&                 test_case = m_test_cases[test_case_index];
25110
25111         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25112
25113         return stream.str();
25114 }
25115
25116 /** Get number of test cases
25117  *
25118  * @return Number of test cases
25119  **/
25120 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25121 {
25122         return static_cast<GLuint>(m_test_cases.size());
25123 }
25124
25125 /** Selects if "compute" stage is relevant for test
25126  *
25127  * @param ignored
25128  *
25129  * @return false
25130  **/
25131 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25132 {
25133         return false;
25134 }
25135
25136 /** Prepare all test cases
25137  *
25138  **/
25139 void XFBBlockMemberBufferTest::testInit()
25140 {
25141         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25142         {
25143                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25144                         (Utils::Shader::FRAGMENT == stage))
25145                 {
25146                         continue;
25147                 }
25148
25149                 testCase test_case = { (Utils::Shader::STAGES)stage };
25150
25151                 m_test_cases.push_back(test_case);
25152         }
25153 }
25154
25155 /** Constructor
25156  *
25157  * @param context Test framework context
25158  **/
25159 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25160         : NegativeTestBase(context, "xfb_output_overlapping",
25161                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25162 {
25163 }
25164
25165 /** Source for given test case and stage
25166  *
25167  * @param test_case_index Index of test case
25168  * @param stage           Shader stage
25169  *
25170  * @return Shader source
25171  **/
25172 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25173 {
25174         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25175                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25176         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25177                                                                    "    gotenINDEX = TYPE(1);\n"
25178                                                                    "    if (vec4(0) == result)\n"
25179                                                                    "    {\n"
25180                                                                    "        gohanINDEX = TYPE(1);\n"
25181                                                                    "        gotenINDEX = TYPE(0);\n"
25182                                                                    "    }\n";
25183         static const GLchar* fs = "#version 430 core\n"
25184                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25185                                                           "\n"
25186                                                           "in  vec4 gs_fs;\n"
25187                                                           "out vec4 fs_out;\n"
25188                                                           "\n"
25189                                                           "void main()\n"
25190                                                           "{\n"
25191                                                           "    fs_out = gs_fs;\n"
25192                                                           "}\n"
25193                                                           "\n";
25194         static const GLchar* gs_tested = "#version 430 core\n"
25195                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25196                                                                          "\n"
25197                                                                          "layout(points)                           in;\n"
25198                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25199                                                                          "\n"
25200                                                                          "VAR_DEFINITION"
25201                                                                          "\n"
25202                                                                          "in  vec4 tes_gs[];\n"
25203                                                                          "out vec4 gs_fs;\n"
25204                                                                          "\n"
25205                                                                          "void main()\n"
25206                                                                          "{\n"
25207                                                                          "    vec4 result = tes_gs[0];\n"
25208                                                                          "\n"
25209                                                                          "VARIABLE_USE"
25210                                                                          "\n"
25211                                                                          "    gs_fs = result;\n"
25212                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25213                                                                          "    EmitVertex();\n"
25214                                                                          "    gs_fs = result;\n"
25215                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25216                                                                          "    EmitVertex();\n"
25217                                                                          "    gs_fs = result;\n"
25218                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25219                                                                          "    EmitVertex();\n"
25220                                                                          "    gs_fs = result;\n"
25221                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25222                                                                          "    EmitVertex();\n"
25223                                                                          "}\n"
25224                                                                          "\n";
25225         static const GLchar* tcs = "#version 430 core\n"
25226                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25227                                                            "\n"
25228                                                            "layout(vertices = 1) out;\n"
25229                                                            "\n"
25230                                                            "in  vec4 vs_tcs[];\n"
25231                                                            "out vec4 tcs_tes[];\n"
25232                                                            "\n"
25233                                                            "void main()\n"
25234                                                            "{\n"
25235                                                            "\n"
25236                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25237                                                            "\n"
25238                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25239                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25240                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25241                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25242                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25243                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25244                                                            "}\n"
25245                                                            "\n";
25246         static const GLchar* tcs_tested = "#version 430 core\n"
25247                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25248                                                                           "\n"
25249                                                                           "layout(vertices = 1) out;\n"
25250                                                                           "\n"
25251                                                                           "VAR_DEFINITION"
25252                                                                           "\n"
25253                                                                           "in  vec4 vs_tcs[];\n"
25254                                                                           "out vec4 tcs_tes[];\n"
25255                                                                           "\n"
25256                                                                           "void main()\n"
25257                                                                           "{\n"
25258                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25259                                                                           "\n"
25260                                                                           "VARIABLE_USE"
25261                                                                           "\n"
25262                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25263                                                                           "\n"
25264                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25265                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25266                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25267                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25268                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25269                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25270                                                                           "}\n"
25271                                                                           "\n";
25272         static const GLchar* tes_tested = "#version 430 core\n"
25273                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25274                                                                           "\n"
25275                                                                           "layout(isolines, point_mode) in;\n"
25276                                                                           "\n"
25277                                                                           "VAR_DEFINITION"
25278                                                                           "\n"
25279                                                                           "in  vec4 tcs_tes[];\n"
25280                                                                           "out vec4 tes_gs;\n"
25281                                                                           "\n"
25282                                                                           "void main()\n"
25283                                                                           "{\n"
25284                                                                           "    vec4 result = tcs_tes[0];\n"
25285                                                                           "\n"
25286                                                                           "VARIABLE_USE"
25287                                                                           "\n"
25288                                                                           "    tes_gs += result;\n"
25289                                                                           "}\n"
25290                                                                           "\n";
25291         static const GLchar* vs = "#version 430 core\n"
25292                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25293                                                           "\n"
25294                                                           "in  vec4 in_vs;\n"
25295                                                           "out vec4 vs_tcs;\n"
25296                                                           "\n"
25297                                                           "void main()\n"
25298                                                           "{\n"
25299                                                           "    vs_tcs = in_vs;\n"
25300                                                           "}\n"
25301                                                           "\n";
25302         static const GLchar* vs_tested = "#version 430 core\n"
25303                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25304                                                                          "\n"
25305                                                                          "VAR_DEFINITION"
25306                                                                          "\n"
25307                                                                          "in  vec4 in_vs;\n"
25308                                                                          "out vec4 vs_tcs;\n"
25309                                                                          "\n"
25310                                                                          "void main()\n"
25311                                                                          "{\n"
25312                                                                          "    vec4 result = in_vs;\n"
25313                                                                          "\n"
25314                                                                          "VARIABLE_USE"
25315                                                                          "\n"
25316                                                                          "    vs_tcs = result;\n"
25317                                                                          "}\n"
25318                                                                          "\n";
25319
25320         std::string source;
25321         testCase&   test_case = m_test_cases[test_case_index];
25322
25323         if (test_case.m_stage == stage)
25324         {
25325                 const GLchar* array = "";
25326                 GLchar            buffer_gohan[16];
25327                 GLchar            buffer_goten[16];
25328                 const GLchar* index                      = "";
25329                 size_t            position               = 0;
25330                 size_t            position_start = 0;
25331                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25332
25333                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25334                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25335
25336                 switch (stage)
25337                 {
25338                 case Utils::Shader::GEOMETRY:
25339                         source = gs_tested;
25340                         array  = "[]";
25341                         index  = "[0]";
25342                         break;
25343                 case Utils::Shader::TESS_CTRL:
25344                         source = tcs_tested;
25345                         array  = "[]";
25346                         index  = "[gl_InvocationID]";
25347                         break;
25348                 case Utils::Shader::TESS_EVAL:
25349                         source = tes_tested;
25350                         array  = "[]";
25351                         index  = "[0]";
25352                         break;
25353                 case Utils::Shader::VERTEX:
25354                         source = vs_tested;
25355                         break;
25356                 default:
25357                         TCU_FAIL("Invalid enum");
25358                 }
25359
25360                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25361                 position = 0;
25362                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25363                 Utils::replaceToken("TYPE", position, type_name, source);
25364                 Utils::replaceToken("ARRAY", position, array, source);
25365                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25366                 Utils::replaceToken("TYPE", position, type_name, source);
25367                 Utils::replaceToken("ARRAY", position, array, source);
25368                 position_start = position;
25369                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25370                 position = position_start;
25371                 Utils::replaceToken("INDEX", position, index, source);
25372                 Utils::replaceToken("TYPE", position, type_name, source);
25373                 Utils::replaceToken("INDEX", position, index, source);
25374                 Utils::replaceToken("TYPE", position, type_name, source);
25375                 Utils::replaceToken("INDEX", position, index, source);
25376                 Utils::replaceToken("TYPE", position, type_name, source);
25377                 Utils::replaceToken("INDEX", position, index, source);
25378                 Utils::replaceToken("TYPE", position, type_name, source);
25379         }
25380         else
25381         {
25382                 switch (test_case.m_stage)
25383                 {
25384                 case Utils::Shader::GEOMETRY:
25385                         switch (stage)
25386                         {
25387                         case Utils::Shader::FRAGMENT:
25388                                 source = fs;
25389                                 break;
25390                         case Utils::Shader::VERTEX:
25391                                 source = vs;
25392                                 break;
25393                         default:
25394                                 source = "";
25395                         }
25396                         break;
25397                 case Utils::Shader::TESS_CTRL:
25398                         switch (stage)
25399                         {
25400                         case Utils::Shader::FRAGMENT:
25401                                 source = fs;
25402                                 break;
25403                         case Utils::Shader::VERTEX:
25404                                 source = vs;
25405                                 break;
25406                         default:
25407                                 source = "";
25408                         }
25409                         break;
25410                 case Utils::Shader::TESS_EVAL:
25411                         switch (stage)
25412                         {
25413                         case Utils::Shader::FRAGMENT:
25414                                 source = fs;
25415                                 break;
25416                         case Utils::Shader::TESS_CTRL:
25417                                 source = tcs;
25418                                 break;
25419                         case Utils::Shader::VERTEX:
25420                                 source = vs;
25421                                 break;
25422                         default:
25423                                 source = "";
25424                         }
25425                         break;
25426                 case Utils::Shader::VERTEX:
25427                         switch (stage)
25428                         {
25429                         case Utils::Shader::FRAGMENT:
25430                                 source = fs;
25431                                 break;
25432                         default:
25433                                 source = "";
25434                         }
25435                         break;
25436                 default:
25437                         TCU_FAIL("Invalid enum");
25438                         break;
25439                 }
25440         }
25441
25442         return source;
25443 }
25444
25445 /** Get description of test case
25446  *
25447  * @param test_case_index Index of test case
25448  *
25449  * @return Test case description
25450  **/
25451 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25452 {
25453         std::stringstream stream;
25454         testCase&                 test_case = m_test_cases[test_case_index];
25455
25456         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25457                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25458                    << test_case.m_offset_goten;
25459
25460         return stream.str();
25461 }
25462
25463 /** Get number of test cases
25464  *
25465  * @return Number of test cases
25466  **/
25467 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25468 {
25469         return static_cast<GLuint>(m_test_cases.size());
25470 }
25471
25472 /** Selects if "compute" stage is relevant for test
25473  *
25474  * @param ignored
25475  *
25476  * @return false
25477  **/
25478 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25479 {
25480         return false;
25481 }
25482
25483 /** Prepare all test cases
25484  *
25485  **/
25486 void XFBOutputOverlappingTest::testInit()
25487 {
25488         const GLuint n_types = getTypesNumber();
25489
25490         for (GLuint i = 0; i < n_types; ++i)
25491         {
25492                 const Utils::Type& type                   = getType(i);
25493                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25494
25495                 /* Skip scalars, not applicable as:
25496                  *
25497                  *     The offset must be a multiple of the size of the first component of the first
25498                  *     qualified variable or block member, or a compile-time error results.
25499                  */
25500                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25501                 {
25502                         continue;
25503                 }
25504
25505                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25506                 {
25507                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25508                                 (Utils::Shader::FRAGMENT == stage))
25509                         {
25510                                 continue;
25511                         }
25512
25513                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25514                                                                    (Utils::Shader::STAGES)stage, type };
25515
25516                         m_test_cases.push_back(test_case);
25517                 }
25518         }
25519 }
25520
25521 /** Constructor
25522  *
25523  * @param context Test framework context
25524  **/
25525 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25526         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25527                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25528 {
25529 }
25530
25531 /** Source for given test case and stage
25532  *
25533  * @param test_case_index Index of test case
25534  * @param stage           Shader stage
25535  *
25536  * @return Shader source
25537  **/
25538 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25539 {
25540         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25541         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25542                                                                    "    if (vec4(0) == result)\n"
25543                                                                    "    {\n"
25544                                                                    "        gohanINDEX = TYPE(1);\n"
25545                                                                    "    }\n";
25546         static const GLchar* fs = "#version 430 core\n"
25547                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25548                                                           "\n"
25549                                                           "in  vec4 gs_fs;\n"
25550                                                           "out vec4 fs_out;\n"
25551                                                           "\n"
25552                                                           "void main()\n"
25553                                                           "{\n"
25554                                                           "    fs_out = gs_fs;\n"
25555                                                           "}\n"
25556                                                           "\n";
25557         static const GLchar* gs_tested = "#version 430 core\n"
25558                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25559                                                                          "\n"
25560                                                                          "layout(points)                           in;\n"
25561                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25562                                                                          "\n"
25563                                                                          "VAR_DEFINITION"
25564                                                                          "\n"
25565                                                                          "in  vec4 tes_gs[];\n"
25566                                                                          "out vec4 gs_fs;\n"
25567                                                                          "\n"
25568                                                                          "void main()\n"
25569                                                                          "{\n"
25570                                                                          "    vec4 result = tes_gs[0];\n"
25571                                                                          "\n"
25572                                                                          "VARIABLE_USE"
25573                                                                          "\n"
25574                                                                          "    gs_fs = result;\n"
25575                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25576                                                                          "    EmitVertex();\n"
25577                                                                          "    gs_fs = result;\n"
25578                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25579                                                                          "    EmitVertex();\n"
25580                                                                          "    gs_fs = result;\n"
25581                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25582                                                                          "    EmitVertex();\n"
25583                                                                          "    gs_fs = result;\n"
25584                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25585                                                                          "    EmitVertex();\n"
25586                                                                          "}\n"
25587                                                                          "\n";
25588         static const GLchar* tcs = "#version 430 core\n"
25589                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25590                                                            "\n"
25591                                                            "layout(vertices = 1) out;\n"
25592                                                            "\n"
25593                                                            "in  vec4 vs_tcs[];\n"
25594                                                            "out vec4 tcs_tes[];\n"
25595                                                            "\n"
25596                                                            "void main()\n"
25597                                                            "{\n"
25598                                                            "\n"
25599                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25600                                                            "\n"
25601                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25602                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25603                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25604                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25605                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25606                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25607                                                            "}\n"
25608                                                            "\n";
25609         static const GLchar* tcs_tested = "#version 430 core\n"
25610                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25611                                                                           "\n"
25612                                                                           "layout(vertices = 1) out;\n"
25613                                                                           "\n"
25614                                                                           "VAR_DEFINITION"
25615                                                                           "\n"
25616                                                                           "in  vec4 vs_tcs[];\n"
25617                                                                           "out vec4 tcs_tes[];\n"
25618                                                                           "\n"
25619                                                                           "void main()\n"
25620                                                                           "{\n"
25621                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25622                                                                           "\n"
25623                                                                           "VARIABLE_USE"
25624                                                                           "\n"
25625                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25626                                                                           "\n"
25627                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25628                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25629                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25630                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25631                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25632                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25633                                                                           "}\n"
25634                                                                           "\n";
25635         static const GLchar* tes_tested = "#version 430 core\n"
25636                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25637                                                                           "\n"
25638                                                                           "layout(isolines, point_mode) in;\n"
25639                                                                           "\n"
25640                                                                           "VAR_DEFINITION"
25641                                                                           "\n"
25642                                                                           "in  vec4 tcs_tes[];\n"
25643                                                                           "out vec4 tes_gs;\n"
25644                                                                           "\n"
25645                                                                           "void main()\n"
25646                                                                           "{\n"
25647                                                                           "    vec4 result = tcs_tes[0];\n"
25648                                                                           "\n"
25649                                                                           "VARIABLE_USE"
25650                                                                           "\n"
25651                                                                           "    tes_gs += result;\n"
25652                                                                           "}\n"
25653                                                                           "\n";
25654         static const GLchar* vs = "#version 430 core\n"
25655                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25656                                                           "\n"
25657                                                           "in  vec4 in_vs;\n"
25658                                                           "out vec4 vs_tcs;\n"
25659                                                           "\n"
25660                                                           "void main()\n"
25661                                                           "{\n"
25662                                                           "    vs_tcs = in_vs;\n"
25663                                                           "}\n"
25664                                                           "\n";
25665         static const GLchar* vs_tested = "#version 430 core\n"
25666                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25667                                                                          "\n"
25668                                                                          "VAR_DEFINITION"
25669                                                                          "\n"
25670                                                                          "in  vec4 in_vs;\n"
25671                                                                          "out vec4 vs_tcs;\n"
25672                                                                          "\n"
25673                                                                          "void main()\n"
25674                                                                          "{\n"
25675                                                                          "    vec4 result = in_vs;\n"
25676                                                                          "\n"
25677                                                                          "VARIABLE_USE"
25678                                                                          "\n"
25679                                                                          "    vs_tcs = result;\n"
25680                                                                          "}\n"
25681                                                                          "\n";
25682
25683         std::string source;
25684         testCase&   test_case = m_test_cases[test_case_index];
25685
25686         if (test_case.m_stage == stage)
25687         {
25688                 const GLchar* array = "";
25689                 GLchar            buffer[16];
25690                 const GLchar* index                      = "";
25691                 size_t            position               = 0;
25692                 size_t            position_start = 0;
25693                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25694
25695                 sprintf(buffer, "%d", test_case.m_offset);
25696
25697                 switch (stage)
25698                 {
25699                 case Utils::Shader::GEOMETRY:
25700                         source = gs_tested;
25701                         array  = "[]";
25702                         index  = "[0]";
25703                         break;
25704                 case Utils::Shader::TESS_CTRL:
25705                         source = tcs_tested;
25706                         array  = "[]";
25707                         index  = "[gl_InvocationID]";
25708                         break;
25709                 case Utils::Shader::TESS_EVAL:
25710                         source = tes_tested;
25711                         array  = "[]";
25712                         index  = "[0]";
25713                         break;
25714                 case Utils::Shader::VERTEX:
25715                         source = vs_tested;
25716                         break;
25717                 default:
25718                         TCU_FAIL("Invalid enum");
25719                 }
25720
25721                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25722                 position = 0;
25723                 Utils::replaceToken("OFFSET", position, buffer, source);
25724                 Utils::replaceToken("TYPE", position, type_name, source);
25725                 Utils::replaceToken("ARRAY", position, array, source);
25726                 position_start = position;
25727                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25728                 position = position_start;
25729                 Utils::replaceToken("INDEX", position, index, source);
25730                 Utils::replaceToken("TYPE", position, type_name, source);
25731                 Utils::replaceToken("INDEX", position, index, source);
25732                 Utils::replaceToken("TYPE", position, type_name, source);
25733         }
25734         else
25735         {
25736                 switch (test_case.m_stage)
25737                 {
25738                 case Utils::Shader::GEOMETRY:
25739                         switch (stage)
25740                         {
25741                         case Utils::Shader::FRAGMENT:
25742                                 source = fs;
25743                                 break;
25744                         case Utils::Shader::VERTEX:
25745                                 source = vs;
25746                                 break;
25747                         default:
25748                                 source = "";
25749                         }
25750                         break;
25751                 case Utils::Shader::TESS_CTRL:
25752                         switch (stage)
25753                         {
25754                         case Utils::Shader::FRAGMENT:
25755                                 source = fs;
25756                                 break;
25757                         case Utils::Shader::VERTEX:
25758                                 source = vs;
25759                                 break;
25760                         default:
25761                                 source = "";
25762                         }
25763                         break;
25764                 case Utils::Shader::TESS_EVAL:
25765                         switch (stage)
25766                         {
25767                         case Utils::Shader::FRAGMENT:
25768                                 source = fs;
25769                                 break;
25770                         case Utils::Shader::TESS_CTRL:
25771                                 source = tcs;
25772                                 break;
25773                         case Utils::Shader::VERTEX:
25774                                 source = vs;
25775                                 break;
25776                         default:
25777                                 source = "";
25778                         }
25779                         break;
25780                 case Utils::Shader::VERTEX:
25781                         switch (stage)
25782                         {
25783                         case Utils::Shader::FRAGMENT:
25784                                 source = fs;
25785                                 break;
25786                         default:
25787                                 source = "";
25788                         }
25789                         break;
25790                 default:
25791                         TCU_FAIL("Invalid enum");
25792                         break;
25793                 }
25794         }
25795
25796         return source;
25797 }
25798
25799 /** Get description of test case
25800  *
25801  * @param test_case_index Index of test case
25802  *
25803  * @return Test case description
25804  **/
25805 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25806 {
25807         std::stringstream stream;
25808         testCase&                 test_case = m_test_cases[test_case_index];
25809
25810         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25811                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25812
25813         return stream.str();
25814 }
25815
25816 /** Get number of test cases
25817  *
25818  * @return Number of test cases
25819  **/
25820 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25821 {
25822         return static_cast<GLuint>(m_test_cases.size());
25823 }
25824
25825 /** Selects if "compute" stage is relevant for test
25826  *
25827  * @param ignored
25828  *
25829  * @return false
25830  **/
25831 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25832 {
25833         return false;
25834 }
25835
25836 /** Prepare all test cases
25837  *
25838  **/
25839 void XFBInvalidOffsetAlignmentTest::testInit()
25840 {
25841         const GLuint n_types = getTypesNumber();
25842
25843         for (GLuint i = 0; i < n_types; ++i)
25844         {
25845                 const Utils::Type& type                   = getType(i);
25846                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25847
25848                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25849                 {
25850                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25851                                 (Utils::Shader::FRAGMENT == stage))
25852                         {
25853                                 continue;
25854                         }
25855
25856                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25857                         {
25858                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25859
25860                                 m_test_cases.push_back(test_case);
25861                         }
25862                 }
25863         }
25864 }
25865
25866 /** Constructor
25867  *
25868  * @param context Test context
25869  **/
25870 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25871         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25872                                          "Test verifies that inactive variables are captured")
25873 {
25874         /* Nothing to be done here */
25875 }
25876
25877 /** Execute drawArrays for single vertex
25878  *
25879  * @param test_case_index
25880  *
25881  * @return true
25882  **/
25883 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
25884 {
25885         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25886         GLenum                   primitive_type = GL_PATCHES;
25887
25888         if (TEST_VS == test_case_index)
25889         {
25890                 primitive_type = GL_POINTS;
25891         }
25892
25893         gl.disable(GL_RASTERIZER_DISCARD);
25894         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25895
25896         gl.beginTransformFeedback(GL_POINTS);
25897         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25898
25899         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25900         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25901
25902         gl.endTransformFeedback();
25903         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25904
25905         return true;
25906 }
25907
25908 /** Get descriptors of buffers necessary for test
25909  *
25910  * @param ignored
25911  * @param out_descriptors Descriptors of buffers used by test
25912  **/
25913 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25914                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25915 {
25916         const Utils::Type& type = Utils::Type::vec4;
25917
25918         /* Test needs single uniform and xfb */
25919         out_descriptors.resize(2);
25920
25921         /* Get references */
25922         bufferDescriptor& uniform = out_descriptors[0];
25923         bufferDescriptor& xfb    = out_descriptors[1];
25924
25925         /* Index */
25926         uniform.m_index = 0;
25927         xfb.m_index             = 0;
25928
25929         /* Target */
25930         uniform.m_target = Utils::Buffer::Uniform;
25931         xfb.m_target     = Utils::Buffer::Transform_feedback;
25932
25933         /* Data */
25934         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25935         const std::vector<GLubyte>& goten_data = type.GenerateData();
25936
25937         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25938
25939         /* Uniform data */
25940         uniform.m_initial_data.resize(2 * type_size);
25941         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25942         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25943
25944         /* XFB data */
25945         xfb.m_initial_data.resize(3 * type_size);
25946         xfb.m_expected_data.resize(3 * type_size);
25947
25948         for (GLuint i = 0; i < 3 * type_size; ++i)
25949         {
25950                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25951                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25952         }
25953
25954         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25955         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25956 }
25957
25958 /** Get body of main function for given shader stage
25959  *
25960  * @param test_case_index  Index of test case
25961  * @param stage            Shader stage
25962  * @param out_assignments  Set to empty
25963  * @param out_calculations Set to empty
25964  **/
25965 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25966                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25967 {
25968         out_calculations = "";
25969
25970         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25971                                                                          "    gohan = uni_gohan;\n";
25972         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25973
25974         const GLchar* assignments = "";
25975
25976         switch (stage)
25977         {
25978         case Utils::Shader::FRAGMENT:
25979                 assignments = fs;
25980                 break;
25981
25982         case Utils::Shader::GEOMETRY:
25983                 if (TEST_GS == test_case_index)
25984                 {
25985                         assignments = vs_tes_gs;
25986                 }
25987                 break;
25988
25989         case Utils::Shader::TESS_CTRL:
25990                 break;
25991
25992         case Utils::Shader::TESS_EVAL:
25993                 if (TEST_TES == test_case_index)
25994                 {
25995                         assignments = vs_tes_gs;
25996                 }
25997                 break;
25998
25999         case Utils::Shader::VERTEX:
26000                 if (TEST_VS == test_case_index)
26001                 {
26002                         assignments = vs_tes_gs;
26003                 }
26004                 break;
26005
26006         default:
26007                 TCU_FAIL("Invalid enum");
26008         }
26009
26010         out_assignments = assignments;
26011 }
26012
26013 /** Get interface of shader
26014  *
26015  * @param test_case_index  Index of test case
26016  * @param stage            Shader stage
26017  * @param out_interface    Set to ""
26018  **/
26019 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26020                                                                                                                           std::string& out_interface)
26021 {
26022         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26023                                                                          "\n"
26024                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
26025                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
26026                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
26027                                                                          "\n"
26028                                                                          "layout(binding = 0) uniform block {\n"
26029                                                                          "    vec4 uni_gohan;\n"
26030                                                                          "    vec4 uni_goten;\n"
26031                                                                          "};\n";
26032         static const GLchar* fs = "in vec4 goku;\n"
26033                                                           "in vec4 gohan;\n"
26034                                                           "in vec4 goten;\n"
26035                                                           "out vec4 fs_out;\n";
26036
26037         const GLchar* interface = "";
26038
26039         switch (stage)
26040         {
26041         case Utils::Shader::FRAGMENT:
26042                 interface = fs;
26043                 break;
26044
26045         case Utils::Shader::GEOMETRY:
26046                 if (TEST_GS == test_case_index)
26047                 {
26048                         interface = vs_tes_gs;
26049                 }
26050                 break;
26051
26052         case Utils::Shader::TESS_CTRL:
26053                 break;
26054
26055         case Utils::Shader::TESS_EVAL:
26056                 if (TEST_TES == test_case_index)
26057                 {
26058                         interface = vs_tes_gs;
26059                 }
26060                 break;
26061
26062         case Utils::Shader::VERTEX:
26063                 if (TEST_VS == test_case_index)
26064                 {
26065                         interface = vs_tes_gs;
26066                 }
26067                 break;
26068
26069         default:
26070                 TCU_FAIL("Invalid enum");
26071         }
26072
26073         out_interface = interface;
26074 }
26075
26076 /** Get source code of shader
26077  *
26078  * @param test_case_index Index of test case
26079  * @param stage           Shader stage
26080  *
26081  * @return Source
26082  **/
26083 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26084 {
26085         std::string source;
26086
26087         switch (test_case_index)
26088         {
26089         case TEST_VS:
26090                 switch (stage)
26091                 {
26092                 case Utils::Shader::FRAGMENT:
26093                 case Utils::Shader::VERTEX:
26094                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26095                         break;
26096                 default:
26097                         break;
26098                 }
26099                 break;
26100
26101         case TEST_TES:
26102                 switch (stage)
26103                 {
26104                 case Utils::Shader::FRAGMENT:
26105                 case Utils::Shader::TESS_CTRL:
26106                 case Utils::Shader::TESS_EVAL:
26107                 case Utils::Shader::VERTEX:
26108                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26109                         break;
26110                 default:
26111                         break;
26112                 }
26113                 break;
26114
26115         case TEST_GS:
26116                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26117                 break;
26118
26119         default:
26120                 TCU_FAIL("Invalid enum");
26121                 break;
26122         }
26123
26124         /* */
26125         return source;
26126 }
26127
26128 /** Get name of test case
26129  *
26130  * @param test_case_index Index of test case
26131  *
26132  * @return Name of tested stage
26133  **/
26134 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26135 {
26136         const GLchar* name = 0;
26137
26138         switch (test_case_index)
26139         {
26140         case TEST_VS:
26141                 name = "vertex";
26142                 break;
26143         case TEST_TES:
26144                 name = "tessellation evaluation";
26145                 break;
26146         case TEST_GS:
26147                 name = "geometry";
26148                 break;
26149         default:
26150                 TCU_FAIL("Invalid enum");
26151         }
26152
26153         return name;
26154 }
26155
26156 /** Returns number of test cases
26157  *
26158  * @return TEST_MAX
26159  **/
26160 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26161 {
26162         return TEST_MAX;
26163 }
26164
26165 /** Inspects program to check if all resources are as expected
26166  *
26167  * @param ignored
26168  * @param program         Program instance
26169  * @param out_stream      Error message
26170  *
26171  * @return true if everything is ok, false otherwise
26172  **/
26173 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26174                                                                                                                   std::stringstream& out_stream)
26175 {
26176         GLint                      stride       = 0;
26177         const Utils::Type& type          = Utils::Type::vec4;
26178         const GLuint       type_size = type.GetSize();
26179
26180         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26181                                                 1 /* buf_size */, &stride);
26182
26183         if ((GLint)(3 * type_size) != stride)
26184         {
26185                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26186
26187                 return false;
26188         }
26189
26190         return true;
26191 }
26192
26193 /** Verify contents of buffers
26194  *
26195  * @param buffers Collection of buffers to be verified
26196  *
26197  * @return true if everything is as expected, false otherwise
26198  **/
26199 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26200 {
26201         bool result = true;
26202
26203         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26204         Utils::Buffer*                  buffer   = pair.m_buffer;
26205         bufferDescriptor*               descriptor = pair.m_descriptor;
26206
26207         /* Get pointer to contents of buffer */
26208         buffer->Bind();
26209         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26210
26211         /* Get pointer to expected data */
26212         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26213
26214         /* Compare */
26215         static const GLuint vec4_size = 16;
26216
26217         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26218         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26219
26220         if ((0 != res_gohan) || (0 != res_goten))
26221         {
26222                 m_context.getTestContext().getLog()
26223                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26224                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26225
26226                 result = false;
26227         }
26228
26229         /* Release buffer mapping */
26230         buffer->UnMap();
26231
26232         return result;
26233 }
26234
26235 /** Constructor
26236  *
26237  * @param context Test context
26238  **/
26239 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26240         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26241                                          "Test verifies that inactive components are not modified")
26242 {
26243         /* Nothing to be done here */
26244 }
26245
26246 /** Execute drawArrays for single vertex
26247  *
26248  * @param test_case_index
26249  *
26250  * @return true
26251  **/
26252 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26253 {
26254         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26255         GLenum                   primitive_type = GL_PATCHES;
26256
26257         if (TEST_VS == test_case_index)
26258         {
26259                 primitive_type = GL_POINTS;
26260         }
26261
26262         gl.disable(GL_RASTERIZER_DISCARD);
26263         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26264
26265         gl.beginTransformFeedback(GL_POINTS);
26266         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26267
26268         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26269         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26270
26271         gl.endTransformFeedback();
26272         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26273
26274         return true;
26275 }
26276
26277 /** Get descriptors of buffers necessary for test
26278  *
26279  * @param ignored
26280  * @param out_descriptors Descriptors of buffers used by test
26281  **/
26282 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26283                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26284 {
26285         const Utils::Type& type = Utils::Type::vec4;
26286
26287         /* Test needs single uniform and xfb */
26288         out_descriptors.resize(2);
26289
26290         /* Get references */
26291         bufferDescriptor& uniform = out_descriptors[0];
26292         bufferDescriptor& xfb    = out_descriptors[1];
26293
26294         /* Index */
26295         uniform.m_index = 0;
26296         xfb.m_index             = 0;
26297
26298         /* Target */
26299         uniform.m_target = Utils::Buffer::Uniform;
26300         xfb.m_target     = Utils::Buffer::Transform_feedback;
26301
26302         /* Data */
26303         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26304         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26305         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26306         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26307         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26308         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26309         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26310         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26311
26312         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26313         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26314
26315         /* Uniform data */
26316         uniform.m_initial_data.resize(8 * type_size);
26317         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26318         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26319         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26320         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26321         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26322         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26323         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26324         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26325
26326         /* XFB data */
26327         xfb.m_initial_data.resize(8 * type_size);
26328         xfb.m_expected_data.resize(8 * type_size);
26329
26330         for (GLuint i = 0; i < 8 * type_size; ++i)
26331         {
26332                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26333                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26334         }
26335
26336         /* goku - x, z - 32 */
26337         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26338         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26339
26340         /* gohan - y, w - 0 */
26341         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26342         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26343
26344         /* goten - x, y - 16 */
26345         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26346         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26347
26348         /* chichi - z, w - 48 */
26349         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26350         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26351
26352         /* vegeta - x - 112 */
26353         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26354
26355         /* trunks - y - 96 */
26356         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26357
26358         /* bra - z - 80 */
26359         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26360
26361         /* bulma - w - 64 */
26362         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26363 }
26364
26365 /** Get body of main function for given shader stage
26366  *
26367  * @param test_case_index  Index of test case
26368  * @param stage            Shader stage
26369  * @param out_assignments  Set to empty
26370  * @param out_calculations Set to empty
26371  **/
26372 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26373                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26374 {
26375         out_calculations = "";
26376
26377         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26378                                                                          "    goku.z    = uni_goku.z   ;\n"
26379                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26380                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26381                                                                          "    goten.x   = uni_goten.x  ;\n"
26382                                                                          "    goten.y   = uni_goten.y  ;\n"
26383                                                                          "    chichi.z  = uni_chichi.z ;\n"
26384                                                                          "    chichi.w  = uni_chichi.w ;\n"
26385                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26386                                                                          "    trunks.y  = uni_trunks.y ;\n"
26387                                                                          "    bra.z     = uni_bra.z    ;\n"
26388                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26389         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26390
26391         const GLchar* assignments = "";
26392
26393         switch (stage)
26394         {
26395         case Utils::Shader::FRAGMENT:
26396                 assignments = fs;
26397                 break;
26398
26399         case Utils::Shader::GEOMETRY:
26400                 if (TEST_GS == test_case_index)
26401                 {
26402                         assignments = vs_tes_gs;
26403                 }
26404                 break;
26405
26406         case Utils::Shader::TESS_CTRL:
26407                 break;
26408
26409         case Utils::Shader::TESS_EVAL:
26410                 if (TEST_TES == test_case_index)
26411                 {
26412                         assignments = vs_tes_gs;
26413                 }
26414                 break;
26415
26416         case Utils::Shader::VERTEX:
26417                 if (TEST_VS == test_case_index)
26418                 {
26419                         assignments = vs_tes_gs;
26420                 }
26421                 break;
26422
26423         default:
26424                 TCU_FAIL("Invalid enum");
26425         }
26426
26427         out_assignments = assignments;
26428 }
26429
26430 /** Get interface of shader
26431  *
26432  * @param test_case_index  Index of test case
26433  * @param stage            Shader stage
26434  * @param out_interface    Set to ""
26435  **/
26436 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26437                                                                                                                            std::string& out_interface)
26438 {
26439         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26440                                                                          "\n"
26441                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26442                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26443                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26444                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26445                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26446                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26447                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26448                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26449                                                                          "\n"
26450                                                                          "layout(binding = 0) uniform block {\n"
26451                                                                          "    vec4 uni_goku;\n"
26452                                                                          "    vec4 uni_gohan;\n"
26453                                                                          "    vec4 uni_goten;\n"
26454                                                                          "    vec4 uni_chichi;\n"
26455                                                                          "    vec4 uni_vegeta;\n"
26456                                                                          "    vec4 uni_trunks;\n"
26457                                                                          "    vec4 uni_bra;\n"
26458                                                                          "    vec4 uni_bulma;\n"
26459                                                                          "};\n";
26460         static const GLchar* fs = "in vec4 vegeta;\n"
26461                                                           "in vec4 trunks;\n"
26462                                                           "in vec4 bra;\n"
26463                                                           "in vec4 bulma;\n"
26464                                                           "in vec4 goku;\n"
26465                                                           "in vec4 gohan;\n"
26466                                                           "in vec4 goten;\n"
26467                                                           "in vec4 chichi;\n"
26468                                                           "\n"
26469                                                           "out vec4 fs_out;\n";
26470
26471         const GLchar* interface = "";
26472
26473         switch (stage)
26474         {
26475         case Utils::Shader::FRAGMENT:
26476                 interface = fs;
26477                 break;
26478
26479         case Utils::Shader::GEOMETRY:
26480                 if (TEST_GS == test_case_index)
26481                 {
26482                         interface = vs_tes_gs;
26483                 }
26484                 break;
26485
26486         case Utils::Shader::TESS_CTRL:
26487                 break;
26488
26489         case Utils::Shader::TESS_EVAL:
26490                 if (TEST_TES == test_case_index)
26491                 {
26492                         interface = vs_tes_gs;
26493                 }
26494                 break;
26495
26496         case Utils::Shader::VERTEX:
26497                 if (TEST_VS == test_case_index)
26498                 {
26499                         interface = vs_tes_gs;
26500                 }
26501                 break;
26502
26503         default:
26504                 TCU_FAIL("Invalid enum");
26505         }
26506
26507         out_interface = interface;
26508 }
26509
26510 /** Get source code of shader
26511  *
26512  * @param test_case_index Index of test case
26513  * @param stage           Shader stage
26514  *
26515  * @return Source
26516  **/
26517 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26518 {
26519         std::string source;
26520
26521         switch (test_case_index)
26522         {
26523         case TEST_VS:
26524                 switch (stage)
26525                 {
26526                 case Utils::Shader::FRAGMENT:
26527                 case Utils::Shader::VERTEX:
26528                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26529                         break;
26530                 default:
26531                         break;
26532                 }
26533                 break;
26534
26535         case TEST_TES:
26536                 switch (stage)
26537                 {
26538                 case Utils::Shader::FRAGMENT:
26539                 case Utils::Shader::TESS_CTRL:
26540                 case Utils::Shader::TESS_EVAL:
26541                 case Utils::Shader::VERTEX:
26542                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26543                         break;
26544                 default:
26545                         break;
26546                 }
26547                 break;
26548
26549         case TEST_GS:
26550                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26551                 break;
26552
26553         default:
26554                 TCU_FAIL("Invalid enum");
26555                 break;
26556         }
26557
26558         /* */
26559         return source;
26560 }
26561
26562 /** Get name of test case
26563  *
26564  * @param test_case_index Index of test case
26565  *
26566  * @return Name of tested stage
26567  **/
26568 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26569 {
26570         const GLchar* name = 0;
26571
26572         switch (test_case_index)
26573         {
26574         case TEST_VS:
26575                 name = "vertex";
26576                 break;
26577         case TEST_TES:
26578                 name = "tessellation evaluation";
26579                 break;
26580         case TEST_GS:
26581                 name = "geometry";
26582                 break;
26583         default:
26584                 TCU_FAIL("Invalid enum");
26585         }
26586
26587         return name;
26588 }
26589
26590 /** Returns number of test cases
26591  *
26592  * @return TEST_MAX
26593  **/
26594 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26595 {
26596         return TEST_MAX;
26597 }
26598
26599 /** Verify contents of buffers
26600  *
26601  * @param buffers Collection of buffers to be verified
26602  *
26603  * @return true if everything is as expected, false otherwise
26604  **/
26605 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26606 {
26607         bool result = true;
26608
26609         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26610         Utils::Buffer*                  buffer   = pair.m_buffer;
26611         bufferDescriptor*               descriptor = pair.m_descriptor;
26612
26613         /* Get pointer to contents of buffer */
26614         buffer->Bind();
26615         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26616
26617         /* Get pointer to expected data */
26618         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26619
26620         /* Compare */
26621         static const GLuint comp_size = 4;
26622         static const GLuint vec4_size = 16;
26623
26624         int res_goku_x =
26625                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26626         int res_goku_z =
26627                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26628
26629         int res_gohan_y =
26630                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26631         int res_gohan_w =
26632                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26633
26634         int res_goten_x =
26635                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26636         int res_goten_y =
26637                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26638
26639         int res_chichi_z =
26640                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26641         int res_chichi_w =
26642                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26643
26644         int res_vegeta_x =
26645                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26646
26647         int res_trunks_y =
26648                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26649
26650         int res_bra_z =
26651                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26652
26653         int res_bulma_w =
26654                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26655
26656         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26657                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26658                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26659         {
26660                 m_context.getTestContext().getLog()
26661                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26662                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26663
26664                 result = false;
26665         }
26666
26667         /* Release buffer mapping */
26668         buffer->UnMap();
26669
26670         return result;
26671 }
26672
26673 /** Constructor
26674  *
26675  * @param context Test context
26676  **/
26677 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26678         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26679                                          "Test verifies that inactive block members are captured")
26680 {
26681         /* Nothing to be done here */
26682 }
26683
26684 /** Execute drawArrays for single vertex
26685  *
26686  * @param test_case_index
26687  *
26688  * @return true
26689  **/
26690 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26691 {
26692         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26693         GLenum                   primitive_type = GL_PATCHES;
26694
26695         if (TEST_VS == test_case_index)
26696         {
26697                 primitive_type = GL_POINTS;
26698         }
26699
26700         gl.disable(GL_RASTERIZER_DISCARD);
26701         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26702
26703         gl.beginTransformFeedback(GL_POINTS);
26704         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26705
26706         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26707         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26708
26709         gl.endTransformFeedback();
26710         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26711
26712         return true;
26713 }
26714
26715 /** Get descriptors of buffers necessary for test
26716  *
26717  * @param ignored
26718  * @param out_descriptors Descriptors of buffers used by test
26719  **/
26720 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26721                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26722 {
26723         const Utils::Type& type = Utils::Type::vec4;
26724
26725         /* Test needs single uniform and xfb */
26726         out_descriptors.resize(2);
26727
26728         /* Get references */
26729         bufferDescriptor& uniform = out_descriptors[0];
26730         bufferDescriptor& xfb    = out_descriptors[1];
26731
26732         /* Index */
26733         uniform.m_index = 0;
26734         xfb.m_index             = 0;
26735
26736         /* Target */
26737         uniform.m_target = Utils::Buffer::Uniform;
26738         xfb.m_target     = Utils::Buffer::Transform_feedback;
26739
26740         /* Data */
26741         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26742         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26743
26744         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26745
26746         /* Uniform data */
26747         uniform.m_initial_data.resize(2 * type_size);
26748         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26749         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26750
26751         /* XFB data */
26752         xfb.m_initial_data.resize(4 * type_size);
26753         xfb.m_expected_data.resize(4 * type_size);
26754
26755         for (GLuint i = 0; i < 4 * type_size; ++i)
26756         {
26757                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26758                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26759         }
26760
26761         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26762         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26763 }
26764
26765 /** Get body of main function for given shader stage
26766  *
26767  * @param test_case_index  Index of test case
26768  * @param stage            Shader stage
26769  * @param out_assignments  Set to empty
26770  * @param out_calculations Set to empty
26771  **/
26772 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26773                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26774 {
26775         out_calculations = "";
26776
26777         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26778                                                                          "    gohan  = uni_gohan;\n";
26779         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26780
26781         const GLchar* assignments = "";
26782
26783         switch (stage)
26784         {
26785         case Utils::Shader::FRAGMENT:
26786                 assignments = fs;
26787                 break;
26788
26789         case Utils::Shader::GEOMETRY:
26790                 if (TEST_GS == test_case_index)
26791                 {
26792                         assignments = vs_tes_gs;
26793                 }
26794                 break;
26795
26796         case Utils::Shader::TESS_CTRL:
26797                 break;
26798
26799         case Utils::Shader::TESS_EVAL:
26800                 if (TEST_TES == test_case_index)
26801                 {
26802                         assignments = vs_tes_gs;
26803                 }
26804                 break;
26805
26806         case Utils::Shader::VERTEX:
26807                 if (TEST_VS == test_case_index)
26808                 {
26809                         assignments = vs_tes_gs;
26810                 }
26811                 break;
26812
26813         default:
26814                 TCU_FAIL("Invalid enum");
26815         }
26816
26817         out_assignments = assignments;
26818 }
26819
26820 /** Get interface of shader
26821  *
26822  * @param test_case_index  Index of test case
26823  * @param stage            Shader stage
26824  * @param out_interface    Set to ""
26825  **/
26826 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26827                                                                                                                                  std::string& out_interface)
26828 {
26829         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26830                                                                          "\n"
26831                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26832                                                                          "    vec4 gohan;\n"
26833                                                                          "    vec4 goten;\n"
26834                                                                          "    vec4 chichi;\n"
26835                                                                          "};\n"
26836                                                                          "\n"
26837                                                                          "layout(binding = 0) uniform block {\n"
26838                                                                          "    vec4 uni_gohan;\n"
26839                                                                          "    vec4 uni_chichi;\n"
26840                                                                          "};\n";
26841         static const GLchar* fs = "in Goku {\n"
26842                                                           "    vec4 gohan;\n"
26843                                                           "    vec4 goten;\n"
26844                                                           "    vec4 chichi;\n"
26845                                                           "};\n"
26846                                                           "out vec4 fs_out;\n";
26847
26848         const GLchar* interface = "";
26849
26850         switch (stage)
26851         {
26852         case Utils::Shader::FRAGMENT:
26853                 interface = fs;
26854                 break;
26855
26856         case Utils::Shader::GEOMETRY:
26857                 if (TEST_GS == test_case_index)
26858                 {
26859                         interface = vs_tes_gs;
26860                 }
26861                 break;
26862
26863         case Utils::Shader::TESS_CTRL:
26864                 break;
26865
26866         case Utils::Shader::TESS_EVAL:
26867                 if (TEST_TES == test_case_index)
26868                 {
26869                         interface = vs_tes_gs;
26870                 }
26871                 break;
26872
26873         case Utils::Shader::VERTEX:
26874                 if (TEST_VS == test_case_index)
26875                 {
26876                         interface = vs_tes_gs;
26877                 }
26878                 break;
26879
26880         default:
26881                 TCU_FAIL("Invalid enum");
26882         }
26883
26884         out_interface = interface;
26885 }
26886
26887 /** Get source code of shader
26888  *
26889  * @param test_case_index Index of test case
26890  * @param stage           Shader stage
26891  *
26892  * @return Source
26893  **/
26894 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26895                                                                                                                                          Utils::Shader::STAGES stage)
26896 {
26897         std::string source;
26898
26899         switch (test_case_index)
26900         {
26901         case TEST_VS:
26902                 switch (stage)
26903                 {
26904                 case Utils::Shader::FRAGMENT:
26905                 case Utils::Shader::VERTEX:
26906                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26907                         break;
26908                 default:
26909                         break;
26910                 }
26911                 break;
26912
26913         case TEST_TES:
26914                 switch (stage)
26915                 {
26916                 case Utils::Shader::FRAGMENT:
26917                 case Utils::Shader::TESS_CTRL:
26918                 case Utils::Shader::TESS_EVAL:
26919                 case Utils::Shader::VERTEX:
26920                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26921                         break;
26922                 default:
26923                         break;
26924                 }
26925                 break;
26926
26927         case TEST_GS:
26928                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26929                 break;
26930
26931         default:
26932                 TCU_FAIL("Invalid enum");
26933                 break;
26934         }
26935
26936         /* */
26937         return source;
26938 }
26939
26940 /** Get name of test case
26941  *
26942  * @param test_case_index Index of test case
26943  *
26944  * @return Name of tested stage
26945  **/
26946 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26947 {
26948         const GLchar* name = 0;
26949
26950         switch (test_case_index)
26951         {
26952         case TEST_VS:
26953                 name = "vertex";
26954                 break;
26955         case TEST_TES:
26956                 name = "tessellation evaluation";
26957                 break;
26958         case TEST_GS:
26959                 name = "geometry";
26960                 break;
26961         default:
26962                 TCU_FAIL("Invalid enum");
26963         }
26964
26965         return name;
26966 }
26967
26968 /** Returns number of test cases
26969  *
26970  * @return TEST_MAX
26971  **/
26972 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26973 {
26974         return TEST_MAX;
26975 }
26976
26977 /** Verify contents of buffers
26978  *
26979  * @param buffers Collection of buffers to be verified
26980  *
26981  * @return true if everything is as expected, false otherwise
26982  **/
26983 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26984 {
26985         bool result = true;
26986
26987         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26988         Utils::Buffer*                  buffer   = pair.m_buffer;
26989         bufferDescriptor*               descriptor = pair.m_descriptor;
26990
26991         /* Get pointer to contents of buffer */
26992         buffer->Bind();
26993         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26994
26995         /* Get pointer to expected data */
26996         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26997
26998         /* Compare */
26999         static const GLuint vec4_size = 16;
27000
27001         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27002         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27003         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27004
27005         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27006         {
27007                 m_context.getTestContext().getLog()
27008                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27009                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27010
27011                 result = false;
27012         }
27013
27014         /* Release buffer mapping */
27015         buffer->UnMap();
27016
27017         return result;
27018 }
27019
27020 /** Constructor
27021  *
27022  * @param context Test context
27023  **/
27024 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
27025         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
27026 {
27027         /* Nothing to be done here */
27028 }
27029
27030 /** Execute drawArrays for single vertex
27031  *
27032  * @param test_case_index
27033  *
27034  * @return true
27035  **/
27036 bool XFBCaptureStructTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
27037 {
27038         const Functions& gl                             = m_context.getRenderContext().getFunctions();
27039         GLenum                   primitive_type = GL_PATCHES;
27040
27041         if (TEST_VS == test_case_index)
27042         {
27043                 primitive_type = GL_POINTS;
27044         }
27045
27046         gl.disable(GL_RASTERIZER_DISCARD);
27047         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
27048
27049         gl.beginTransformFeedback(GL_POINTS);
27050         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
27051
27052         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
27053         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
27054
27055         gl.endTransformFeedback();
27056         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
27057
27058         return true;
27059 }
27060
27061 /** Get descriptors of buffers necessary for test
27062  *
27063  * @param ignored
27064  * @param out_descriptors Descriptors of buffers used by test
27065  **/
27066 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
27067                                                                                                 bufferDescriptor::Vector& out_descriptors)
27068 {
27069         const Utils::Type& type = Utils::Type::vec4;
27070
27071         /* Test needs single uniform and xfb */
27072         out_descriptors.resize(2);
27073
27074         /* Get references */
27075         bufferDescriptor& uniform = out_descriptors[0];
27076         bufferDescriptor& xfb    = out_descriptors[1];
27077
27078         /* Index */
27079         uniform.m_index = 0;
27080         xfb.m_index             = 0;
27081
27082         /* Target */
27083         uniform.m_target = Utils::Buffer::Uniform;
27084         xfb.m_target     = Utils::Buffer::Transform_feedback;
27085
27086         /* Data */
27087         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
27088         const std::vector<GLubyte>& chichi_data = type.GenerateData();
27089
27090         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
27091
27092         /* Uniform data */
27093         uniform.m_initial_data.resize(2 * type_size);
27094         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
27095         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
27096
27097         /* XFB data */
27098         xfb.m_initial_data.resize(4 * type_size);
27099         xfb.m_expected_data.resize(4 * type_size);
27100
27101         for (GLuint i = 0; i < 4 * type_size; ++i)
27102         {
27103                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
27104                 xfb.m_expected_data[i] = (glw::GLubyte)i;
27105         }
27106
27107         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
27108         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
27109 }
27110
27111 /** Get body of main function for given shader stage
27112  *
27113  * @param test_case_index  Index of test case
27114  * @param stage            Shader stage
27115  * @param out_assignments  Set to empty
27116  * @param out_calculations Set to empty
27117  **/
27118 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27119                                                                                  std::string& out_assignments, std::string& out_calculations)
27120 {
27121         out_calculations = "";
27122
27123         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27124                                                                          "    goku.gohan  = uni_gohan;\n";
27125         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27126
27127         const GLchar* assignments = "";
27128
27129         switch (stage)
27130         {
27131         case Utils::Shader::FRAGMENT:
27132                 assignments = fs;
27133                 break;
27134
27135         case Utils::Shader::GEOMETRY:
27136                 if (TEST_GS == test_case_index)
27137                 {
27138                         assignments = vs_tes_gs;
27139                 }
27140                 break;
27141
27142         case Utils::Shader::TESS_CTRL:
27143                 break;
27144
27145         case Utils::Shader::TESS_EVAL:
27146                 if (TEST_TES == test_case_index)
27147                 {
27148                         assignments = vs_tes_gs;
27149                 }
27150                 break;
27151
27152         case Utils::Shader::VERTEX:
27153                 if (TEST_VS == test_case_index)
27154                 {
27155                         assignments = vs_tes_gs;
27156                 }
27157                 break;
27158
27159         default:
27160                 TCU_FAIL("Invalid enum");
27161         }
27162
27163         out_assignments = assignments;
27164 }
27165
27166 /** Get interface of shader
27167  *
27168  * @param test_case_index  Index of test case
27169  * @param stage            Shader stage
27170  * @param out_interface    Set to ""
27171  **/
27172 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27173                                                                                           std::string& out_interface)
27174 {
27175         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27176                                                                          "\n"
27177                                                                          "struct Goku {\n"
27178                                                                          "    vec4 gohan;\n"
27179                                                                          "    vec4 goten;\n"
27180                                                                          "    vec4 chichi;\n"
27181                                                                          "};\n"
27182                                                                          "\n"
27183                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27184                                                                          "\n"
27185                                                                          "layout(binding = 0, std140) uniform block {\n"
27186                                                                          "    vec4 uni_gohan;\n"
27187                                                                          "    vec4 uni_chichi;\n"
27188                                                                          "};\n";
27189         static const GLchar* fs = "struct Goku {\n"
27190                                                           "    vec4 gohan;\n"
27191                                                           "    vec4 goten;\n"
27192                                                           "    vec4 chichi;\n"
27193                                                           "};\n"
27194                                                           "\n"
27195                                                           "in Goku goku;\n"
27196                                                           "\n"
27197                                                           "out vec4 fs_out;\n";
27198
27199         const GLchar* interface = "";
27200
27201         switch (stage)
27202         {
27203         case Utils::Shader::FRAGMENT:
27204                 interface = fs;
27205                 break;
27206
27207         case Utils::Shader::GEOMETRY:
27208                 if (TEST_GS == test_case_index)
27209                 {
27210                         interface = vs_tes_gs;
27211                 }
27212                 break;
27213
27214         case Utils::Shader::TESS_CTRL:
27215                 break;
27216
27217         case Utils::Shader::TESS_EVAL:
27218                 if (TEST_TES == test_case_index)
27219                 {
27220                         interface = vs_tes_gs;
27221                 }
27222                 break;
27223
27224         case Utils::Shader::VERTEX:
27225                 if (TEST_VS == test_case_index)
27226                 {
27227                         interface = vs_tes_gs;
27228                 }
27229                 break;
27230
27231         default:
27232                 TCU_FAIL("Invalid enum");
27233         }
27234
27235         out_interface = interface;
27236 }
27237
27238 /** Get source code of shader
27239  *
27240  * @param test_case_index Index of test case
27241  * @param stage           Shader stage
27242  *
27243  * @return Source
27244  **/
27245 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27246 {
27247         std::string source;
27248
27249         switch (test_case_index)
27250         {
27251         case TEST_VS:
27252                 switch (stage)
27253                 {
27254                 case Utils::Shader::FRAGMENT:
27255                 case Utils::Shader::VERTEX:
27256                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27257                         break;
27258                 default:
27259                         break;
27260                 }
27261                 break;
27262
27263         case TEST_TES:
27264                 switch (stage)
27265                 {
27266                 case Utils::Shader::FRAGMENT:
27267                 case Utils::Shader::TESS_CTRL:
27268                 case Utils::Shader::TESS_EVAL:
27269                 case Utils::Shader::VERTEX:
27270                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27271                         break;
27272                 default:
27273                         break;
27274                 }
27275                 break;
27276
27277         case TEST_GS:
27278                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27279                 break;
27280
27281         default:
27282                 TCU_FAIL("Invalid enum");
27283                 break;
27284         }
27285
27286         /* */
27287         return source;
27288 }
27289
27290 /** Get name of test case
27291  *
27292  * @param test_case_index Index of test case
27293  *
27294  * @return Name of tested stage
27295  **/
27296 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27297 {
27298         const GLchar* name = 0;
27299
27300         switch (test_case_index)
27301         {
27302         case TEST_VS:
27303                 name = "vertex";
27304                 break;
27305         case TEST_TES:
27306                 name = "tessellation evaluation";
27307                 break;
27308         case TEST_GS:
27309                 name = "geometry";
27310                 break;
27311         default:
27312                 TCU_FAIL("Invalid enum");
27313         }
27314
27315         return name;
27316 }
27317
27318 /** Returns number of test cases
27319  *
27320  * @return TEST_MAX
27321  **/
27322 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27323 {
27324         return TEST_MAX;
27325 }
27326
27327 /** Verify contents of buffers
27328  *
27329  * @param buffers Collection of buffers to be verified
27330  *
27331  * @return true if everything is as expected, false otherwise
27332  **/
27333 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27334 {
27335         bool result = true;
27336
27337         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27338         Utils::Buffer*                  buffer   = pair.m_buffer;
27339         bufferDescriptor*               descriptor = pair.m_descriptor;
27340
27341         /* Get pointer to contents of buffer */
27342         buffer->Bind();
27343         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27344
27345         /* Get pointer to expected data */
27346         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27347
27348         /* Compare */
27349         static const GLuint vec4_size = 16;
27350
27351         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27352         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27353         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27354
27355         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27356         {
27357                 m_context.getTestContext().getLog()
27358                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27359                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27360
27361                 result = false;
27362         }
27363
27364         /* Release buffer mapping */
27365         buffer->UnMap();
27366
27367         return result;
27368 }
27369
27370 /** Constructor
27371  *
27372  * @param context Test framework context
27373  **/
27374 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27375         : NegativeTestBase(context, "xfb_capture_unsized_array",
27376                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27377 {
27378 }
27379
27380 /** Source for given test case and stage
27381  *
27382  * @param test_case_index Index of test case
27383  * @param stage           Shader stage
27384  *
27385  * @return Shader source
27386  **/
27387 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27388 {
27389         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27390         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27391         static const GLchar* fs                         = "#version 430 core\n"
27392                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27393                                                           "\n"
27394                                                           "in  vec4 gs_fs;\n"
27395                                                           "out vec4 fs_out;\n"
27396                                                           "\n"
27397                                                           "void main()\n"
27398                                                           "{\n"
27399                                                           "    fs_out = gs_fs;\n"
27400                                                           "}\n"
27401                                                           "\n";
27402         static const GLchar* gs_tested = "#version 430 core\n"
27403                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27404                                                                          "\n"
27405                                                                          "layout(points)                           in;\n"
27406                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27407                                                                          "\n"
27408                                                                          "VAR_DEFINITION"
27409                                                                          "\n"
27410                                                                          "in  vec4 tes_gs[];\n"
27411                                                                          "out vec4 gs_fs;\n"
27412                                                                          "\n"
27413                                                                          "void main()\n"
27414                                                                          "{\n"
27415                                                                          "    vec4 result = tes_gs[0];\n"
27416                                                                          "\n"
27417                                                                          "VARIABLE_USE"
27418                                                                          "\n"
27419                                                                          "    gs_fs = result;\n"
27420                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27421                                                                          "    EmitVertex();\n"
27422                                                                          "    gs_fs = result;\n"
27423                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27424                                                                          "    EmitVertex();\n"
27425                                                                          "    gs_fs = result;\n"
27426                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27427                                                                          "    EmitVertex();\n"
27428                                                                          "    gs_fs = result;\n"
27429                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27430                                                                          "    EmitVertex();\n"
27431                                                                          "}\n"
27432                                                                          "\n";
27433         static const GLchar* tcs = "#version 430 core\n"
27434                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27435                                                            "\n"
27436                                                            "layout(vertices = 1) out;\n"
27437                                                            "\n"
27438                                                            "in  vec4 vs_tcs[];\n"
27439                                                            "out vec4 tcs_tes[];\n"
27440                                                            "\n"
27441                                                            "void main()\n"
27442                                                            "{\n"
27443                                                            "\n"
27444                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27445                                                            "\n"
27446                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27447                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27448                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27449                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27450                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27451                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27452                                                            "}\n"
27453                                                            "\n";
27454         static const GLchar* tcs_tested = "#version 430 core\n"
27455                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27456                                                                           "\n"
27457                                                                           "layout(vertices = 1) out;\n"
27458                                                                           "\n"
27459                                                                           "VAR_DEFINITION"
27460                                                                           "\n"
27461                                                                           "in  vec4 vs_tcs[];\n"
27462                                                                           "out vec4 tcs_tes[];\n"
27463                                                                           "\n"
27464                                                                           "void main()\n"
27465                                                                           "{\n"
27466                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27467                                                                           "\n"
27468                                                                           "VARIABLE_USE"
27469                                                                           "\n"
27470                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27471                                                                           "\n"
27472                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27473                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27474                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27475                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27476                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27477                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27478                                                                           "}\n"
27479                                                                           "\n";
27480         static const GLchar* tes_tested = "#version 430 core\n"
27481                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27482                                                                           "\n"
27483                                                                           "layout(isolines, point_mode) in;\n"
27484                                                                           "\n"
27485                                                                           "VAR_DEFINITION"
27486                                                                           "\n"
27487                                                                           "in  vec4 tcs_tes[];\n"
27488                                                                           "out vec4 tes_gs;\n"
27489                                                                           "\n"
27490                                                                           "void main()\n"
27491                                                                           "{\n"
27492                                                                           "    vec4 result = tcs_tes[0];\n"
27493                                                                           "\n"
27494                                                                           "VARIABLE_USE"
27495                                                                           "\n"
27496                                                                           "    tes_gs += result;\n"
27497                                                                           "}\n"
27498                                                                           "\n";
27499         static const GLchar* vs = "#version 430 core\n"
27500                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27501                                                           "\n"
27502                                                           "in  vec4 in_vs;\n"
27503                                                           "out vec4 vs_tcs;\n"
27504                                                           "\n"
27505                                                           "void main()\n"
27506                                                           "{\n"
27507                                                           "    vs_tcs = in_vs;\n"
27508                                                           "}\n"
27509                                                           "\n";
27510         static const GLchar* vs_tested = "#version 430 core\n"
27511                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27512                                                                          "\n"
27513                                                                          "VAR_DEFINITION"
27514                                                                          "\n"
27515                                                                          "in  vec4 in_vs;\n"
27516                                                                          "out vec4 vs_tcs;\n"
27517                                                                          "\n"
27518                                                                          "void main()\n"
27519                                                                          "{\n"
27520                                                                          "    vec4 result = in_vs;\n"
27521                                                                          "\n"
27522                                                                          "VARIABLE_USE"
27523                                                                          "\n"
27524                                                                          "    vs_tcs = result;\n"
27525                                                                          "}\n"
27526                                                                          "\n";
27527
27528         std::string source;
27529         testCase&   test_case = m_test_cases[test_case_index];
27530
27531         if (test_case.m_stage == stage)
27532         {
27533                 const GLchar* array     = "";
27534                 const GLchar* index     = "";
27535                 size_t            position = 0;
27536
27537                 switch (stage)
27538                 {
27539                 case Utils::Shader::GEOMETRY:
27540                         source = gs_tested;
27541                         array  = "[]";
27542                         index  = "[0]";
27543                         break;
27544                 case Utils::Shader::TESS_CTRL:
27545                         source = tcs_tested;
27546                         array  = "[]";
27547                         index  = "[gl_InvocationID]";
27548                         break;
27549                 case Utils::Shader::TESS_EVAL:
27550                         source = tes_tested;
27551                         array  = "[]";
27552                         index  = "[0]";
27553                         break;
27554                 case Utils::Shader::VERTEX:
27555                         source = vs_tested;
27556                         break;
27557                 default:
27558                         TCU_FAIL("Invalid enum");
27559                 }
27560
27561                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27562                 position = 0;
27563                 Utils::replaceToken("ARRAY", position, array, source);
27564                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27565
27566                 Utils::replaceAllTokens("INDEX", index, source);
27567         }
27568         else
27569         {
27570                 switch (test_case.m_stage)
27571                 {
27572                 case Utils::Shader::GEOMETRY:
27573                         switch (stage)
27574                         {
27575                         case Utils::Shader::FRAGMENT:
27576                                 source = fs;
27577                                 break;
27578                         case Utils::Shader::VERTEX:
27579                                 source = vs;
27580                                 break;
27581                         default:
27582                                 source = "";
27583                         }
27584                         break;
27585                 case Utils::Shader::TESS_CTRL:
27586                         switch (stage)
27587                         {
27588                         case Utils::Shader::FRAGMENT:
27589                                 source = fs;
27590                                 break;
27591                         case Utils::Shader::VERTEX:
27592                                 source = vs;
27593                                 break;
27594                         default:
27595                                 source = "";
27596                         }
27597                         break;
27598                 case Utils::Shader::TESS_EVAL:
27599                         switch (stage)
27600                         {
27601                         case Utils::Shader::FRAGMENT:
27602                                 source = fs;
27603                                 break;
27604                         case Utils::Shader::TESS_CTRL:
27605                                 source = tcs;
27606                                 break;
27607                         case Utils::Shader::VERTEX:
27608                                 source = vs;
27609                                 break;
27610                         default:
27611                                 source = "";
27612                         }
27613                         break;
27614                 case Utils::Shader::VERTEX:
27615                         switch (stage)
27616                         {
27617                         case Utils::Shader::FRAGMENT:
27618                                 source = fs;
27619                                 break;
27620                         default:
27621                                 source = "";
27622                         }
27623                         break;
27624                 default:
27625                         TCU_FAIL("Invalid enum");
27626                         break;
27627                 }
27628         }
27629
27630         return source;
27631 }
27632
27633 /** Get description of test case
27634  *
27635  * @param test_case_index Index of test case
27636  *
27637  * @return Test case description
27638  **/
27639 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27640 {
27641         std::stringstream stream;
27642         testCase&                 test_case = m_test_cases[test_case_index];
27643
27644         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27645
27646         return stream.str();
27647 }
27648
27649 /** Get number of test cases
27650  *
27651  * @return Number of test cases
27652  **/
27653 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27654 {
27655         return static_cast<GLuint>(m_test_cases.size());
27656 }
27657
27658 /** Selects if "compute" stage is relevant for test
27659  *
27660  * @param ignored
27661  *
27662  * @return false
27663  **/
27664 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27665 {
27666         return false;
27667 }
27668
27669 /** Prepare all test cases
27670  *
27671  **/
27672 void XFBCaptureUnsizedArrayTest::testInit()
27673 {
27674         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27675         {
27676                 /* Not aplicable for */
27677                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27678                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27679                 {
27680                         continue;
27681                 }
27682
27683                 testCase test_case = { (Utils::Shader::STAGES)stage };
27684
27685                 m_test_cases.push_back(test_case);
27686         }
27687 }
27688 } /* EnhancedLayouts namespace */
27689
27690 /** Constructor.
27691  *
27692  *  @param context Rendering context.
27693  **/
27694 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27695         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27696 {
27697         /* Left blank on purpose */
27698 }
27699
27700 /** Initializes a texture_storage_multisample test group.
27701  *
27702  **/
27703 void EnhancedLayoutsTests::init(void)
27704 {
27705         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27706         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27707         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27708         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27709         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27710         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27711         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27712         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27713         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27714         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27715         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27716         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27717         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27718         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27719         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27720         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27721         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27722         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27723
27724         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27725         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27726         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27727         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27728         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27729         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27730         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27731         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27732         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27733         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27734         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27735         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27736         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27737         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27738         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27739         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27740         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27741         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27742         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27743         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27744         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27745         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27746         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27747         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27748         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27749         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27750         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27751         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27752         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27753         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27754         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27755         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27756         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27757         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27758         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27759         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27760         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27761         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27762         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27763         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27764         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27765         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27766         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27767         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27768         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27769 }
27770
27771 } /* gl4cts namespace */